Documentation ¶
Index ¶
- Constants
- type Bucket
- type Framework
- func (f *Framework) Address() common.Address
- func (f *Framework) Bootstrap()
- func (f *Framework) Configure(l *network.Legion) error
- func (f *Framework) NewMessage(ctx *network.MessageContext)
- func (f *Framework) PeerDisconnect(ctx *network.PeerContext)
- func (f *Framework) RecieveMessageChan() chan *IncomingMessage
- func (f *Framework) SendMessage(recipient common.Address, messageType string, body proto.Message) error
- func (f *Framework) ValidateMessage(ctx *network.MessageContext) bool
- type ID
- type IncomingMessage
- type RoutingTable
- func (t *RoutingTable) Bucket(id int) *Bucket
- func (t *RoutingTable) FindClosestPeers(target ID, count int) (peers []ID)
- func (t *RoutingTable) GetPeerAddresses() (peers []string)
- func (t *RoutingTable) GetPeers() (peers []ID)
- func (t *RoutingTable) PeerExists(target ID) bool
- func (t *RoutingTable) RemovePeer(target ID) bool
- func (t *RoutingTable) Self() []byte
- func (t *RoutingTable) Update(target ID)
Constants ¶
const BucketSize = 16
BucketSize defines the NodeID, Key, and routing table data structures.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Framework ¶
type Framework struct { // Inherit methods we don't use network.GenericFramework // contains filtered or unexported fields }
Framework is a framework for interacting with other peers using ethereum signatures and a kademlia style DHT, and only accepting messages from peers that are specified as valid.
func New ¶
New returns a Framework that uses the specified function to check if an address is valid, if nil all addresses will be considered valid
func (*Framework) Bootstrap ¶
func (f *Framework) Bootstrap()
Bootstrap will ping any connected nodes with a DHT message
func (*Framework) Configure ¶
Configure is used to set up our keystore, and block until we are ready to send/receive messages
func (*Framework) NewMessage ¶
func (f *Framework) NewMessage(ctx *network.MessageContext)
NewMessage is called when a message is received by the network
func (*Framework) PeerDisconnect ¶
func (f *Framework) PeerDisconnect(ctx *network.PeerContext)
PeerDisconnect is called when a peer is deleted
func (*Framework) RecieveMessageChan ¶
func (f *Framework) RecieveMessageChan() chan *IncomingMessage
RecieveMessageChan returns a channel that receives messages
func (*Framework) SendMessage ¶
func (f *Framework) SendMessage(recipient common.Address, messageType string, body proto.Message) error
SendMessage will send a signed version of the message to specified recipient it will error if the recipient can't be connected to or found
func (*Framework) ValidateMessage ¶
func (f *Framework) ValidateMessage(ctx *network.MessageContext) bool
ValidateMessage is called before any message is passed to the framework NewMessage()
type ID ¶
ID wraps helper methods around the protobuf type
func (ID) AddressHex ¶
AddressHex generates a hex-encoded string of the address.
func (ID) EthereumAddress ¶
EthereumAddress returns the Ethereum address representation of the ID
func (ID) Less ¶
Less determines if this peer ID's ethereum address is less than other ID's ethereum address.
type IncomingMessage ¶
IncomingMessage represents an incoming message after parsing
type RoutingTable ¶
type RoutingTable struct {
// contains filtered or unexported fields
}
RoutingTable contains one bucket list for lookups.
func CreateRoutingTable ¶
func CreateRoutingTable(self ID) *RoutingTable
CreateRoutingTable is a Factory method of RoutingTable containing empty buckets.
func (*RoutingTable) Bucket ¶
func (t *RoutingTable) Bucket(id int) *Bucket
Bucket returns a specific Bucket by ID.
func (*RoutingTable) FindClosestPeers ¶
func (t *RoutingTable) FindClosestPeers(target ID, count int) (peers []ID)
FindClosestPeers returns a list of k(count) peers with smallest XOR distance.
func (*RoutingTable) GetPeerAddresses ¶
func (t *RoutingTable) GetPeerAddresses() (peers []string)
GetPeerAddresses returns a unique list of all peer network addresses within the routing network.
func (*RoutingTable) GetPeers ¶
func (t *RoutingTable) GetPeers() (peers []ID)
GetPeers returns a randomly-ordered, unique list of all peers within the routing network (excluding itself).
func (*RoutingTable) PeerExists ¶
func (t *RoutingTable) PeerExists(target ID) bool
PeerExists checks if a peer exists in the routing table with O(bucket_size) time complexity.
func (*RoutingTable) RemovePeer ¶
func (t *RoutingTable) RemovePeer(target ID) bool
RemovePeer removes a peer from the routing table with O(bucket_size) time complexity.
func (*RoutingTable) Self ¶
func (t *RoutingTable) Self() []byte
Self returns the ID of the node hosting the current routing table instance.
func (*RoutingTable) Update ¶
func (t *RoutingTable) Update(target ID)
Update moves a peer to the front of a bucket in the routing table.