Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Last active September 12, 2018 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/745d0f73cae6e9c20bea23cc0f77e961 to your computer and use it in GitHub Desktop.
Save arriqaaq/745d0f73cae6e9c20bea23cc0f77e961 to your computer and use it in GitHub Desktop.
func (n *Node) join(joinNode *internal.Node) error {
// First check if node already present in the circle
// Join this node to the same chord ring as parent
var foo *internal.Node
// // Ask if our id already exists on the ring.
if joinNode != nil {
remoteNode, err := n.findSuccessorRPC(joinNode, n.Id)
if err != nil {
return err
}
if isEqual(remoteNode.Id, n.Id) {
return ERR_NODE_EXISTS
}
foo = joinNode
} else {
foo = n.Node
}
succ, err := n.findSuccessorRPC(foo, n.Id)
if err != nil {
return err
}
n.succMtx.Lock()
n.successor = succ
n.succMtx.Unlock()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment