diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-02-23 14:18:21 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-02-23 17:47:35 +0100 |
commit | 5a2d590a6f4b4f2c35d1240e65cc43aff111eb8b (patch) | |
tree | 58390ef70785c1247cf5e5794f80f987ce03cb87 /src/set | |
parent | 5c9c418d2b7ac6cf10c577fb9c6bc687cb3b4a09 (diff) | |
download | gnunet-5a2d590a6f4b4f2c35d1240e65cc43aff111eb8b.tar.gz gnunet-5a2d590a6f4b4f2c35d1240e65cc43aff111eb8b.zip |
abort union if we receive too little fresh elements
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set_union.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index acaabd94a..832018723 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -183,6 +183,17 @@ struct OperationState | |||
183 | * Salt for the IBF we've received and that we're currently decoding. | 183 | * Salt for the IBF we've received and that we're currently decoding. |
184 | */ | 184 | */ |
185 | uint32_t salt_receive; | 185 | uint32_t salt_receive; |
186 | |||
187 | /** | ||
188 | * Number of elements we received from the other peer | ||
189 | * that were not in the local set yet. | ||
190 | */ | ||
191 | uint32_t received_fresh; | ||
192 | |||
193 | /** | ||
194 | * Total number of elements received from the other peer. | ||
195 | */ | ||
196 | uint32_t received_total; | ||
186 | }; | 197 | }; |
187 | 198 | ||
188 | 199 | ||
@@ -1210,6 +1221,8 @@ maybe_finish (struct Operation *op) | |||
1210 | 1221 | ||
1211 | /** | 1222 | /** |
1212 | * Handle an element message from a remote peer. | 1223 | * Handle an element message from a remote peer. |
1224 | * Sent by the other peer either because we decoded an IBF and placed a demand, | ||
1225 | * or because the other peer switched to full set transmission. | ||
1213 | * | 1226 | * |
1214 | * @param cls the union operation | 1227 | * @param cls the union operation |
1215 | * @param mh the message | 1228 | * @param mh the message |
@@ -1273,6 +1286,8 @@ handle_p2p_elements (void *cls, | |||
1273 | 1, | 1286 | 1, |
1274 | GNUNET_NO); | 1287 | GNUNET_NO); |
1275 | 1288 | ||
1289 | op->state->received_total += 1; | ||
1290 | |||
1276 | if (GNUNET_YES == op_has_element (op, &ee->element_hash)) | 1291 | if (GNUNET_YES == op_has_element (op, &ee->element_hash)) |
1277 | { | 1292 | { |
1278 | /* Got repeated element. Should not happen since | 1293 | /* Got repeated element. Should not happen since |
@@ -1287,6 +1302,7 @@ handle_p2p_elements (void *cls, | |||
1287 | { | 1302 | { |
1288 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1303 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1289 | "Registering new element from remote peer\n"); | 1304 | "Registering new element from remote peer\n"); |
1305 | op->state->received_fresh += 1; | ||
1290 | op_register_element (op, ee); | 1306 | op_register_element (op, ee); |
1291 | /* only send results immediately if the client wants it */ | 1307 | /* only send results immediately if the client wants it */ |
1292 | switch (op->spec->result_mode) | 1308 | switch (op->spec->result_mode) |
@@ -1304,6 +1320,14 @@ handle_p2p_elements (void *cls, | |||
1304 | } | 1320 | } |
1305 | } | 1321 | } |
1306 | 1322 | ||
1323 | if (op->state->received_total > 8 && op->state->received_fresh < op->state->received_total / 3) | ||
1324 | { | ||
1325 | /* The other peer gave us lots of old elements, there's something wrong. */ | ||
1326 | GNUNET_break_op (0); | ||
1327 | fail_union_operation (op); | ||
1328 | return; | ||
1329 | } | ||
1330 | |||
1307 | maybe_finish (op); | 1331 | maybe_finish (op); |
1308 | } | 1332 | } |
1309 | 1333 | ||