-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschord.c
98 lines (67 loc) · 1.69 KB
/
schord.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<stdio.h>
#include<stdlib.h>
#include"headers.h"
void makeschordcircle(sftnode** pointer,int nodeId,char * IP){
if(pointer[0] == NULL){
sftnode* node = initializeNode(nodeId,IP);//check this TODO
pointer[0] = node;
}
else{
sftnode* node = initializeNode(nodeId,IP);
pointer[nodeId] = node;
pointer[nodeId]->predecessor = pointer[nodeId-1];
}
}
sftnode* initializeNode(int nodeId,char* IP)
{
sftnode* node=(sftnode*)malloc(sizeof(sftnode));
if(!node)
return NULL;
node->nodeId = nodeId;
node->IP = (char*)malloc(sizeof(char)*12);
node->IP = IP;
node->predecessor=NULL;
node->tree=NULL;
//for splay tree
node->left = NULL;
node->right = NULL;
node->data = 0;
return node;
}
//for each node we have to call this function along with its last modified node
void joinSchordNetwork(sftnode* node,sftnode** pointer)
{
node->tree=initializeFingertable(pointer,node);
}
//for creating fingertable for one node
sft* initializeFingertable(sftnode** pointer,sftnode* node)
{
sft* tree = NULL;
tree = constructsft(node,pointer);
return tree;
}
int isBetween(int value,int start,int end){
if(start<=end){
if(value>=start && value<=end)
return 1;
}
else{
if(value<=start && value>=end)
return 1;
}
return 0;
}
//perform lookup
char* lookupipaddress(sftnode** pointer,int nodeId,int data){
for(int i=0; i<m; i++){
if(isBetween(nodeId,pointer[i]->tree->min,pointer[i]->tree->max)){
//assuming that pointer[i] contains nodeId wala node in its splay tree
sftnode* node = searchnodeByIp(pointer[i]->tree,nodeId,data);
if(node){
char* str = (char*)malloc(sizeof(char)*12);
str = node->IP;
return str;
}
}
}
}