dual

package
v0.0.0-...-eca426a Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (

	// messaging with group routing table
	OP_GROUP_MULTICAST   = 0x02 // register outbound target in group routing table
	OP_REQUEST_GROUP     = 0x03
	OP_REQUEST_GROUP_SUB = 0x04
	OP_REQUEST_JOIN      = 0x05
	OP_JOIN_GROUP        = 0x06
	OP_FED_COMP          = 0x07
	OP_REPORT            = 0x08

	OP_ONE_TIME = 0x09
	OP_NEW_CONN = 0x10
	OP_DISCOVER = 0x11

	// hybrid fed comp
	OP_FED_COMP_PUSH     = 0x12
	OP_FED_COMP_PULL_REQ = 0x13

	// general gossip messaging
	OP_GOSSIP_PUSH_ONLY = 0x14
	OP_GOSSIP_PUSH      = 0x15
	OP_GOSSIP_PULL_REQ  = 0x16
)

protocol opcode

View Source
const (
	ID_NOBODY    = 0x00
	ID_PUBLISHER = 0x01
	ID_INITIATOR = 0x02
	ID_SUBLEADER = 0x03
	ID_WORKER    = 0x04
)

Identification state

View Source
const (
	NOOP = 0x00
	// Project state
	STATE_PUBLISHED = 0x01
	STATE_ACTIVE    = 0x02
	STATE_COMMITTED = 0x03

	MSG_TYPE_ADMSG   = 0x04
	MSG_TYPE_SUBSMSG = 0x05
)

protocol opcode

View Source
const BucketSize int = 16

BucketSize returns the capacity, or the total number of peer ID entries a single routing table bucket may hold.

Variables

View Source
var ErrBucketFull = errors.New("bucket is full")

ErrBucketFull is returned when a routing table bucket is at max capacity.

Functions

func CreateUUID

func CreateUUID() string

func PrefixDiff

func PrefixDiff(a, b []byte, n int) int

PrefixDiff counts the number of equal prefixed bits of a and b.

func PrefixLen

func PrefixLen(a []byte) int

PrefixLen returns the number of prefixed zero bits of a.

func SortByDistance

func SortByDistance(id GRING.PublicKey, ids []GRING.ID) []GRING.ID

SortByDistance sorts ids by descending XOR distance with respect to id.

func XOR

func XOR(a, b []byte) []byte

XOR allocates a new byte slice with the computed result of XOR(a, b).

Types

type ADMessage

type ADMessage struct {
	PjtID   []byte
	PubID   GRING.ID
	PjtDesc []byte
}

func UnmarshalADMessage

func UnmarshalADMessage(buf []byte) (ADMessage, error)

func (ADMessage) Marshal

func (m ADMessage) Marshal() []byte

type ADtoken

type ADtoken struct {
	PjtID       string
	NumToken    uint32
	MaxNumToken uint32
}

internal data. user cannot control PubSub protocol creates N tokens every T time

type Deny

type Deny struct{}

func UnmarshalDeny

func UnmarshalDeny([]byte) (Deny, error)

func (Deny) Marshal

func (r Deny) Marshal() []byte

type DownloadMessage

type DownloadMessage struct {
	UUID     []byte //32bytes for plain, 34bytes for encoded
	Contents []byte
}

func UnmarshalDownloadMessage

func UnmarshalDownloadMessage(buf []byte) (DownloadMessage, error)

func (DownloadMessage) Marshal

func (m DownloadMessage) Marshal() []byte

type Events

