ethpool

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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 Bucket

type Bucket struct {
	*list.List
	// contains filtered or unexported fields
}

Bucket holds a list of contacts of this node.

func NewBucket

func NewBucket() *Bucket

NewBucket is a Factory method of Bucket, contains an empty list.

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

func New(addressValidator func(common.Address) bool, privKey *ecdsa.PrivateKey) *Framework

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

func (f *Framework) Address() common.Address

Address returns the ethereum address registered with the framework

func (*Framework) Bootstrap

func (f *Framework) Bootstrap()

Bootstrap will ping any connected nodes with a DHT message

func (*Framework) Configure

func (f *Framework) Configure(l *network.Legion) error

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

type ID protobuf.ID

ID wraps helper methods around the protobuf type

func CreateID

func CreateID(address common.Address, networkAddr string) ID

CreateID is a factory function creating ID.

func (ID) AddressHex

func (id ID) AddressHex() string

AddressHex generates a hex-encoded string of the address.

func (ID) Equals

func (id ID) Equals(other ID) bool

Equals returns true if both have the same ethereum address and network address

func (ID) EthereumAddress

func (id ID) EthereumAddress() common.Address

EthereumAddress returns the Ethereum address representation of the ID

func (ID) Less

func (id ID) Less(other interface{}) bool

Less determines if this peer ID's ethereum address is less than other ID's ethereum address.

func (ID) PrefixLen

func (id ID) PrefixLen() int

PrefixLen returns the number of prefixed zeros in a peer ID.

func (ID) String

func (id ID) String() string

String returns the ethereum address and network address

func (ID) Xor

func (id ID) Xor(other ID) ID

Xor performs XOR (^) over another peer ID's public key.

type IncomingMessage

type IncomingMessage struct {
	Sender *protobuf.ID
	Body   proto.Message
	Type   string
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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