network

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 31 Imported by: 0

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

View Source
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
)
View Source
const (
	PacketTypeSize           = 4
	PacketLenSize            = 4
	PacketHeadSize           = PacketTypeSize + PacketLenSize
	MaxUnhandledMessageCount = 10000
	P2PMessageCodeBase       = 10000
)
View Source
const (
	BasePort = 22000

	SuperBasePort = 1122

	NodeIDLength = 32
)
View Source
const BizMessageIDLength = 32
View Source
const DEFAULT_MAX_PEER_SIZE_PER_IP = 16
View Source
const DefaultBucketGroupName = "BucketGroup"
View Source
const DefaultBucketGroupSize = 100
View Source
const FastGroupName = "FastProposerGroup"
View Source
const FastGroupSize = 100
View Source
const FullNodeVirtualGroupID = "full_node_virtual_group_id"
View Source
const GroupMinRowSize = 4
View Source
const MaxFastSize = 500
View Source
const MaxPendingSend = 10
View Source
const MaxSendListSize = 256
View Source
const MaxSendPriority = 3
View Source
const NormalGroupName = "NormalProposerGroup"
View Source
const NormalGroupSize = 500
View Source
const RelayTestTimeOut = 30 * time.Minute
View Source
const Version = 1

Version is p2p proto version

View Source
const WaitTimeout = 3 * time.Second

Variables

View Source
var (
	ErrInvalidLengthP2P = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowP2P   = fmt.Errorf("proto: integer overflow")
)
View Source
var DataType_name = map[int32]string{
	0: "DataNormal",
	1: "DataGlobal",
	2: "DataGlobalRandom",
	3: "DataGroup",
	4: "DataGroupColumn",
	5: "DataGroupRow",
}
View Source
var DataType_value = map[string]int32{
	"DataNormal":       0,
	"DataGlobal":       1,
	"DataGlobalRandom": 2,
	"DataGroup":        3,
	"DataGroupColumn":  4,
	"DataGroupRow":     5,
}
View Source
var Logger *logrus.Logger
View Source
var MessageType_name = map[int32]string{
	0: "MessageNone",
	1: "MessagePing",
	2: "MessagePong",
	3: "MessageFindnode",
	4: "MessageNeighbors",
	5: "MessageData",
}
View Source
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 IsJoinedThisGroup(members []NodeID) bool

func OnP2PAccepted

func OnP2PAccepted(id uint64, session uint32, p2pType uint32, ip string, port uint16)

func OnP2PChecked

func OnP2PChecked(p2pType uint32, privateIP string, publicIP string)

func OnP2PConnected

func OnP2PConnected(id uint64, session uint32, p2pType uint32)

func OnP2PDisconnected

func OnP2PDisconnected(id uint64, session uint32, p2pCode uint32)

func OnP2PListened

func OnP2PListened(ip string, port uint16, latency uint64)

func OnP2PLoginSign

func OnP2PLoginSign() unsafe.Pointer

func OnP2PRecved

func OnP2PRecved(id uint64, session uint32, data []byte)

func OnP2PSendWaited

func OnP2PSendWaited(session uint32, peerID uint64)

func P2PClose

func P2PClose()

func P2PConfig

func P2PConfig(id uint64)

func P2PConnect

func P2PConnect(id uint64, ip string, port uint16)

func P2PListen

func P2PListen(ip string, port uint16)

func P2PLoginSign

func P2PLoginSign() unsafe.Pointer

func P2PProxy

func P2PProxy(ip string, port uint16)

func P2PSend

func P2PSend(session uint32, data []byte)

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 Conn

type Conn struct {
	ID   string
	IP   string
	Port string
}

type DataType

type DataType int32
const (
	DataType_DataNormal       DataType = 0
	DataType_DataGlobal       DataType = 1
	DataType_DataGlobalRandom DataType = 2
	DataType_DataGroup        DataType = 3
	DataType_DataGroupColumn  DataType = 4
	DataType_DataGroupRow     DataType = 5
)

func (DataType) EnumDescriptor

func (DataType) EnumDescriptor() ([]byte, []int)

func (DataType) String

func (x DataType) String() string

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

func (*Group) Broadcast

func (g *Group) Broadcast(msg *MsgData)

func (*Group) Len

func (g *Group) Len() int

func (*Group) Less

func (g *Group) Less(i, j int) bool

func (*Group) Swap

func (g *Group) Swap(i, j int)

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 Kad

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

Kad kad

func (*Kad) Close

func (kad *Kad) Close()

func (*Kad) Lookup

func (kad *Kad) Lookup(targetID NodeID) []*Node

find node on network

func (*Kad) Self

func (kad *Kad) Self() *Node

type Message

type Message struct {
	ChainID uint16

	ProtocolVersion uint16

	Code uint32

	Body []byte
}

func (Message) Hash

func (m Message) Hash() string

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) Descriptor() ([]byte, []int)

func (*MsgData) GetBizMessageID

func (m *MsgData) GetBizMessageID() []byte

func (*MsgData) GetData

