diff options
Diffstat (limited to 'src/gnunet/message/msg_dht.go')
-rw-r--r-- | src/gnunet/message/msg_dht.go | 96 |
1 files changed, 30 insertions, 66 deletions
diff --git a/src/gnunet/message/msg_dht.go b/src/gnunet/message/msg_dht.go index 9e1a747..0f8b9cc 100644 --- a/src/gnunet/message/msg_dht.go +++ b/src/gnunet/message/msg_dht.go | |||
@@ -19,7 +19,6 @@ | |||
19 | package message | 19 | package message |
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "encoding/hex" | ||
23 | "fmt" | 22 | "fmt" |
24 | 23 | ||
25 | "gnunet/crypto" | 24 | "gnunet/crypto" |
@@ -33,9 +32,8 @@ import ( | |||
33 | 32 | ||
34 | // DHTClientPutMsg is the message for putting values into the DHT | 33 | // DHTClientPutMsg is the message for putting values into the DHT |
35 | type DHTClientPutMsg struct { | 34 | type DHTClientPutMsg struct { |
36 | MsgSize uint16 `order:"big"` // total size of message | 35 | MsgHeader |
37 | MsgType uint16 `order:"big"` // DHT_CLIENT_PUT (142) | 36 | BType enums.BlockType `order:"big"` // The type of the data (BLOCK_TYPE_???) |
38 | Type uint32 `order:"big"` // The type of the data (BLOCK_TYPE_???) | ||
39 | Options uint32 `order:"big"` // Message options (DHT_RO_???) | 37 | Options uint32 `order:"big"` // Message options (DHT_RO_???) |
40 | ReplLevel uint32 `order:"big"` // Replication level for this message | 38 | ReplLevel uint32 `order:"big"` // Replication level for this message |
41 | Expire util.AbsoluteTime // Expiration time | 39 | Expire util.AbsoluteTime // Expiration time |
@@ -44,7 +42,7 @@ type DHTClientPutMsg struct { | |||
44 | } | 42 | } |
45 | 43 | ||
46 | // NewDHTClientPutMsg creates a new default DHTClientPutMsg object. | 44 | // NewDHTClientPutMsg creates a new default DHTClientPutMsg object. |
47 | func NewDHTClientPutMsg(key *crypto.HashCode, btype int, data []byte) *DHTClientPutMsg { | 45 | func NewDHTClientPutMsg(key *crypto.HashCode, btype enums.BlockType, data []byte) *DHTClientPutMsg { |
48 | if key == nil { | 46 | if key == nil { |
49 | key = new(crypto.HashCode) | 47 | key = new(crypto.HashCode) |
50 | } | 48 | } |
@@ -53,9 +51,8 @@ func NewDHTClientPutMsg(key *crypto.HashCode, btype int, data []byte) *DHTClient | |||
53 | size += uint16(len(data)) | 51 | size += uint16(len(data)) |
54 | } | 52 | } |
55 | return &DHTClientPutMsg{ | 53 | return &DHTClientPutMsg{ |
56 | MsgSize: size, | 54 | MsgHeader: MsgHeader{size, enums.MSG_DHT_CLIENT_PUT}, |
57 | MsgType: DHT_CLIENT_PUT, | 55 | BType: btype, |
58 | Type: uint32(btype), | ||
59 | Options: uint32(enums.DHT_RO_NONE), | 56 | Options: uint32(enums.DHT_RO_NONE), |
60 | ReplLevel: 1, | 57 | ReplLevel: 1, |
61 | Expire: util.AbsoluteTimeNever(), | 58 | Expire: util.AbsoluteTimeNever(), |
@@ -66,13 +63,8 @@ func NewDHTClientPutMsg(key *crypto.HashCode, btype int, data []byte) *DHTClient | |||
66 | 63 | ||
67 | // String returns a human-readable representation of the message. | 64 | // String returns a human-readable representation of the message. |
68 | func (m *DHTClientPutMsg) String() string { | 65 | func (m *DHTClientPutMsg) String() string { |
69 | return fmt.Sprintf("DHTClientPutMsg{Type=%d,Expire=%s,Options=%d,Repl=%d,Key=%s}", | 66 | return fmt.Sprintf("DHTClientPutMsg{Type=%s,Expire=%s,Options=%d,Repl=%d,Key=%s}", |
70 | m.Type, m.Expire, m.Options, m.ReplLevel, hex.EncodeToString(m.Key.Bits)) | 67 | m.BType, m.Expire, m.Options, m.ReplLevel, m.Key) |
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 | } | 68 | } |
77 | 69 | ||
78 | //---------------------------------------------------------------------- | 70 | //---------------------------------------------------------------------- |
@@ -81,11 +73,10 @@ func (m *DHTClientPutMsg) Header() *Header { | |||
81 | 73 | ||
82 | // DHTClientGetMsg is the message for getting values from the DHT | 74 | // DHTClientGetMsg is the message for getting values from the DHT |
83 | type DHTClientGetMsg struct { | 75 | type DHTClientGetMsg struct { |
84 | MsgSize uint16 `order:"big"` // total size of message | 76 | MsgHeader |
85 | MsgType uint16 `order:"big"` // DHT_CLIENT_GET (143) | ||
86 | Options uint32 `order:"big"` // Message options (DHT_RO_???) | 77 | Options uint32 `order:"big"` // Message options (DHT_RO_???) |
87 | ReplLevel uint32 `order:"big"` // Replication level for this message | 78 | ReplLevel uint32 `order:"big"` // Replication level for this message |
88 | Type uint32 `order:"big"` // The type for the data for the GET request (BLOCK_TYPE_???) | 79 | BType enums.BlockType `order:"big"` // The type for the data for the GET request (BLOCK_TYPE_???) |
89 | Key *crypto.HashCode // The key to search for | 80 | Key *crypto.HashCode // The key to search for |
90 | ID uint64 `order:"big"` // Unique ID identifying this request | 81 | ID uint64 `order:"big"` // Unique ID identifying this request |
91 | XQuery []byte `size:"*"` // Optional xquery | 82 | XQuery []byte `size:"*"` // Optional xquery |
@@ -97,11 +88,10 @@ func NewDHTClientGetMsg(key *crypto.HashCode) *DHTClientGetMsg { | |||
97 | key = new(crypto.HashCode) | 88 | key = new(crypto.HashCode) |
98 | } | 89 | } |
99 | return &DHTClientGetMsg{ | 90 | return &DHTClientGetMsg{ |
100 | MsgSize: 88, | 91 | MsgHeader: MsgHeader{88, enums.MSG_DHT_CLIENT_GET}, |
101 | MsgType: DHT_CLIENT_GET, | ||
102 | Options: uint32(enums.DHT_RO_NONE), | 92 | Options: uint32(enums.DHT_RO_NONE), |
103 | ReplLevel: 1, | 93 | ReplLevel: 1, |
104 | Type: uint32(enums.BLOCK_TYPE_ANY), | 94 | BType: enums.BLOCK_TYPE_ANY, |
105 | Key: key, | 95 | Key: key, |
106 | ID: 0, | 96 | ID: 0, |
107 | XQuery: nil, | 97 | XQuery: nil, |
@@ -119,13 +109,8 @@ func (m *DHTClientGetMsg) SetXQuery(xq []byte) []byte { | |||
119 | 109 | ||
120 | // String returns a human-readable representation of the message. | 110 | // String returns a human-readable representation of the message. |
121 | func (m *DHTClientGetMsg) String() string { | 111 | func (m *DHTClientGetMsg) String() string { |
122 | return fmt.Sprintf("DHTClientGetMsg{Id:%d,Type=%d,Options=%d,Repl=%d,Key=%s}", | 112 | return fmt.Sprintf("DHTClientGetMsg{Id:%d,Type=%s,Options=%d,Repl=%d,Key=%s}", |
123 | m.ID, m.Type, m.Options, m.ReplLevel, hex.EncodeToString(m.Key.Bits)) | 113 | m.ID, m.BType, m.Options, m.ReplLevel, m.Key) |
124 | } | ||
125 | |||
126 | // Header returns the message header in a separate instance. | ||
127 | func (m *DHTClientGetMsg) Header() *Header { | ||
128 | return &Header{m.MsgSize, m.MsgType} | ||
129 | } | 114 | } |
130 | 115 | ||
131 | //---------------------------------------------------------------------- | 116 | //---------------------------------------------------------------------- |
@@ -134,9 +119,8 @@ func (m *DHTClientGetMsg) Header() *Header { | |||
134 | 119 | ||
135 | // DHTClientResultMsg is a message for DHT results | 120 | // DHTClientResultMsg is a message for DHT results |
136 | type DHTClientResultMsg struct { | 121 | type DHTClientResultMsg struct { |
137 | MsgSize uint16 `order:"big"` // total size of message | 122 | MsgHeader |
138 | MsgType uint16 `order:"big"` // DHT_CLIENT_RESULT (145) | 123 | BType enums.BlockType `order:"big"` // The type for the data |
139 | Type uint32 `order:"big"` // The type for the data | ||
140 | PutPathLen uint32 `order:"big"` // Number of peers recorded in outgoing path | 124 | PutPathLen uint32 `order:"big"` // Number of peers recorded in outgoing path |
141 | GetPathLen uint32 `order:"big"` // Number of peers recorded from storage location | 125 | GetPathLen uint32 `order:"big"` // Number of peers recorded from storage location |
142 | ID uint64 `order:"big"` // Unique ID of the matching GET request | 126 | ID uint64 `order:"big"` // Unique ID of the matching GET request |
@@ -153,9 +137,8 @@ func NewDHTClientResultMsg(key *crypto.HashCode) *DHTClientResultMsg { | |||
153 | key = crypto.NewHashCode(nil) | 137 | key = crypto.NewHashCode(nil) |
154 | } | 138 | } |
155 | return &DHTClientResultMsg{ | 139 | return &DHTClientResultMsg{ |
156 | MsgSize: 64, // empty message size (no data) | 140 | MsgHeader: MsgHeader{64, enums.MSG_DHT_CLIENT_RESULT}, |
157 | MsgType: DHT_CLIENT_RESULT, | 141 | BType: 0, |
158 | Type: 0, | ||
159 | PutPathLen: 0, | 142 | PutPathLen: 0, |
160 | GetPathLen: 0, | 143 | GetPathLen: 0, |
161 | ID: 0, | 144 | ID: 0, |
@@ -167,12 +150,7 @@ func NewDHTClientResultMsg(key *crypto.HashCode) *DHTClientResultMsg { | |||
167 | 150 | ||
168 | // String returns a human-readable representation of the message. | 151 | // String returns a human-readable representation of the message. |
169 | func (m *DHTClientResultMsg) String() string { | 152 | func (m *DHTClientResultMsg) String() string { |
170 | return fmt.Sprintf("DHTClientResultMsg{id:%d,expire=%s}", m.ID, m.Expire) | 153 | return fmt.Sprintf("DHTClientResultMsg{id:%d,type=%s,expire=%s}", m.ID, m.BType, m.Expire) |
171 | } | ||
172 | |||
173 | // Header returns the message header in a separate instance. | ||
174 | func (m *DHTClientResultMsg) Header() *Header { | ||
175 | return &Header{m.MsgSize, m.MsgType} | ||
176 | } | 154 | } |
177 | 155 | ||
178 | //---------------------------------------------------------------------- | 156 | //---------------------------------------------------------------------- |
@@ -181,8 +159,7 @@ func (m *DHTClientResultMsg) Header() *Header { | |||
181 | 159 | ||
182 | // DHTClientGetStopMsg stops a pending DHT operation | 160 | // DHTClientGetStopMsg stops a pending DHT operation |
183 | type DHTClientGetStopMsg struct { | 161 | type DHTClientGetStopMsg struct { |
184 | MsgSize uint16 `order:"big"` // total size of message | 162 | MsgHeader |
185 | MsgType uint16 `order:"big"` // DHT_CLIENT_GET_STOP (144) | ||
186 | Reserved uint32 `order:"big"` // Reserved (0) | 163 | Reserved uint32 `order:"big"` // Reserved (0) |
187 | ID uint64 `order:"big"` // Unique ID identifying this request | 164 | ID uint64 `order:"big"` // Unique ID identifying this request |
188 | Key *crypto.HashCode // The key to search for | 165 | Key *crypto.HashCode // The key to search for |
@@ -194,22 +171,16 @@ func NewDHTClientGetStopMsg(key *crypto.HashCode) *DHTClientGetStopMsg { | |||
194 | key = new(crypto.HashCode) | 171 | key = new(crypto.HashCode) |
195 | } | 172 | } |
196 | return &DHTClientGetStopMsg{ | 173 | return &DHTClientGetStopMsg{ |
197 | MsgSize: 80, | 174 | MsgHeader: MsgHeader{80, enums.MSG_DHT_CLIENT_GET_STOP}, |
198 | MsgType: DHT_CLIENT_GET_STOP, | 175 | Reserved: 0, // mandatory |
199 | Reserved: 0, // mandatory | 176 | ID: 0, |
200 | ID: 0, | 177 | Key: key, |
201 | Key: key, | ||
202 | } | 178 | } |
203 | } | 179 | } |
204 | 180 | ||
205 | // String returns a human-readable representation of the message. | 181 | // String returns a human-readable representation of the message. |
206 | func (m *DHTClientGetStopMsg) String() string { | 182 | func (m *DHTClientGetStopMsg) String() string { |
207 | return fmt.Sprintf("DHTClientGetStopMsg{Id:%d,Key=%s}", m.ID, hex.EncodeToString(m.Key.Bits)) | 183 | return fmt.Sprintf("DHTClientGetStopMsg{Id:%d,Key=%s}", m.ID, m.Key) |
208 | } | ||
209 | |||
210 | // Header returns the message header in a separate instance. | ||
211 | func (m *DHTClientGetStopMsg) Header() *Header { | ||
212 | return &Header{m.MsgSize, m.MsgType} | ||
213 | } | 184 | } |
214 | 185 | ||
215 | //---------------------------------------------------------------------- | 186 | //---------------------------------------------------------------------- |
@@ -218,8 +189,7 @@ func (m *DHTClientGetStopMsg) Header() *Header { | |||
218 | 189 | ||
219 | // DHTClientGetResultsKnownMsg is the message for putting values into the DHT | 190 | // DHTClientGetResultsKnownMsg is the message for putting values into the DHT |
220 | type DHTClientGetResultsKnownMsg struct { | 191 | type DHTClientGetResultsKnownMsg struct { |
221 | MsgSize uint16 `order:"big"` // total size of message | 192 | MsgHeader |
222 | MsgType uint16 `order:"big"` // DHT_CLIENT_GET_RESULTS_KNOWN (156) | ||
223 | Reserved uint32 `order:"big"` // Reserved for further use | 193 | Reserved uint32 `order:"big"` // Reserved for further use |
224 | Key *crypto.HashCode // The key to search for | 194 | Key *crypto.HashCode // The key to search for |
225 | ID uint64 `order:"big"` // Unique ID identifying this request | 195 | ID uint64 `order:"big"` // Unique ID identifying this request |
@@ -232,11 +202,10 @@ func NewDHTClientGetResultsKnownMsg(key *crypto.HashCode) *DHTClientGetResultsKn | |||
232 | key = new(crypto.HashCode) | 202 | key = new(crypto.HashCode) |
233 | } | 203 | } |
234 | return &DHTClientGetResultsKnownMsg{ | 204 | return &DHTClientGetResultsKnownMsg{ |
235 | MsgSize: 80, | 205 | MsgHeader: MsgHeader{80, enums.MSG_DHT_CLIENT_GET_RESULTS_KNOWN}, |
236 | MsgType: DHT_CLIENT_GET_RESULTS_KNOWN, | 206 | Key: key, |
237 | Key: key, | 207 | ID: 0, |
238 | ID: 0, | 208 | Known: make([]*crypto.HashCode, 0), |
239 | Known: make([]*crypto.HashCode, 0), | ||
240 | } | 209 | } |
241 | } | 210 | } |
242 | 211 | ||
@@ -249,10 +218,5 @@ func (m *DHTClientGetResultsKnownMsg) AddKnown(hc *crypto.HashCode) { | |||
249 | // String returns a human-readable representation of the message. | 218 | // String returns a human-readable representation of the message. |
250 | func (m *DHTClientGetResultsKnownMsg) String() string { | 219 | func (m *DHTClientGetResultsKnownMsg) String() string { |
251 | return fmt.Sprintf("DHTClientGetResultsKnownMsg{Id:%d,Key=%s,Num=%d}", | 220 | return fmt.Sprintf("DHTClientGetResultsKnownMsg{Id:%d,Key=%s,Num=%d}", |
252 | m.ID, hex.EncodeToString(m.Key.Bits), len(m.Known)) | 221 | m.ID, m.Key.Data, 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 | } | 222 | } |