Documentation ¶
Overview ¶
Package p2p implements the Lemochain p2p network protocols.
Index ¶
- Constants
- Variables
- type Config
- type DialManager
- type DiscoverManager
- func (m *DiscoverManager) AddNewList(nodes []string)
- func (m *DiscoverManager) GetNodesForDiscover(sequence uint) []string
- func (m *DiscoverManager) SetConnectResult(node string, success bool) error
- func (m *DiscoverManager) SetDeputyNodes(nodes []string)
- func (m *DiscoverManager) SetReconnect(node string) error
- func (m *DiscoverManager) Start() error
- func (m *DiscoverManager) Stop() error
- type HandleConnFunc
- type Msg
- type Netlist
- type Node
- type NodeID
- type Peer
- type PeerConnInfo
- type PeerEventFlag
- type PeerEventFn
- type RawNode
- type Server
Constants ¶
View Source
const ( MaxReconnectCount int8 = 5 MaxNodeCount = 200 WhiteFile = "whitelist" FindFile = "findnode" )
View Source
const NodeIDBits = 512
Variables ¶
View Source
var ( ErrMaxReconnect = errors.New("reconnect has reached max count") ErrNoSpecialNode = errors.New("doesn't have this special node") ErrHasStared = errors.New("has been started") ErrNotStart = errors.New("not start") )
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 DialManager ¶ added in v1.0.1
type DialManager struct {
// contains filtered or unexported fields
}
func NewDialManager ¶ added in v1.0.1
func NewDialManager(handleConn HandleConnFunc, discover *DiscoverManager) *DialManager
func (*DialManager) Start ¶ added in v1.0.1
func (m *DialManager) Start() error
func (*DialManager) Stop ¶ added in v1.0.1
func (m *DialManager) Stop() error
type DiscoverManager ¶ added in v1.0.1
type DiscoverManager struct {
// contains filtered or unexported fields
}
func NewDiscoverManager ¶ added in v1.0.1
func NewDiscoverManager(datadir string) *DiscoverManager
func (*DiscoverManager) AddNewList ¶ added in v1.0.1
func (m *DiscoverManager) AddNewList(nodes []string)
func (*DiscoverManager) GetNodesForDiscover ¶ added in v1.0.1
func (m *DiscoverManager) GetNodesForDiscover(sequence uint) []string
func (*DiscoverManager) SetConnectResult ¶ added in v1.0.1
func (m *DiscoverManager) SetConnectResult(node string, success bool) error
SetConnectResult set connect result
func (*DiscoverManager) SetDeputyNodes ¶ added in v1.0.1
func (m *DiscoverManager) SetDeputyNodes(nodes []string)
SetDeputyNodes add deputy nodes
func (*DiscoverManager) SetReconnect ¶ added in v1.0.1
func (m *DiscoverManager) SetReconnect(node string) error
SetReconnect start reconnect
func (*DiscoverManager) Start ¶ added in v1.0.1
func (m *DiscoverManager) Start() error
func (*DiscoverManager) Stop ¶ added in v1.0.1
func (m *DiscoverManager) Stop() error
type HandleConnFunc ¶ added in v1.0.1
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 ¶
func (*Peer) RemoteAddr ¶ added in v1.0.1
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的一些基本配置 // contains filtered or unexported fields }
Server manages all peer connections.
func NewServer ¶ added in v1.0.1
func NewServer(config Config, discover *DiscoverManager) *Server
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.