This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathaction_addlist.go
70 lines (58 loc) · 1.54 KB
/
action_addlist.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
package holochain
import (
"fmt"
peer "github.com/libp2p/go-libp2p-peer"
)
//------------------------------------------------------------
// ListAdd
type ActionListAdd struct {
list PeerList
}
func NewListAddAction(peerList PeerList) *ActionListAdd {
a := ActionListAdd{list: peerList}
return &a
}
func (a *ActionListAdd) Name() string {
return "put"
}
var prefix string = "List add request rejected on warrant failure"
func (a *ActionListAdd) Receive(dht *DHT, msg *Message) (response interface{}, err error) {
t := msg.Body.(ListAddReq)
a.list.Type = PeerListType(t.ListType)
a.list.Records = make([]PeerRecord, 0)
var pid peer.ID
for _, pStr := range t.Peers {
pid, err = peer.IDB58Decode(pStr)
if err != nil {
return
}
r := PeerRecord{ID: pid}
a.list.Records = append(a.list.Records, r)
}
// validate the warrant sent with the list add request
var w Warrant
w, err = DecodeWarrant(t.WarrantType, t.Warrant)
if err != nil {
err = fmt.Errorf("%s: unable to decode warrant (%v)", prefix, err)
return
}
err = w.Verify(dht.h)
if err != nil {
err = fmt.Errorf("%s: %v", prefix, err)
return
}
// TODO verify that the warrant, if valid, is sufficient to allow list addition #300
err = dht.addToList(msg, a.list)
if err != nil {
return
}
// special case to add blockedlist peers to node cache and delete them from the gossipers list
if a.list.Type == BlockedList {
for _, node := range a.list.Records {
dht.h.node.Block(node.ID)
dht.DeleteGossiper(node.ID) // ignore error
}
}
response = DHTChangeOK
return
}