Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (67 loc) · 1.77 KB
/
Copy pathmain.go
File metadata and controls
79 lines (67 loc) · 1.77 KB
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
package main
import (
"log"
"net"
"net/http"
"net/rpc"
"os"
"strconv"
)
func main() {
// start with the following format "./node bs id ip" -> "./node 127.0.0.1:8033 1 127.0.0.1:8001"
// for starting node, bs can be START
bs_addr := os.Args[1]
id := os.Args[2]
log_addr := os.Args[3]
node_id, _ := strconv.ParseUint(id, 10, 64)
// log_addr := "127.0.0.1:" + strconv.Itoa(int(8000 + node_id))
py_addr := "127.0.0.1:" + strconv.Itoa(int(7000 + node_id))
// node_bs, _ := strconv.ParseUint(bs, 10, 64)
// bs_addr := "127.0.0.1:" + strconv.Itoa(int(8000 + node_bs))
n := Node{
hashtable: make(map[string]Value),
successor_list: make([]NodeInfo, 2),
id: uint64(node_id),
addr: log_addr,
// neighbors: make(map[uint64]string),
}
log_updates(n.id, "Joined the system, yet to be placed")
rpc.Register(&n)
// Start listening
listener, err := net.Listen("tcp", log_addr)
if err != nil {
log.Fatal(err)
}
// Accept RPC connections on the existing startup port.
go func() {
for {
conn, err := listener.Accept()
if err != nil {
continue
}
go rpc.ServeConn(conn)
}
}()
http.HandleFunc("/put_chunk", n.put_chunk)
http.HandleFunc("/get_chunk", n.get_chunk)
http.HandleFunc("/delete_chunk", n.delete_chunk)
http.HandleFunc("/search_chunk", n.search_chunk)
go func() {
log.Printf("HTTP endpoint listening on " + py_addr)
if err := http.ListenAndServe(py_addr, nil); err != nil {
log.Printf("http server stopped: %v", err)
}
}()
if err := n.JoinSystem(bs_addr); err != nil {
log_updates(n.id, "Join failed: "+err.Error())
}
n.fingers = make([]Fingers, 8)
// make ft here
go n.FailureDetector()
go n.MakeFingerTable()
go n.Stabilize()
go n.Replication()
go n.DiskBackup()
n.event_manage()
// switch {}
}