Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeDistance(peer1, peer2 encoding.PeerInfo) (uint16, [16]byte)
- func DidNetworkReceivedMsg(nodes []*Node, senderIndex int, sentBlock *block.Block) bool
- func GetOutboundIP() net.IP
- func InitBootstrap(router *RoutingTable, bootNodes []encoding.PeerInfo) error
- func JoinNetwork(router *RoutingTable, bootstrapAddrs []string)
- func StartNetworkDiscovery(router *RoutingTable, d time.Duration)
- func TestReceivedMsgOnce(t *testing.T, nodes []*Node, i int, blk *block.Block)
- func TraceRoutingState(r *RoutingTable)
- type ByXORDist
- type Maintainer
- type Node
- type Peer
- type PeerSort
- type RaptorCodeReader
- type Reader
- type RoutingTable
- type Tree
- type Writer
Constants ¶
const ( // MaxTCPacketSize is the max size allowed of TCP packet. MaxTCPacketSize = 500000 // MaxUDPacketSize max size of a UDP packet. As per default MTU 1500, UDP // packet should be up to 1472 bytes. MaxUDPacketSize = 1472 )
const Alpha int = 3
Alpha is the number of nodes to which a node will ask for new nodes with `FIND_NODES` messages.
const InitHeight byte = 128
InitHeight sets the default initial height for a broadcast process.
const (
// MaxFrameSize is set based on max block size expected.
MaxFrameSize = 500000
)
Variables ¶
var DefaultAlphaClosestNodes int = 1
DefaultAlphaClosestNodes the node looks up the α closest nodes regarding the XOR-metric in its own buckets.
var DefaultKNumber int = 20
DefaultKNumber is the K number of peers that a node will send on a `FIND_NODES` message.
var DefaultMaxBetaDelegates uint8 = 3
DefaultMaxBetaDelegates maximum number of delegates per bucket.
var DefaultMaxBucketPeers uint8 = 25
DefaultMaxBucketPeers is the maximum number of peers that a `bucket` can hold.
var ErrExceedMaxLen = errors.New("message size exceeds max frame length")
ErrExceedMaxLen is the error thrown if the message size exceeds the max frame length.
Functions ¶
func ComputeDistance ¶ added in v0.4.0
ComputeDistance returns both bucket number and XOR distance between two Peers.
func DidNetworkReceivedMsg ¶ added in v0.4.0
DidNetworkReceivedMsg checks if all network nodes have received the msgPayload only once.
func GetOutboundIP ¶ added in v0.4.0
GetOutboundIP returns local address.
func InitBootstrap ¶
func InitBootstrap(router *RoutingTable, bootNodes []encoding.PeerInfo) error
InitBootstrap inits the Bootstrapping process by sending a `PING` message to every bootstrapping node repeatedly. If it tried 3 or more times and no new `Peers` were added, it panics. Otherways, it returns `nil` and logs the Number of peers the node is connected to at the end of the process.
func JoinNetwork ¶ added in v0.4.0
func JoinNetwork(router *RoutingTable, bootstrapAddrs []string)
JoinNetwork makes attempts to join the network based on the configured bootstrapping nodes.
func StartNetworkDiscovery ¶
func StartNetworkDiscovery(router *RoutingTable, d time.Duration)
StartNetworkDiscovery triggers the network discovery process. The node basically sends `FIND_NODES` messages to the nodes it is currently connected to and evaluates the `Peers` that were added on each iteration. If the closest peer to ours is the same during two iterations of the `FIND_NODES` message, we finish the process logging the ammout of peers we are currently connected to. Otherways, if the closest Peer on two consecutive iterations changes, we keep queriyng the `alpha` closest nodes with `FIND_NODES` messages.
func TestReceivedMsgOnce ¶ added in v0.4.0
TestReceivedMsgOnce check periodically (up to 7 sec) if network has received the message.
func TraceRoutingState ¶ added in v0.3.0
func TraceRoutingState(r *RoutingTable)
TraceRoutingState logs the routing table of a peer.
Types ¶
type ByXORDist ¶
type ByXORDist []PeerSort
ByXORDist implements sort.Interface based on the IdDistance respective to myPeerId.
type Maintainer ¶ added in v0.4.0
type Maintainer struct {
// contains filtered or unexported fields
}
Maintainer is responsible for building and maintaining Kadcast routing state.
func NewMaintainer ¶ added in v0.4.0
func NewMaintainer(rtable *RoutingTable) *Maintainer
NewMaintainer returns a UDP Reader for maintaining routing state up-to-date.
func (*Maintainer) Close ¶ added in v0.4.0
func (m *Maintainer) Close() error
Close terminates udp read loop. Even terminated, there might be some processPacket routines still running a job.
func (*Maintainer) Serve ¶ added in v0.4.0
func (m *Maintainer) Serve()
Serve starts maintainer main loop of listening and handling UDP packets.
type Node ¶ added in v0.4.0
type Node struct { Router *RoutingTable EventBus *eventbus.EventBus Lock sync.RWMutex Blocks []*block.Block Duplicated bool }
Node a very limited instance of a node running kadcast peer only.
func TestNetwork ¶ added in v0.3.0
TestNetwork initiates kadcast network bootstraping of N nodes. This will run a set of nodes bound on local addresses (port per node), execute bootstrapping and network discovery.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer is a wrapper of all 2 kadcast processing routing.
type PeerSort ¶
type PeerSort struct {
// contains filtered or unexported fields
}
PeerSort is a helper type to sort `Peers`.
type RaptorCodeReader ¶ added in v0.4.0
type RaptorCodeReader struct {
// contains filtered or unexported fields
}
RaptorCodeReader is rc-udp based listener that reads Broadcast messages from the Kadcast network and delegates their processing to the messageRouter.
func NewRaptorCodeReader ¶ added in v0.4.0
func NewRaptorCodeReader(lpeerInfo encoding.PeerInfo, publisher eventbus.Publisher, gossip *protocol.Gossip, dupeMap *dupemap.DupeMap) *RaptorCodeReader
NewRaptorCodeReader makes an instance of RaptorCodeReader.
func (*RaptorCodeReader) Close ¶ added in v0.4.0
func (r *RaptorCodeReader) Close() error
Close closes reader TCP listener.
func (*RaptorCodeReader) Serve ¶ added in v0.4.0
func (r *RaptorCodeReader) Serve()
Serve starts accepting and processing TCP connection and packets.
type Reader ¶ added in v0.4.0
type Reader struct {
// contains filtered or unexported fields
}
Reader is running a TCP listner handling TCP Broadcast packets from kadcast network
On a TCP connection Read a single tcp packet from the accepted connection Validate the packet Extract Gossip Packet Build and Publish eventBus message The alternative to this reader is the RaptorCodeReader that is based on RC-UDP.
func NewReader ¶ added in v0.4.0
func NewReader(lpeerInfo encoding.PeerInfo, publisher eventbus.Publisher, gossip *protocol.Gossip, dupeMap *dupemap.DupeMap) *Reader
NewReader makes a new kadcast reader that handles TCP packets of broadcasting.
type RoutingTable ¶ added in v0.4.0
RoutingTable holds all of the data needed to interact with the routing data and also the networking utils.
func MakeRoutingTable ¶ added in v0.4.0
func MakeRoutingTable(address string) RoutingTable
MakeRoutingTable allows to create a router which holds the peerInfo and also the routing tree information.
func TestRouter ¶ added in v0.4.0
func TestRouter(port uint16, id [16]byte) *RoutingTable
TestRouter creates a peer router with a fixed id.
func (*RoutingTable) GetTotalPeers ¶ added in v0.4.0
func (rt *RoutingTable) GetTotalPeers() uint64
GetTotalPeers the total amount of peers that a `Peer` is connected to.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree stores `L` buckets inside of it. This is basically the routing info of every peer.
type Writer ¶ added in v0.4.0
type Writer struct {
// contains filtered or unexported fields
}
Writer abstracts all of the logic and fields needed to write messages to other network nodes.
func NewWriter ¶ added in v0.4.0
func NewWriter(router *RoutingTable, subscriber eventbus.Subscriber, gossip *protocol.Gossip, raptorCodeEnabled bool) *Writer
NewWriter returns a Writer. It will still need to be initialized by subscribing to the gossip topic with a stream handler, and by running the WriteLoop in a goroutine..