p2p

package
v0.0.0-...-ee99c87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2018 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cap

type Cap struct {
	Name    string
	Version uint
}

Cap is the structure of a peer capability.

func (Cap) String

func (cap Cap) String() string

type Config

type Config struct {
	// Name node's name
	Name string //`toml:"-"`

	// ECDSAKey dumped string of Node's ecdsa.PrivateKey
	ECDSAKey string

	// PrivateKey Node's ecdsa.PrivateKey
	PrivateKey *ecdsa.PrivateKey

	// MyNodeID public key extracted from PrivateKey, so need not load from config
	MyNodeID string `toml:"-"`

	// MaxPeers max number of peers that can be connected
	MaxPeers int

	// MaxPendingPeers is the maximum number of peers that can be pending in the
	// handshake phase, counted separately for inbound and outbound connections.
	// Zero defaults to preset values.
	MaxPendingPeers int `toml:",omitempty"`

	// pre-configured nodes.
	StaticNodes []*discovery.Node

	// KadPort udp port for Kad network
	KadPort string

	// Protocols should contain the protocols supported by the server.
	Protocols []ProtocolInterface `toml:"-"`

	// p2p.server will listen for incoming tcp connections.
	ListenAddr string
}

Config holds Server options.

type Message

type Message struct {
	MsgCode    uint16 // message code, defined in each protocol
	Payload    []byte
	ReceivedAt time.Time
	CurPeer    *Peer // peer that handle this message
}

Message exposed for high level layer to receive

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

Peer represents a connected remote node.

func (*Peer) Disconnect

func (p *Peer) Disconnect(reason uint)

Disconnect terminates the peer connection with the given reason. It returns immediately and does not wait until the connection is closed.

func (*Peer) SendMsg

func (p *Peer) SendMsg(proto *Protocol, msgCode uint16, message interface{}) error

SendMsg called by subProtocols, message can be any data type

type ProtoHandShake

type ProtoHandShake struct {
	Caps   []Cap
	NodeID discovery.NodeID
}

ProtoHandShake handshake message for two peer to exchage base information TODO add public key or other information for encryption?

type Protocol

type Protocol struct {
	// Name should contain the official protocol name,
	// often a three-letter word.
	Name string

	// Version should contain the version number of the protocol.
	Version uint
	// AddPeerCh a peer joins protocol, SubProtocol should handle the channel
	AddPeerCh chan *Peer

	// DelPeerCh a peer leaves protocol
	DelPeerCh chan *Peer

	// ReadMsgCh a whole Message has recved, SubProtocol can handle as quickly as possible
	ReadMsgCh chan *Message

	// IsSelfConnect if value is true, means SubProtocol maintains peers itself, for example when to initiate a tcp connection.
	// Otherwise, all SubProtols share one tcp connection which is initiated by p2p.scheduleTasks
	IsSelfConnect bool
}

Protocol base class for high level transfer protocol.

type ProtocolInterface

type ProtocolInterface interface {
	Run()
	GetBaseProtocol() *Protocol
}

ProtocolInterface high level protocol should implement this interface

type Server

type Server struct {
	// Config fields may not be modified while the server is running.
	Config
	// contains filtered or unexported fields
}

Server manages all p2p peer connections.

func (*Server) Start

func (srv *Server) Start() (err error)

Start starts running the server.

Directories

Path Synopsis
* * @file * @copyright defined in go-seele/LICENSE
* * @file * @copyright defined in go-seele/LICENSE

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL