-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_node.go
88 lines (73 loc) · 2.04 KB
/
remote_node.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
package main
import (
"encoding/json"
"fmt"
)
// remoteNode contains the actual node Id(hash value)
// and remote address(ip:port)
type remoteNode struct {
Id []byte
Address string // ip:port
}
func (r *remoteNode) String() string {
return fmt.Sprintf("Id: %x, Address: %s", r.Id, r.Address)
}
// TODO: cache client connections, no need to create every time
// GetPredecessor
func (rn *remoteNode) GetPredecessorRemote() (*remoteNode, error) {
fmt.Println("GetPredecessorRemote", rn)
client := newClient(rn)
return client.GetPredecessor(rn.Address)
}
// FindSuccessorRemote contacts the appropriate remoteNode
// to find the successor
func (rn *remoteNode) FindSuccessorRemote(id []byte) (*remoteNode, error) {
client := newClient(rn)
return client.FindSuccessor(rn.Address, id)
}
func (rn *remoteNode) NotifyRemote(address string) {
client := newClient(rn)
client.Notify(address)
}
func (rn *remoteNode) Marshal() string {
data, err := json.Marshal(&rn)
checkErrPanic(err)
return string(data)
}
func (rn *remoteNode) Unmarshal(data string) error {
err := json.Unmarshal([]byte(data), &rn)
checkErrPanic(err)
return err
}
func (rn *remoteNode) GetRemote(key string) (string, error) {
// client := newClient(rn)
// TODO: Implementz
// return client.Get(rn.Address, key)
return "", nil
}
func (rn *remoteNode) GetValRemote(key string) (string, error) {
// client := newClient(rn)
// TODO: Implement
// return client.GetVal(rn.Address, key)
return "", nil
}
func (rn *remoteNode) PutRemote(key string, value string) {
// client := newClient(rn)
// TODO: Implement
// client.Put(rn.Address, key, value)
}
func (rn *remoteNode) PutKeyValRemote(key string, value string) {
// client := newClient(rn)
// TODO: Implement
// client.PutKeyVal(rn.Address, key, value)
}
func (rn *remoteNode) DeleteRemote(key string) {
// client := newClient(rn)
// TODO: Implement
// client.Delete(rn.Address, key)
}
func (rn *remoteNode) DeleteKeyRemote(key string) {
// TODO: Implement
// client := newClient(rn)
// client.DeleteKey(rn.Address, key)
}