diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-26 04:14:43 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-26 04:14:43 +0200 |
commit | 7978b76868ba81efaa4b65b47a54ee55cd092382 (patch) | |
tree | 7248f8a1c07364ba66435fe31d915e50df138d4c /src/cadet/gnunet-service-cadet.c | |
parent | 9cfc671375ef346c3ff40fbcdd7c2c090972072a (diff) | |
download | gnunet-7978b76868ba81efaa4b65b47a54ee55cd092382.tar.gz gnunet-7978b76868ba81efaa4b65b47a54ee55cd092382.zip |
implement #4973
Diffstat (limited to 'src/cadet/gnunet-service-cadet.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet.c | 90 |
1 files changed, 54 insertions, 36 deletions
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index a7e1fca47..af4cebfaa 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -75,7 +75,7 @@ struct CadetClient | |||
75 | * Handle to communicate with the client | 75 | * Handle to communicate with the client |
76 | */ | 76 | */ |
77 | struct GNUNET_MQ_Handle *mq; | 77 | struct GNUNET_MQ_Handle *mq; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Client handle. | 80 | * Client handle. |
81 | */ | 81 | */ |
@@ -83,7 +83,7 @@ struct CadetClient | |||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Ports that this client has declared interest in. | 85 | * Ports that this client has declared interest in. |
86 | * Indexed by port, contains *Client. | 86 | * Indexed by port, contains `struct OpenPort` |
87 | */ | 87 | */ |
88 | struct GNUNET_CONTAINER_MultiHashMap *ports; | 88 | struct GNUNET_CONTAINER_MultiHashMap *ports; |
89 | 89 | ||
@@ -99,6 +99,7 @@ struct CadetClient | |||
99 | unsigned int id; | 99 | unsigned int id; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | |||
102 | /******************************************************************************/ | 103 | /******************************************************************************/ |
103 | /*********************** GLOBAL VARIABLES ****************************/ | 104 | /*********************** GLOBAL VARIABLES ****************************/ |
104 | /******************************************************************************/ | 105 | /******************************************************************************/ |
@@ -151,14 +152,15 @@ static struct CadetClient *clients_tail; | |||
151 | static unsigned int next_client_id; | 152 | static unsigned int next_client_id; |
152 | 153 | ||
153 | /** | 154 | /** |
154 | * All ports clients of this peer have opened. | 155 | * All ports clients of this peer have opened. Maps from |
156 | * a hashed port to a `struct OpenPort`. | ||
155 | */ | 157 | */ |
156 | struct GNUNET_CONTAINER_MultiHashMap *open_ports; | 158 | struct GNUNET_CONTAINER_MultiHashMap *open_ports; |
157 | 159 | ||
158 | /** | 160 | /** |
159 | * Map from ports to channels where the ports were closed at the | 161 | * Map from ports to channels where the ports were closed at the |
160 | * time we got the inbound connection. | 162 | * time we got the inbound connection. |
161 | * Indexed by port, contains `struct CadetChannel`. | 163 | * Indexed by h_port, contains `struct CadetChannel`. |
162 | */ | 164 | */ |
163 | struct GNUNET_CONTAINER_MultiHashMap *loose_channels; | 165 | struct GNUNET_CONTAINER_MultiHashMap *loose_channels; |
164 | 166 | ||
@@ -436,11 +438,11 @@ shutdown_task (void *cls) | |||
436 | 438 | ||
437 | 439 | ||
438 | /** | 440 | /** |
439 | * We had a remote connection @a value to port @a port before | 441 | * We had a remote connection @a value to port @a h_port before |
440 | * client @a cls opened port @a port. Bind them now. | 442 | * client @a cls opened port @a port. Bind them now. |
441 | * | 443 | * |
442 | * @param cls the `struct CadetClient` | 444 | * @param cls the `struct CadetClient` |
443 | * @param port the port | 445 | * @param h_port the hashed port |
444 | * @param value the `struct CadetChannel` | 446 | * @param value the `struct CadetChannel` |
445 | * @return #GNUNET_YES (iterate over all such channels) | 447 | * @return #GNUNET_YES (iterate over all such channels) |
446 | */ | 448 | */ |
@@ -449,15 +451,16 @@ bind_loose_channel (void *cls, | |||
449 | const struct GNUNET_HashCode *port, | 451 | const struct GNUNET_HashCode *port, |
450 | void *value) | 452 | void *value) |
451 | { | 453 | { |
452 | struct CadetClient *c = cls; | 454 | struct OpenPort *op = cls; |
453 | struct CadetChannel *ch = value; | 455 | struct CadetChannel *ch = value; |
454 | 456 | ||
455 | GCCH_bind (ch, | 457 | GCCH_bind (ch, |
456 | c); | 458 | op->c, |
459 | &op->port); | ||
457 | GNUNET_assert (GNUNET_YES == | 460 | GNUNET_assert (GNUNET_YES == |
458 | GNUNET_CONTAINER_multihashmap_remove (loose_channels, | 461 | GNUNET_CONTAINER_multihashmap_remove (loose_channels, |
459 | port, | 462 | &op->h_port, |
460 | value)); | 463 | ch)); |
461 | return GNUNET_YES; | 464 | return GNUNET_YES; |
462 | } | 465 | } |
463 | 466 | ||
@@ -476,6 +479,7 @@ handle_port_open (void *cls, | |||
476 | const struct GNUNET_CADET_PortMessage *pmsg) | 479 | const struct GNUNET_CADET_PortMessage *pmsg) |
477 | { | 480 | { |
478 | struct CadetClient *c = cls; | 481 | struct CadetClient *c = cls; |
482 | struct OpenPort *op; | ||
479 | 483 | ||
480 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 484 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
481 | "Open port %s requested by %s\n", | 485 | "Open port %s requested by %s\n", |
@@ -483,11 +487,17 @@ handle_port_open (void *cls, | |||
483 | GSC_2s (c)); | 487 | GSC_2s (c)); |
484 | if (NULL == c->ports) | 488 | if (NULL == c->ports) |
485 | c->ports = GNUNET_CONTAINER_multihashmap_create (4, | 489 | c->ports = GNUNET_CONTAINER_multihashmap_create (4, |
486 | GNUNET_NO); | 490 | GNUNET_NO); |
491 | op = GNUNET_new (struct OpenPort); | ||
492 | op->c = c; | ||
493 | op->port = pmsg->port; | ||
494 | GCCH_hash_port (&op->h_port, | ||
495 | &pmsg->port, | ||
496 | &my_full_id); | ||
487 | if (GNUNET_OK != | 497 | if (GNUNET_OK != |
488 | GNUNET_CONTAINER_multihashmap_put (c->ports, | 498 | GNUNET_CONTAINER_multihashmap_put (c->ports, |
489 | &pmsg->port, | 499 | &op->port, |
490 | c, | 500 | op, |
491 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 501 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
492 | { | 502 | { |
493 | GNUNET_break (0); | 503 | GNUNET_break (0); |
@@ -495,13 +505,13 @@ handle_port_open (void *cls, | |||
495 | return; | 505 | return; |
496 | } | 506 | } |
497 | (void) GNUNET_CONTAINER_multihashmap_put (open_ports, | 507 | (void) GNUNET_CONTAINER_multihashmap_put (open_ports, |
498 | &pmsg->port, | 508 | &op->h_port, |
499 | c, | 509 | op, |
500 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 510 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
501 | GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels, | 511 | GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels, |
502 | &pmsg->port, | 512 | &op->h_port, |
503 | &bind_loose_channel, | 513 | &bind_loose_channel, |
504 | c); | 514 | op); |
505 | GNUNET_SERVICE_client_continue (c->client); | 515 | GNUNET_SERVICE_client_continue (c->client); |
506 | } | 516 | } |
507 | 517 | ||
@@ -520,24 +530,29 @@ handle_port_close (void *cls, | |||
520 | const struct GNUNET_CADET_PortMessage *pmsg) | 530 | const struct GNUNET_CADET_PortMessage *pmsg) |
521 | { | 531 | { |
522 | struct CadetClient *c = cls; | 532 | struct CadetClient *c = cls; |
533 | struct OpenPort *op; | ||
523 | 534 | ||
524 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 535 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
525 | "Closing port %s as requested by %s\n", | 536 | "Closing port %s as requested by %s\n", |
526 | GNUNET_h2s (&pmsg->port), | 537 | GNUNET_h2s (&pmsg->port), |
527 | GSC_2s (c)); | 538 | GSC_2s (c)); |
528 | if (GNUNET_YES != | 539 | op = GNUNET_CONTAINER_multihashmap_get (c->ports, |
529 | GNUNET_CONTAINER_multihashmap_remove (c->ports, | 540 | &pmsg->port); |
530 | &pmsg->port, | 541 | if (NULL == op) |
531 | c)) | ||
532 | { | 542 | { |
533 | GNUNET_break (0); | 543 | GNUNET_break (0); |
534 | GNUNET_SERVICE_client_drop (c->client); | 544 | GNUNET_SERVICE_client_drop (c->client); |
535 | return; | 545 | return; |
536 | } | 546 | } |
537 | GNUNET_assert (GNUNET_YES == | 547 | GNUNET_assert (GNUNET_YES == |
548 | GNUNET_CONTAINER_multihashmap_remove (c->ports, | ||
549 | &op->port, | ||
550 | op)); | ||
551 | GNUNET_assert (GNUNET_YES == | ||
538 | GNUNET_CONTAINER_multihashmap_remove (open_ports, | 552 | GNUNET_CONTAINER_multihashmap_remove (open_ports, |
539 | &pmsg->port, | 553 | &op->h_port, |
540 | c)); | 554 | op)); |
555 | GNUNET_free (op); | ||
541 | GNUNET_SERVICE_client_continue (c->client); | 556 | GNUNET_SERVICE_client_continue (c->client); |
542 | } | 557 | } |
543 | 558 | ||
@@ -1214,16 +1229,16 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c, | |||
1214 | * A client that created a loose channel that was not bound to a port | 1229 | * A client that created a loose channel that was not bound to a port |
1215 | * disconnected, drop it from the #loose_channels list. | 1230 | * disconnected, drop it from the #loose_channels list. |
1216 | * | 1231 | * |
1217 | * @param port the port the channel was trying to bind to | 1232 | * @param h_port the hashed port the channel was trying to bind to |
1218 | * @param ch the channel that was lost | 1233 | * @param ch the channel that was lost |
1219 | */ | 1234 | */ |
1220 | void | 1235 | void |
1221 | GSC_drop_loose_channel (const struct GNUNET_HashCode *port, | 1236 | GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port, |
1222 | struct CadetChannel *ch) | 1237 | struct CadetChannel *ch) |
1223 | { | 1238 | { |
1224 | GNUNET_assert (GNUNET_YES == | 1239 | GNUNET_assert (GNUNET_YES == |
1225 | GNUNET_CONTAINER_multihashmap_remove (loose_channels, | 1240 | GNUNET_CONTAINER_multihashmap_remove (loose_channels, |
1226 | port, | 1241 | h_port, |
1227 | ch)); | 1242 | ch)); |
1228 | } | 1243 | } |
1229 | 1244 | ||
@@ -1264,30 +1279,33 @@ channel_destroy_iterator (void *cls, | |||
1264 | /** | 1279 | /** |
1265 | * Remove client's ports from the global hashmap on disconnect. | 1280 | * Remove client's ports from the global hashmap on disconnect. |
1266 | * | 1281 | * |
1267 | * @param cls Closure (unused). | 1282 | * @param cls the `struct CadetClient` |
1268 | * @param key the port. | 1283 | * @param port the port. |
1269 | * @param value the `struct CadetClient` to remove | 1284 | * @param value the `struct OpenPort` to remove |
1270 | * @return #GNUNET_OK, keep iterating. | 1285 | * @return #GNUNET_OK, keep iterating. |
1271 | */ | 1286 | */ |
1272 | static int | 1287 | static int |
1273 | client_release_ports (void *cls, | 1288 | client_release_ports (void *cls, |
1274 | const struct GNUNET_HashCode *key, | 1289 | const struct GNUNET_HashCode *port, |
1275 | void *value) | 1290 | void *value) |
1276 | { | 1291 | { |
1277 | struct CadetClient *c = value; | 1292 | struct CadetClient *c = cls; |
1293 | struct OpenPort *op = value; | ||
1278 | 1294 | ||
1295 | GNUNET_assert (c == op->c); | ||
1279 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1296 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1280 | "Closing port %s due to %s disconnect.\n", | 1297 | "Closing port %s due to %s disconnect.\n", |
1281 | GNUNET_h2s (key), | 1298 | GNUNET_h2s (port), |
1282 | GSC_2s (c)); | 1299 | GSC_2s (c)); |
1283 | GNUNET_assert (GNUNET_YES == | 1300 | GNUNET_assert (GNUNET_YES == |
1284 | GNUNET_CONTAINER_multihashmap_remove (open_ports, | 1301 | GNUNET_CONTAINER_multihashmap_remove (open_ports, |
1285 | key, | 1302 | &op->h_port, |
1286 | value)); | 1303 | op)); |
1287 | GNUNET_assert (GNUNET_YES == | 1304 | GNUNET_assert (GNUNET_YES == |
1288 | GNUNET_CONTAINER_multihashmap_remove (c->ports, | 1305 | GNUNET_CONTAINER_multihashmap_remove (c->ports, |
1289 | key, | 1306 | port, |
1290 | value)); | 1307 | op)); |
1308 | GNUNET_free (op); | ||
1291 | return GNUNET_OK; | 1309 | return GNUNET_OK; |
1292 | } | 1310 | } |
1293 | 1311 | ||