Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/find successor #33

Open
wants to merge 11 commits into
base: project1-master
Choose a base branch
from
26 changes: 26 additions & 0 deletions PROJ1/findSuccessor/findSuccessor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package findSuccessor

import (
nodeDefs "../utils/node_defs"
)

//FindSuccessor ... This function is used to find successor of node with ID targetID
func FindSuccessor(sponsoringNode *nodeDefs.Node, targetID int64) (successor *nodeDefs.Node) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sponsoring node is represented as an int64 (if you look at the join ring function in the code, the *node object is the node that needs a successor...that way you wont have to return a successor object. You will already have the node object that needs a successor, and can assign the correct successor to that node object directly)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought passing Node instead of only its ID would be nice because FindSucc needs access to successor of sponsoring node which will be available in its node structure.
If we pass only ID then we will need the information of nodes_in_ring so that we can link that ID with its node and then find the successor

Copy link
Owner

@bama4 bama4 Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. I think then that passing the sponsoring node as a node object is fine then here. Do you think though that the node that needs the successor should also be an argument so that you can update its successor once you find it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by the notes in the HW it says it's only responding to a node ID.. which is then used to lookup the specific node in ring_nodes which can also be used to look up the node's successor/predecessor..etc

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. I think that is fine then. respond-to is the node that needs a successor right? The function would just need to be in the main file so that you can use the respond-to id to lookup the node respond-to object to update its successor.

if targetID > sponsoringNode.ChannelId && targetID <= sponsoringNode.Successor.ChannelId {
successor = sponsoringNode.Successor
} else {
precedingNode := findClosestPrecedingNode(sponsoringNode, targetID)
successor = FindSuccessor(precedingNode, targetID)
}
return successor
}

func findClosestPrecedingNode(sponsoringNode *nodeDefs.Node, targetID int64) (precedingNode *nodeDefs.Node) {

for i := range sponsoringNode.FingerTable {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think based on the pseudocode in the paper, you should find the closest preceding node by starting from the end of the fingertable

if sponsoringNode.FingerTable[int64(i)].ChannelId > sponsoringNode.ChannelId && sponsoringNode.FingerTable[int64(i)].ChannelId < targetID {
precedingNode = sponsoringNode.FingerTable[int64(i)]
}
}
return
}
2 changes: 1 addition & 1 deletion PROJ1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func net_node(channel_id int64){
if val, ok := ring_nodes[channel_id]; ok != true {
_ = val
sponsoring_node_id := message.SponsoringNode
join.Join_ring(sponsoring_node_id, &node_obj)
join.Join_ring(int64(sponsoring_node_id), &node_obj)
ring_nodes[channel_id] = &node_obj
}else{
log.Printf("\nNode %d is already in the ring; cannot join-ring\n", channel_id)
Expand Down
14 changes: 7 additions & 7 deletions PROJ1/utils/message_defs/message_defs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package message_defs


/*
This struct defines the json messages for the
CHORD protocol.
Expand All @@ -13,14 +12,15 @@ respond_to - The node (represented as a channel id) to direct the given action t
data - The key/value pair in the ring representing a hash entry.
*/
type Message struct {
Do string `json:"do"`
SponsoringNode int64 `json:"sponsoring_node"`
Mode string `json:"mode"`
RespondTo string `json:"respond_to"`
Data Data `json:"data"`
Do string `json:"do"`
SponsoringNode int64 `json:"sponsoring-node"`
Mode string `json:"mode"`
RespondTo int64 `json:"respond-to"`
Data Data `json:"data"`
TargetID int64 `json:"target-id"`
}

type Data struct {
Key string `json:"string"`
Key string `json:"string"`
Value string `json:"string"`
}