Documentation ¶
Overview ¶
Package discover implements the Node Discovery Protocol.
The Node Discovery protocol provides a way to find RLPx nodes that can be connected to. It uses a Kademlia-like protocol to maintain a distributed database of the IDs and endpoints of all listening nodes.
Index ¶
- Constants
- Variables
- func Compress(c []byte) (string, error)
- func Decode2(s string, datatype string) (interface{}, error)
- func Encode2(obj interface{}) (string, error)
- func GetEnode() string
- func GetEnodeStatus(enode string) (string, string)
- func GetLocalIP() string
- func GetRemoteIP() string
- func GetRemotePort() string
- func InitGroup(groupsNum, nodesNum int) error
- func ParseNodes(n []*Node) (int, string)
- func PingNode(id NodeID, ip net.IP, port int) error
- func RecoverGroupAll(SdkGroup map[NodeID]*Group) error
- func RegisterDcrmMsgCallback(callbackfunc func(interface{}) <-chan string)
- func RegisterDcrmMsgRetCallback(callbackfunc func(interface{}))
- func RegisterGroupCallback(callbackfunc func(NodeID, string, interface{}, int, string))
- func RegisterPriKeyCallback(callbackfunc func(interface{}))
- func RegisterSdkMsgCallback(sdkbackfunc func(interface{}, string) <-chan string)
- func RegisterSdkMsgRetCallback(sdkbackfunc func(interface{}, string))
- func RegisterSendCallback(callbackfunc func(interface{}))
- func RegisterUpdateOrderCacheCallback(callbackfunc func(interface{}))
- func RegisterXpMsgCallback(callbackfunc func(interface{}) <-chan string)
- func RegisterXpMsgRetCallback(callbackfunc func(interface{}))
- func SendMsgToNode(toid NodeID, toaddr *net.UDPAddr, msg string) error
- func SendToGroup(gid NodeID, msg string, allNodes bool, p2pType int, gg []*Node) (string, error)
- func SendToGroupCC(toid NodeID, toaddr *net.UDPAddr, msg string, p2pType int) (string, error)
- func SendToMyselfAndReturn(selfID, msg string, p2pType int)
- func SendToPeer(gid, toid NodeID, toaddr *net.UDPAddr, msg string, p2pType int) error
- func StartCreateSDKGroup(gid NodeID, mode string, enode []*Node, Type string) string
- func StoreGroupToDb(groupInfo *Group) error
- func UnCompress(s string) (string, error)
- func UpdateGroupNodesNumber(number, p2pType int)
- type Config
- type Group
- type Node
- type NodeID
- type ReadPacket
- type RpcNode
- type Table
Constants ¶
const ( Dcrmprotocol_type = iota + 1 Xprotocol_type Sdkprotocol_type Dcrm_findGroupPacket = iota + 10 + neighborsPacket //14 Xp_findGroupPacket Sdk_findGroupPacket Dcrm_groupPacket Sdk_groupPacket Xp_groupPacket Dcrm_groupInfoPacket Sdk_groupStatusPacket PeerMsgPacket Xp_getCCPacket )
const NodeIDBits = 512
Variables ¶
var ( Dcrmdelimiter = "dcrmmsg" Dcrm_groupList *Group Xp_groupList *Group RemoteIP = "127.0.0.1" RemotePort = "0" RemoteUpdate = false Xp_changed = 0 SDK_groupList map[NodeID]*Group = make(map[NodeID]*Group) SelfID = "" )
var ( Dcrm_groupMemNum = 0 Xp_groupMemNum = 0 SDK_groupNum = 0 )
Functions ¶
func GetEnodeStatus ¶
func GetLocalIP ¶
func GetLocalIP() string
func GetRemoteIP ¶
func GetRemoteIP() string
func GetRemotePort ¶
func GetRemotePort() string
func ParseNodes ¶
func RecoverGroupAll ¶
func RegisterDcrmMsgCallback ¶
func RegisterDcrmMsgCallback(callbackfunc func(interface{}) <-chan string)
func RegisterDcrmMsgRetCallback ¶
func RegisterDcrmMsgRetCallback(callbackfunc func(interface{}))
func RegisterGroupCallback ¶
func RegisterPriKeyCallback ¶
func RegisterPriKeyCallback(callbackfunc func(interface{}))
func RegisterSdkMsgCallback ¶
func RegisterSdkMsgRetCallback ¶
func RegisterSdkMsgRetCallback(sdkbackfunc func(interface{}, string))
func RegisterSendCallback ¶
func RegisterSendCallback(callbackfunc func(interface{}))
func RegisterUpdateOrderCacheCallback ¶
func RegisterUpdateOrderCacheCallback(callbackfunc func(interface{}))
func RegisterXpMsgCallback ¶
func RegisterXpMsgCallback(callbackfunc func(interface{}) <-chan string)
func RegisterXpMsgRetCallback ¶
func RegisterXpMsgRetCallback(callbackfunc func(interface{}))
func SendMsgToNode ¶
send group info
func SendToGroup ¶
func SendToGroupCC ¶
func SendToMyselfAndReturn ¶
func SendToPeer ¶
func StartCreateSDKGroup ¶
func StoreGroupToDb ¶
func UnCompress ¶
func UpdateGroupNodesNumber ¶
func UpdateGroupNodesNumber(number, p2pType int)
Types ¶
type Config ¶
type Config struct { // These settings are required and configure the UDP listener: PrivateKey *ecdsa.PrivateKey // These settings are optional: AnnounceAddr *net.UDPAddr // local address announced in the DHT NodeDBPath string // if set, the node database is stored at this filesystem location NetRestrict *netutil.Netlist // network whitelist Bootnodes []*Node // list of bootstrap nodes Unhandled chan<- ReadPacket // unhandled packets are sent on this channel }
Config holds Table-related settings.
type Group ¶
type Group struct { sync.Mutex ID NodeID //Gname string Mode string // 2/3 P2pType byte Nodes []RpcNode Type string // group type: 1+2, 1+1+1 //userID []string Expiration uint64 // Ignore additional fields (for forward compatibility). Rest []rlp.RawValue `rlp:"tail"` // contains filtered or unexported fields }
func RecoverGroupByGID ¶
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 represents a host on the network. The fields of Node may not be modified.
func MustParseNode ¶
MustParseNode parses a node URL. It panics if the URL is not valid.
func ParseNode ¶
ParseNode parses a node designator.
There are two basic forms of node designators
- incomplete nodes, which only have the public key (node ID)
- complete nodes, which contain the public key and IP/Port information
For incomplete nodes, the designator must look like one of these
enode://<hex node id> <hex node id>
For complete nodes, the node ID is encoded in the username portion of the URL, separated from the host by an @ sign. The hostname can only be given as an IP address, DNS domain names are not allowed. The port in the host name section is the TCP listening port. If the TCP and UDP (discovery) ports differ, the UDP port is specified as query parameter "discport".
In the following example, the node URL describes a node with IP address 10.3.58.6, TCP listening port 30303 and UDP discovery port 30301.
enode://<hex node id>@10.3.58.6:30303?discport=30301
func (*Node) Incomplete ¶
Incomplete returns true for nodes with no IP address.
func (*Node) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Node) String ¶
The string representation of a Node is a URL. Please see ParseNode for a description of the format.
func (*Node) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type NodeID ¶
type NodeID [NodeIDBits / 8]byte
NodeID is a unique identifier for each node. The node identifier is a marshaled elliptic curve public key.
func GetLocalID ¶
func GetLocalID() NodeID
func MustBytesID ¶
MustBytesID converts a byte slice to a NodeID. It panics if the byte slice is not a valid NodeID.
func MustHexID ¶
MustHexID converts a hex string to a NodeID. It panics if the string is not a valid NodeID.
func (NodeID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (NodeID) Pubkey ¶
Pubkey returns the public key represented by the node ID. It returns an error if the ID is not a point on the curve.
func (NodeID) TerminalString ¶
TerminalString returns a shortened hex string for terminal logging.
func (*NodeID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type ReadPacket ¶
ReadPacket is sent to the unhandled channel when it could not be processed
type RpcNode ¶
type RpcNode struct { IP net.IP // len 4 for IPv4 or 16 for IPv6 UDP uint16 // for discovery protocol TCP uint16 // for RLPx protocol ID NodeID }
RPC request structures
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
var Table4group *Table
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) Lookup ¶
Lookup performs a network search for nodes close to the given target. It approaches the target by querying nodes that are closer to it on each iteration. The given target does not need to be an actual node identifier.
func (*Table) ReadRandomNodes ¶
ReadRandomNodes fills the given slice with random nodes from the table. It will not write the same node more than once. The nodes in the slice are copies and can be modified by the caller.