Documentation
¶
Overview ¶
Package p2p implements the Lemochain p2p network protocols.
Index ¶
Constants ¶
View Source
const NodeIDBits = 512
Variables ¶
View Source
var ( ErrConnectSelf = fmt.Errorf("can't connect yourself") ErrGenesisNotMatch = fmt.Errorf("can't match genesis block") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// private key
PrivateKey *ecdsa.PrivateKey
// max accept connection count
MaxPeerNum int
// 最大连接中的节点数
MaxPendingPeerNum int // reserve
// server's Name
Name string
// 黑名单
NetRestrict *Netlist
// 节点数据库路径
NodeDatabase string
// listen port
Port int
}
Config holds Server options.
func (*Config) ListenAddr ¶
type Msg ¶
type Node ¶
type Node struct {
IP net.IP // len 4 for IPv4 or 16 for IPv6
UDP, TCP uint16 // port numbers
ID NodeID // the node's public key
// contains filtered or unexported fields
}
Node 一个网络节点
type NodeID ¶
type NodeID [NodeIDBits / 8]byte
NodeID 节点唯一编码
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer represents a connected remote node.
func (*Peer) DisableReConnect ¶
func (p *Peer) DisableReConnect()
func (*Peer) NeedReConnect ¶
type PeerConnInfo ¶
type PeerConnInfo struct {
LocalAddr string `json:"localAddress"`
RemoteAddr string `json:"remoteAddress"`
NodeID string `json:"nodeID"`
}
func (PeerConnInfo) MarshalJSON ¶
func (p PeerConnInfo) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*PeerConnInfo) UnmarshalJSON ¶
func (p *PeerConnInfo) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.
type PeerEventFlag ¶
type PeerEventFlag int
对外节点通知类型
const ( AddPeerFlag PeerEventFlag = iota DropPeerFlag )
type PeerEventFn ¶
type PeerEventFn func(peer *Peer, flag PeerEventFlag) error
type Server ¶
type Server struct {
Config // server的一些基本配置
PeerEvent PeerEventFn // 外界注册使用
// contains filtered or unexported fields
}
Server manages all peer connections.
func (*Server) Connections ¶
func (srv *Server) Connections() []PeerConnInfo
func (*Server) Disconnect ¶
func (*Server) HandleConn ¶
处理接收到的连接 服务端客户端均走此函数 isSelfServer == true ? server : client
Click to show internal directories.
Click to hide internal directories.