type Events struct {
	// OnPeerAdmitted is called when a peer is admitted to being inserted into your nodes' routing table.
	OnPeerAdmitted_bc func(id GRING.ID)

	// OnPeerAdmitted is called when a peer is admitted to being inserted into your nodes' routing table.
	OnPeerAdmitted_gr func(id GRING.ID)

	// OnPeerContacted is called when a peer is contacting this node. It is for collecting subscribers.
	OnPeerContacted func(id GRING.ID)

	// OnPeerActivity is called when your node interacts with a peer, causing the peer's entry in your nodes' routing
	// table to be bumped to the head of its respective bucket.
	OnPeerActivity func(id GRING.ID)

	// OnPeerEvicted is called when your node fails to ping/dial a peer that was previously admitted into your nodes'
	// routing table, which leads to an eviction of the peers ID from your nodes' routing table.
	OnPeerEvicted func(id GRING.ID)

	OnRequestGroup func(msg P2pMessage)

	OnRequestGroupSub func(msg P2pMessage)

	OnRequestJoin func(msg P2pMessage)

	OnSortByMetric func(list map[string]Subscriber) []Subscriber

	OnJoinGroup func(msg P2pMessage)

	OnQueryGroupInfo func() []byte

	OnAggregateGroupInfo func([][]byte)

	OnGroupDone func(msg P2pMessage)

	OnFedComputation func(msg P2pMessage)

	OnReport func(msg P2pMessage)

	OnFedComputationPush func(msg GossipMessage, ctx GRING.HandlerContext)

	OnFedComputationPullReq func(msg GossipMessage, ctx GRING.HandlerContext)

	OnFedComputationPull func(msg GossipMessage, ctx GRING.HandlerContext)

	OnRecvGossipPush func(msg GossipMessage, ctx GRING.HandlerContext)

	OnRecvGossipPullReq func(msg GossipMessage, ctx GRING.HandlerContext)

	OnRecvRelayMessage func(msg RelayMessage, ctx GRING.HandlerContext)

	OnRecvGossipMsg func(msg GossipMessage)
}

Events comprise of callbacks that are to be called upon the encountering of various events as a node follows the Kademlia protocol. An Events declaration may be registered to a Protocol upon instantiation through calling New with the WithProtocolEvents functional option.

type FindNodeRequest

type FindNodeRequest struct {
	Target GRING.PublicKey
}

FindNodeRequest represents a FIND_NODE RPC call in the Kademlia specification. It contains a target public key to which a peer is supposed to respond with a slice of IDs that neighbor the target ID w.r.t. XOR distance.

func UnmarshalFindNodeRequest

func UnmarshalFindNodeRequest(buf []byte) (FindNodeRequest, error)

UnmarshalFindNodeRequest decodes buf, which must be the exact size of a public key, into a FindNodeRequest. It throws an io.ErrUnexpectedEOF if buf is malformed.

func (FindNodeRequest) Marshal

func (r FindNodeRequest) Marshal() []byte

Marshal implements GRING.Serializable and returns the public key of the target for this search request as a byte slice.

type FindNodeResponse

type FindNodeResponse struct {
	Results []GRING.ID
}

FindNodeResponse returns the results of a FIND_NODE RPC call which comprises of the IDs of peers closest to a target public key specified in a FindNodeRequest.

func UnmarshalFindNodeResponse

func UnmarshalFindNodeResponse(buf []byte) (FindNodeResponse, error)

UnmarshalFindNodeResponse decodes buf, which is expected to encode a list of closest peer ID results, into a FindNodeResponse. It throws an io.ErrUnexpectedEOF if buf is malformed.

func (FindNodeResponse) Marshal

func (r FindNodeResponse) Marshal() []byte

Marshal implements GRING.Serializable and encodes the list of closest peer ID results into a byte representative of the length of the list, concatenated with the serialized byte representation of the peer IDs themselves.

type GossipMessage

type GossipMessage struct {
	Opcode   byte
	Type     byte   // type of contents e.g. nested msg type in contents
	UUID     []byte //32bytes for plain, 34bytes for encoded
	Count    uint32
	TargetID GRING.ID //ID is publickey
	List     []byte
	Contents []byte
}

func UnmarshalGossipMessage

func UnmarshalGossipMessage(buf []byte) (GossipMessage, error)

func (GossipMessage) Marshal

func (m GossipMessage) Marshal() []byte

type Iterator

type Iterator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Iterator represents a S/Kademlia overlay network iterator over all peers that may be discovered in the network. It is used for peer discovery, and for finding peers by their public key over an overlay network.

func NewIterator

func NewIterator(node *GRING.Node, table *Table, opts ...IteratorOption) *Iterator

