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_delete.go
111 lines (91 loc) · 2.47 KB
/
action_delete.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package holochain
import (
. "github.com/holochain/holochain-proto/hash"
peer "github.com/libp2p/go-libp2p-peer"
)
//------------------------------------------------------------
// Del
type APIFnDel struct {
action ActionDel
}
func (fn *APIFnDel) Name() string {
return fn.action.Name()
}
func (fn *APIFnDel) Args() []Arg {
return []Arg{{Name: "hash", Type: HashArg}, {Name: "message", Type: StringArg}}
}
func (fn *APIFnDel) Call(h *Holochain) (response interface{}, err error) {
a := &fn.action
response, err = h.commitAndShare(a, NullHash())
return
}
type ActionDel struct {
entry DelEntry
header *Header
}
func NewDelAction(entry DelEntry) *ActionDel {
a := ActionDel{entry: entry}
return &a
}
func (a *ActionDel) Name() string {
return "del"
}
func (a *ActionDel) Entry() Entry {
j, err := a.entry.ToJSON()
if err != nil {
panic(err)
}
return &GobEntry{C: j}
}
func (a *ActionDel) EntryType() string {
return DelEntryType
}
func (a *ActionDel) SetHeader(header *Header) {
a.header = header
}
func (a *ActionDel) GetHeader() (header *Header) {
return a.header
}
func (a *ActionDel) Share(h *Holochain, def *EntryDef) (err error) {
if def.isSharingPublic() {
// if it's a public entry send the DHT DEL & PUT messages
h.dht.Change(a.header.EntryLink, PUT_REQUEST, HoldReq{EntryHash: a.header.EntryLink})
h.dht.Change(a.entry.Hash, DEL_REQUEST, HoldReq{RelatedHash: a.entry.Hash, EntryHash: a.header.EntryLink})
}
return
}
func (a *ActionDel) SysValidation(h *Holochain, def *EntryDef, pkg *Package, sources []peer.ID) (err error) {
if def != DelEntryDef {
err = ErrEntryDefInvalid
return
}
return
}
func (a *ActionDel) Receive(dht *DHT, msg *Message) (response interface{}, err error) {
t := msg.Body.(HoldReq)
var holdResp *HoldResp
err = RunValidationPhase(dht.h, msg.From, VALIDATE_DEL_REQUEST, t.EntryHash, func(resp ValidateResponse) error {
var delEntry DelEntry
delEntry, err = DelEntryFromJSON(resp.Entry.Content().(string))
a := NewDelAction(delEntry)
//@TODO what comes back from Validate Del
_, err = dht.h.ValidateAction(a, resp.Type, &resp.Package, []peer.ID{msg.From})
if err != nil {
// how do we record an invalid DEL?
//@TODO store as REJECTED
} else {
err = dht.Del(msg, delEntry.Hash)
if err == nil {
holdResp, err = dht.MakeHoldResp(msg, StatusLive)
}
}
return err
})
if holdResp != nil {
response = *holdResp
}
return
}
func (a *ActionDel) CheckValidationRequest(def *EntryDef) (err error) {
return
}