diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-26 22:42:40 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-26 22:42:40 +0100 |
commit | 8d7c29c4684f807d5e9a3004bbbab132b158c5aa (patch) | |
tree | 9eca177e00a387d0c18395fde7dbf91289272d98 /src/dns | |
parent | e87663cf00dd102e8bb60f400db4bad6d82b3b6c (diff) | |
download | gnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.tar.gz gnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.zip |
ensure all plugins properly use BF, move shared logic to shared library
Diffstat (limited to 'src/dns')
-rw-r--r-- | src/dns/plugin_block_dns.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index 65da0de63..fe416e450 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013, 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 |
@@ -31,6 +31,61 @@ | |||
31 | #include "gnunet_block_plugin.h" | 31 | #include "gnunet_block_plugin.h" |
32 | #include "block_dns.h" | 32 | #include "block_dns.h" |
33 | #include "gnunet_signatures.h" | 33 | #include "gnunet_signatures.h" |
34 | #include "gnunet_block_group_lib.h" | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Number of bits we set per entry in the bloomfilter. | ||
39 | * Do not change! | ||
40 | */ | ||
41 | #define BLOOMFILTER_K 16 | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Create a new block group. | ||
46 | * | ||
47 | * @param ctx block context in which the block group is created | ||
48 | * @param type type of the block for which we are creating the group | ||
49 | * @param nonce random value used to seed the group creation | ||
50 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
51 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
52 | * @param va variable arguments specific to @a type | ||
53 | * @return block group handle, NULL if block groups are not supported | ||
54 | * by this @a type of block (this is not an error) | ||
55 | */ | ||
56 | static struct GNUNET_BLOCK_Group * | ||
57 | block_plugin_dns_create_group (void *cls, | ||
58 | enum GNUNET_BLOCK_Type type, | ||
59 | uint32_t nonce, | ||
60 | const void *raw_data, | ||
61 | size_t raw_data_size, | ||
62 | va_list va) | ||
63 | { | ||
64 | unsigned int bf_size; | ||
65 | const char *guard; | ||
66 | |||
67 | guard = va_arg (va, const char *); | ||
68 | if (0 == strcmp (guard, | ||
69 | "seen-set-size")) | ||
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | ||
71 | BLOOMFILTER_K); | ||
72 | else if (0 == strcmp (guard, | ||
73 | "filter-size")) | ||
74 | bf_size = va_arg (va, unsigned int); | ||
75 | else | ||
76 | { | ||
77 | GNUNET_break (0); | ||
78 | bf_size = 8; | ||
79 | } | ||
80 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
81 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
82 | bf_size, | ||
83 | BLOOMFILTER_K, | ||
84 | type, | ||
85 | nonce, | ||
86 | raw_data, | ||
87 | raw_data_size); | ||
88 | } | ||
34 | 89 | ||
35 | 90 | ||
36 | /** | 91 | /** |
@@ -60,6 +115,7 @@ block_plugin_dns_evaluate (void *cls, | |||
60 | size_t reply_block_size) | 115 | size_t reply_block_size) |
61 | { | 116 | { |
62 | const struct GNUNET_DNS_Advertisement *ad; | 117 | const struct GNUNET_DNS_Advertisement *ad; |
118 | struct GNUNET_HashCode phash; | ||
63 | 119 | ||
64 | switch (type) | 120 | switch (type) |
65 | { | 121 | { |
@@ -101,6 +157,13 @@ block_plugin_dns_evaluate (void *cls, | |||
101 | GNUNET_break_op (0); | 157 | GNUNET_break_op (0); |
102 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 158 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
103 | } | 159 | } |
160 | GNUNET_CRYPTO_hash (reply_block, | ||
161 | reply_block_size, | ||
162 | &phash); | ||
163 | if (GNUNET_YES == | ||
164 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
165 | &phash)) | ||
166 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
104 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 167 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
105 | default: | 168 | default: |
106 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 169 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
@@ -147,6 +210,7 @@ libgnunet_plugin_block_dns_init (void *cls) | |||
147 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 210 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
148 | api->evaluate = &block_plugin_dns_evaluate; | 211 | api->evaluate = &block_plugin_dns_evaluate; |
149 | api->get_key = &block_plugin_dns_get_key; | 212 | api->get_key = &block_plugin_dns_get_key; |
213 | api->create_group = &block_plugin_dns_create_group; | ||
150 | api->types = types; | 214 | api->types = types; |
151 | return api; | 215 | return api; |
152 | } | 216 | } |