NewIterator instantiates a new overlay network iterator bounded to a node and routing table that may be optionally configured with a variadic list of functional options.

func (*Iterator) Find

func (it *Iterator) Find(target GRING.PublicKey) []GRING.ID

Find attempts to salvage through the Kademlia overlay network through the peers of the node this iterator is bound to for a target public key. It blocks the current goroutine until the search is complete.

type IteratorOption

type IteratorOption func(it *Iterator)

IteratorOption represents a functional option which may be passed to NewIterator, or to (*Protocol).Find or (*Protocol).Discover to configure Iterator.

func WithIteratorLogger

func WithIteratorLogger(logger *zap.Logger) IteratorOption

WithIteratorLogger configures the logger instance for an iterator. By default, the logger used is the logger of the node which the iterator is bound to.

func WithIteratorLookupTimeout

func WithIteratorLookupTimeout(lookupTimeout time.Duration) IteratorOption

WithIteratorLookupTimeout sets the max duration to wait until we declare a lookup request sent in amidst a single disjoint lookup to have timed out. By default, it is set to 3 seconds.

func WithIteratorMaxNumResults

func WithIteratorMaxNumResults(maxNumResults int) IteratorOption

WithIteratorMaxNumResults sets the max number of resultant peer IDs from a single (*Iterator).Find call. By default, it is set to the max capacity of a routing table bucket which is 16 based on the S/Kademlia paper.

func WithIteratorNumParallelLookups

func WithIteratorNumParallelLookups(numParallelLookups int) IteratorOption

WithIteratorNumParallelLookups sets the max number of parallel disjoint lookups that may occur at once while executing (*Iterator).Find. By default, it is set to 3 based on the S/Kademlia paper.

func WithIteratorNumParallelRequestsPerLookup

func WithIteratorNumParallelRequestsPerLookup(numParallelRequestsPerLookup int) IteratorOption

WithIteratorNumParallelRequestsPerLookup sets the max number of parallel requests a single disjoint lookup may make during the execution of (*Iterator).Find. By default, it is set to 8 based on the S/Kademlia paper.

type P2pMessage

type P2pMessage struct {
	Aggregation uint32
	Opcode      byte
	Contents    []byte
}

func (P2pMessage) Marshal

func (m P2pMessage) Marshal() []byte

type Ping

type Ping struct{}

Ping represents an empty ping message.

func UnmarshalPing

func UnmarshalPing([]byte) (Ping, error)

UnmarshalPing returns a Ping instance and never throws an error.

func (Ping) Marshal

func (r Ping) Marshal() []byte

Marshal implements GRING.Serializable and returns a nil byte slice.

type Pong

type Pong struct{}

Pong represents an empty pong message.

func UnmarshalPong

func UnmarshalPong([]byte) (Pong, error)

UnmarshalPong returns a Pong instance and never throws an error.

func (Pong) Marshal

func (r Pong) Marshal() []byte

Marshal implements GRING.Serializable and returns a nil byte slice.

type Project

type Project struct {
	Owner    GRING.ID // project owner
	PjtID    string
	PjtState byte //project state
	SubList  map[string]Subscriber
	// contains filtered or unexported fields
}

TODO : remove export later

func (*Project) AddSubscriber

func (p *Project) AddSubscriber(subID string, subs Subscriber)

func (*Project) GetPjtID

func (p *Project) GetPjtID() string

func (*Project) GetPjtState

func (p *Project) GetPjtState() byte

func (*Project) GetSubList

func (p *Project) GetSubList() map[string]Subscriber

func (*Project) SetPjtState

func (p *Project) SetPjtState(state byte)

func (*Project) Size

func (p *Project) Size() int

type Protocol

type Protocol struct {
	// contains filtered or unexported fields
}

Protocol implements routing/discovery portion of the Kademlia protocol with improvements suggested by the S/Kademlia paper. It is expected that Protocol is bound to a GRING.Node via (*GRING.Node).Bind before the node starts listening for incoming peers.

func New

func New(opts ...ProtocolOption) *Protocol

New returns a new instance of the Kademlia protocol.

func (*Protocol) Ack_bc

