-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
91 lines (77 loc) · 2 KB
/
main.go
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
89
90
91
// Package chord allows a user to generate a network with pseudo-random active nodes or specify active nodes.
// Additionally, it will determine the location of data for a particular node starting at any specified active node.
package chord
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
)
func main() {
// Set flags for node creation and output verbosity.
ml := flag.Bool("manual", false, "Manually enter the active nodes for the network.")
ms := flag.Bool("m", false, "Manually enter the active nodes for the network.")
vl := flag.Bool("verbose", false, "Prints the state of the program after each step. Warning: This will add considerable clutter.")
vs := flag.Bool("v", false, "Prints the state of the program after each step. Warning: This will add considerable clutter.")
flag.Parse()
// Initialize the flags.
man := false
if *ml {
man = *ml
}
if *ms {
man = *ms
}
verb := false
if *vl {
verb = *vl
}
if *vs {
verb = *vs
}
r := bufio.NewReader(os.Stdin)
fmt.Print("Please enter the size of the CHORD network: ")
st, _ := r.ReadString('\n')
st = strings.TrimSpace(st)
s, err := ParseInt32(st)
fts, err := ComputeFTableSize(s)
if err != nil {
fmt.Println("The size of the network must be some exponential of 2 (e.g. 2^5 = 32).")
}
if err != nil {
log.Fatalf("Could not parse the size. Please enter an integer number.")
}
chord := InitializeChord(s)
if verb {
PrintNetwork(chord)
}
if man {
CreateActiveNodes(&chord, r)
} else {
GenerateActiveNodes(&chord, r)
}
if verb {
PrintActiveNodes(chord)
PrintNetwork(chord)
}
DetermineSuccessors(&chord)
if verb {
PrintNetwork(chord)
}
CreateFingerTables(&chord, fts)
if verb {
PrintNetwork(chord)
}
fmt.Println()
fmt.Print("Enter a data node: ")
nt, _ := r.ReadString('\n')
nt = strings.TrimSpace(nt)
n, err := ParseInt32(nt)
fmt.Print("Enter a node from where to search from: ")
at, _ := r.ReadString('\n')
at = strings.TrimSpace(at)
anchor, err := ParseInt32(at)
FindSuccessor(&chord, anchor, n)
}