diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-04 08:25:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-04 08:25:28 +0000 |
commit | a82188f859826f98b209f265531d1fa63f2b6ae2 (patch) | |
tree | 260054d6fa6e71341e2feec387a1ef09988e7a60 /src | |
parent | 6c5be1e49eaeca44de6ec6e2e6ec2e91947a0752 (diff) | |
download | gnunet-a82188f859826f98b209f265531d1fa63f2b6ae2.tar.gz gnunet-a82188f859826f98b209f265531d1fa63f2b6ae2.zip |
passing bf and xquery from client to service
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/dht.h | 85 | ||||
-rw-r--r-- | src/dht/dht_api.c | 8 | ||||
-rw-r--r-- | src/dht/dht_api_find_peer.c | 10 | ||||
-rw-r--r-- | src/dht/dht_api_get_put.c | 51 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 66 | ||||
-rw-r--r-- | src/fs/fs.h | 3 | ||||
-rw-r--r-- | src/include/gnunet_dht_service.h | 12 |
7 files changed, 192 insertions, 43 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 237b91f64..63e95e113 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -34,8 +34,14 @@ | |||
34 | */ | 34 | */ |
35 | #define DEBUG_DHT_ROUTING GNUNET_YES | 35 | #define DEBUG_DHT_ROUTING GNUNET_YES |
36 | 36 | ||
37 | /** | ||
38 | * FIXME: document. | ||
39 | */ | ||
37 | #define DHT_BLOOM_SIZE 128 | 40 | #define DHT_BLOOM_SIZE 128 |
38 | 41 | ||
42 | /** | ||
43 | * FIXME: document. | ||
44 | */ | ||
39 | #define DHT_BLOOM_K 6 | 45 | #define DHT_BLOOM_K 6 |
40 | 46 | ||
41 | /** | 47 | /** |
@@ -48,12 +54,24 @@ | |||
48 | */ | 54 | */ |
49 | #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 55 | #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) |
50 | 56 | ||
57 | /** | ||
58 | * FIXME: document. | ||
59 | */ | ||
51 | #define DEFAULT_DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) | 60 | #define DEFAULT_DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) |
52 | 61 | ||
62 | /** | ||
63 | * FIXME: document. | ||
64 | */ | ||
53 | #define DHT_SEND_PRIORITY 4 | 65 | #define DHT_SEND_PRIORITY 4 |
54 | 66 | ||
67 | /** | ||
68 | * FIXME: document. | ||
69 | */ | ||
55 | #define DEFAULT_GET_REPLICATION 5 | 70 | #define DEFAULT_GET_REPLICATION 5 |
56 | 71 | ||
72 | /** | ||
73 | * FIXME: document. | ||
74 | */ | ||
57 | #define DEFAULT_PUT_REPLICATION 8 | 75 | #define DEFAULT_PUT_REPLICATION 8 |
58 | 76 | ||
59 | #define STAT_ROUTES "# DHT ROUTE Requests Seen" | 77 | #define STAT_ROUTES "# DHT ROUTE Requests Seen" |
@@ -79,9 +97,18 @@ | |||
79 | #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)" | 97 | #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)" |
80 | #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)" | 98 | #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)" |
81 | 99 | ||
100 | |||
101 | /** | ||
102 | * FIXME: document. | ||
103 | */ | ||
82 | typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, | 104 | typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, |
83 | const struct GNUNET_MessageHeader | 105 | const struct GNUNET_MessageHeader |
84 | *msg); | 106 | *msg); |
107 | |||
108 | |||
109 | /** | ||
110 | * FIXME: document. | ||
111 | */ | ||
85 | struct GNUNET_DHT_ControlMessage | 112 | struct GNUNET_DHT_ControlMessage |
86 | { | 113 | { |
87 | /** | 114 | /** |
@@ -100,6 +127,7 @@ struct GNUNET_DHT_ControlMessage | |||
100 | uint16_t variable; | 127 | uint16_t variable; |
101 | }; | 128 | }; |
102 | 129 | ||
130 | |||
103 | /** | 131 | /** |
104 | * Message which indicates the DHT should cancel outstanding | 132 | * Message which indicates the DHT should cancel outstanding |
105 | * requests and discard any state. | 133 | * requests and discard any state. |
@@ -142,11 +170,21 @@ struct GNUNET_DHT_RouteMessage | |||
142 | struct GNUNET_MessageHeader header; | 170 | struct GNUNET_MessageHeader header; |
143 | 171 | ||
144 | /** | 172 | /** |
145 | * Message options | 173 | * Message options, actually an 'enum GNUNET_DHT_RouteOption' value. |
146 | */ | 174 | */ |
147 | uint32_t options GNUNET_PACKED; | 175 | uint32_t options GNUNET_PACKED; |
148 | 176 | ||
149 | /** | 177 | /** |
178 | * Replication level for this message | ||
179 | */ | ||
180 | uint32_t desired_replication_level GNUNET_PACKED; | ||
181 | |||
182 | /** | ||
183 | * For alignment, always zero. | ||
184 | */ | ||
185 | uint32_t reserved GNUNET_PACKED; | ||
186 | |||
187 | /** | ||
150 | * The key to search for | 188 | * The key to search for |
151 | */ | 189 | */ |
152 | GNUNET_HashCode key; | 190 | GNUNET_HashCode key; |
@@ -157,16 +195,12 @@ struct GNUNET_DHT_RouteMessage | |||
157 | */ | 195 | */ |
158 | uint64_t unique_id GNUNET_PACKED; | 196 | uint64_t unique_id GNUNET_PACKED; |
159 | 197 | ||
160 | /** | ||
161 | * Replication level for this message | ||
162 | */ | ||
163 | uint32_t desired_replication_level GNUNET_PACKED; | ||
164 | |||
165 | 198 | ||
166 | /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ | 199 | /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ |
167 | 200 | ||
168 | }; | 201 | }; |
169 | 202 | ||
203 | |||
170 | /** | 204 | /** |
171 | * Generic local route result message | 205 | * Generic local route result message |
172 | */ | 206 | */ |
@@ -178,9 +212,9 @@ struct GNUNET_DHT_RouteResultMessage | |||
178 | struct GNUNET_MessageHeader header; | 212 | struct GNUNET_MessageHeader header; |
179 | 213 | ||
180 | /** | 214 | /** |
181 | * Message options | 215 | * For alignment, always zero. |
182 | */ | 216 | */ |
183 | uint32_t options GNUNET_PACKED; | 217 | uint32_t reserved GNUNET_PACKED; |
184 | 218 | ||
185 | /** | 219 | /** |
186 | * Unique ID identifying this request (necessary for | 220 | * Unique ID identifying this request (necessary for |
@@ -196,6 +230,7 @@ struct GNUNET_DHT_RouteResultMessage | |||
196 | /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ | 230 | /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ |
197 | }; | 231 | }; |
198 | 232 | ||
233 | |||
199 | /** | 234 | /** |
200 | * Generic P2P DHT route message | 235 | * Generic P2P DHT route message |
201 | */ | 236 | */ |
@@ -231,7 +266,7 @@ struct GNUNET_DHT_P2PRouteMessage | |||
231 | */ | 266 | */ |
232 | uint64_t unique_id GNUNET_PACKED; | 267 | uint64_t unique_id GNUNET_PACKED; |
233 | 268 | ||
234 | /* | 269 | /** |
235 | * Bloomfilter to stop circular routes | 270 | * Bloomfilter to stop circular routes |
236 | */ | 271 | */ |
237 | char bloomfilter[DHT_BLOOM_SIZE]; | 272 | char bloomfilter[DHT_BLOOM_SIZE]; |
@@ -277,7 +312,7 @@ struct GNUNET_DHT_P2PRouteResultMessage | |||
277 | */ | 312 | */ |
278 | uint64_t unique_id GNUNET_PACKED; | 313 | uint64_t unique_id GNUNET_PACKED; |
279 | 314 | ||
280 | /* | 315 | /** |
281 | * Bloomfilter to stop circular routes | 316 | * Bloomfilter to stop circular routes |
282 | */ | 317 | */ |
283 | char bloomfilter[DHT_BLOOM_SIZE]; | 318 | char bloomfilter[DHT_BLOOM_SIZE]; |
@@ -313,7 +348,7 @@ struct GNUNET_DHT_PutMessage | |||
313 | /** | 348 | /** |
314 | * The type of data to insert. | 349 | * The type of data to insert. |
315 | */ | 350 | */ |
316 | size_t type GNUNET_PACKED; | 351 | uint32_t type GNUNET_PACKED; |
317 | 352 | ||
318 | /** | 353 | /** |
319 | * How long should this data persist? | 354 | * How long should this data persist? |
@@ -337,12 +372,32 @@ struct GNUNET_DHT_GetMessage | |||
337 | struct GNUNET_MessageHeader header; | 372 | struct GNUNET_MessageHeader header; |
338 | 373 | ||
339 | /** | 374 | /** |
340 | * The type for the data for the GET request | 375 | * The type for the data for the GET request; actually an 'enum |
376 | * GNUNET_BLOCK_Type'. | ||
341 | */ | 377 | */ |
342 | uint32_t type; | 378 | uint32_t type; |
343 | 379 | ||
380 | /** | ||
381 | * Mutator used for the bloom filter (0 if no bf is used). | ||
382 | */ | ||
383 | uint32_t bf_mutator; | ||
384 | |||
385 | /** | ||
386 | * Size of the eXtended query (xquery). | ||
387 | */ | ||
388 | uint16_t xquery_size; | ||
389 | |||
390 | /** | ||
391 | * Size of the bloom filter. | ||
392 | */ | ||
393 | uint16_t bf_size; | ||
394 | |||
395 | /* Followed by the xquery which has 'xquery_size' bytes */ | ||
396 | |||
397 | /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */ | ||
344 | }; | 398 | }; |
345 | 399 | ||
400 | |||
346 | /** | 401 | /** |
347 | * Generic DHT message, indicates that a route request | 402 | * Generic DHT message, indicates that a route request |
348 | * should be issued, if coming from a client. Shared | 403 | * should be issued, if coming from a client. Shared |
@@ -361,6 +416,7 @@ struct GNUNET_DHT_FindPeerMessage | |||
361 | char bloomfilter[DHT_BLOOM_SIZE]; | 416 | char bloomfilter[DHT_BLOOM_SIZE]; |
362 | }; | 417 | }; |
363 | 418 | ||
419 | |||
364 | /** | 420 | /** |
365 | * Message to return data either to the client API | 421 | * Message to return data either to the client API |
366 | * or to respond to a request received from another | 422 | * or to respond to a request received from another |
@@ -379,11 +435,6 @@ struct GNUNET_DHT_GetResultMessage | |||
379 | uint32_t type; | 435 | uint32_t type; |
380 | 436 | ||
381 | /** | 437 | /** |
382 | * The key that was searched for | ||
383 | */ | ||
384 | //GNUNET_HashCode key; | ||
385 | |||
386 | /** | ||
387 | * When does this entry expire? | 438 | * When does this entry expire? |
388 | */ | 439 | */ |
389 | struct GNUNET_TIME_AbsoluteNBO expiration; | 440 | struct GNUNET_TIME_AbsoluteNBO expiration; |
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 5abc228a3..0dd40a735 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -398,6 +398,8 @@ process_reply (void *cls, | |||
398 | const struct GNUNET_MessageHeader *enc_msg; | 398 | const struct GNUNET_MessageHeader *enc_msg; |
399 | size_t enc_size; | 399 | size_t enc_size; |
400 | uint64_t uid; | 400 | uint64_t uid; |
401 | const struct GNUNET_PeerIdentity *const*get_path; | ||
402 | const struct GNUNET_PeerIdentity *const*put_path; | ||
401 | 403 | ||
402 | uid = GNUNET_ntohll (dht_msg->unique_id); | 404 | uid = GNUNET_ntohll (dht_msg->unique_id); |
403 | if (uid != rh->uid) | 405 | if (uid != rh->uid) |
@@ -420,8 +422,12 @@ process_reply (void *cls, | |||
420 | } | 422 | } |
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
422 | "Processing reply.\n"); | 424 | "Processing reply.\n"); |
425 | get_path = NULL; // FIXME: parse path info! | ||
426 | put_path = NULL; // FIXME: parse path info! | ||
423 | rh->iter (rh->iter_cls, | 427 | rh->iter (rh->iter_cls, |
424 | &rh->key, | 428 | &rh->key, |
429 | get_path, | ||
430 | put_path, | ||
425 | enc_msg); | 431 | enc_msg); |
426 | return GNUNET_YES; | 432 | return GNUNET_YES; |
427 | } | 433 | } |
@@ -613,7 +619,7 @@ timeout_route_request (void *cls, | |||
613 | */ | 619 | */ |
614 | struct GNUNET_DHT_RouteHandle * | 620 | struct GNUNET_DHT_RouteHandle * |
615 | GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, | 621 | GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, |
616 | const GNUNET_HashCode * key, | 622 | const GNUNET_HashCode *key, |
617 | uint32_t desired_replication_level, | 623 | uint32_t desired_replication_level, |
618 | enum GNUNET_DHT_RouteOption options, | 624 | enum GNUNET_DHT_RouteOption options, |
619 | const struct GNUNET_MessageHeader *enc, | 625 | const struct GNUNET_MessageHeader *enc, |
diff --git a/src/dht/dht_api_find_peer.c b/src/dht/dht_api_find_peer.c index fb27820ad..cd3bed5ba 100644 --- a/src/dht/dht_api_find_peer.c +++ b/src/dht/dht_api_find_peer.c | |||
@@ -62,10 +62,20 @@ struct GNUNET_DHT_FindPeerHandle | |||
62 | /** | 62 | /** |
63 | * Iterator called on each result obtained from a generic route | 63 | * Iterator called on each result obtained from a generic route |
64 | * operation | 64 | * operation |
65 | * | ||
66 | * @param cls closure | ||
67 | * @param key key that was used | ||
68 | * @param get_path NULL-terminated array of pointers | ||
69 | * to the peers on reverse GET path (or NULL if not recorded) | ||
70 | * @param put_path NULL-terminated array of pointers | ||
71 | * to the peers on the PUT path (or NULL if not recorded) | ||
72 | * @param reply response | ||
65 | */ | 73 | */ |
66 | static void | 74 | static void |
67 | find_peer_reply_iterator (void *cls, | 75 | find_peer_reply_iterator (void *cls, |
68 | const GNUNET_HashCode *key, | 76 | const GNUNET_HashCode *key, |
77 | const struct GNUNET_PeerIdentity * const *get_path, | ||
78 | const struct GNUNET_PeerIdentity * const *put_path, | ||
69 | const struct GNUNET_MessageHeader *reply) | 79 | const struct GNUNET_MessageHeader *reply) |
70 | { | 80 | { |
71 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls; | 81 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls; |
diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c index b1b80b01e..d0e40ca70 100644 --- a/src/dht/dht_api_get_put.c +++ b/src/dht/dht_api_get_put.c | |||
@@ -121,17 +121,21 @@ struct GNUNET_DHT_GetHandle | |||
121 | * | 121 | * |
122 | * @param cls the 'struct GNUNET_DHT_GetHandle' | 122 | * @param cls the 'struct GNUNET_DHT_GetHandle' |
123 | * @param key key that was used | 123 | * @param key key that was used |
124 | * @param get_path NULL-terminated array of pointers | ||
125 | * to the peers on reverse GET path (or NULL if not recorded) | ||
126 | * @param put_path NULL-terminated array of pointers | ||
127 | * to the peers on the PUT path (or NULL if not recorded) | ||
124 | * @param reply response | 128 | * @param reply response |
125 | */ | 129 | */ |
126 | static void | 130 | static void |
127 | get_reply_iterator (void *cls, | 131 | get_reply_iterator (void *cls, |
128 | const GNUNET_HashCode *key, | 132 | const GNUNET_HashCode *key, |
133 | const struct GNUNET_PeerIdentity * const *get_path, | ||
134 | const struct GNUNET_PeerIdentity * const *put_path, | ||
129 | const struct GNUNET_MessageHeader *reply) | 135 | const struct GNUNET_MessageHeader *reply) |
130 | { | 136 | { |
131 | struct GNUNET_DHT_GetHandle *get_handle = cls; | 137 | struct GNUNET_DHT_GetHandle *get_handle = cls; |
132 | const struct GNUNET_DHT_GetResultMessage *result; | 138 | const struct GNUNET_DHT_GetResultMessage *result; |
133 | const struct GNUNET_PeerIdentity *const*get_path; | ||
134 | const struct GNUNET_PeerIdentity *const*put_path; | ||
135 | size_t payload; | 139 | size_t payload; |
136 | 140 | ||
137 | if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) | 141 | if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_GET_RESULT) |
@@ -144,9 +148,6 @@ get_reply_iterator (void *cls, | |||
144 | sizeof (struct GNUNET_DHT_GetResultMessage)); | 148 | sizeof (struct GNUNET_DHT_GetResultMessage)); |
145 | result = (const struct GNUNET_DHT_GetResultMessage *) reply; | 149 | result = (const struct GNUNET_DHT_GetResultMessage *) reply; |
146 | payload = ntohs (reply->size) - sizeof(struct GNUNET_DHT_GetResultMessage); | 150 | payload = ntohs (reply->size) - sizeof(struct GNUNET_DHT_GetResultMessage); |
147 | get_path = NULL; // FIXME: parse path info! | ||
148 | put_path = NULL; // FIXME: parse path info! | ||
149 | |||
150 | get_handle->iter (get_handle->iter_cls, | 151 | get_handle->iter (get_handle->iter_cls, |
151 | GNUNET_TIME_absolute_ntoh (result->expiration), | 152 | GNUNET_TIME_absolute_ntoh (result->expiration), |
152 | key, | 153 | key, |
@@ -191,25 +192,49 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
191 | void *iter_cls) | 192 | void *iter_cls) |
192 | { | 193 | { |
193 | struct GNUNET_DHT_GetHandle *get_handle; | 194 | struct GNUNET_DHT_GetHandle *get_handle; |
194 | struct GNUNET_DHT_GetMessage get_msg; | 195 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
195 | 196 | struct GNUNET_DHT_GetMessage *get_msg; | |
196 | /* FIXME: transmit bf, mutator, xquery & xquery_size as well... */ | 197 | size_t bf_size; |
198 | |||
199 | bf_size = GNUNET_CONTAINER_bloomfilter_get_size (bf); | ||
200 | if ( (sizeof (buf) <= | ||
201 | sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) || | ||
202 | (sizeof (buf) <= bf_size)) | ||
203 | { | ||
204 | GNUNET_break (0); | ||
205 | return NULL; | ||
206 | } | ||
197 | get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle)); | 207 | get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle)); |
198 | get_handle->iter = iter; | 208 | get_handle->iter = iter; |
199 | get_handle->iter_cls = iter_cls; | 209 | get_handle->iter_cls = iter_cls; |
200 | get_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); | 210 | get_msg = (struct GNUNET_DHT_GetMessage*) buf; |
201 | get_msg.header.size = htons (sizeof (struct GNUNET_DHT_GetMessage)); | 211 | get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); |
202 | get_msg.type = htons (type); | 212 | get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) + |
213 | xquery_size + | ||
214 | bf_size); | ||
215 | get_msg->type = htons ((uint32_t) type); | ||
216 | get_msg->bf_mutator = bf_mutator; | ||
217 | get_msg->xquery_size = htons ((uint16_t) xquery_size); | ||
218 | get_msg->bf_size = htons (bf_size); | ||
219 | if (xquery != NULL) | ||
220 | memcpy (&buf[sizeof(struct GNUNET_DHT_GetMessage)], | ||
221 | xquery, | ||
222 | xquery_size); | ||
223 | else | ||
224 | GNUNET_assert (xquery_size == 0); | ||
225 | (void) GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, | ||
226 | &buf[sizeof(struct GNUNET_DHT_GetMessage) + xquery_size], | ||
227 | bf_size); | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "Starting route for %u byte `%s' message\n", | 229 | "Starting route for %u byte `%s' message\n", |
205 | (unsigned int) sizeof (struct GNUNET_DHT_GetMessage), | 230 | (unsigned int) (sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size) , |
206 | "GET"); | 231 | "GET"); |
207 | get_handle->route_handle = | 232 | get_handle->route_handle = |
208 | GNUNET_DHT_route_start (handle, | 233 | GNUNET_DHT_route_start (handle, |
209 | key, | 234 | key, |
210 | DEFAULT_GET_REPLICATION, | 235 | DEFAULT_GET_REPLICATION, |
211 | options, | 236 | options, |
212 | &get_msg.header, | 237 | &get_msg->header, |
213 | timeout, | 238 | timeout, |
214 | &get_reply_iterator, get_handle, | 239 | &get_reply_iterator, get_handle, |
215 | NULL, NULL); | 240 | NULL, NULL); |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index b97f56893..c03e0b1ac 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -1877,16 +1877,15 @@ send_reply_to_client (struct ClientList *client, | |||
1877 | GNUNET_break_op (0); | 1877 | GNUNET_break_op (0); |
1878 | return; | 1878 | return; |
1879 | } | 1879 | } |
1880 | |||
1881 | pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + tsize); | 1880 | pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + tsize); |
1882 | pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; | 1881 | pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; |
1883 | reply = (struct GNUNET_DHT_RouteResultMessage *)&pending_message[1]; | 1882 | reply = (struct GNUNET_DHT_RouteResultMessage *)&pending_message[1]; |
1884 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); | 1883 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT); |
1885 | reply->header.size = htons (tsize); | 1884 | reply->header.size = htons (tsize); |
1885 | reply->reserved = 0; | ||
1886 | reply->unique_id = GNUNET_htonll (uid); | 1886 | reply->unique_id = GNUNET_htonll (uid); |
1887 | reply->key = *key; | 1887 | reply->key = *key; |
1888 | memcpy (&reply[1], message, msize); | 1888 | memcpy (&reply[1], message, msize); |
1889 | |||
1890 | add_pending_message (client, pending_message); | 1889 | add_pending_message (client, pending_message); |
1891 | } | 1890 | } |
1892 | 1891 | ||
@@ -2156,31 +2155,76 @@ handle_dht_get (void *cls, | |||
2156 | { | 2155 | { |
2157 | const struct GNUNET_DHT_GetMessage *get_msg; | 2156 | const struct GNUNET_DHT_GetMessage *get_msg; |
2158 | uint16_t get_type; | 2157 | uint16_t get_type; |
2158 | uint16_t bf_size; | ||
2159 | uint16_t msize; | ||
2160 | uint16_t xquery_size; | ||
2159 | unsigned int results; | 2161 | unsigned int results; |
2162 | struct GNUNET_CONTAINER_BloomFilter *bf; | ||
2163 | const void *xquery; | ||
2164 | const char *end; | ||
2160 | 2165 | ||
2166 | msize = ntohs (msg->size); | ||
2167 | if (msize < sizeof (struct GNUNET_DHT_GetMessage)) | ||
2168 | { | ||
2169 | GNUNET_break (0); | ||
2170 | return 0; | ||
2171 | } | ||
2161 | get_msg = (const struct GNUNET_DHT_GetMessage *) msg; | 2172 | get_msg = (const struct GNUNET_DHT_GetMessage *) msg; |
2162 | if (ntohs (get_msg->header.size) != sizeof (struct GNUNET_DHT_GetMessage)) | 2173 | bf_size = ntohs (get_msg->bf_size); |
2174 | xquery_size = ntohs (get_msg->xquery_size); | ||
2175 | if (msize != sizeof (struct GNUNET_DHT_GetMessage) + bf_size + xquery_size) | ||
2163 | { | 2176 | { |
2164 | GNUNET_break (0); | 2177 | GNUNET_break (0); |
2165 | return 0; | 2178 | return 0; |
2166 | } | 2179 | } |
2180 | end = (const char*) &get_msg[1]; | ||
2181 | if (xquery_size == 0) | ||
2182 | { | ||
2183 | xquery = NULL; | ||
2184 | } | ||
2185 | else | ||
2186 | { | ||
2187 | xquery = (const void*) end; | ||
2188 | end += xquery_size; | ||
2189 | } | ||
2190 | if (bf_size == 0) | ||
2191 | { | ||
2192 | bf = NULL; | ||
2193 | } | ||
2194 | else | ||
2195 | { | ||
2196 | bf = GNUNET_CONTAINER_bloomfilter_init (end, | ||
2197 | bf_size, | ||
2198 | GNUNET_DHT_GET_BLOOMFILTER_K); | ||
2199 | } | ||
2167 | 2200 | ||
2168 | get_type = ntohs (get_msg->type); | 2201 | get_type = ntohs (get_msg->type); |
2169 | #if DEBUG_DHT | 2202 | #if DEBUG_DHT |
2170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2171 | "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", my_short_id, | 2204 | "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", |
2172 | "DHT", "GET", get_type, GNUNET_h2s (&message_context->key), | 2205 | my_short_id, |
2206 | "DHT", "GET", | ||
2207 | get_type, | ||
2208 | GNUNET_h2s (&message_context->key), | ||
2173 | message_context->unique_id); | 2209 | message_context->unique_id); |
2174 | #endif | 2210 | #endif |
2175 | increment_stats(STAT_GETS); | 2211 | increment_stats(STAT_GETS); |
2176 | results = 0; | 2212 | results = 0; |
2213 | #if HAVE_MALICIOUS | ||
2177 | if (get_type == DHT_MALICIOUS_MESSAGE_TYPE) | 2214 | if (get_type == DHT_MALICIOUS_MESSAGE_TYPE) |
2178 | return results; | 2215 | { |
2179 | 2216 | GNUNET_CONTAINER_bloomfilter_free (bf); | |
2217 | return results; | ||
2218 | } | ||
2219 | #endif | ||
2220 | /* FIXME: put xquery / bf into message_context and use | ||
2221 | them for processing! */ | ||
2180 | if (datacache != NULL) | 2222 | if (datacache != NULL) |
2181 | results = | 2223 | results |
2182 | GNUNET_DATACACHE_get (datacache, &message_context->key, get_type, | 2224 | = GNUNET_DATACACHE_get (datacache, |
2183 | &datacache_get_iterator, message_context); | 2225 | &message_context->key, get_type, |
2226 | &datacache_get_iterator, | ||
2227 | message_context); | ||
2184 | 2228 | ||
2185 | if (results >= 1) | 2229 | if (results >= 1) |
2186 | { | 2230 | { |
@@ -2218,7 +2262,7 @@ handle_dht_get (void *cls, | |||
2218 | } | 2262 | } |
2219 | #endif | 2263 | #endif |
2220 | } | 2264 | } |
2221 | 2265 | GNUNET_CONTAINER_bloomfilter_free (bf); | |
2222 | return results; | 2266 | return results; |
2223 | } | 2267 | } |
2224 | 2268 | ||
diff --git a/src/fs/fs.h b/src/fs/fs.h index edbde19da..0eba5615c 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #include "gnunet_constants.h" | 30 | #include "gnunet_constants.h" |
31 | #include "gnunet_datastore_service.h" | 31 | #include "gnunet_datastore_service.h" |
32 | #include "gnunet_dht_service.h" | ||
32 | #include "gnunet_fs_service.h" | 33 | #include "gnunet_fs_service.h" |
33 | #include "gnunet_block_lib.h" | 34 | #include "gnunet_block_lib.h" |
34 | #include "block_fs.h" | 35 | #include "block_fs.h" |
@@ -114,7 +115,7 @@ | |||
114 | * Number of bits we set per entry in the bloomfilter. | 115 | * Number of bits we set per entry in the bloomfilter. |
115 | * Do not change! | 116 | * Do not change! |
116 | */ | 117 | */ |
117 | #define BLOOMFILTER_K 16 | 118 | #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K |
118 | 119 | ||
119 | /** | 120 | /** |
120 | * Number of availability trials we perform per search result. | 121 | * Number of availability trials we perform per search result. |
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 00d9851b9..9ad4cc809 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h | |||
@@ -41,6 +41,12 @@ extern "C" | |||
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * K-value that must be used for the bloom filter 'GET' | ||
45 | * queries. | ||
46 | */ | ||
47 | #define GNUNET_DHT_GET_BLOOMFILTER_K 16 | ||
48 | |||
49 | /** | ||
44 | * Connection to the DHT service. | 50 | * Connection to the DHT service. |
45 | */ | 51 | */ |
46 | struct GNUNET_DHT_Handle; | 52 | struct GNUNET_DHT_Handle; |
@@ -260,10 +266,16 @@ GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle); | |||
260 | * | 266 | * |
261 | * @param cls closure | 267 | * @param cls closure |
262 | * @param key key that was used | 268 | * @param key key that was used |
269 | * @param get_path NULL-terminated array of pointers | ||
270 | * to the peers on reverse GET path (or NULL if not recorded) | ||
271 | * @param put_path NULL-terminated array of pointers | ||
272 | * to the peers on the PUT path (or NULL if not recorded) | ||
263 | * @param reply response | 273 | * @param reply response |
264 | */ | 274 | */ |
265 | typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls, | 275 | typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls, |
266 | const GNUNET_HashCode *key, | 276 | const GNUNET_HashCode *key, |
277 | const struct GNUNET_PeerIdentity * const *get_path, | ||
278 | const struct GNUNET_PeerIdentity * const *put_path, | ||
267 | const struct GNUNET_MessageHeader *reply); | 279 | const struct GNUNET_MessageHeader *reply); |
268 | 280 | ||
269 | 281 | ||