func (p *Protocol) Ack_bc(id GRING.ID, isInbound bool, opcode ...byte)

Ack attempts to insert a peer ID into your nodes routing table. If the routing table bucket in which your peer ID was expected to be inserted on is full, the peer ID at the tail of the bucket is pinged. If the ping fails, the peer ID at the tail of the bucket is evicted and your peer ID is inserted to the head of the bucket.

func (*Protocol) Ack_gr

func (p *Protocol) Ack_gr(id GRING.ID)

Ack attempts to insert a peer ID into your nodes routing table. If the routing table bucket in which your peer ID was expected to be inserted on is full, the peer ID at the tail of the bucket is pinged. If the ping fails, the peer ID at the tail of the bucket is evicted and your peer ID is inserted to the head of the bucket.

func (*Protocol) Bind

func (p *Protocol) Bind(node *GRING.Node) error

Bind registers messages Ping, Pong, FindNodeRequest, FindNodeResponse, and handles them by registering the (*Protocol).Handle Handler.

func (*Protocol) Broadcast_BC

func (p *Protocol) Broadcast_BC(sender GRING.ID, data []byte, opcode byte)

func (*Protocol) Choose

func (p *Protocol) Choose(peers []GRING.ID, entry []string) ([]GRING.ID, []GRING.ID)

func (*Protocol) DiscoverLocal

func (p *Protocol) DiscoverLocal(isBootstrap bool, opts ...IteratorOption) []GRING.ID

Discover attempts to discover new peers to your node through peers your node already knows about by calling the FIND_NODE S/Kademlia RPC call with your nodes ID.

func (*Protocol) DiscoverRandom

func (p *Protocol) DiscoverRandom(isBootstrap bool, opts ...IteratorOption) []GRING.ID

Discover attempts to discover new peers to your node through peers your node already knows about by calling the FIND_NODE S/Kademlia RPC call with your nodes ID.

func (*Protocol) DoneUse

func (p *Protocol) DoneUse()

func (*Protocol) Fedcomp_GR

func (p *Protocol) Fedcomp_GR(sender GRING.ID, data []byte)

func (*Protocol) Find

func (p *Protocol) Find(target GRING.PublicKey, isBootstrap bool, opts ...IteratorOption) []GRING.ID

Find executes the FIND_NODE S/Kademlia RPC call to find the closest peers to some given target public key. It returns the IDs of the closest peers it finds.

func (*Protocol) FindRandMember

func (p *Protocol) FindRandMember(push int, len_peers int, peers []GRING.ID) ([]GRING.ID, []GRING.ID)

func (*Protocol) GetGroupSize

func (p *Protocol) GetGroupSize() int

func (*Protocol) GetID

func (p *Protocol) GetID() byte

GetID returns the identification of myself

func (*Protocol) GetItem

func (p *Protocol) GetItem() DownloadMessage

func (*Protocol) GetLeader

func (p *Protocol) GetLeader() string

GetLeader returns the address of leader node

func (*Protocol) GetNumMembers

func (p *Protocol) GetNumMembers() int

func (*Protocol) GetReport

func (p *Protocol) GetReport() bool

func (*Protocol) GetTotMembers

func (p *Protocol) GetTotMembers() int

func (*Protocol) Gossip_BC

func (p *Protocol) Gossip_BC(uuid string, data []byte, avoid []string, msgtype byte, targetid GRING.ID)

func (*Protocol) GridSearchGroupSize

func (p *Protocol) GridSearchGroupSize(tot_num_sub int) int

func (*Protocol) Handle

func (p *Protocol) Handle(ctx GRING.HandlerContext) error

Handle implements GRING.Protocol and handles Ping and FindNodeRequest messages.

func (*Protocol) HasSeenPush

func (p *Protocol) HasSeenPush(target GRING.ID, euuid []byte) bool

func (*Protocol) HasUUID

func (p *Protocol) HasUUID(euuid []byte) bool

func (*Protocol) KPeers_bc

func (p *Protocol) KPeers_bc(k int)

peers prints out all peers we are already aware of.

func (*Protocol) Lock

func (p *Protocol) Lock()

func (*Protocol) MarkSeenPush

