From 9e4f9d82934d7f84fc733cd1a75ab0720228241f Mon Sep 17 00:00:00 2001 From: mohitkhatwani Date: Sat, 14 Apr 2018 15:15:05 -0400 Subject: [PATCH 1/5] added findSuccessor module --- PROJ1/utils/message_defs/message_defs.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PROJ1/utils/message_defs/message_defs.go b/PROJ1/utils/message_defs/message_defs.go index cab5174..3337dbf 100644 --- a/PROJ1/utils/message_defs/message_defs.go +++ b/PROJ1/utils/message_defs/message_defs.go @@ -1,6 +1,5 @@ package message_defs - /* This struct defines the json messages for the CHORD protocol. @@ -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 string `json:"sponsoring-node"` + Mode string `json:"mode"` + RespondTo string `json:"respond-to"` + Data Data `json:"data"` + TargetID string `json:"target-id"` } type Data struct { - Key string `json:"string"` + Key string `json:"string"` Value string `json:"string"` } From 6d7f000b8b03c58d3cb02fb49afe6ad7a42caef6 Mon Sep 17 00:00:00 2001 From: mohitkhatwani Date: Sat, 14 Apr 2018 15:56:55 -0400 Subject: [PATCH 2/5] Added findSucc --- PROJ1/findSuccessor/findSuccessor.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 PROJ1/findSuccessor/findSuccessor.go diff --git a/PROJ1/findSuccessor/findSuccessor.go b/PROJ1/findSuccessor/findSuccessor.go new file mode 100644 index 0000000..8b88dd4 --- /dev/null +++ b/PROJ1/findSuccessor/findSuccessor.go @@ -0,0 +1,28 @@ +package findSuccessor + +import ( + "math" + + nodeDefs "../utils/node_defs" +) + +//FindSuccessor ... This function is used to find successor of node with ID targetID +func FindSuccessor(sponsoringNode *nodeDefs.Node, targetID int64, totalNodes int) (successor *nodeDefs.Node) { + if targetID > sponsoringNode.ChannelId && targetID <= sponsoringNode.Successor.ChannelId { + successor = sponsoringNode.Successor + } else { + precedingNode := findClosestPrecedingNode(sponsoringNode, targetID, totalNodes) + successor = FindSuccessor(precedingNode, targetID, totalNodes) + } + return successor +} + +func findClosestPrecedingNode(sponsoringNode *nodeDefs.Node, targetID int64, totalNodes int) (precedingNode *nodeDefs.Node) { + + for i := int(math.Log2(float64(totalNodes))); i >= 0; i-- { + if sponsoringNode.FingerTable[int64(i)].ChannelId > sponsoringNode.ChannelId && sponsoringNode.FingerTable[int64(i)].ChannelId < targetID { + precedingNode = sponsoringNode.FingerTable[int64(i)] + } + } + return +} From fd5320fb1841f2a27d9e90bf015845cff52582b0 Mon Sep 17 00:00:00 2001 From: mohitkhatwani Date: Sat, 14 Apr 2018 15:58:55 -0400 Subject: [PATCH 3/5] Changed message_defs to string --- PROJ1/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index d534858..9761a14 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -171,8 +171,8 @@ func net_node(channel_id int64){ if message.Do == "join-ring" { if val, ok := ring_nodes[channel_id]; ok != true { _ = val - sponsoring_node_id := message.SponsoringNode - join.Join_ring(sponsoring_node_id, &node_obj) + sponsoring_node_id,_ := strconv.Atoi(message.SponsoringNode) + 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) @@ -267,7 +267,7 @@ func coordinator(prog_args []string){ if message.Do == "join-ring" { if random_node_id > 0 { - message.SponsoringNode = random_node_id + message.SponsoringNode = string(random_node_id) }else{ log.Println("There is no node to sponsor for join ring: %d") continue From ca1866c81ad2b23697e04decc38a3caa2a579ac3 Mon Sep 17 00:00:00 2001 From: mohitkhatwani Date: Sat, 14 Apr 2018 16:11:19 -0400 Subject: [PATCH 4/5] Changed All id's to int64 --- PROJ1/utils/message_defs/message_defs.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PROJ1/utils/message_defs/message_defs.go b/PROJ1/utils/message_defs/message_defs.go index 3337dbf..ba89b7d 100644 --- a/PROJ1/utils/message_defs/message_defs.go +++ b/PROJ1/utils/message_defs/message_defs.go @@ -13,11 +13,11 @@ data - The key/value pair in the ring representing a hash entry. */ type Message struct { Do string `json:"do"` - SponsoringNode string `json:"sponsoring-node"` + SponsoringNode int64 `json:"sponsoring-node"` Mode string `json:"mode"` - RespondTo string `json:"respond-to"` + RespondTo int64 `json:"respond-to"` Data Data `json:"data"` - TargetID string `json:"target-id"` + TargetID int64 `json:"target-id"` } type Data struct { From a20494bb997d6f272ff80399b6935e7256bc336b Mon Sep 17 00:00:00 2001 From: mohitkhatwani Date: Sat, 14 Apr 2018 16:13:39 -0400 Subject: [PATCH 5/5] Changed main.go --- PROJ1/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index 9761a14..6b5f737 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -171,7 +171,7 @@ func net_node(channel_id int64){ if message.Do == "join-ring" { if val, ok := ring_nodes[channel_id]; ok != true { _ = val - sponsoring_node_id,_ := strconv.Atoi(message.SponsoringNode) + sponsoring_node_id := message.SponsoringNode join.Join_ring(int64(sponsoring_node_id), &node_obj) ring_nodes[channel_id] = &node_obj }else{ @@ -267,7 +267,7 @@ func coordinator(prog_args []string){ if message.Do == "join-ring" { if random_node_id > 0 { - message.SponsoringNode = string(random_node_id) + message.SponsoringNode = random_node_id }else{ log.Println("There is no node to sponsor for join ring: %d") continue