diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-22 11:10:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-22 11:10:02 +0100 |
commit | 8000747074b82caeacb0f43710940220d9840d37 (patch) | |
tree | ef0f40343a0acf45894e9cfc8bc2d571fa3db8e9 | |
parent | cccdf454e79ab779989876135b964f039c647a10 (diff) | |
download | gnunet-8000747074b82caeacb0f43710940220d9840d37.tar.gz gnunet-8000747074b82caeacb0f43710940220d9840d37.zip |
clean up new block logic, avoid direct linkage against blockgroup lib from DHT service
-rw-r--r-- | src/block/block.c | 34 | ||||
-rw-r--r-- | src/dht/Makefile.am | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 70 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 2 |
4 files changed, 64 insertions, 43 deletions
diff --git a/src/block/block.c b/src/block/block.c index b7a19ae90..23caacd38 100644 --- a/src/block/block.c +++ b/src/block/block.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -84,8 +84,12 @@ GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, | |||
84 | { | 84 | { |
85 | struct GNUNET_HashCode m; | 85 | struct GNUNET_HashCode m; |
86 | 86 | ||
87 | GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m); | 87 | GNUNET_CRYPTO_hash (&mingle_number, |
88 | GNUNET_CRYPTO_hash_xor (&m, in, hc); | 88 | sizeof (uint32_t), |
89 | &m); | ||
90 | GNUNET_CRYPTO_hash_xor (&m, | ||
91 | in, | ||
92 | hc); | ||
89 | } | 93 | } |
90 | 94 | ||
91 | 95 | ||
@@ -111,7 +115,9 @@ add_plugin (void *cls, | |||
111 | plugin = GNUNET_new (struct Plugin); | 115 | plugin = GNUNET_new (struct Plugin); |
112 | plugin->api = api; | 116 | plugin->api = api; |
113 | plugin->library_name = GNUNET_strdup (library_name); | 117 | plugin->library_name = GNUNET_strdup (library_name); |
114 | GNUNET_array_append (ctx->plugins, ctx->num_plugins, plugin); | 118 | GNUNET_array_append (ctx->plugins, |
119 | ctx->num_plugins, | ||
120 | plugin); | ||
115 | } | 121 | } |
116 | 122 | ||
117 | 123 | ||
@@ -129,7 +135,10 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
129 | 135 | ||
130 | ctx = GNUNET_new (struct GNUNET_BLOCK_Context); | 136 | ctx = GNUNET_new (struct GNUNET_BLOCK_Context); |
131 | ctx->cfg = cfg; | 137 | ctx->cfg = cfg; |
132 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", NULL, &add_plugin, ctx); | 138 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", |
139 | NULL, | ||
140 | &add_plugin, | ||
141 | ctx); | ||
133 | return ctx; | 142 | return ctx; |
134 | } | 143 | } |
135 | 144 | ||
@@ -149,7 +158,8 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) | |||
149 | { | 158 | { |
150 | plugin = ctx->plugins[i]; | 159 | plugin = ctx->plugins[i]; |
151 | GNUNET_break (NULL == | 160 | GNUNET_break (NULL == |
152 | GNUNET_PLUGIN_unload (plugin->library_name, plugin->api)); | 161 | GNUNET_PLUGIN_unload (plugin->library_name, |
162 | plugin->api)); | ||
153 | GNUNET_free (plugin->library_name); | 163 | GNUNET_free (plugin->library_name); |
154 | GNUNET_free (plugin); | 164 | GNUNET_free (plugin); |
155 | } | 165 | } |
@@ -249,10 +259,9 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, | |||
249 | enum GNUNET_BLOCK_Type type) | 259 | enum GNUNET_BLOCK_Type type) |
250 | { | 260 | { |
251 | struct Plugin *plugin; | 261 | struct Plugin *plugin; |
252 | unsigned int i; | ||
253 | unsigned int j; | 262 | unsigned int j; |
254 | 263 | ||
255 | for (i = 0; i < ctx->num_plugins; i++) | 264 | for (unsigned i = 0; i < ctx->num_plugins; i++) |
256 | { | 265 | { |
257 | plugin = ctx->plugins[i]; | 266 | plugin = ctx->plugins[i]; |
258 | j = 0; | 267 | j = 0; |
@@ -294,7 +303,8 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
294 | type); | 303 | type); |
295 | if (NULL == plugin->create_group) | 304 | if (NULL == plugin->create_group) |
296 | return NULL; | 305 | return NULL; |
297 | va_start (ap, raw_data_size); | 306 | va_start (ap, |
307 | raw_data_size); | ||
298 | bg = plugin->create_group (plugin->cls, | 308 | bg = plugin->create_group (plugin->cls, |
299 | type, | 309 | type, |
300 | nonce, | 310 | nonce, |
@@ -375,7 +385,11 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | |||
375 | 385 | ||
376 | if (plugin == NULL) | 386 | if (plugin == NULL) |
377 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 387 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
378 | return plugin->get_key (plugin->cls, type, block, block_size, key); | 388 | return plugin->get_key (plugin->cls, |
389 | type, | ||
390 | block, | ||
391 | block_size, | ||
392 | key); | ||
379 | } | 393 | } |
380 | 394 | ||
381 | 395 | ||
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 4216af400..b95083c85 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -82,7 +82,6 @@ gnunet_service_dht_LDADD = \ | |||
82 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | 82 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ |
83 | $(top_builddir)/src/hello/libgnunethello.la \ | 83 | $(top_builddir)/src/hello/libgnunethello.la \ |
84 | $(top_builddir)/src/block/libgnunetblock.la \ | 84 | $(top_builddir)/src/block/libgnunetblock.la \ |
85 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | ||
86 | $(top_builddir)/src/datacache/libgnunetdatacache.la \ | 85 | $(top_builddir)/src/datacache/libgnunetdatacache.la \ |
87 | $(top_builddir)/src/util/libgnunetutil.la \ | 86 | $(top_builddir)/src/util/libgnunetutil.la \ |
88 | -lm | 87 | -lm |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 1bbc95a06..975872f1b 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_block_lib.h" | 29 | #include "gnunet_block_lib.h" |
30 | #include "gnunet_block_group_lib.h" | ||
31 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_constants.h" | 31 | #include "gnunet_constants.h" |
33 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
@@ -622,8 +621,9 @@ add_known_to_bloom (void *cls, | |||
622 | GNUNET_CRYPTO_hash (key, | 621 | GNUNET_CRYPTO_hash (key, |
623 | sizeof (struct GNUNET_PeerIdentity), | 622 | sizeof (struct GNUNET_PeerIdentity), |
624 | &key_hash); | 623 | &key_hash); |
625 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 624 | GNUNET_BLOCK_group_set_seen (bg, |
626 | &key_hash); | 625 | &key_hash, |
626 | 1); | ||
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
628 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", | 628 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", |
629 | GNUNET_i2s (key)); | 629 | GNUNET_i2s (key)); |
@@ -656,14 +656,12 @@ send_find_peer_message (void *cls) | |||
656 | newly_found_peers = 0; | 656 | newly_found_peers = 0; |
657 | return; | 657 | return; |
658 | } | 658 | } |
659 | bg = GNUNET_BLOCK_GROUP_bf_create (NULL, | 659 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
660 | DHT_BLOOM_SIZE, | 660 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
661 | GNUNET_CONSTANTS_BLOOMFILTER_K, | 661 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
662 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 662 | UINT32_MAX), |
663 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 663 | NULL, |
664 | UINT32_MAX), | 664 | 0); |
665 | NULL, | ||
666 | 0); | ||
667 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, | 665 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
668 | &add_known_to_bloom, | 666 | &add_known_to_bloom, |
669 | bg); | 667 | bg); |
@@ -1839,22 +1837,26 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1839 | struct PeerInfo *peer; | 1837 | struct PeerInfo *peer; |
1840 | unsigned int choice; | 1838 | unsigned int choice; |
1841 | const struct GNUNET_HELLO_Message *hello; | 1839 | const struct GNUNET_HELLO_Message *hello; |
1840 | size_t hello_size; | ||
1842 | 1841 | ||
1843 | /* first, check about our own HELLO */ | 1842 | /* first, check about our own HELLO */ |
1844 | if (NULL != GDS_my_hello) | 1843 | if (NULL != GDS_my_hello) |
1845 | { | 1844 | { |
1846 | if (GNUNET_YES != | 1845 | hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); |
1847 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 1846 | GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); |
1848 | &my_identity_hash)) | 1847 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == |
1848 | GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1849 | GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
1850 | bg, | ||
1851 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1852 | &my_identity_hash, | ||
1853 | NULL, 0, | ||
1854 | GDS_my_hello, | ||
1855 | hello_size)) | ||
1849 | { | 1856 | { |
1850 | size_t hello_size; | ||
1851 | |||
1852 | hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); | ||
1853 | GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); | ||
1854 | GDS_NEIGHBOURS_handle_reply (sender, | 1857 | GDS_NEIGHBOURS_handle_reply (sender, |
1855 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1858 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1856 | GNUNET_TIME_relative_to_absolute | 1859 | GNUNET_TIME_relative_to_absolute (hello_expiration), |
1857 | (hello_expiration), | ||
1858 | key, | 1860 | key, |
1859 | 0, | 1861 | 0, |
1860 | NULL, | 1862 | NULL, |
@@ -1910,10 +1912,17 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1910 | if (NULL == peer) | 1912 | if (NULL == peer) |
1911 | peer = bucket->head; | 1913 | peer = bucket->head; |
1912 | hello = GDS_HELLO_get (peer->id); | 1914 | hello = GDS_HELLO_get (peer->id); |
1915 | hello_size = GNUNET_HELLO_size (hello); | ||
1913 | } while ( (NULL == hello) || | 1916 | } while ( (NULL == hello) || |
1914 | (GNUNET_YES == | 1917 | (GNUNET_BLOCK_EVALUATION_OK_MORE != |
1915 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 1918 | GNUNET_BLOCK_evaluate (GDS_block_context, |
1916 | &peer->phash)) ); | 1919 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1920 | bg, | ||
1921 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1922 | &peer->phash, | ||
1923 | NULL, 0, | ||
1924 | hello, | ||
1925 | hello_size)) ); | ||
1917 | GDS_NEIGHBOURS_handle_reply (sender, | 1926 | GDS_NEIGHBOURS_handle_reply (sender, |
1918 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1927 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1919 | GNUNET_TIME_relative_to_absolute | 1928 | GNUNET_TIME_relative_to_absolute |
@@ -1924,7 +1933,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1924 | 0, | 1933 | 0, |
1925 | NULL, | 1934 | NULL, |
1926 | hello, | 1935 | hello, |
1927 | GNUNET_HELLO_size (hello)); | 1936 | hello_size); |
1928 | } | 1937 | } |
1929 | 1938 | ||
1930 | 1939 | ||
@@ -2052,15 +2061,10 @@ handle_dht_p2p_get (void *cls, | |||
2052 | xquery); | 2061 | xquery); |
2053 | GNUNET_free (tmp); | 2062 | GNUNET_free (tmp); |
2054 | } | 2063 | } |
2055 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | ||
2056 | type, | ||
2057 | get->bf_mutator, | ||
2058 | &xquery[xquery_size], | ||
2059 | reply_bf_size); | ||
2060 | eval | 2064 | eval |
2061 | = GNUNET_BLOCK_evaluate (GDS_block_context, | 2065 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
2062 | type, | 2066 | type, |
2063 | bg, | 2067 | NULL, |
2064 | GNUNET_BLOCK_EO_NONE, | 2068 | GNUNET_BLOCK_EO_NONE, |
2065 | &get->key, | 2069 | &get->key, |
2066 | xquery, | 2070 | xquery, |
@@ -2071,7 +2075,6 @@ handle_dht_p2p_get (void *cls, | |||
2071 | { | 2075 | { |
2072 | /* request invalid or block type not supported */ | 2076 | /* request invalid or block type not supported */ |
2073 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); | 2077 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); |
2074 | GNUNET_BLOCK_group_destroy (bg); | ||
2075 | return; | 2078 | return; |
2076 | } | 2079 | } |
2077 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | 2080 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, |
@@ -2080,6 +2083,11 @@ handle_dht_p2p_get (void *cls, | |||
2080 | GNUNET_break_op (GNUNET_YES == | 2083 | GNUNET_break_op (GNUNET_YES == |
2081 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, | 2084 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
2082 | &peer->phash)); | 2085 | &peer->phash)); |
2086 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | ||
2087 | type, | ||
2088 | get->bf_mutator, | ||
2089 | &xquery[xquery_size], | ||
2090 | reply_bf_size); | ||
2083 | /* remember request for routing replies */ | 2091 | /* remember request for routing replies */ |
2084 | GDS_ROUTING_add (peer->id, | 2092 | GDS_ROUTING_add (peer->id, |
2085 | type, | 2093 | type, |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 0304dad87..168497440 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |