Documentation ¶
Index ¶
- Constants
- func CheckRelayIP(sender, addr net.IP) error
- func GetConnectedChains(boots []*ChainDataNodes, centre common.ChainID) common.ChainIDs
- func GetTargetChain(boots []*ChainDataNodes, selfChain common.ChainID, targetChain common.ChainID) common.ChainID
- func GetVisitChainIds(boots []*ChainDataNodes, centre common.ChainID) common.ChainIDs
- func IsIn(cids common.ChainIDs, cid common.ChainID) bool
- func IsLAN(ip net.IP) bool
- func IsSpecialNetwork(ip net.IP) bool
- func IsTemporaryError(err error) bool
- func SameNet(bits uint, ip, other net.IP) bool
- type AbsTime
- type ChainDataNodes
- type ChanTimer
- type Clock
- type DiscoverTable
- type Discovery
- type DiscoveryType
- type DistinctNetSet
- type Netlist
- type Node
- type P2PConfig
- type ReadPacket
- type STable
- func (tab *STable) Close()
- func (tab *STable) Find(target common.NodeID) *Node
- func (tab *STable) GetAccessChains() common.ChainIDs
- func (tab *STable) GetDataNodes() []*ChainDataNodes
- func (tab *STable) Len() (n int)
- func (tab *STable) Lookup(target interface{}) []*Node
- func (tab *STable) ReadRandomNodes(buf []*Node) (n int)
- func (tab *STable) Resolve(targetID common.NodeID) *Node
- func (tab *STable) Self() *Node
- func (tab *STable) SetTmpNodes(dataNodes []*ChainDataNodes)
- func (tab *STable) SwitchToTmpNodes()
- type System
- type Table
- func (tab *Table) Close()
- func (tab *Table) GetAccessChains() common.ChainIDs
- func (tab *Table) GetDataNodes() []*ChainDataNodes
- func (tab *Table) Len() (n int)
- func (tab *Table) Lookup(targetID interface{}) []*Node
- func (tab *Table) ReadRandomNodes(buf []*Node) (n int)
- func (tab *Table) Resolve(targetID common.NodeID) *Node
- func (tab *Table) Self() *Node
- func (tab *Table) SetTmpNodes(dataNodes []*ChainDataNodes)
- func (tab *Table) SwitchToTmpNodes()
- type Timer
- type UDPConfig
Constants ¶
const MaxPeersPerChain = 10
const (
// sort tab size
SortTableSize = 64
)
Variables ¶
This section is empty.
Functions ¶
func CheckRelayIP ¶
CheckRelayIP reports whether an IP relayed from the given sender IP is a valid connection target.
There are four rules:
- Special network addresses are never valid.
- Loopback addresses are OK if relayed by a loopback host.
- LAN addresses are OK if relayed by a LAN host.
- All other addresses are always acceptable.
func GetConnectedChains ¶
func GetConnectedChains(boots []*ChainDataNodes, centre common.ChainID) common.ChainIDs
get all the connected chains
func GetTargetChain ¶
func GetTargetChain(boots []*ChainDataNodes, selfChain common.ChainID, targetChain common.ChainID) common.ChainID
find a chain who was closet to the target chain
func GetVisitChainIds ¶
func GetVisitChainIds(boots []*ChainDataNodes, centre common.ChainID) common.ChainIDs
Get the chainId list which needs to dial out
func IsSpecialNetwork ¶
IsSpecialNetwork reports whether an IP is located in a special-use network range This includes broadcast, multicast and documentation addresses.
func IsTemporaryError ¶
Types ¶
type AbsTime ¶
AbsTime represents absolute monotonic time.
type ChainDataNodes ¶
type ChainDataNodes struct { ChainId common.ChainID DataNodes []*Node }
func ToChainDataNodes ¶
func ToChainDataNodes(net common.NetType, bootId common.ChainID, infos []*common.ChainInfos) []*ChainDataNodes
type ChanTimer ¶
type ChanTimer interface { Timer // The channel returned by C receives a value when the timer expires. C() <-chan AbsTime // Reset reschedules the timer with a new timeout. // It should be invoked only on stopped or expired timers with drained channels. Reset(time.Duration) }
ChanTimer is a cancellable event created by NewTimer.
type Clock ¶
type Clock interface { Now() AbsTime Sleep(time.Duration) NewTimer(time.Duration) ChanTimer After(time.Duration) <-chan AbsTime AfterFunc(d time.Duration, f func()) Timer }
The Clock interface makes it possible to replace the monotonic system clock with a simulated clock.
type DiscoverTable ¶
type DiscoverTable interface { Self() *Node Close() // modify by gy Len() int Resolve(target common.NodeID) *Node Lookup(target interface{}) []*Node ReadRandomNodes([]*Node) int // FOR SORT TABLE GetDataNodes() []*ChainDataNodes GetAccessChains() common.ChainIDs SetTmpNodes(dataNodes []*ChainDataNodes) SwitchToTmpNodes() }
type Discovery ¶
type Discovery interface { // discovery type Type() DiscoveryType // version Version() uint32 // read msg from udp connection NodeTable() DiscoverTable //Get chainid from tab GetChainID(id common.NodeID) (common.ChainID, error) // ping Ping(common.NodeID, *net.UDPAddr) error // find node FindNode(toid common.NodeID, addr *net.UDPAddr, target interface{}) (map[common.ChainID][]*Node, error) // close Close() error }
func SetupDiscoveryKAD ¶
ListenUDP returns a new table that listens for UDP packets on laddr.
type DiscoveryType ¶
type DiscoveryType string
const ( KAD DiscoveryType = "KAD" SRT DiscoveryType = "SORT" )
func (DiscoveryType) IsKAD ¶
func (d DiscoveryType) IsKAD() bool
func (DiscoveryType) IsSRT ¶
func (d DiscoveryType) IsSRT() bool
type DistinctNetSet ¶
type DistinctNetSet struct { Subnet uint // number of common prefix bits Limit uint // maximum number of IPs in each subnet // contains filtered or unexported fields }
DistinctNetSet tracks IPs, ensuring that at most N of them fall into the same network range.
func (*DistinctNetSet) Add ¶
func (s *DistinctNetSet) Add(ip net.IP) bool
Add adds an IP address to the set. It returns false (and doesn't add the IP) if the number of existing IPs in the defined range exceeds the limit.
func (DistinctNetSet) Contains ¶
func (s DistinctNetSet) Contains(ip net.IP) bool
Contains whether the given IP is contained in the set.
func (DistinctNetSet) Len ¶
func (s DistinctNetSet) Len() int
Len returns the number of tracked IPs.
func (*DistinctNetSet) Remove ¶
func (s *DistinctNetSet) Remove(ip net.IP)
Remove removes an IP from the set.
func (DistinctNetSet) String ¶
func (s DistinctNetSet) String() string
String implements fmt.Stringer
type Netlist ¶
Netlist is a list of IP networks.
func (*Netlist) Add ¶
Add parses a CIDR mask and appends it to the list. It panics for invalid masks and is intended to be used for setting up static lists.
func (Netlist) MarshalTOML ¶
func (l Netlist) MarshalTOML() interface{}
MarshalTOML implements toml.MarshalerRec.
func (*Netlist) UnmarshalTOML ¶
UnmarshalTOML implements toml.UnmarshalerRec.
type Node ¶
type Node struct { ID common.NodeID IP net.IP TCP uint16 UDP uint16 RPC uint16 PUB []byte Hash common.Hash // contains filtered or unexported fields }
p2p node struct
func (*Node) GetRpcAddress ¶
func (*Node) GetTcpAddress ¶
func (*Node) GetUdpAddress ¶
func (*Node) Incomplete ¶
type P2PConfig ¶
type P2PConfig struct { DatabasePath string BootstrapNodes []*Node StaticNodes []*Node TrustedNodes []*Node NetRestrict *Netlist ListenAddr string MaxPeersCount int MaxPendCount int DialRatio int Nat nat.Nat AnnounceAddr *net.UDPAddr DiscoveryType DiscoveryType ChainDataNodes []*ChainDataNodes Clock Clock }
type ReadPacket ¶
ReadPacket is sent to the unhandled channel when it could not be processed
type STable ¶
type STable struct {
// contains filtered or unexported fields
}
func (*STable) Close ¶
func (tab *STable) Close()
Close terminates the network listener and flushes the node database.
func (*STable) GetAccessChains ¶
func (tab *STable) GetAccessChains() common.ChainIDs
Server uses this to filter the keys of ChainToPeers,close the peers in value if the key is not in return list
func (*STable) 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 (*STable) 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.
func (*STable) Resolve ¶
Resolve searches for a specific node with the given ID. It returns nil if the node could not be found.
func (*STable) Self ¶
Self returns the local node. The returned node should not be modified by the caller.
func (*STable) SetTmpNodes ¶
func (tab *STable) SetTmpNodes(dataNodes []*ChainDataNodes)
Update the tmp nodes when chain structure was changed
type System ¶
type System struct{}
System implements Clock using the system clock.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) GetAccessChains ¶
func (tab *Table) GetAccessChains() common.ChainIDs
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.
func (*Table) Resolve ¶
Resolve searches for a specific node with the given ID. It returns nil if the node could not be found.
func (*Table) Self ¶
Self returns the local node. The returned node should not be modified by the caller.
func (*Table) SetTmpNodes ¶
func (tab *Table) SetTmpNodes(dataNodes []*ChainDataNodes)
func (*Table) SwitchToTmpNodes ¶
func (tab *Table) SwitchToTmpNodes()
type Timer ¶
type Timer interface { // Stop cancels the timer. It returns false if the timer has already // expired or been stopped. Stop() bool }
Timer is a cancellable event created by AfterFunc.
type UDPConfig ¶
type UDPConfig struct { ChainID common.ChainID BootId common.ChainID NetType common.NetType // 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 Bootnodes []*Node // list of bootstrap nodes ChainDataNodes []*ChainDataNodes }
Config holds Table-related settings.