summaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/.gitignore7
-rw-r--r--src/dht/Makefile.am6
-rw-r--r--src/dht/dht_api.c2
-rw-r--r--src/dht/gnunet-service-dht_hello.c20
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c16
-rw-r--r--src/dht/gnunet-service-dht_routing.c44
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.c4
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c4
-rw-r--r--src/dht/plugin_block_dht.c15
9 files changed, 79 insertions, 39 deletions
diff --git a/src/dht/.gitignore b/src/dht/.gitignore
index b8b0ff7d4..e7f3c2a86 100644
--- a/src/dht/.gitignore
+++ b/src/dht/.gitignore
@@ -5,3 +5,10 @@ gnunet-dht-profiler
5gnunet-dht-put 5gnunet-dht-put
6gnunet-service-dht 6gnunet-service-dht
7gnunet-service-dht-whanau 7gnunet-service-dht-whanau
8test_dht_2dtorus
9test_dht_api
10test_dht_line
11test_dht_monitor
12test_dht_multipeer
13test_dht_tools.py
14test_dht_twopeer
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index f91917768..1a174165c 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -58,8 +58,12 @@ endif
58noinst_PROGRAMS = \ 58noinst_PROGRAMS = \
59 gnunet-dht-monitor \ 59 gnunet-dht-monitor \
60 gnunet-dht-get \ 60 gnunet-dht-get \
61 gnunet-dht-put \ 61 gnunet-dht-put
62
63if HAVE_TESTING
64noinst_PROGRAMS += \
62 gnunet-dht-profiler 65 gnunet-dht-profiler
66endif
63 67
64gnunet_service_dht_SOURCES = \ 68gnunet_service_dht_SOURCES = \
65 gnunet-service-dht.c gnunet-service-dht.h \ 69 gnunet-service-dht.c gnunet-service-dht.h \
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 57880165e..66eaf1064 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -867,7 +867,7 @@ try_connect (struct GNUNET_DHT_Handle *h)
867 }; 867 };
868 if (NULL != h->mq) 868 if (NULL != h->mq)
869 return GNUNET_OK; 869 return GNUNET_OK;
870 h->mq = GNUNET_CLIENT_connecT (h->cfg, 870 h->mq = GNUNET_CLIENT_connect (h->cfg,
871 "dht", 871 "dht",
872 handlers, 872 handlers,
873 &mq_error_handler, 873 &mq_error_handler,
diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c
index 3716ea3af..5a5c41567 100644
--- a/src/dht/gnunet-service-dht_hello.c
+++ b/src/dht/gnunet-service-dht_hello.c
@@ -69,13 +69,15 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
69 * FIXME this is called once per address. Merge instead of replacing? 69 * FIXME this is called once per address. Merge instead of replacing?
70 */ 70 */
71static void 71static void
72process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, 72process_hello (void *cls,
73 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 73 const struct GNUNET_PeerIdentity *peer,
74 const struct GNUNET_HELLO_Message *hello,
75 const char *err_msg)
74{ 76{
75 struct GNUNET_TIME_Absolute ex; 77 struct GNUNET_TIME_Absolute ex;
76 struct GNUNET_HELLO_Message *hm; 78 struct GNUNET_HELLO_Message *hm;
77 79
78 if (hello == NULL) 80 if (NULL == hello)
79 return; 81 return;
80 ex = GNUNET_HELLO_get_last_expiration (hello); 82 ex = GNUNET_HELLO_get_last_expiration (hello);
81 if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us) 83 if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us)
@@ -100,8 +102,12 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
100void 102void
101GDS_HELLO_init () 103GDS_HELLO_init ()
102{ 104{
103 pnc = GNUNET_PEERINFO_notify (GDS_cfg, GNUNET_NO, &process_hello, NULL); 105 pnc = GNUNET_PEERINFO_notify (GDS_cfg,
104 peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); 106 GNUNET_NO,
107 &process_hello,
108 NULL);
109 peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256,
110 GNUNET_NO);
105} 111}
106 112
107 113
@@ -131,7 +137,9 @@ GDS_HELLO_done ()
131 } 137 }
132 if (NULL != peer_to_hello) 138 if (NULL != peer_to_hello)
133 { 139 {
134 GNUNET_CONTAINER_multipeermap_iterate (peer_to_hello, &free_hello, NULL); 140 GNUNET_CONTAINER_multipeermap_iterate (peer_to_hello,
141 &free_hello,
142 NULL);
135 GNUNET_CONTAINER_multipeermap_destroy (peer_to_hello); 143 GNUNET_CONTAINER_multipeermap_destroy (peer_to_hello);
136 } 144 }
137} 145}
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 574ed9ad0..20bdc0ce4 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1830,10 +1830,16 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1830 /* first, check about our own HELLO */ 1830 /* first, check about our own HELLO */
1831 if (NULL != GDS_my_hello) 1831 if (NULL != GDS_my_hello)
1832 { 1832 {
1833 GNUNET_BLOCK_mingle_hash (&my_identity_hash, bf_mutator, &mhash); 1833 GNUNET_BLOCK_mingle_hash (&my_identity_hash,
1834 bf_mutator,
1835 &mhash);
1834 if ((NULL == bf) || 1836 if ((NULL == bf) ||
1835 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash))) 1837 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)))
1836 { 1838 {
1839 size_t hello_size;
1840
1841 hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello);
1842 GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader));
1837 GDS_NEIGHBOURS_handle_reply (sender, 1843 GDS_NEIGHBOURS_handle_reply (sender,
1838 GNUNET_BLOCK_TYPE_DHT_HELLO, 1844 GNUNET_BLOCK_TYPE_DHT_HELLO,
1839 GNUNET_TIME_relative_to_absolute 1845 GNUNET_TIME_relative_to_absolute
@@ -1844,9 +1850,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1844 0, 1850 0,
1845 NULL, 1851 NULL,
1846 GDS_my_hello, 1852 GDS_my_hello,
1847 GNUNET_HELLO_size ((const struct 1853 hello_size);
1848 GNUNET_HELLO_Message *)
1849 GDS_my_hello));
1850 } 1854 }
1851 else 1855 else
1852 { 1856 {
@@ -2377,7 +2381,7 @@ GDS_NEIGHBOURS_init ()
2377 log_route_details_stderr = 2381 log_route_details_stderr =
2378 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; 2382 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2379 ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); 2383 ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg);
2380 core_api = GNUNET_CORE_connecT (GDS_cfg, 2384 core_api = GNUNET_CORE_connect (GDS_cfg,
2381 NULL, 2385 NULL,
2382 &core_init, 2386 &core_init,
2383 &handle_core_connect, 2387 &handle_core_connect,
@@ -2401,7 +2405,7 @@ GDS_NEIGHBOURS_done ()
2401{ 2405{
2402 if (NULL == core_api) 2406 if (NULL == core_api)
2403 return; 2407 return;
2404 GNUNET_CORE_disconnecT (core_api); 2408 GNUNET_CORE_disconnect (core_api);
2405 core_api = NULL; 2409 core_api = NULL;
2406 GNUNET_assert (0 == 2410 GNUNET_assert (0 ==
2407 GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); 2411 GNUNET_CONTAINER_multipeermap_size (all_connected_peers));
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index 48bece35e..978c46d73 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -160,7 +160,9 @@ struct ProcessContext
160 * #GNUNET_SYSERR if the result is malformed or type unsupported 160 * #GNUNET_SYSERR if the result is malformed or type unsupported
161 */ 161 */
162static int 162static int
163process (void *cls, const struct GNUNET_HashCode * key, void *value) 163process (void *cls,
164 const struct GNUNET_HashCode *key,
165 void *value)
164{ 166{
165 struct ProcessContext *pc = cls; 167 struct ProcessContext *pc = cls;
166 struct RecentRequest *rr = value; 168 struct RecentRequest *rr = value;
@@ -170,7 +172,8 @@ process (void *cls, const struct GNUNET_HashCode * key, void *value)
170 struct GNUNET_HashCode hc; 172 struct GNUNET_HashCode hc;
171 const struct GNUNET_HashCode *eval_key; 173 const struct GNUNET_HashCode *eval_key;
172 174
173 if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type)) 175 if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) &&
176 (rr->type != pc->type) )
174 return GNUNET_OK; /* type missmatch */ 177 return GNUNET_OK; /* type missmatch */
175 178
176 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) 179 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE))
@@ -183,23 +186,26 @@ process (void *cls, const struct GNUNET_HashCode * key, void *value)
183 gpl = 0; 186 gpl = 0;
184 ppl = 0; 187 ppl = 0;
185 } 188 }
186 if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && 189 if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
187 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) 190 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) )
188 { 191 {
189 /* key may not match HELLO, which is OK since 192 /* key may not match HELLO, which is OK since
190 * the search is approximate. Still, the evaluation 193 * the search is approximate. Still, the evaluation
191 * would fail since the match is not exact. So 194 * would fail since the match is not exact. So
192 * we fake it by changing the key to the actual PID ... */ 195 * we fake it by changing the key to the actual PID ... */
193 GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO, 196 GNUNET_BLOCK_get_key (GDS_block_context,
194 pc->data, pc->data_size, &hc); 197 GNUNET_BLOCK_TYPE_DHT_HELLO,
198 pc->data,
199 pc->data_size,
200 &hc);
195 eval_key = &hc; 201 eval_key = &hc;
196 } 202 }
197 else 203 else
198 { 204 {
199 eval_key = key; 205 eval_key = key;
200 } 206 }
201 eval = 207 eval
202 GNUNET_BLOCK_evaluate (GDS_block_context, 208 = GNUNET_BLOCK_evaluate (GDS_block_context,
203 pc->type, 209 pc->type,
204 GNUNET_BLOCK_EO_NONE, 210 GNUNET_BLOCK_EO_NONE,
205 eval_key, 211 eval_key,
@@ -308,7 +314,10 @@ GDS_ROUTING_process (void *cls,
308 pc.data_size = 0; 314 pc.data_size = 0;
309 pc.data = ""; /* something not null */ 315 pc.data = ""; /* something not null */
310 } 316 }
311 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc); 317 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map,
318 key,
319 &process,
320 &pc);
312} 321}
313 322
314 323
@@ -345,11 +354,13 @@ expire_oldest_entry ()
345 * @param cls the new 'struct RecentRequest' (to discard upon successful combination) 354 * @param cls the new 'struct RecentRequest' (to discard upon successful combination)
346 * @param key the query 355 * @param key the query
347 * @param value the existing 'struct RecentRequest' (to update upon successful combination) 356 * @param value the existing 'struct RecentRequest' (to update upon successful combination)
348 * @return GNUNET_OK (continue to iterate), 357 * @return #GNUNET_OK (continue to iterate),
349 * GNUNET_SYSERR if the request was successfully combined 358 * #GNUNET_SYSERR if the request was successfully combined
350 */ 359 */
351static int 360static int
352try_combine_recent (void *cls, const struct GNUNET_HashCode * key, void *value) 361try_combine_recent (void *cls,
362 const struct GNUNET_HashCode *key,
363 void *value)
353{ 364{
354 struct RecentRequest *in = cls; 365 struct RecentRequest *in = cls;
355 struct RecentRequest *rr = value; 366 struct RecentRequest *rr = value;
@@ -396,7 +407,8 @@ void
396GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, 407GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
397 enum GNUNET_BLOCK_Type type, 408 enum GNUNET_BLOCK_Type type,
398 enum GNUNET_DHT_RouteOption options, 409 enum GNUNET_DHT_RouteOption options,
399 const struct GNUNET_HashCode * key, const void *xquery, 410 const struct GNUNET_HashCode *key,
411 const void *xquery,
400 size_t xquery_size, 412 size_t xquery_size,
401 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 413 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
402 uint32_t reply_bf_mutator) 414 uint32_t reply_bf_mutator)
@@ -419,8 +431,10 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
419 recent_req->xquery_size = xquery_size; 431 recent_req->xquery_size = xquery_size;
420 recent_req->reply_bf_mutator = reply_bf_mutator; 432 recent_req->reply_bf_mutator = reply_bf_mutator;
421 if (GNUNET_SYSERR == 433 if (GNUNET_SYSERR ==
422 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, 434 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map,
423 &try_combine_recent, recent_req)) 435 key,
436 &try_combine_recent,
437 recent_req))
424 { 438 {
425 GNUNET_STATISTICS_update (GDS_stats, 439 GNUNET_STATISTICS_update (GDS_stats,
426 gettext_noop 440 gettext_noop
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c
index d3b92585b..78a04d66d 100644
--- a/src/dht/gnunet-service-wdht_neighbours.c
+++ b/src/dht/gnunet-service-wdht_neighbours.c
@@ -1712,7 +1712,7 @@ GDS_NEIGHBOURS_init (void)
1712 GNUNET_MQ_handler_end () 1712 GNUNET_MQ_handler_end ()
1713 }; 1713 };
1714 1714
1715 core_api = GNUNET_CORE_connecT (GDS_cfg, NULL, 1715 core_api = GNUNET_CORE_connect (GDS_cfg, NULL,
1716 &core_init, 1716 &core_init,
1717 &handle_core_connect, 1717 &handle_core_connect,
1718 &handle_core_disconnect, 1718 &handle_core_disconnect,
@@ -1736,7 +1736,7 @@ GDS_NEIGHBOURS_done (void)
1736{ 1736{
1737 if (NULL == core_api) 1737 if (NULL == core_api)
1738 return; 1738 return;
1739 GNUNET_CORE_disconnecT (core_api); 1739 GNUNET_CORE_disconnect (core_api);
1740 core_api = NULL; 1740 core_api = NULL;
1741 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friends_peermap)); 1741 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friends_peermap));
1742 GNUNET_CONTAINER_multipeermap_destroy (friends_peermap); 1742 GNUNET_CONTAINER_multipeermap_destroy (friends_peermap);
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index e3462f618..d41eb1900 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -6150,7 +6150,7 @@ GDS_NEIGHBOURS_init (void)
6150 GNUNET_MQ_handler_end () 6150 GNUNET_MQ_handler_end ()
6151 }; 6151 };
6152 6152
6153 core_api = GNUNET_CORE_connecT (GDS_cfg, 6153 core_api = GNUNET_CORE_connect (GDS_cfg,
6154 NULL, 6154 NULL,
6155 &core_init, 6155 &core_init,
6156 &handle_core_connect, 6156 &handle_core_connect,
@@ -6212,7 +6212,7 @@ GDS_NEIGHBOURS_done (void)
6212 if (NULL == core_api) 6212 if (NULL == core_api)
6213 return; 6213 return;
6214 6214
6215 GNUNET_CORE_disconnecT (core_api); 6215 GNUNET_CORE_disconnect (core_api);
6216 core_api = NULL; 6216 core_api = NULL;
6217 6217
6218 delete_finger_table_entries(); 6218 delete_finger_table_entries();
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 17594efcb..8bb533961 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -70,12 +70,13 @@ block_plugin_dht_evaluate (void *cls,
70 70
71 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 71 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
72 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 72 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
73 if (xquery_size != 0) 73 if (0 != xquery_size)
74 { 74 {
75 GNUNET_break_op (0); 75 GNUNET_break_op (0);
76 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 76 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
77 } 77 }
78 if (NULL == reply_block) 78 if ( (NULL == reply_block) ||
79 (0 == reply_block_size) )
79 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 80 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
80 if (reply_block_size < sizeof (struct GNUNET_MessageHeader)) 81 if (reply_block_size < sizeof (struct GNUNET_MessageHeader))
81 { 82 {
@@ -121,14 +122,16 @@ block_plugin_dht_evaluate (void *cls,
121 * @param type block type 122 * @param type block type
122 * @param block block to get the key for 123 * @param block block to get the key for
123 * @param block_size number of bytes @a block 124 * @param block_size number of bytes @a block
124 * @param key set to the key (query) for the given block 125 * @param[out] key set to the key (query) for the given block
125 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 126 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
126 * (or if extracting a key from a block of this type does not work) 127 * (or if extracting a key from a block of this type does not work)
127 */ 128 */
128static int 129static int
129block_plugin_dht_get_key (void *cls, enum GNUNET_BLOCK_Type type, 130block_plugin_dht_get_key (void *cls,
130 const void *block, size_t block_size, 131 enum GNUNET_BLOCK_Type type,
131 struct GNUNET_HashCode * key) 132 const void *block,
133 size_t block_size,
134 struct GNUNET_HashCode *key)
132{ 135{
133 const struct GNUNET_MessageHeader *msg; 136 const struct GNUNET_MessageHeader *msg;
134 const struct GNUNET_HELLO_Message *hello; 137 const struct GNUNET_HELLO_Message *hello;