func (p *Protocol) MarkSeenPush(target GRING.ID, euuid []byte)

func (*Protocol) MaxNeighborsBC

func (p *Protocol) MaxNeighborsBC() int

MaxNeighbors returns cap of routing table

func (*Protocol) MaxNeighborsGR

func (p *Protocol) MaxNeighborsGR() int

MaxNeighbors returns cap of routing table

func (*Protocol) Multicast_GR

func (p *Protocol) Multicast_GR(sender GRING.ID, data []byte, opcode byte)

func (*Protocol) OnExistingConnection

func (p *Protocol) OnExistingConnection(isInbound bool, client *GRING.Client, opcode ...byte)

func (*Protocol) OnJoinGroup

func (p *Protocol) OnJoinGroup(msg P2pMessage)

func (*Protocol) OnMessageRecv

func (p *Protocol) OnMessageRecv(client *GRING.Client, opcode ...byte)

OnMessageRecv implements GRING.Protocol and attempts to push the position in which the clients ID resides in your nodes' routing table's to the head of the bucket it reside within.

func (*Protocol) OnMessageSent

func (p *Protocol) OnMessageSent(client *GRING.Client, opcode ...byte)

OnMessageSent implements GRING.Protocol and attempts to push the position in which the clients ID resides in your nodes' routing table's to the head of the bucket it reside within.

func (*Protocol) OnPeerConnected

func (p *Protocol) OnPeerConnected(isInbound bool, client *GRING.Client, opcode ...byte)

OnPeerConnected attempts to acknowledge the new peers existence by placing its entry into your nodes' routing table via (*Protocol).Ack.

func (*Protocol) OnPingFailed

func (p *Protocol) OnPingFailed(addr string, err error)

OnPingFailed evicts peers that your node has failed to dial.

func (*Protocol) OnRequestGroupInitiator

func (p *Protocol) OnRequestGroupInitiator(msg P2pMessage)

forming a group is p2p level protocol. later, we need to move it to protocol

func (*Protocol) OnRequestGroupSubleader

func (p *Protocol) OnRequestGroupSubleader(msg P2pMessage)

forming a group is p2p level protocol. later, we need to move it to protocol

func (*Protocol) OnRequestJoinWorker

func (p *Protocol) OnRequestJoinWorker(msg P2pMessage)

func (*Protocol) On_recv_gossip_pullreq

func (p *Protocol) On_recv_gossip_pullreq(msg GossipMessage, ctx GRING.HandlerContext)

func (*Protocol) On_recv_gossip_push

func (p *Protocol) On_recv_gossip_push(msg GossipMessage, ctx GRING.HandlerContext)

func (*Protocol) On_recv_gossip_push_only

func (p *Protocol) On_recv_gossip_push_only(msg GossipMessage, ctx GRING.HandlerContext)

func (*Protocol) On_recv_relay

func (p *Protocol) On_recv_relay(relaymsg RelayMessage, ctx GRING.HandlerContext)

func (*Protocol) Peers_bc

func (p *Protocol) Peers_bc()

print a bucket

func (*Protocol) Peers_gr

func (p *Protocol) Peers_gr()

func (*Protocol) Ping

func (p *Protocol) Ping(ctx context.Context, addr string, opcode ...byte) error

Ping sends a ping request to addr, and returns no error if a p!!!ong is received back before ctx has expired/was cancelled. It also throws an error if the connection to addr intermittently drops, or if handshaking with addr should there be no live connection to addr yet fails.

func (*Protocol) Protocol

func (p *Protocol) Protocol() GRING.Protocol

Protocol returns a GRING.Protocol that may registered to a node via (*GRING.Node).Bind.

func (*Protocol) PubSub

func (p *Protocol) PubSub() *PubSub

func (*Protocol) Remove

func (p *Protocol) Remove(peers []GRING.ID, entry []string) []GRING.ID

func (*Protocol) RemoveConn

func (p *Protocol) RemoveConn(table *Table, id GRING.ID, isInbound bool)

func (*Protocol) ReplaceConn

func (p *Protocol) ReplaceConn(id GRING.ID, isInbound bool)