func (m *MsgData) GetData() []byte

func (*MsgData) GetDataType

func (m *MsgData) GetDataType() DataType

func (*MsgData) GetExpiration

func (m *MsgData) GetExpiration() uint64

func (*MsgData) GetGroupID

func (m *MsgData) GetGroupID() string

func (*MsgData) GetMessageCode

func (m *MsgData) GetMessageCode() uint32

func (*MsgData) GetMessageID

func (m *MsgData) GetMessageID() uint64

func (*MsgData) GetMessageInfo

func (m *MsgData) GetMessageInfo() uint32

func (*MsgData) GetRelayCount

func (m *MsgData) GetRelayCount() int32

func (*MsgData) GetSrcNodeID

func (m *MsgData) GetSrcNodeID() []byte

func (*MsgData) Marshal

func (m *MsgData) Marshal() (dAtA []byte, err error)

func (*MsgData) MarshalTo

func (m *MsgData) MarshalTo(dAtA []byte) (int, error)

func (*MsgData) ProtoMessage

func (*MsgData) ProtoMessage()

func (*MsgData) Reset

func (m *MsgData) Reset()

func (*MsgData) Size

func (m *MsgData) Size() (n int)

func (*MsgData) String

func (m *MsgData) String() string

func (*MsgData) Unmarshal

func (m *MsgData) Unmarshal(dAtA []byte) error

func (*MsgData) XXX_DiscardUnknown

func (m *MsgData) XXX_DiscardUnknown()

func (*MsgData) XXX_Marshal

func (m *MsgData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgData) XXX_Merge

func (m *MsgData) XXX_Merge(src proto.Message)

func (*MsgData) XXX_Size

func (m *MsgData) XXX_Size() int

func (*MsgData) XXX_Unmarshal

func (m *MsgData) XXX_Unmarshal(b []byte) error

type MsgDigest

type MsgDigest []byte

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) MarshalTo

func (m *MsgFindNode) MarshalTo(dAtA []byte) (int, 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 MsgHandler interface {
	Handle(sourceID string, msg Message) error
}

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) MarshalTo

func (m *MsgNeighbors) MarshalTo(dAtA []byte) (int, 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) Descriptor() ([]byte, []int)

func (*MsgPing) GetChainID

func (m *MsgPing) GetChainID() uint32

func (*MsgPing) GetCurTime

func (m *MsgPing) GetCurTime() uint64

func (*MsgPing) GetExpiration

func (m *MsgPing) GetExpiration() uint64

func (*MsgPing) GetFrom

func (m *MsgPing) GetFrom() *RpcEndPoint

func (*MsgPing) GetPK

func (m *MsgPing) GetPK() []byte

func (*MsgPing) GetSign

func (m *MsgPing) GetSign() []byte

func (*MsgPing) GetTo

func (m *MsgPing) GetTo() *RpcEndPoint

func (*MsgPing) GetVersion

func (m *MsgPing) GetVersion() int32

func (*MsgPing) Marshal

func (m *MsgPing) Marshal() (dAtA []byte, err error)

func (*MsgPing) MarshalTo

func (m *MsgPing) MarshalTo(dAtA []byte) (int, error)

func (*MsgPing) ProtoMessage

func (*MsgPing) ProtoMessage()

func (*MsgPing) Reset

func (m *MsgPing) Reset()

func (*MsgPing) Size

func (m *MsgPing) Size() (n int)

func (*MsgPing) String

func (m *MsgPing) String() string

func (*MsgPing) Unmarshal

func (m *MsgPing) Unmarshal(dAtA []byte) error

func (*MsgPing) XXX_DiscardUnknown

func (m *MsgPing) XXX_DiscardUnknown()

func (*MsgPing) XXX_Marshal

func (m *MsgPing) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgPing) XXX_Merge

func (m *MsgPing) XXX_Merge(src proto.Message)

func (*MsgPing) XXX_Size

func (m *MsgPing) XXX_Size() int

func (*MsgPing) XXX_Unmarshal

func (m *MsgPing) XXX_Unmarshal(b []byte) error

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) Descriptor() ([]byte, []int)

func (*MsgPong) GetVerifyResult

func (m *MsgPong) GetVerifyResult() bool

func (*MsgPong) GetVersion

func (m *MsgPong) GetVersion() int32

func (*MsgPong) Marshal

func (m *MsgPong) Marshal() (dAtA []byte, err error)

func (*MsgPong) MarshalTo

func (m *MsgPong) MarshalTo(dAtA []byte) (int, error)

func (*MsgPong) ProtoMessage

func (*MsgPong) ProtoMessage()

func (*MsgPong) Reset

func (m *MsgPong) Reset()

func (*MsgPong) Size

func (m *MsgPong) Size() (n int)

func (*MsgPong) String

func (m *MsgPong) String() string

func (*MsgPong) Unmarshal

func (m *MsgPong) Unmarshal(dAtA []byte) error

func (*MsgPong) XXX_DiscardUnknown

func (m *MsgPong) XXX_DiscardUnknown()

