Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// p2p.server will listen for incoming tcp connections. And it is for udp address used for Kad protocol
ListenAddr string `json:"address"`
// NetworkID used to define net type, for example main net and test net.
NetworkID string `json:"networkID"`
// static nodes which will be connected to find more nodes when the node started
StaticNodes []*discovery.Node `json:"staticNodes"`
// SubPrivateKey which will be make PrivateKey
SubPrivateKey string `json:"privateKey"`
// PrivateKey private key for p2p module, do not use it as any accounts
PrivateKey *ecdsa.PrivateKey `json:"-"`
}
Config is the Configuration of p2p
type Message ¶
type Message struct {
Code uint16 // message code, defined in each protocol
Payload []byte
ReceivedAt time.Time
}
Message exposed for high level layer to receive
type MsgReadWriter ¶
MsgReadWriter provides reading and writing of encoded messages. Implementations should ensure that ReadMsg and WriteMsg can be called simultaneously from multiple goroutines.
type MsgReader ¶
type MsgReader interface {
// ReadMsg read a message. It will block until send the message out or get errors
ReadMsg() (*Message, error)
}
MsgReader interface
type MsgWriter ¶
type MsgWriter interface {
// WriteMsg sends a message. It will block until the message's
// Payload has been consumed by the other end.
//
// Note that messages can be sent only once because their
// payload reader is drained.
WriteMsg(*Message) error
}
MsgWriter interface
type Peer ¶
type Peer struct {
Node *discovery.Node // remote peer that this peer connects
// contains filtered or unexported fields
}
Peer represents a connected remote node.
func (*Peer) Disconnect ¶
Disconnect terminates the peer connection with the given reason. It returns immediately and does not wait until the connection is closed.
func (*Peer) RemoteAddr ¶
RemoteAddr returns the remote address of the network connection.
type PeerInfo ¶
type PeerInfo struct {
ID string `json:"id"` // Unique of the node
Caps []string `json:"caps"` // Sum-protocols advertised by this particular peer
Network struct {
LocalAddress string `json:"localAddress"` // Local endpoint of the TCP data connection
RemoteAddress string `json:"remoteAddress"` // Remote endpoint of the TCP data connection
} `json:"network"`
Protocols map[string]interface{} `json:"protocols"` // Sub-protocol specific metadata fields
Shard uint `json:"shard"` // shard id of the node
}
PeerInfo represents a short summary of a connected peer
type PeerInfos ¶
type PeerInfos []PeerInfo
PeerInfos array of PeerInfo for sort alphabetically by node identifier
type ProtoHandShake ¶
ProtoHandShake handshake message for two peer to exchange 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
// Length should contain the number of message codes used by the protocol.
Length uint16
// AddPeer find a new peer will call this method
AddPeer func(peer *Peer, rw MsgReadWriter) bool
// DeletePeer this method will be called when a peer is disconnected
DeletePeer func(peer *Peer)
// GetPeer this method will be called for get peer information
GetPeer func(address common.Address) interface{}
}
Protocol base class for high level transfer protocol.
type Server ¶
type Server struct {
// Config fields may not be modified while the server is running.
Config
// 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
// Protocols should contain the protocols supported by the server.
Protocols []Protocol
SelfNode *discovery.Node
// contains filtered or unexported fields
}
Server manages all p2p peer connections.
func NewServer ¶
func NewServer(genesis core.GenesisInfo, config Config, protocols []Protocol) *Server
NewServer initialize a server
func (*Server) PeersInfo ¶
PeersInfo returns an array of metadata objects describing connected peers.