func (*Protocol) Report_GR

func (p *Protocol) Report_GR(sender GRING.ID, data []byte, aggregation int)

func (*Protocol) RequestDownload

func (p *Protocol) RequestDownload(euuid []byte, preferred []string) (DownloadMessage, bool)

func (*Protocol) Sendmsg

func (p *Protocol) Sendmsg(euuid []byte, data []byte, length int, listdata []byte, id GRING.ID, opcode byte, msgtype byte, targetid GRING.ID)

func (*Protocol) SetGroupSize

func (p *Protocol) SetGroupSize(size int)

func (*Protocol) SetID

func (p *Protocol) SetID(id byte)

SetID sets the identification of myself

func (*Protocol) SetItem

func (p *Protocol) SetItem(msg DownloadMessage)

func (*Protocol) SetLeader

func (p *Protocol) SetLeader(addr string)

SetLeader sets the address of leader node

func (*Protocol) SetMaxNeighborsGR

func (p *Protocol) SetMaxNeighborsGR(max int)

func (*Protocol) SetNumMembers

func (p *Protocol) SetNumMembers(mem int)

func (*Protocol) SetReport

func (p *Protocol) SetReport(b bool)

func (*Protocol) SetTotMembers

func (p *Protocol) SetTotMembers(totmem int)

func (*Protocol) SetUUID

func (p *Protocol) SetUUID(euuid []byte)

func (*Protocol) SetUse

func (p *Protocol) SetUse()

func (*Protocol) Table_bc

func (p *Protocol) Table_bc() *Table

Table returns this Kademlia p's routing table from your nodes perspective.

func (*Protocol) Table_gr

func (p *Protocol) Table_gr() *Table

func (*Protocol) Unlock

func (p *Protocol) Unlock()

type ProtocolOption

type ProtocolOption func(p *Protocol)

ProtocolOption represents a functional option which may be passed to New to configure a Protocol.

func WithProtocolEvents

func WithProtocolEvents(events Events) ProtocolOption

WithProtocolEvents configures an event listener for a Protocol.

func WithProtocolLogger

func WithProtocolLogger(logger *zap.Logger) ProtocolOption

WithProtocolLogger configures the logger instance for an iterator. By default, the logger used is the logger of the node which the iterator is bound to.

func WithProtocolMaxNeighborsBC

func WithProtocolMaxNeighborsBC(maxNeighbors int) ProtocolOption

func WithProtocolMaxNeighborsGR

func WithProtocolMaxNeighborsGR(maxNeighbors int) ProtocolOption

func WithProtocolPingTimeout

func WithProtocolPingTimeout(pingTimeout time.Duration) ProtocolOption

WithProtocolPingTimeout configures the amount of time to wait for until we declare a ping to have failed. Peers typically either are pinged through a call of (*Protocol).Ping, or in amidst the execution of Kademlia's peer eviction policy. By default, it is set to 3 seconds.

type PubSub

type PubSub struct {
	MapPidToPjt map[string]*Project
}

func NewPubSub

func NewPubSub() *PubSub

func (*PubSub) GetProject

func (ps *PubSub) GetProject(pjtid string) (*Project, bool)

func (*PubSub) NewProject

func (ps *PubSub) NewProject(owner GRING.ID) (string, *Project)

type RelayMessage

type RelayMessage struct {
	UUID     []byte //32bytes for plain, 34bytes for encoded. we expect encoded one
	Opcode   byte
	Fuel     uint32
	TargetID GRING.ID //ID is publickey
	Contents []byte
}

func UnmarshalRelayMessage

func UnmarshalRelayMessage(buf []byte) (RelayMessage, error)

func (RelayMessage) Marshal

func (m RelayMessage) Marshal() []byte

type Request

type Request struct {
	UUID []byte //32bytes for plain, 34bytes for encoded
}

func UnmarshalRequest

func UnmarshalRequest(buf []byte) (Request, error)

func (Request) Marshal

func (m Request) Marshal() []byte

type SubsMessage