func (*MsgPong) XXX_Marshal

func (m *MsgPong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgPong) XXX_Merge

func (m *MsgPong) XXX_Merge(src proto.Message)

func (*MsgPong) XXX_Size

func (m *MsgPong) XXX_Size() int

func (*MsgPong) XXX_Unmarshal

func (m *MsgPong) XXX_Unmarshal(b []byte) error

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

func InitSelfNode(isSuper bool, ID NodeID) (*Node, error)

InitSelfNode initialize local user's node

func NewNode

func NewNode(ID NodeID, IP net.IP, port int) *Node

NewNode create a new node

func (*Node) Incomplete

func (n *Node) Incomplete() bool

Incomplete is address is Incomplete

func (*Node) String

func (n *Node) String() string

String return node detail description

type NodeID

type NodeID [NodeIDLength]byte

func NewNodeID

func NewNodeID(hex string) *NodeID

func (NodeID) Bytes

func (nid NodeID) Bytes() []byte

func (NodeID) GetHexString

func (nid NodeID) GetHexString() string

func (NodeID) IsValid

func (netID NodeID) IsValid() bool

func (*NodeID) SetBytes

func (nid *NodeID) SetBytes(b []byte)

type Peer

type Peer struct {
	ID NodeID

	IP   net.IP
	Port int
	// contains filtered or unexported fields
}

Peer is node connection object

func (*Peer) AuthContext

func (p *Peer) AuthContext() *PeerAuthContext

func (*Peer) IsCompatible

func (p *Peer) IsCompatible() bool

type PeerAuthContext

type PeerAuthContext struct {
	PK      []byte
	Sign    []byte
	CurTime uint64
}

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

func (*PeerIPSet) Add

func (s *PeerIPSet) Add(ip string) bool

Add add an IP to the set.

func (PeerIPSet) Contains

func (s PeerIPSet) Contains(ip string) bool

Contains whether the given IP is contained in the set.

func (PeerIPSet) Len

func (s PeerIPSet) Len() int

Len returns the number of tracked IPs.

func (*PeerIPSet) Remove

func (s *PeerIPSet) Remove(ip string)

Remove removes an IP from the set.

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 Proposer

type Proposer struct {
	ID    NodeID
	Stake uint64
}

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) MarshalTo

func (m *RpcEndPoint) MarshalTo(dAtA []byte) (int, 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) Descriptor() ([]byte, []int)

func (*RpcNode) GetID

func (m *RpcNode) GetID() string

func (*RpcNode) GetIP

func (m *RpcNode) GetIP() string

func (*RpcNode) GetPort

func (m *RpcNode) GetPort() int32

func (*RpcNode) Marshal

func (m *RpcNode) Marshal() (dAtA []byte, err error)

func (*RpcNode) MarshalTo

func (m *RpcNode) MarshalTo(dAtA []byte) (int, error)

func (*RpcNode) ProtoMessage

func (*RpcNode) ProtoMessage()

func (*RpcNode) Reset

func (m *RpcNode) Reset()

func (*RpcNode) Size

func (m *RpcNode) Size() (n int)

func (*RpcNode) String

func (m *RpcNode) String() string

func (*RpcNode) Unmarshal

func (m *RpcNode) Unmarshal(dAtA []byte) error

func (*RpcNode) XXX_DiscardUnknown

func (m *RpcNode) XXX_DiscardUnknown()

func (*RpcNode) XXX_Marshal

func (m *RpcNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RpcNode) XXX_Merge

func (m *RpcNode) XXX_Merge(src proto.Message)

func (*RpcNode) XXX_Size

func (m *RpcNode) XXX_Size() int

func (*RpcNode) XXX_Unmarshal

func (m *RpcNode) XXX_Unmarshal(b []byte) error

type SendList

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

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
}

func (*Server) AddGroup

func (s *Server) AddGroup(groupID string, members []string) *Group

func (*Server) AddProposers

func (s *Server) AddProposers(proposers []*Proposer)

func (*Server) Broadcast

func (s *Server) Broadcast(msg Message) error

func (*Server) BuildGroupNet

func (s *Server) BuildGroupNet(groupID string, members []string)

func (*Server) BuildProposerGroupNet

func (s *Server) BuildProposerGroupNet(proposers []*Proposer)

func (*Server) ConnInfo

func (s *Server) ConnInfo() []Conn

func (*Server) DissolveGroupNet

func (s *Server) DissolveGroupNet(groupID string)

func (*Server) RemoveGroup

func (s *Server) RemoveGroup(ID string)

func (*Server) Send

func (s *Server) Send(id string, msg Message) error

func (*Server) SpreadAmongGroup

func (s *Server) SpreadAmongGroup(groupID string, msg Message) error

func (*Server) SpreadToGroup

func (s *Server) SpreadToGroup(groupID string, groupMembers []string, msg Message, digest MsgDigest) error

func (*Server) TransmitToNeighbor

func (s *Server) TransmitToNeighbor(msg Message, blacklist []string) error

Jump to

Keyboard shortcuts

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