Documentation ¶
Overview ¶
Package network module implements p2p network, It uses a Kademlia-like protocol to maintain and discover Nodes. network transfer protocol use KCP, a open source RUDP implementation,it provide NAT Traversal ability,let nodes under NAT can be connecting with other.
Index ¶
- Constants
- Variables
- func Init(config *common.ConfManager, consensusHandler MsgHandler, ...) (err error)
- func IsJoinedThisGroup(members []NodeID) bool
- func OnP2PAccepted(id uint64, session uint32, p2pType uint32, ip string, port uint16)
- func OnP2PChecked(p2pType uint32, privateIP string, publicIP string)
- func OnP2PConnected(id uint64, session uint32, p2pType uint32)
- func OnP2PDisconnected(id uint64, session uint32, p2pCode uint32)
- func OnP2PListened(ip string, port uint16, latency uint64)
- func OnP2PLoginSign() unsafe.Pointer
- func OnP2PRecved(id uint64, session uint32, data []byte)
- func OnP2PSendWaited(session uint32, peerID uint64)
- func P2PClose()
- func P2PConfig(id uint64)
- func P2PConnect(id uint64, ip string, port uint16)
- func P2PListen(ip string, port uint16)
- func P2PLoginSign() unsafe.Pointer
- func P2PProxy(ip string, port uint16)
- func P2PSend(session uint32, data []byte)
- func P2PShutdown(session uint32)
- type BizMessageID
- type BufferPool
- type BufferPoolItem
- type Conn
- type DataType
- type FlowMeter
- type FlowMeterItem
- type Group
- type GroupManager
- type Kad
- type Message
- type MessageManager
- type MessageType
- type MsgData
- func (*MsgData) Descriptor() ([]byte, []int)
- func (m *MsgData) GetBizMessageID() []byte
- func (m *MsgData) GetData() []byte
- func (m *MsgData) GetDataType() DataType
- func (m *MsgData) GetExpiration() uint64
- func (m *MsgData) GetGroupID() string
- func (m *MsgData) GetMessageCode() uint32
- func (m *MsgData) GetMessageID() uint64
- func (m *MsgData) GetMessageInfo() uint32
- func (m *MsgData) GetRelayCount() int32
- func (m *MsgData) GetSrcNodeID() []byte
- func (m *MsgData) Marshal() (dAtA []byte, err error)
- func (m *MsgData) MarshalTo(dAtA []byte) (int, error)
- func (*MsgData) ProtoMessage()
- func (m *MsgData) Reset()
- func (m *MsgData) Size() (n int)
- func (m *MsgData) String() string
- func (m *MsgData) Unmarshal(dAtA []byte) error
- func (m *MsgData) XXX_DiscardUnknown()
- func (m *MsgData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgData) XXX_Merge(src proto.Message)
- func (m *MsgData) XXX_Size() int
- func (m *MsgData) XXX_Unmarshal(b []byte) error
- type MsgDigest
- type MsgFindNode
- func (*MsgFindNode) Descriptor() ([]byte, []int)
- func (m *MsgFindNode) GetExpiration() uint64
- func (m *MsgFindNode) GetTarget() []byte
- func (m *MsgFindNode) Marshal() (dAtA []byte, err error)
- func (m *MsgFindNode) MarshalTo(dAtA []byte) (int, error)
- func (*MsgFindNode) ProtoMessage()
- func (m *MsgFindNode) Reset()
- func (m *MsgFindNode) Size() (n int)
- func (m *MsgFindNode) String() string
- func (m *MsgFindNode) Unmarshal(dAtA []byte) error
- func (m *MsgFindNode) XXX_DiscardUnknown()
- func (m *MsgFindNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgFindNode) XXX_Merge(src proto.Message)
- func (m *MsgFindNode) XXX_Size() int
- func (m *MsgFindNode) XXX_Unmarshal(b []byte) error
- type MsgHandler
- type MsgNeighbors
- func (*MsgNeighbors) Descriptor() ([]byte, []int)
- func (m *MsgNeighbors) GetExpiration() uint64
- func (m *MsgNeighbors) GetNodes() []*RpcNode
- func (m *MsgNeighbors) Marshal() (dAtA []byte, err error)
- func (m *MsgNeighbors) MarshalTo(dAtA []byte) (int, error)
- func (*MsgNeighbors) ProtoMessage()
- func (m *MsgNeighbors) Reset()
- func (m *MsgNeighbors) Size() (n int)
- func (m *MsgNeighbors) String() string
- func (m *MsgNeighbors) Unmarshal(dAtA []byte) error
- func (m *MsgNeighbors) XXX_DiscardUnknown()
- func (m *MsgNeighbors) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgNeighbors) XXX_Merge(src proto.Message)
- func (m *MsgNeighbors) XXX_Size() int
- func (m *MsgNeighbors) XXX_Unmarshal(b []byte) error
- type MsgPing
- func (*MsgPing) Descriptor() ([]byte, []int)
- func (m *MsgPing) GetChainID() uint32
- func (m *MsgPing) GetCurTime() uint64
- func (m *MsgPing) GetExpiration() uint64
- func (m *MsgPing) GetFrom() *RpcEndPoint
- func (m *MsgPing) GetPK() []byte
- func (m *MsgPing) GetSign() []byte
- func (m *MsgPing) GetTo() *RpcEndPoint
- func (m *MsgPing) GetVersion() int32
- func (m *MsgPing) Marshal() (dAtA []byte, err error)
- func (m *MsgPing) MarshalTo(dAtA []byte) (int, error)
- func (*MsgPing) ProtoMessage()
- func (m *MsgPing) Reset()
- func (m *MsgPing) Size() (n int)
- func (m *MsgPing) String() string
- func (m *MsgPing) Unmarshal(dAtA []byte) error
- func (m *MsgPing) XXX_DiscardUnknown()
- func (m *MsgPing) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgPing) XXX_Merge(src proto.Message)
- func (m *MsgPing) XXX_Size() int
- func (m *MsgPing) XXX_Unmarshal(b []byte) error
- type MsgPong
- func (*MsgPong) Descriptor() ([]byte, []int)
- func (m *MsgPong) GetVerifyResult() bool
- func (m *MsgPong) GetVersion() int32
- func (m *MsgPong) Marshal() (dAtA []byte, err error)
- func (m *MsgPong) MarshalTo(dAtA []byte) (int, error)
- func (*MsgPong) ProtoMessage()
- func (m *MsgPong) Reset()
- func (m *MsgPong) Size() (n int)
- func (m *MsgPong) String() string
- func (m *MsgPong) Unmarshal(dAtA []byte) error
- func (m *MsgPong) XXX_DiscardUnknown()
- func (m *MsgPong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgPong) XXX_Merge(src proto.Message)
- func (m *MsgPong) XXX_Size() int
- func (m *MsgPong) XXX_Unmarshal(b []byte) error
- type NetCore
- type NetCoreConfig
- type NetInterface
- type Network
- type NetworkConfig
- type Node
- type NodeID
- type Peer
- type PeerAuthContext
- type PeerIPSet
- type PeerManager
- type PeerSource
- type Proposer
- type ProposerBucket
- func (pb *ProposerBucket) AddProposers(proposers []*Proposer)
- func (pb *ProposerBucket) Broadcast(msg *MsgData, code uint32)
- func (pb *ProposerBucket) Build(proposers []*Proposer)
- func (pb *ProposerBucket) GroupNameByIndex(index int) string
- func (pb *ProposerBucket) IsContained(proposer *Proposer) bool
- func (pb *ProposerBucket) Len() int
- func (pb *ProposerBucket) Less(i, j int) bool
- func (pb *ProposerBucket) Swap(i, j int)
- type ProposerManager
- func (pm *ProposerManager) AddProposers(proposers []*Proposer)
- func (pm *ProposerManager) Broadcast(msg *MsgData, code uint32)
- func (pm *ProposerManager) Build(proposers []*Proposer)
- func (pm *ProposerManager) Len() int
- func (pm *ProposerManager) Less(i, j int) bool
- func (pm *ProposerManager) Swap(i, j int)
- type RpcEndPoint
- func (*RpcEndPoint) Descriptor() ([]byte, []int)
- func (m *RpcEndPoint) GetIP() string
- func (m *RpcEndPoint) GetPort() int32
- func (m *RpcEndPoint) Marshal() (dAtA []byte, err error)
- func (m *RpcEndPoint) MarshalTo(dAtA []byte) (int, error)
- func (*RpcEndPoint) ProtoMessage()
- func (m *RpcEndPoint) Reset()
- func (m *RpcEndPoint) Size() (n int)
- func (m *RpcEndPoint) String() string
- func (m *RpcEndPoint) Unmarshal(dAtA []byte) error
- func (m *RpcEndPoint) XXX_DiscardUnknown()
- func (m *RpcEndPoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RpcEndPoint) XXX_Merge(src proto.Message)
- func (m *RpcEndPoint) XXX_Size() int
- func (m *RpcEndPoint) XXX_Unmarshal(b []byte) error
- type RpcNode
- func (*RpcNode) Descriptor() ([]byte, []int)
- func (m *RpcNode) GetID() string
- func (m *RpcNode) GetIP() string
- func (m *RpcNode) GetPort() int32
- func (m *RpcNode) Marshal() (dAtA []byte, err error)
- func (m *RpcNode) MarshalTo(dAtA []byte) (int, error)
- func (*RpcNode) ProtoMessage()
- func (m *RpcNode) Reset()
- func (m *RpcNode) Size() (n int)
- func (m *RpcNode) String() string
- func (m *RpcNode) Unmarshal(dAtA []byte) error
- func (m *RpcNode) XXX_DiscardUnknown()
- func (m *RpcNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RpcNode) XXX_Merge(src proto.Message)
- func (m *RpcNode) XXX_Size() int
- func (m *RpcNode) XXX_Unmarshal(b []byte) error
- type SendList
- type SendListItem
- type SendPriorityType
- type Server
- func (s *Server) AddGroup(groupID string, members []string) *Group
- func (s *Server) AddProposers(proposers []*Proposer)
- func (s *Server) Broadcast(msg Message) error
- func (s *Server) BuildGroupNet(groupID string, members []string)
- func (s *Server) BuildProposerGroupNet(proposers []*Proposer)
- func (s *Server) ConnInfo() []Conn
- func (s *Server) DissolveGroupNet(groupID string)
- func (s *Server) RemoveGroup(ID string)
- func (s *Server) Send(id string, msg Message) error
- func (s *Server) SpreadAmongGroup(groupID string, msg Message) error
- func (s *Server) SpreadToGroup(groupID string, groupMembers []string, msg Message, digest MsgDigest) error
- func (s *Server) TransmitToNeighbor(msg Message, blacklist []string) error
Constants ¶
const ( //the following six messages are used for casting block CastVerifyMsg uint32 = 1 // The proposal sends the proposal msg to the verifier VerifiedCastMsg uint32 = 2 // The verifier sends the verified msg to the verifier group. CastRewardSignReq uint32 = 3 // Verifier reward: the verifier sends the piece request msg to the other verifiers. CastRewardSignGot uint32 = 4 // Verifier reward: the verifies sends the piece response msg to the other verifiers. ReqProposalBlock uint32 = 5 // The verifies sends the request to the proposal to get the block ResponseProposalBlock uint32 = 6 // The proposal sends the response to the verifies to deliver the block /*********************** chain message code *********************** ************************* range from 10000 to 19999 ************** */ //The following four messages are used for block sync BlockInfoNotifyMsg uint32 = 10001 ReqBlock uint32 = 10002 BlockResponseMsg uint32 = 10003 NewBlockMsg uint32 = 10004 //The following two messages are used for block fork processing ForkFindAncestorResponse uint32 = 10008 ForkFindAncestorReq uint32 = 10009 ForkChainSliceReq uint32 = 10013 ForkChainSliceResponse uint32 = 10014 //The following three message are used for tx sync TxSyncNotify uint32 = 10010 TxSyncReq uint32 = 10011 TxSyncResponse uint32 = 10012 )
const ( PacketTypeSize = 4 PacketLenSize = 4 PacketHeadSize = PacketTypeSize + PacketLenSize MaxUnhandledMessageCount = 10000 P2PMessageCodeBase = 10000 )
const ( BasePort = 22000 SuperBasePort = 1122 NodeIDLength = 32 )
const BizMessageIDLength = 32
const DEFAULT_MAX_PEER_SIZE_PER_IP = 16
const DefaultBucketGroupName = "BucketGroup"
const DefaultBucketGroupSize = 100
const FastGroupName = "FastProposerGroup"
const FastGroupSize = 100
const FullNodeVirtualGroupID = "full_node_virtual_group_id"
const GroupMinRowSize = 4
const MaxFastSize = 500
const MaxPendingSend = 10
const MaxSendListSize = 256
const MaxSendPriority = 3
const NormalGroupName = "NormalProposerGroup"
const NormalGroupSize = 500
const RelayTestTimeOut = 30 * time.Minute
const Version = 1
Version is p2p proto version
const WaitTimeout = 3 * time.Second
Variables ¶
var ( ErrInvalidLengthP2P = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowP2P = fmt.Errorf("proto: integer overflow") )
var DataType_name = map[int32]string{
0: "DataNormal",
1: "DataGlobal",
2: "DataGlobalRandom",
3: "DataGroup",
4: "DataGroupColumn",
5: "DataGroupRow",
}
var DataType_value = map[string]int32{
"DataNormal": 0,
"DataGlobal": 1,
"DataGlobalRandom": 2,
"DataGroup": 3,
"DataGroupColumn": 4,
"DataGroupRow": 5,
}
var Logger *logrus.Logger
var MessageType_name = map[int32]string{
0: "MessageNone",
1: "MessagePing",
2: "MessagePong",
3: "MessageFindnode",
4: "MessageNeighbors",
5: "MessageData",
}
var MessageType_value = map[string]int32{
"MessageNone": 0,
"MessagePing": 1,
"MessagePong": 2,
"MessageFindnode": 3,
"MessageNeighbors": 4,
"MessageData": 5,
}
Functions ¶
func Init ¶
func Init(config *common.ConfManager, consensusHandler MsgHandler, networkConfig NetworkConfig) (err error)
Init initialize network instance,register message handler,join p2p network
func IsJoinedThisGroup ¶
func OnP2PAccepted ¶
func OnP2PChecked ¶
func OnP2PConnected ¶
func OnP2PDisconnected ¶
func OnP2PListened ¶
func OnP2PLoginSign ¶
func OnP2PRecved ¶
func OnP2PSendWaited ¶
func P2PConnect ¶
func P2PLoginSign ¶
func P2PShutdown ¶
func P2PShutdown(session uint32)
Types ¶
type BizMessageID ¶
type BizMessageID = [BizMessageIDLength]byte
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool Cache the buffers used to send and recv data, reduce alloc and free times of memory to improve performance
func (*BufferPool) Print ¶
func (pool *BufferPool) Print()
type BufferPoolItem ¶
type BufferPoolItem struct {
// contains filtered or unexported fields
}
BufferPoolItem maintain the buffers of this size
type FlowMeter ¶
type FlowMeter struct {
// contains filtered or unexported fields
}
FlowMeter network dataflow statistics by protocal code
type FlowMeterItem ¶
type FlowMeterItem struct {
// contains filtered or unexported fields
}
type Group ¶
type Group struct { ID string // contains filtered or unexported fields }
Group network is Ring topology network with several accelerate links,to implement group broadcast
type GroupManager ¶
type GroupManager struct {
// contains filtered or unexported fields
}
GroupManager represents group management
func (*GroupManager) Broadcast ¶
func (gm *GroupManager) Broadcast(ID string, msg *MsgData, members []string, code uint32)
func (*GroupManager) BroadcastExternal ¶
func (gm *GroupManager) BroadcastExternal(ID string, msg *MsgData, members []string, code uint32)
type MessageManager ¶
type MessageManager struct {
// contains filtered or unexported fields
}
MessageManager is a message management
type MessageType ¶
type MessageType int32
const ( MessageType_MessageNone MessageType = 0 MessageType_MessagePing MessageType = 1 MessageType_MessagePong MessageType = 2 MessageType_MessageFindnode MessageType = 3 MessageType_MessageNeighbors MessageType = 4 MessageType_MessageData MessageType = 5 )
func (MessageType) EnumDescriptor ¶
func (MessageType) EnumDescriptor() ([]byte, []int)
func (MessageType) String ¶
func (x MessageType) String() string
type MsgData ¶
type MsgData struct { DataType DataType `protobuf:"varint,1,opt,name=DataType,proto3,enum=network.DataType" json:"DataType,omitempty"` GroupID string `protobuf:"bytes,2,opt,name=GroupID,proto3" json:"GroupID,omitempty"` Expiration uint64 `protobuf:"varint,3,opt,name=Expiration,proto3" json:"Expiration,omitempty"` MessageID uint64 `protobuf:"varint,4,opt,name=MessageID,proto3" json:"MessageID,omitempty"` BizMessageID []byte `protobuf:"bytes,5,opt,name=BizMessageID,proto3" json:"BizMessageID,omitempty"` SrcNodeID []byte `protobuf:"bytes,6,opt,name=SrcNodeID,proto3" json:"SrcNodeID,omitempty"` Data []byte `protobuf:"bytes,7,opt,name=Data,proto3" json:"Data,omitempty"` RelayCount int32 `protobuf:"varint,8,opt,name=RelayCount,proto3" json:"RelayCount,omitempty"` MessageCode uint32 `protobuf:"varint,9,opt,name=MessageCode,proto3" json:"MessageCode,omitempty"` MessageInfo uint32 `protobuf:"varint,10,opt,name=MessageInfo,proto3" json:"MessageInfo,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*MsgData) Descriptor ¶
func (*MsgData) GetBizMessageID ¶
func (*MsgData) GetDataType ¶
func (*MsgData) GetExpiration ¶
func (*MsgData) GetGroupID ¶
func (*MsgData) GetMessageCode ¶
func (*MsgData) GetMessageID ¶
func (*MsgData) GetMessageInfo ¶
func (*MsgData) GetRelayCount ¶
func (*MsgData) GetSrcNodeID ¶
func (*MsgData) ProtoMessage ¶
func (*MsgData) ProtoMessage()
func (*MsgData) XXX_DiscardUnknown ¶
func (m *MsgData) XXX_DiscardUnknown()
func (*MsgData) XXX_Marshal ¶
func (*MsgData) XXX_Unmarshal ¶
type MsgFindNode ¶
type MsgFindNode struct { Target []byte `protobuf:"bytes,1,opt,name=Target,proto3" json:"Target,omitempty"` Expiration uint64 `protobuf:"varint,2,opt,name=Expiration,proto3" json:"Expiration,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*MsgFindNode) Descriptor ¶
func (*MsgFindNode) Descriptor() ([]byte, []int)
func (*MsgFindNode) GetExpiration ¶
func (m *MsgFindNode) GetExpiration() uint64
func (*MsgFindNode) GetTarget ¶
func (m *MsgFindNode) GetTarget() []byte
func (*MsgFindNode) Marshal ¶
func (m *MsgFindNode) Marshal() (dAtA []byte, err error)
func (*MsgFindNode) ProtoMessage ¶
func (*MsgFindNode) ProtoMessage()
func (*MsgFindNode) Reset ¶
func (m *MsgFindNode) Reset()
func (*MsgFindNode) Size ¶
func (m *MsgFindNode) Size() (n int)
func (*MsgFindNode) String ¶
func (m *MsgFindNode) String() string
func (*MsgFindNode) Unmarshal ¶
func (m *MsgFindNode) Unmarshal(dAtA []byte) error
func (*MsgFindNode) XXX_DiscardUnknown ¶
func (m *MsgFindNode) XXX_DiscardUnknown()
func (*MsgFindNode) XXX_Marshal ¶
func (m *MsgFindNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*MsgFindNode) XXX_Merge ¶
func (m *MsgFindNode) XXX_Merge(src proto.Message)
func (*MsgFindNode) XXX_Size ¶
func (m *MsgFindNode) XXX_Size() int
func (*MsgFindNode) XXX_Unmarshal ¶
func (m *MsgFindNode) XXX_Unmarshal(b []byte) error
type MsgHandler ¶
type MsgNeighbors ¶
type MsgNeighbors struct { Nodes []*RpcNode `protobuf:"bytes,1,rep,name=Nodes,proto3" json:"Nodes,omitempty"` Expiration uint64 `protobuf:"varint,2,opt,name=Expiration,proto3" json:"Expiration,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*MsgNeighbors) Descriptor ¶
func (*MsgNeighbors) Descriptor() ([]byte, []int)
func (*MsgNeighbors) GetExpiration ¶
func (m *MsgNeighbors) GetExpiration() uint64
func (*MsgNeighbors) GetNodes ¶
func (m *MsgNeighbors) GetNodes() []*RpcNode
func (*MsgNeighbors) Marshal ¶
func (m *MsgNeighbors) Marshal() (dAtA []byte, err error)
func (*MsgNeighbors) ProtoMessage ¶
func (*MsgNeighbors) ProtoMessage()
func (*MsgNeighbors) Reset ¶
func (m *MsgNeighbors) Reset()
func (*MsgNeighbors) Size ¶
func (m *MsgNeighbors) Size() (n int)
func (*MsgNeighbors) String ¶
func (m *MsgNeighbors) String() string
func (*MsgNeighbors) Unmarshal ¶
func (m *MsgNeighbors) Unmarshal(dAtA []byte) error
func (*MsgNeighbors) XXX_DiscardUnknown ¶
func (m *MsgNeighbors) XXX_DiscardUnknown()
func (*MsgNeighbors) XXX_Marshal ¶
func (m *MsgNeighbors) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*MsgNeighbors) XXX_Merge ¶
func (m *MsgNeighbors) XXX_Merge(src proto.Message)
func (*MsgNeighbors) XXX_Size ¶
func (m *MsgNeighbors) XXX_Size() int
func (*MsgNeighbors) XXX_Unmarshal ¶
func (m *MsgNeighbors) XXX_Unmarshal(b []byte) error
type MsgPing ¶
type MsgPing struct { Version int32 `protobuf:"varint,1,opt,name=Version,proto3" json:"Version,omitempty"` From *RpcEndPoint `protobuf:"bytes,2,opt,name=From,proto3" json:"From,omitempty"` To *RpcEndPoint `protobuf:"bytes,3,opt,name=To,proto3" json:"To,omitempty"` ChainID uint32 `protobuf:"varint,4,opt,name=chainID,proto3" json:"chainID,omitempty"` Expiration uint64 `protobuf:"varint,5,opt,name=Expiration,proto3" json:"Expiration,omitempty"` PK []byte `protobuf:"bytes,6,opt,name=PK,proto3" json:"PK,omitempty"` Sign []byte `protobuf:"bytes,7,opt,name=Sign,proto3" json:"Sign,omitempty"` CurTime uint64 `protobuf:"varint,8,opt,name=CurTime,proto3" json:"CurTime,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*MsgPing) Descriptor ¶
func (*MsgPing) GetChainID ¶
func (*MsgPing) GetCurTime ¶
func (*MsgPing) GetExpiration ¶
func (*MsgPing) GetFrom ¶
func (m *MsgPing) GetFrom() *RpcEndPoint
func (*MsgPing) GetTo ¶
func (m *MsgPing) GetTo() *RpcEndPoint
func (*MsgPing) GetVersion ¶
func (*MsgPing) ProtoMessage ¶
func (*MsgPing) ProtoMessage()
func (*MsgPing) XXX_DiscardUnknown ¶
func (m *MsgPing) XXX_DiscardUnknown()
func (*MsgPing) XXX_Marshal ¶
func (*MsgPing) XXX_Unmarshal ¶
type MsgPong ¶
type MsgPong struct { Version int32 `protobuf:"varint,1,opt,name=Version,proto3" json:"Version,omitempty"` VerifyResult bool `protobuf:"varint,2,opt,name=VerifyResult,proto3" json:"VerifyResult,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*MsgPong) Descriptor ¶
func (*MsgPong) GetVerifyResult ¶
func (*MsgPong) GetVersion ¶
func (*MsgPong) ProtoMessage ¶
func (*MsgPong) ProtoMessage()
func (*MsgPong) XXX_DiscardUnknown ¶
func (m *MsgPong) XXX_DiscardUnknown()
func (*MsgPong) XXX_Marshal ¶
func (*MsgPong) XXX_Unmarshal ¶
type NetCore ¶
type NetCore struct { ID NodeID // contains filtered or unexported fields }
NetCore p2p network
func (*NetCore) InitNetCore ¶
func (nc *NetCore) InitNetCore(cfg NetCoreConfig) (*NetCore, error)
InitNetCore For initialization
type NetCoreConfig ¶
type NetCoreConfig struct { ListenAddr *net.UDPAddr ID NodeID Seeds []*Node NatTraversalEnable bool NatPort uint16 NatIP string ChainID uint16 ProtocolVersion uint16 }
NetCoreConfig net core configure
type NetInterface ¶
type NetInterface interface {
// contains filtered or unexported methods
}
type Network ¶
type Network interface { //Send message to the node which id represents.If self doesn't connect to the node, // resolve the kad net to find the node and then send the message Send(id string, msg Message) error //Broadcast the message among the group which self belongs to SpreadAmongGroup(groupID string, msg Message) error //SpreadToGroup Broadcast the message to the group which self do not belong to SpreadToGroup(groupID string, groupMembers []string, msg Message, digest MsgDigest) error //TransmitToNeighbor Send message to neighbor nodes TransmitToNeighbor(msg Message, blacklist []string) error //Broadcast Send the message to all nodes it connects to and the node which receive the message also broadcast the message to their neighbor once Broadcast(msg Message) error //ConnInfo Return all connections self has ConnInfo() []Conn //BuildGroupNet build group network BuildGroupNet(groupID string, members []string) //DissolveGroupNet dissolve group network DissolveGroupNet(groupID string) //BuildProposerGroupNet build proposer group network BuildProposerGroupNet(proposers []*Proposer) //AddProposers add proposers to proposer group network AddProposers(proposers []*Proposer) }
func GetNetInstance ¶
func GetNetInstance() Network
type NetworkConfig ¶
type NetworkConfig struct { NodeIDHex string NatAddr string NatPort uint16 SeedAddr string ChainID uint16 // Chain id ProtocolVersion uint16 // Protocol version TestMode bool IsSuper bool SeedIDs []string PK string SK string }
NetworkConfig is the network configuration
type Node ¶
type Node struct { ID NodeID IP net.IP Port int NatType int // contains filtered or unexported fields }
Node Kad node struct
func InitSelfNode ¶
InitSelfNode initialize local user's node
type Peer ¶
Peer is node connection object
func (*Peer) AuthContext ¶
func (p *Peer) AuthContext() *PeerAuthContext
func (*Peer) IsCompatible ¶
type PeerAuthContext ¶
func (*PeerAuthContext) Verify ¶
func (pa *PeerAuthContext) Verify() (bool, string)
type PeerIPSet ¶
type PeerIPSet struct { Limit uint // maximum number of IPs in each subnet // contains filtered or unexported fields }
PeerIPSet tracks IP of peers
type PeerManager ¶
type PeerManager struct {
// contains filtered or unexported fields
}
PeerManager is node connection management
func (*PeerManager) ConnInfo ¶
func (pm *PeerManager) ConnInfo() []Conn
type PeerSource ¶
type PeerSource int32
const ( PeerSourceUnkown PeerSource = 0 PeerSourceKad PeerSource = 1 PeerSourceGroup PeerSource = 2 )
type ProposerBucket ¶
type ProposerBucket struct {
// contains filtered or unexported fields
}
func (*ProposerBucket) AddProposers ¶
func (pb *ProposerBucket) AddProposers(proposers []*Proposer)
func (*ProposerBucket) Broadcast ¶
func (pb *ProposerBucket) Broadcast(msg *MsgData, code uint32)
func (*ProposerBucket) Build ¶
func (pb *ProposerBucket) Build(proposers []*Proposer)
func (*ProposerBucket) GroupNameByIndex ¶
func (pb *ProposerBucket) GroupNameByIndex(index int) string
func (*ProposerBucket) IsContained ¶
func (pb *ProposerBucket) IsContained(proposer *Proposer) bool
func (*ProposerBucket) Len ¶
func (pb *ProposerBucket) Len() int
func (*ProposerBucket) Less ¶
func (pb *ProposerBucket) Less(i, j int) bool
func (*ProposerBucket) Swap ¶
func (pb *ProposerBucket) Swap(i, j int)
type ProposerManager ¶
type ProposerManager struct {
// contains filtered or unexported fields
}
func (*ProposerManager) AddProposers ¶
func (pm *ProposerManager) AddProposers(proposers []*Proposer)
func (*ProposerManager) Broadcast ¶
func (pm *ProposerManager) Broadcast(msg *MsgData, code uint32)
func (*ProposerManager) Build ¶
func (pm *ProposerManager) Build(proposers []*Proposer)
func (*ProposerManager) Len ¶
func (pm *ProposerManager) Len() int
func (*ProposerManager) Less ¶
func (pm *ProposerManager) Less(i, j int) bool
func (*ProposerManager) Swap ¶
func (pm *ProposerManager) Swap(i, j int)
type RpcEndPoint ¶
type RpcEndPoint struct { IP string `protobuf:"bytes,1,opt,name=IP,proto3" json:"IP,omitempty"` Port int32 `protobuf:"varint,2,opt,name=Port,proto3" json:"Port,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func MakeEndPoint ¶
func MakeEndPoint(addr *net.UDPAddr, tcpPort int32) RpcEndPoint
MakeEndPoint create the node description object
func (*RpcEndPoint) Descriptor ¶
func (*RpcEndPoint) Descriptor() ([]byte, []int)
func (*RpcEndPoint) GetIP ¶
func (m *RpcEndPoint) GetIP() string
func (*RpcEndPoint) GetPort ¶
func (m *RpcEndPoint) GetPort() int32
func (*RpcEndPoint) Marshal ¶
func (m *RpcEndPoint) Marshal() (dAtA []byte, err error)
func (*RpcEndPoint) ProtoMessage ¶
func (*RpcEndPoint) ProtoMessage()
func (*RpcEndPoint) Reset ¶
func (m *RpcEndPoint) Reset()
func (*RpcEndPoint) Size ¶
func (m *RpcEndPoint) Size() (n int)
func (*RpcEndPoint) String ¶
func (m *RpcEndPoint) String() string
func (*RpcEndPoint) Unmarshal ¶
func (m *RpcEndPoint) Unmarshal(dAtA []byte) error
func (*RpcEndPoint) XXX_DiscardUnknown ¶
func (m *RpcEndPoint) XXX_DiscardUnknown()
func (*RpcEndPoint) XXX_Marshal ¶
func (m *RpcEndPoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RpcEndPoint) XXX_Merge ¶
func (m *RpcEndPoint) XXX_Merge(src proto.Message)
func (*RpcEndPoint) XXX_Size ¶
func (m *RpcEndPoint) XXX_Size() int
func (*RpcEndPoint) XXX_Unmarshal ¶
func (m *RpcEndPoint) XXX_Unmarshal(b []byte) error
type RpcNode ¶
type RpcNode struct { IP string `protobuf:"bytes,1,opt,name=IP,proto3" json:"IP,omitempty"` Port int32 `protobuf:"varint,2,opt,name=Port,proto3" json:"Port,omitempty"` ID string `protobuf:"bytes,3,opt,name=ID,proto3" json:"ID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*RpcNode) Descriptor ¶
func (*RpcNode) ProtoMessage ¶
func (*RpcNode) ProtoMessage()
func (*RpcNode) XXX_DiscardUnknown ¶
func (m *RpcNode) XXX_DiscardUnknown()
func (*RpcNode) XXX_Marshal ¶
func (*RpcNode) XXX_Unmarshal ¶
type SendListItem ¶
type SendListItem struct {
// contains filtered or unexported fields
}
type SendPriorityType ¶
type SendPriorityType uint32
const ( SendPriorityHigh SendPriorityType = 0 SendPriorityMedium SendPriorityType = 1 SendPriorityLow SendPriorityType = 2 )
type Server ¶
type Server struct { Self *Node // contains filtered or unexported fields }