Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ChordNode(nodeId){
- this.nodeId = nodeId; /*Node IP:port or its id*/
- this.nodeKey = new ChordKey(nodeId); /*Contains hashed key of node*/
- this.fingerTable = new FingerTable(this.nodeKey); /*Finger table of node*/
- this.predecessor = null; /*predecessor of node*/
- this.successor = this; /*successor of node*/
- }
- ChordNode.prototype.findSuccessor_id(id){ /*Will take argument as string*/
- var key = new ChordKey(id);
- return findSuccessor_Chordkey(key);
- }
- ChordNode.prototype.findSuccessor_Chordkey(key){ /*Will take argument as ChordKey object*/
- if(this == this.successor)
- return this;
- if (key.isBetween(this.getNodeKey(), this.successor.getNodeKey()) || /*If requested key is inbetween (n,n.sucessor]*/
- key.compareTo(this.successor.getNodeKey()) == 0)
- return this.successor; /*return n.sucessor*/
- else {
- var node = this.closestPrecedingNode(key);
- if (node == this) return this.successor.findSuccessor(key);
- return node.findSuccessor(key);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement