diff options
Diffstat (limited to 'src/dns/plugin_block_dns.c')
-rw-r--r-- | src/dns/plugin_block_dns.c | 193 |
1 files changed, 97 insertions, 96 deletions
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index fd4d844c5..fc07a4073 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -54,37 +54,38 @@ | |||
54 | * by this @a type of block (this is not an error) | 54 | * by this @a type of block (this is not an error) |
55 | */ | 55 | */ |
56 | static struct GNUNET_BLOCK_Group * | 56 | static struct GNUNET_BLOCK_Group * |
57 | block_plugin_dns_create_group(void *cls, | 57 | block_plugin_dns_create_group (void *cls, |
58 | enum GNUNET_BLOCK_Type type, | 58 | enum GNUNET_BLOCK_Type type, |
59 | uint32_t nonce, | 59 | uint32_t nonce, |
60 | const void *raw_data, | 60 | const void *raw_data, |
61 | size_t raw_data_size, | 61 | size_t raw_data_size, |
62 | va_list va) | 62 | va_list va) |
63 | { | 63 | { |
64 | unsigned int bf_size; | 64 | unsigned int bf_size; |
65 | const char *guard; | 65 | const char *guard; |
66 | 66 | ||
67 | guard = va_arg(va, const char *); | 67 | guard = va_arg (va, const char *); |
68 | if (0 == strcmp(guard, | 68 | if (0 == strcmp (guard, |
69 | "seen-set-size")) | 69 | "seen-set-size")) |
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | 70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned |
71 | BLOOMFILTER_K); | 71 | int), |
72 | else if (0 == strcmp(guard, | 72 | BLOOMFILTER_K); |
73 | "filter-size")) | 73 | else if (0 == strcmp (guard, |
74 | bf_size = va_arg(va, unsigned int); | 74 | "filter-size")) |
75 | bf_size = va_arg (va, unsigned int); | ||
75 | else | 76 | else |
76 | { | 77 | { |
77 | GNUNET_break(0); | 78 | GNUNET_break (0); |
78 | bf_size = 8; | 79 | bf_size = 8; |
79 | } | 80 | } |
80 | GNUNET_break(NULL == va_arg(va, const char *)); | 81 | GNUNET_break (NULL == va_arg (va, const char *)); |
81 | return GNUNET_BLOCK_GROUP_bf_create(cls, | 82 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
82 | bf_size, | 83 | bf_size, |
83 | BLOOMFILTER_K, | 84 | BLOOMFILTER_K, |
84 | type, | 85 | type, |
85 | nonce, | 86 | nonce, |
86 | raw_data, | 87 | raw_data, |
87 | raw_data_size); | 88 | raw_data_size); |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
@@ -105,72 +106,73 @@ block_plugin_dns_create_group(void *cls, | |||
105 | * @return characterization of result | 106 | * @return characterization of result |
106 | */ | 107 | */ |
107 | static enum GNUNET_BLOCK_EvaluationResult | 108 | static enum GNUNET_BLOCK_EvaluationResult |
108 | block_plugin_dns_evaluate(void *cls, | 109 | block_plugin_dns_evaluate (void *cls, |
109 | struct GNUNET_BLOCK_Context *ctx, | 110 | struct GNUNET_BLOCK_Context *ctx, |
110 | enum GNUNET_BLOCK_Type type, | 111 | enum GNUNET_BLOCK_Type type, |
111 | struct GNUNET_BLOCK_Group *bg, | 112 | struct GNUNET_BLOCK_Group *bg, |
112 | enum GNUNET_BLOCK_EvaluationOptions eo, | 113 | enum GNUNET_BLOCK_EvaluationOptions eo, |
113 | const struct GNUNET_HashCode * query, | 114 | const struct GNUNET_HashCode *query, |
114 | const void *xquery, | 115 | const void *xquery, |
115 | size_t xquery_size, | 116 | size_t xquery_size, |
116 | const void *reply_block, | 117 | const void *reply_block, |
117 | size_t reply_block_size) | 118 | size_t reply_block_size) |
118 | { | 119 | { |
119 | const struct GNUNET_DNS_Advertisement *ad; | 120 | const struct GNUNET_DNS_Advertisement *ad; |
120 | struct GNUNET_HashCode phash; | 121 | struct GNUNET_HashCode phash; |
121 | 122 | ||
122 | switch (type) | 123 | switch (type) |
124 | { | ||
125 | case GNUNET_BLOCK_TYPE_DNS: | ||
126 | if (0 != xquery_size) | ||
127 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
128 | |||
129 | if (NULL == reply_block) | ||
130 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
131 | |||
132 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
133 | { | ||
134 | GNUNET_break_op (0); | ||
135 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
136 | } | ||
137 | ad = reply_block; | ||
138 | |||
139 | if (ntohl (ad->purpose.size) != | ||
140 | sizeof(struct GNUNET_DNS_Advertisement) | ||
141 | - sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
142 | { | ||
143 | GNUNET_break_op (0); | ||
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
145 | } | ||
146 | if (0 == | ||
147 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh | ||
148 | (ad->expiration_time)). | ||
149 | rel_value_us) | ||
123 | { | 150 | { |
124 | case GNUNET_BLOCK_TYPE_DNS: | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
125 | if (0 != xquery_size) | 152 | "DNS advertisement has expired\n"); |
126 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 153 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
127 | |||
128 | if (NULL == reply_block) | ||
129 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
130 | |||
131 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
132 | { | ||
133 | GNUNET_break_op(0); | ||
134 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
135 | } | ||
136 | ad = reply_block; | ||
137 | |||
138 | if (ntohl(ad->purpose.size) != | ||
139 | sizeof(struct GNUNET_DNS_Advertisement) - | ||
140 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
141 | { | ||
142 | GNUNET_break_op(0); | ||
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
144 | } | ||
145 | if (0 == | ||
146 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh | ||
147 | (ad->expiration_time)).rel_value_us) | ||
148 | { | ||
149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "DNS advertisement has expired\n"); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | if (GNUNET_OK != | ||
154 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
155 | &ad->purpose, | ||
156 | &ad->signature, | ||
157 | &ad->peer.public_key)) | ||
158 | { | ||
159 | GNUNET_break_op(0); | ||
160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
161 | } | ||
162 | GNUNET_CRYPTO_hash(reply_block, | ||
163 | reply_block_size, | ||
164 | &phash); | ||
165 | if (GNUNET_YES == | ||
166 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | ||
167 | &phash)) | ||
168 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
169 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
170 | |||
171 | default: | ||
172 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
173 | } | 154 | } |
155 | if (GNUNET_OK != | ||
156 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
157 | &ad->purpose, | ||
158 | &ad->signature, | ||
159 | &ad->peer.public_key)) | ||
160 | { | ||
161 | GNUNET_break_op (0); | ||
162 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
163 | } | ||
164 | GNUNET_CRYPTO_hash (reply_block, | ||
165 | reply_block_size, | ||
166 | &phash); | ||
167 | if (GNUNET_YES == | ||
168 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
169 | &phash)) | ||
170 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
171 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
172 | |||
173 | default: | ||
174 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
175 | } | ||
174 | } | 176 | } |
175 | 177 | ||
176 | 178 | ||
@@ -186,11 +188,11 @@ block_plugin_dns_evaluate(void *cls, | |||
186 | * (or if extracting a key from a block of this type does not work) | 188 | * (or if extracting a key from a block of this type does not work) |
187 | */ | 189 | */ |
188 | static int | 190 | static int |
189 | block_plugin_dns_get_key(void *cls, | 191 | block_plugin_dns_get_key (void *cls, |
190 | enum GNUNET_BLOCK_Type type, | 192 | enum GNUNET_BLOCK_Type type, |
191 | const void *block, | 193 | const void *block, |
192 | size_t block_size, | 194 | size_t block_size, |
193 | struct GNUNET_HashCode *key) | 195 | struct GNUNET_HashCode *key) |
194 | { | 196 | { |
195 | /* we cannot extract a key from a block of this type */ | 197 | /* we cannot extract a key from a block of this type */ |
196 | return GNUNET_SYSERR; | 198 | return GNUNET_SYSERR; |
@@ -201,16 +203,15 @@ block_plugin_dns_get_key(void *cls, | |||
201 | * Entry point for the plugin. | 203 | * Entry point for the plugin. |
202 | */ | 204 | */ |
203 | void * | 205 | void * |
204 | libgnunet_plugin_block_dns_init(void *cls) | 206 | libgnunet_plugin_block_dns_init (void *cls) |
205 | { | 207 | { |
206 | static enum GNUNET_BLOCK_Type types[] = | 208 | static enum GNUNET_BLOCK_Type types[] = { |
207 | { | ||
208 | GNUNET_BLOCK_TYPE_DNS, | 209 | GNUNET_BLOCK_TYPE_DNS, |
209 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 210 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
210 | }; | 211 | }; |
211 | struct GNUNET_BLOCK_PluginFunctions *api; | 212 | struct GNUNET_BLOCK_PluginFunctions *api; |
212 | 213 | ||
213 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 214 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
214 | api->evaluate = &block_plugin_dns_evaluate; | 215 | api->evaluate = &block_plugin_dns_evaluate; |
215 | api->get_key = &block_plugin_dns_get_key; | 216 | api->get_key = &block_plugin_dns_get_key; |
216 | api->create_group = &block_plugin_dns_create_group; | 217 | api->create_group = &block_plugin_dns_create_group; |
@@ -223,11 +224,11 @@ libgnunet_plugin_block_dns_init(void *cls) | |||
223 | * Exit point from the plugin. | 224 | * Exit point from the plugin. |
224 | */ | 225 | */ |
225 | void * | 226 | void * |
226 | libgnunet_plugin_block_dns_done(void *cls) | 227 | libgnunet_plugin_block_dns_done (void *cls) |
227 | { | 228 | { |
228 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 229 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
229 | 230 | ||
230 | GNUNET_free(api); | 231 | GNUNET_free (api); |
231 | return NULL; | 232 | return NULL; |
232 | } | 233 | } |
233 | 234 | ||