type SubsMessage struct {
	//PjtID GRING.ID //TODO: add pjt ID for multi project
	SubID      GRING.ID // ID is publickey
	Host       net.IP   `json:"address"` //subs ip
	Port       uint16   //subs port
	StaticInfo []byte
}

subscriber replies with this message to join the project

func UnmarshalSubsMessage

func UnmarshalSubsMessage(buf []byte) (SubsMessage, error)

func (SubsMessage) Marshal

func (m SubsMessage) Marshal() []byte

TODO

type Subscriber

type Subscriber struct {
	Key      string   // string of node ID
	Addr     string   //string of IP:Port
	UserInfo UserInfo // user should define the information field
}

type Table

type Table struct {
	sync.RWMutex

	Direction   map[string]bool
	NumOutBound int
	NumInBound  int
	// contains filtered or unexported fields
}

Table represents a Kademlia routing table.

func NewTable

func NewTable(self GRING.ID) *Table

NewTable instantiates a new routing table whose XOR distance metric is defined with respect to some given ID.

func (*Table) Bucket

func (t *Table) Bucket(target GRING.PublicKey) []GRING.ID

Bucket returns all entries of a bucket where target reside within.

func (*Table) DecreaseInBound

func (t *Table) DecreaseInBound()

func (*Table) DecreaseOutBound

func (t *Table) DecreaseOutBound()

func (*Table) Delete

func (t *Table) Delete(target GRING.PublicKey) (GRING.ID, bool)

Delete removes target from this routing table. It returns the id of the delted target and true if found, or a zero-value ID and false otherwise.

func (*Table) DeleteByAddress

func (t *Table) DeleteByAddress(target string) (GRING.ID, bool)

DeleteByAddress removes the first occurrence of an id with target as its address from this routing table. It returns the id of the deleted target and true if found, or a zero-value ID and false otherwise.

func (*Table) Entries

func (t *Table) Entries() []GRING.ID

Entries returns all stored ids in this routing table.

func (*Table) FindClosest

func (t *Table) FindClosest(target GRING.PublicKey, k int) []GRING.ID

FindClosest returns the k closest peer IDs to target, and sorts them based on how close they are.

func (*Table) GetDirection

func (t *Table) GetDirection(id GRING.PublicKey) (bool, bool)

func (*Table) GetNumInBound

func (t *Table) GetNumInBound() int

func (*Table) GetNumOutBound

func (t *Table) GetNumOutBound() int

func (*Table) IncreaseInBound

func (t *Table) IncreaseInBound()

func (*Table) IncreaseOutBound

func (t *Table) IncreaseOutBound()

func (*Table) KEntries

func (t *Table) KEntries(k int) []GRING.ID

Entries returns all stored ids in this routing table.

func (*Table) KPeers

func (t *Table) KPeers(k int) []GRING.ID

return k peers

func (*Table) Last

func (t *Table) Last(target GRING.PublicKey) GRING.ID

Last returns the last id of the bucket where target resides within.

func (*Table) NumEntries

func (t *Table) NumEntries() int

NumEntries returns the total amount of ids stored in this routing table.

func (*Table) Peers

func (t *Table) Peers() []GRING.ID

Peers returns BucketSize closest peer IDs to the ID which this routing table's distance metric is defined against.

func (*Table) Recorded

func (t *Table) Recorded(target GRING.PublicKey) bool

Recorded returns true if target is already recorded in this routing table.

func (*Table) RemoveDirection

func (t *Table) RemoveDirection(id GRING.PublicKey)

func (*Table) Self

func (t *Table) Self() GRING.ID

Self returns the ID which this routing table's XOR distance metric is defined with respect to.

func (*Table) SetDirection

func (t *Table) SetDirection(id GRING.PublicKey, isInbound bool)

func (*Table) Update

func (t *Table) Update(target GRING.ID) (bool, error)

Update attempts to insert the target node/peer ID into this routing table. If the bucket it was expected to be inserted within is full, ErrBucketFull is returned. If the ID already exists in its respective routing table bucket, it is moved to the head of the bucket and false is returned. If the ID has yet to exist, it is appended to the head of its intended bucket and true is returned.

type UserInfo

type UserInfo interface{}

Jump to

Keyboard shortcuts

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