diff options
Diffstat (limited to 'src/gnunet/message/msg_dht.go')
-rw-r--r-- | src/gnunet/message/msg_dht.go | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/src/gnunet/message/msg_dht.go b/src/gnunet/message/msg_dht.go index 9b73557..bb8fc1a 100644 --- a/src/gnunet/message/msg_dht.go +++ b/src/gnunet/message/msg_dht.go | |||
@@ -28,6 +28,54 @@ import ( | |||
28 | ) | 28 | ) |
29 | 29 | ||
30 | //---------------------------------------------------------------------- | 30 | //---------------------------------------------------------------------- |
31 | // DHT_CLIENT_PUT | ||
32 | //---------------------------------------------------------------------- | ||
33 | |||
34 | // DHTClientPutMsg is the message for putting values into the DHT | ||
35 | type DHTClientPutMsg struct { | ||
36 | MsgSize uint16 `order:"big"` // total size of message | ||
37 | MsgType uint16 `order:"big"` // DHT_CLIENT_PUT (142) | ||
38 | Type uint32 `order:"big"` // The type of the data (BLOCK_TYPE_???) | ||
39 | Options uint32 `order:"big"` // Message options (DHT_RO_???) | ||
40 | ReplLevel uint32 `order:"big"` // Replication level for this message | ||
41 | Expire util.AbsoluteTime // Expiration time | ||
42 | Key *crypto.HashCode // The key to be used | ||
43 | Data []byte `size:"*"` // Block data | ||
44 | } | ||
45 | |||
46 | // NewDHTClientPutMsg creates a new default DHTClientPutMsg object. | ||
47 | func NewDHTClientPutMsg(key *crypto.HashCode, btype int, data []byte) *DHTClientPutMsg { | ||
48 | if key == nil { | ||
49 | key = new(crypto.HashCode) | ||
50 | } | ||
51 | var size uint16 = 88 | ||
52 | if data != nil { | ||
53 | size += uint16(len(data)) | ||
54 | } | ||
55 | return &DHTClientPutMsg{ | ||
56 | MsgSize: size, | ||
57 | MsgType: DHT_CLIENT_PUT, | ||
58 | Type: uint32(btype), | ||
59 | Options: uint32(enums.DHT_RO_NONE), | ||
60 | ReplLevel: 1, | ||
61 | Expire: util.AbsoluteTimeNever(), | ||
62 | Key: key, | ||
63 | Data: data, | ||
64 | } | ||
65 | } | ||
66 | |||
67 | // String returns a human-readable representation of the message. | ||
68 | func (m *DHTClientPutMsg) String() string { | ||
69 | return fmt.Sprintf("DHTClientPutMsg{Type=%d,Expire=%s,Options=%d,Repl=%d,Key=%s}", | ||
70 | m.Type, m.Expire, m.Options, m.ReplLevel, hex.EncodeToString(m.Key.Bits)) | ||
71 | } | ||
72 | |||
73 | // Header returns the message header in a separate instance. | ||
74 | func (m *DHTClientPutMsg) Header() *Header { | ||
75 | return &Header{m.MsgSize, m.MsgType} | ||
76 | } | ||
77 | |||
78 | //---------------------------------------------------------------------- | ||
31 | // DHT_CLIENT_GET | 79 | // DHT_CLIENT_GET |
32 | //---------------------------------------------------------------------- | 80 | //---------------------------------------------------------------------- |
33 | 81 | ||
@@ -102,7 +150,7 @@ type DHTClientResultMsg struct { | |||
102 | // NewDHTClientResultMsg creates a new default DHTClientResultMsg object. | 150 | // NewDHTClientResultMsg creates a new default DHTClientResultMsg object. |
103 | func NewDHTClientResultMsg(key *crypto.HashCode) *DHTClientResultMsg { | 151 | func NewDHTClientResultMsg(key *crypto.HashCode) *DHTClientResultMsg { |
104 | if key == nil { | 152 | if key == nil { |
105 | key = crypto.NewHashCode() | 153 | key = crypto.NewHashCode(nil) |
106 | } | 154 | } |
107 | return &DHTClientResultMsg{ | 155 | return &DHTClientResultMsg{ |
108 | MsgSize: 64, // empty message size (no data) | 156 | MsgSize: 64, // empty message size (no data) |
@@ -163,3 +211,48 @@ func (m *DHTClientGetStopMsg) String() string { | |||
163 | func (m *DHTClientGetStopMsg) Header() *Header { | 211 | func (m *DHTClientGetStopMsg) Header() *Header { |
164 | return &Header{m.MsgSize, m.MsgType} | 212 | return &Header{m.MsgSize, m.MsgType} |
165 | } | 213 | } |
214 | |||
215 | //---------------------------------------------------------------------- | ||
216 | // DHT_CLIENT_GET_RESULTS_KNOWN | ||
217 | //---------------------------------------------------------------------- | ||
218 | |||
219 | // DHTClientGetResultsKnownMsg is the message for putting values into the DHT | ||
220 | type DHTClientGetResultsKnownMsg struct { | ||
221 | MsgSize uint16 `order:"big"` // total size of message | ||
222 | MsgType uint16 `order:"big"` // DHT_CLIENT_GET_RESULTS_KNOWN (156) | ||
223 | Reserved uint32 `order:"big"` // Reserved for further use | ||
224 | Key *crypto.HashCode // The key to search for | ||
225 | ID uint64 `order:"big"` // Unique ID identifying this request | ||
226 | Known []*crypto.HashCode `size:"*"` // list of known results | ||
227 | } | ||
228 | |||
229 | // NewDHTClientPutMsg creates a new default DHTClientPutMsg object. | ||
230 | func NewDHTClientGetResultsKnownMsg(key *crypto.HashCode) *DHTClientGetResultsKnownMsg { | ||
231 | if key == nil { | ||
232 | key = new(crypto.HashCode) | ||
233 | } | ||
234 | return &DHTClientGetResultsKnownMsg{ | ||
235 | MsgSize: 80, | ||
236 | MsgType: DHT_CLIENT_GET_RESULTS_KNOWN, | ||
237 | Key: key, | ||
238 | ID: 0, | ||
239 | Known: make([]*crypto.HashCode, 0), | ||
240 | } | ||
241 | } | ||
242 | |||
243 | // AddKnown adds a known result to the list | ||
244 | func (m *DHTClientGetResultsKnownMsg) AddKnown(hc *crypto.HashCode) { | ||
245 | m.Known = append(m.Known, hc) | ||
246 | m.MsgSize += 64 | ||
247 | } | ||
248 | |||
249 | // String returns a human-readable representation of the message. | ||
250 | func (m *DHTClientGetResultsKnownMsg) String() string { | ||
251 | return fmt.Sprintf("DHTClientGetResultsKnownMsg{Id:%d,Key=%s,Num=%d}", | ||
252 | m.ID, hex.EncodeToString(m.Key.Bits), len(m.Known)) | ||
253 | } | ||
254 | |||
255 | // Header returns the message header in a separate instance. | ||
256 | func (m *DHTClientGetResultsKnownMsg) Header() *Header { | ||
257 | return &Header{m.MsgSize, m.MsgType} | ||
258 | } | ||