Documentation ¶
Index ¶
- Constants
- func Between(id1, id2, key []byte) bool
- func BetweenIncl(id1, id2, key []byte) bool
- func BetweenLeftIncl(id1, id2, key []byte) bool
- func BetweenRightIncl(id1, id2, key []byte) bool
- func BigIntToID(i big.Int, m uint32) []byte
- func CompareID(id1, id2 []byte) int
- func Distance(a, b []byte, m uint32) *big.Int
- func GetSuccAndPred(remoteNode *node.RemoteNode, numSucc, numPred uint32, msgIDBytes uint8) ([]*pbnode.Node, []*pbnode.Node, error)
- func IDToBigInt(id []byte) big.Int
- func NewGetSuccAndPredMessage(numSucc, numPred uint32, msgIDBytes uint8) (*pbmsg.Message, error)
- func NextID(id []byte, m uint32) []byte
- func Offset(id []byte, offset *big.Int, m uint32) []byte
- func PowerOffset(id []byte, exp uint32, m uint32) []byte
- func PrevID(id []byte, m uint32) []byte
- type BroadcastTreeRouting
- type Chord
- func (store Chord) ApplyMiddleware(mw interface{}) error
- func (c *Chord) Connect(n *pbnode.Node) error
- func (c *Chord) FindPredecessors(key []byte, numPred uint32) ([]*pbnode.Node, error)
- func (c *Chord) FindSuccAndPred(key []byte, numSucc, numPred uint32) ([]*pbnode.Node, []*pbnode.Node, error)
- func (c *Chord) FindSuccessors(key []byte, numSucc uint32) ([]*pbnode.Node, error)
- func (c *Chord) FingerTable() [][]*node.RemoteNode
- func (c *Chord) FingerTableIdxInRemoteNode(remoteNodeID []byte) (int, int)
- func (c *Chord) Join(seedNodeAddr string) error
- func (c *Chord) MaybeStopRemoteNode(remoteNode *node.RemoteNode) bool
- func (c *Chord) NewFindSuccAndPredMessage(key []byte, numSucc, numPred uint32) (*pbmsg.Message, error)
- func (c *Chord) NewFindSuccAndPredReply(replyToID []byte, successors, predecessors []*pbnode.Node) (*pbmsg.Message, error)
- func (c *Chord) NewGetSuccAndPredReply(replyToID []byte, successors, predecessors []*pbnode.Node) (*pbmsg.Message, error)
- func (c *Chord) Predecessors() []*node.RemoteNode
- func (c *Chord) Start(isCreate bool) error
- func (c *Chord) Stop(err error)
- func (c *Chord) Successors() []*node.RemoteNode
- type FingerTableAdded
- type FingerTableRemoved
- type NeighborAdded
- type NeighborList
- func (sl *NeighborList) AddOrReplace(remoteNode *node.RemoteNode) (bool, *node.RemoteNode, error)
- func (sl *NeighborList) Cap() uint32
- func (sl *NeighborList) Exists(id []byte) bool
- func (sl *NeighborList) GetByID(id []byte) *node.RemoteNode
- func (sl *NeighborList) GetFirst() *node.RemoteNode
- func (sl *NeighborList) GetIndex(id []byte) int
- func (sl *NeighborList) GetLast() *node.RemoteNode
- func (sl *NeighborList) IsEmpty() bool
- func (sl *NeighborList) IsIDInRange(id []byte) bool
- func (sl *NeighborList) Len() uint32
- func (sl *NeighborList) Remove(remoteNode *node.RemoteNode) bool
- func (sl *NeighborList) SetMaxNumNodes(maxNumNodes uint32)
- func (sl *NeighborList) ToProtoNodeList(sorted bool) []*pbnode.Node
- func (sl *NeighborList) ToRemoteNodeList(sorted bool) []*node.RemoteNode
- type NeighborRemoved
- type PredecessorAdded
- type PredecessorRemoved
- type RelayPriority
- type RelayRouting
- type SuccessorAdded
- type SuccessorRemoved
Constants ¶
const ( // BroadcastTreeRoutingNumWorkers determines how many concurrent goroutines // are handling broadcast tree messages BroadcastTreeRoutingNumWorkers = 1 )
const ( // RelayRoutingNumWorkers determines how many concurrent goroutines are // handling relay messages RelayRoutingNumWorkers = 1 )
Variables ¶
This section is empty.
Functions ¶
func BetweenIncl ¶
BetweenIncl checks if a key is between two ID, both inclusive
func BetweenLeftIncl ¶
BetweenLeftIncl checks if a key is between two ID, left inclusive
func BetweenRightIncl ¶
BetweenRightIncl checks if a key is between two ID, right inclusive
func BigIntToID ¶
BigIntToID converts a big.Int with m bit rate to Chord ID bytes
func GetSuccAndPred ¶
func GetSuccAndPred(remoteNode *node.RemoteNode, numSucc, numPred uint32, msgIDBytes uint8) ([]*pbnode.Node, []*pbnode.Node, error)
GetSuccAndPred sends a GetSuccAndPred message to remote node and returns its successors and predecessor if no error occurred
func IDToBigInt ¶
IDToBigInt converts a Chord ID bytes to big.Int
func NewGetSuccAndPredMessage ¶
NewGetSuccAndPredMessage creates a GET_SUCC_AND_PRED message to get the successors and predecessor of a remote node
func PowerOffset ¶
PowerOffset computes (id + 2^exp) % (2^m)
Types ¶
type BroadcastTreeRouting ¶
BroadcastTreeRouting is for message from a remote node to all other nodes in the network following spanning tree
func NewBroadcastTreeRouting ¶
func NewBroadcastTreeRouting(localMsgChan chan<- *node.RemoteMessage, rxMsgChan <-chan *node.RemoteMessage, chord *Chord) (*BroadcastTreeRouting, error)
NewBroadcastTreeRouting creates a new BroadcastTreeRouting
func (*BroadcastTreeRouting) GetNodeToRoute ¶
func (btr *BroadcastTreeRouting) GetNodeToRoute(remoteMsg *node.RemoteMessage) (*node.LocalNode, []*node.RemoteNode, error)
GetNodeToRoute returns the local node and remote nodes to route message to
func (*BroadcastTreeRouting) Start ¶
func (btr *BroadcastTreeRouting) Start() error
Start starts handling broadcast tree message from rxChan
type Chord ¶
Chord is the overlay network based on Chord DHT
func (Chord) ApplyMiddleware ¶
func (store Chord) ApplyMiddleware(mw interface{}) error
ApplyMiddleware add a middleware to the store
func (*Chord) FindPredecessors ¶
FindPredecessors sends a FindPredecessors message and returns numPred predecessors of a given key id
func (*Chord) FindSuccAndPred ¶
func (c *Chord) FindSuccAndPred(key []byte, numSucc, numPred uint32) ([]*pbnode.Node, []*pbnode.Node, error)
FindSuccAndPred sends a FindSuccAndPred message and returns numSucc successors and numPred predecessors of a given key id
func (*Chord) FindSuccessors ¶
FindSuccessors sends a FindSuccessors message and returns numSucc successors of a given key id
func (*Chord) FingerTable ¶
func (c *Chord) FingerTable() [][]*node.RemoteNode
FingerTable returns the remote nodes in finger table
func (*Chord) FingerTableIdxInRemoteNode ¶
FingerTableIdxInRemoteNode returns the finger table index (index of finger, index in finger) of local node in remote node's finger table. Returns -1 index if local node is not in remote node's finger table.
func (*Chord) MaybeStopRemoteNode ¶
func (c *Chord) MaybeStopRemoteNode(remoteNode *node.RemoteNode) bool
MaybeStopRemoteNode removes an outbound node that is no longer in successors, predecessor, or finger table
func (*Chord) NewFindSuccAndPredMessage ¶
func (c *Chord) NewFindSuccAndPredMessage(key []byte, numSucc, numPred uint32) (*pbmsg.Message, error)
NewFindSuccAndPredMessage creates a FIND_SUCC_AND_PRED message to find numSucc successors and numPred predecessors of a key
func (*Chord) NewFindSuccAndPredReply ¶
func (c *Chord) NewFindSuccAndPredReply(replyToID []byte, successors, predecessors []*pbnode.Node) (*pbmsg.Message, error)
NewFindSuccAndPredReply creates a FIND_SUCC_AND_PRED reply to send successors and predecessors
func (*Chord) NewGetSuccAndPredReply ¶
func (c *Chord) NewGetSuccAndPredReply(replyToID []byte, successors, predecessors []*pbnode.Node) (*pbmsg.Message, error)
NewGetSuccAndPredReply creates a GET_SUCC_AND_PRED reply to send successors and predecessor
func (*Chord) Predecessors ¶
func (c *Chord) Predecessors() []*node.RemoteNode
Predecessors returns the remote nodes in predecessor list
func (*Chord) Successors ¶
func (c *Chord) Successors() []*node.RemoteNode
Successors returns the remote nodes in succesor list
type FingerTableAdded ¶
FingerTableAdded is called when a new remote node has been added to the finger table. This does not necessarily mean the remote node has just established a new connection with local node, but may also because another remote node previously in finger table was disconnected or removed. When being called, it will also pass the index of finger table and the index of the remote node in that finger table after it is added. Returns if we should proceed to the next middleware.
type FingerTableRemoved ¶
type FingerTableRemoved struct { Func func(*node.RemoteNode, int) bool Priority int32 }
FingerTableRemoved is called when a remote node has been removed from the finger table. This does not necessarily mean the remote node has just disconnected with local node, but may also because another remote node is added to the finger table. Returns if we should proceed to the next middleware.
type NeighborAdded ¶
type NeighborAdded struct { Func func(*node.RemoteNode, int) bool Priority int32 }
NeighborAdded is called when a new remote node has been added to the neighbor list. When being called, it will also pass the index of the remote node in neighbor list after it is added. Returns if we should proceed to the next middleware.
type NeighborList ¶
type NeighborList struct {
// contains filtered or unexported fields
}
NeighborList is a list of nodes with minimal key that is greater than key
func NewNeighborList ¶
func NewNeighborList(startID, endID []byte, nodeIDBits, maxNumNodes uint32, reversed bool) (*NeighborList, error)
NewNeighborList creates a NeighborList
func (*NeighborList) AddOrReplace ¶
func (sl *NeighborList) AddOrReplace(remoteNode *node.RemoteNode) (bool, *node.RemoteNode, error)
AddOrReplace add a node to NeighborList, replace an existing one if there are more than maxNumNodes nodes in list. Returns if node is added, the node that is replaced or nil if not, and error if any
func (*NeighborList) Cap ¶
func (sl *NeighborList) Cap() uint32
Cap returns the maximal number of remote nodes that it can store
func (*NeighborList) Exists ¶
func (sl *NeighborList) Exists(id []byte) bool
Exists returns if an id is in NeighborList
func (*NeighborList) GetByID ¶
func (sl *NeighborList) GetByID(id []byte) *node.RemoteNode
GetByID returns the remote node in NeighborList with give id, or nil if no such node exists
func (*NeighborList) GetFirst ¶
func (sl *NeighborList) GetFirst() *node.RemoteNode
GetFirst returns the remote node in NeighborList that has the smallest distance from/to its startID. This is faster than calling ToRemoteNodeList and then take the first element
func (*NeighborList) GetIndex ¶
func (sl *NeighborList) GetIndex(id []byte) int
GetIndex returns the index of the node with an id when NeighborList is sorted. Returns -1 if id not found.
func (*NeighborList) GetLast ¶
func (sl *NeighborList) GetLast() *node.RemoteNode
GetLast returns the remote node in NeighborList that has the greatest distance from/to its startID. This is faster than calling ToRemoteNodeList and then take the last element
func (*NeighborList) IsEmpty ¶
func (sl *NeighborList) IsEmpty() bool
IsEmpty returns if there is at least one remote node in NeighborList
func (*NeighborList) IsIDInRange ¶
func (sl *NeighborList) IsIDInRange(id []byte) bool
IsIDInRange returns if id is in the range of NeighborList
func (*NeighborList) Len ¶
func (sl *NeighborList) Len() uint32
Len returns the number of remote nodes stored in NeighborList
func (*NeighborList) Remove ¶
func (sl *NeighborList) Remove(remoteNode *node.RemoteNode) bool
Remove remove a node from NeighborList, returns if node is in NeighborList
func (*NeighborList) SetMaxNumNodes ¶
func (sl *NeighborList) SetMaxNumNodes(maxNumNodes uint32)
SetMaxNumNodes changes the maximal number of remote nodes that it can store
func (*NeighborList) ToProtoNodeList ¶
func (sl *NeighborList) ToProtoNodeList(sorted bool) []*pbnode.Node
ToProtoNodeList returns a list of protobuf.Node that are in NeighborList
func (*NeighborList) ToRemoteNodeList ¶
func (sl *NeighborList) ToRemoteNodeList(sorted bool) []*node.RemoteNode
ToRemoteNodeList returns a list of RemoteNode that are in NeighborList
type NeighborRemoved ¶
type NeighborRemoved struct { Func func(*node.RemoteNode) bool Priority int32 }
NeighborRemoved is called when a remote node has been removed from the neighbor list. Returns if we should proceed to the next middleware.
type PredecessorAdded ¶
type PredecessorAdded struct { Func func(*node.RemoteNode, int) bool Priority int32 }
PredecessorAdded is called when a new remote node has been added to the predecessor list. This does not necessarily mean the remote node has just established a new connection with local node, but may also because another remote node previously in predecessor list was disconnected or removed. When being called, it will also pass the index of the remote node in predecessor list after it is added. Returns if we should proceed to the next middleware.
type PredecessorRemoved ¶
type PredecessorRemoved struct { Func func(*node.RemoteNode) bool Priority int32 }
PredecessorRemoved is called when a remote node has been removed from the predecessor list. This does not necessarily mean the remote node has just disconnected with local node, but may also because another remote node is added to the predecessor list. Returns if we should proceed to the next middleware.
type RelayPriority ¶
RelayPriority is called when computing the priority of next hop candidate. Node that has the highest priority value will be selected. Initial priority is negative latency in unit of ms. When being called, it will also pass the current priority value. Returns the new priority value and whether we should proceed to the next middleware.
type RelayRouting ¶
RelayRouting is for message from a remote node to another remote node or local node
func NewRelayRouting ¶
func NewRelayRouting(localMsgChan chan<- *node.RemoteMessage, rxMsgChan <-chan *node.RemoteMessage, chord *Chord) (*RelayRouting, error)
NewRelayRouting creates a new RelayRouting
func (*RelayRouting) GetNodeToRoute ¶
func (rr *RelayRouting) GetNodeToRoute(remoteMsg *node.RemoteMessage) (*node.LocalNode, []*node.RemoteNode, error)
GetNodeToRoute returns the local node and remote nodes to route message to
func (*RelayRouting) Start ¶
func (rr *RelayRouting) Start() error
Start starts handling relay message from rxChan
type SuccessorAdded ¶
type SuccessorAdded struct { Func func(*node.RemoteNode, int) bool Priority int32 }
SuccessorAdded is called when a new remote node has been added to the successor list. This does not necessarily mean the remote node has just established a new connection with local node, but may also because another remote node previously in successor list was disconnected or removed. When being called, it will also pass the index of the remote node in successor list after it is added. Returns if we should proceed to the next middleware.
type SuccessorRemoved ¶
type SuccessorRemoved struct { Func func(*node.RemoteNode) bool Priority int32 }
SuccessorRemoved is called when a remote node has been removed from the successor list. This does not necessarily mean the remote node has just disconnected with local node, but may also because another remote node is added to the successor list. Returns if we should proceed to the next middleware.