aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2018-06-30 07:29:56 +0200
committerxrs <xrs@mail36.net>2018-06-30 07:29:56 +0200
commitf9b0e00a193e735db74f0abe907caf97c7da054b (patch)
treef5e82bc9d6d7b85ae740a32b30d815607259ad90 /src/cadet
parent23567e541296989792ac5db3d8820401d63b50c4 (diff)
parenta5a879c7462f9f1628d2372907a645d9dcaaccf1 (diff)
downloadgnunet-f9b0e00a193e735db74f0abe907caf97c7da054b.tar.gz
gnunet-f9b0e00a193e735db74f0abe907caf97c7da054b.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_api.c192
-rw-r--r--src/cadet/gnunet-cadet.c6
-rw-r--r--src/cadet/gnunet-service-cadet.c18
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c12
4 files changed, 102 insertions, 126 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index b019424f9..319279110 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -357,67 +357,52 @@ reconnect (struct GNUNET_CADET_Handle *h);
357 357
358 358
359/** 359/**
360 * Reconnect callback: tries to reconnect again after a failer previous 360 * Function called during #reconnect_cbk() to (re)open
361 * reconnecttion 361 * all ports that are still open.
362 *
363 * @param cls closure (cadet handle)
364 */
365static void
366reconnect_cbk (void *cls)
367{
368 struct GNUNET_CADET_Handle *h = cls;
369
370 h->reconnect_task = NULL;
371 reconnect (h);
372}
373
374
375/**
376 * Function called during #reconnect() to destroy
377 * all channels that are still open.
378 * 362 *
379 * @param cls the `struct GNUNET_CADET_Handle` 363 * @param cls the `struct GNUNET_CADET_Handle`
380 * @param cid chanenl ID 364 * @param id port ID
381 * @param value a `struct GNUNET_CADET_Channel` to destroy 365 * @param value a `struct GNUNET_CADET_Channel` to open
382 * @return #GNUNET_OK (continue to iterate) 366 * @return #GNUNET_OK (continue to iterate)
383 */ 367 */
384static int 368static int
385destroy_channel_on_reconnect_cb (void *cls, 369open_port_cb (void *cls,
386 uint32_t cid, 370 const struct GNUNET_HashCode *id,
387 void *value) 371 void *value)
388{ 372{
389 /* struct GNUNET_CADET_Handle *handle = cls; */ 373 struct GNUNET_CADET_Handle *h = cls;
390 struct GNUNET_CADET_Channel *ch = value; 374 struct GNUNET_CADET_Port *port = value;
375 struct GNUNET_CADET_PortMessage *msg;
376 struct GNUNET_MQ_Envelope *env;
391 377
392 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 378 (void) id;
393 "Destroying channel due to reconnect\n"); 379 env = GNUNET_MQ_msg (msg,
394 destroy_channel (ch); 380 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN);
381 msg->port = port->id;
382 GNUNET_MQ_send (h->mq,
383 env);
395 return GNUNET_OK; 384 return GNUNET_OK;
396} 385}
397 386
398 387
399/** 388/**
400 * Reconnect to the service, retransmit all infomation to try to restore the 389 * Reconnect callback: tries to reconnect again after a failer previous
401 * original state. 390 * reconnecttion
402 *
403 * @param h handle to the cadet
404 * 391 *
405 * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...) 392 * @param cls closure (cadet handle)
406 */ 393 */
407static void 394static void
408schedule_reconnect (struct GNUNET_CADET_Handle *h) 395reconnect_cbk (void *cls)
409{ 396{
410 if (NULL != h->reconnect_task) 397 struct GNUNET_CADET_Handle *h = cls;
411 return; 398
412 GNUNET_CONTAINER_multihashmap32_iterate (h->channels, 399 h->reconnect_task = NULL;
413 &destroy_channel_on_reconnect_cb,
414 h);
415 h->reconnect_task
416 = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
417 &reconnect_cbk,
418 h);
419 h->reconnect_time 400 h->reconnect_time
420 = GNUNET_TIME_STD_BACKOFF (h->reconnect_time); 401 = GNUNET_TIME_STD_BACKOFF (h->reconnect_time);
402 reconnect (h);
403 GNUNET_CONTAINER_multihashmap_iterate (h->ports,
404 &open_port_cb,
405 h);
421} 406}
422 407
423 408
@@ -555,15 +540,16 @@ cadet_mq_error_handler (void *cls,
555{ 540{
556 struct GNUNET_CADET_Channel *ch = cls; 541 struct GNUNET_CADET_Channel *ch = cls;
557 542
558 GNUNET_break (0);
559 if (GNUNET_MQ_ERROR_NO_MATCH == error) 543 if (GNUNET_MQ_ERROR_NO_MATCH == error)
560 { 544 {
561 /* Got a message we did not understand, still try to continue! */ 545 /* Got a message we did not understand, still try to continue! */
546 GNUNET_break_op (0);
562 GNUNET_CADET_receive_done (ch); 547 GNUNET_CADET_receive_done (ch);
563 } 548 }
564 else 549 else
565 { 550 {
566 schedule_reconnect (ch->cadet); 551 GNUNET_break (0);
552 GNUNET_CADET_channel_destroy (ch);
567 } 553 }
568} 554}
569 555
@@ -581,6 +567,7 @@ cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
581{ 567{
582 struct GNUNET_CADET_Channel *ch = impl_state; 568 struct GNUNET_CADET_Channel *ch = impl_state;
583 569
570 (void) mq;
584 GNUNET_assert (NULL != ch->pending_env); 571 GNUNET_assert (NULL != ch->pending_env);
585 GNUNET_MQ_discard (ch->pending_env); 572 GNUNET_MQ_discard (ch->pending_env);
586 ch->pending_env = NULL; 573 ch->pending_env = NULL;
@@ -709,6 +696,7 @@ check_local_data (void *cls,
709{ 696{
710 uint16_t size; 697 uint16_t size;
711 698
699 (void) cls;
712 size = ntohs (message->header.size); 700 size = ntohs (message->header.size);
713 if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size) 701 if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size)
714 { 702 {
@@ -806,6 +794,32 @@ handle_local_ack (void *cls,
806 794
807 795
808/** 796/**
797 * Function called during #GNUNET_CADET_disconnect() to destroy
798 * all channels that are still open.
799 *
800 * @param cls the `struct GNUNET_CADET_Handle`
801 * @param cid chanenl ID
802 * @param value a `struct GNUNET_CADET_Channel` to destroy
803 * @return #GNUNET_OK (continue to iterate)
804 */
805static int
806destroy_channel_cb (void *cls,
807 uint32_t cid,
808 void *value)
809{
810 /* struct GNUNET_CADET_Handle *handle = cls; */
811 struct GNUNET_CADET_Channel *ch = value;
812
813 (void) cls;
814 (void) cid;
815 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
816 "Destroying channel due to GNUNET_CADET_disconnect()\n");
817 destroy_channel (ch);
818 return GNUNET_OK;
819}
820
821
822/**
809 * Generic error handler, called with the appropriate error code and 823 * Generic error handler, called with the appropriate error code and
810 * the same closure specified at the creation of the message queue. 824 * the same closure specified at the creation of the message queue.
811 * Not every message queue implementation supports an error handler. 825 * Not every message queue implementation supports an error handler.
@@ -822,9 +836,14 @@ handle_mq_error (void *cls,
822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823 "MQ ERROR: %u\n", 837 "MQ ERROR: %u\n",
824 error); 838 error);
839 GNUNET_CONTAINER_multihashmap32_iterate (h->channels,
840 &destroy_channel_cb,
841 h);
825 GNUNET_MQ_destroy (h->mq); 842 GNUNET_MQ_destroy (h->mq);
826 h->mq = NULL; 843 h->mq = NULL;
827 reconnect (h); 844 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
845 &reconnect_cbk,
846 h);
828} 847}
829 848
830 849
@@ -842,6 +861,7 @@ check_get_peers (void *cls,
842{ 861{
843 size_t esize; 862 size_t esize;
844 863
864 (void) cls;
845 esize = ntohs (message->size); 865 esize = ntohs (message->size);
846 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == esize) 866 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == esize)
847 return GNUNET_OK; 867 return GNUNET_OK;
@@ -895,11 +915,9 @@ check_get_peer (void *cls,
895 const struct GNUNET_CADET_LocalInfoPeer *message) 915 const struct GNUNET_CADET_LocalInfoPeer *message)
896{ 916{
897 size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); 917 size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer);
898 const struct GNUNET_PeerIdentity *paths_array;
899 size_t esize; 918 size_t esize;
900 unsigned int epaths;
901 unsigned int peers;
902 919
920 (void) cls;
903 esize = ntohs (message->header.size); 921 esize = ntohs (message->header.size);
904 if (esize < msize) 922 if (esize < msize)
905 { 923 {
@@ -911,10 +929,6 @@ check_get_peer (void *cls,
911 GNUNET_break (0); 929 GNUNET_break (0);
912 return GNUNET_SYSERR; 930 return GNUNET_SYSERR;
913 } 931 }
914 peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity);
915 epaths = ntohs (message->paths);
916 paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
917
918 return GNUNET_OK; 932 return GNUNET_OK;
919} 933}
920 934
@@ -1166,38 +1180,6 @@ reconnect (struct GNUNET_CADET_Handle *h)
1166 handlers, 1180 handlers,
1167 &handle_mq_error, 1181 &handle_mq_error,
1168 h); 1182 h);
1169 if (NULL == h->mq)
1170 {
1171 schedule_reconnect (h);
1172 return;
1173 }
1174 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1175}
1176
1177
1178/**
1179 * Function called during #GNUNET_CADET_disconnect() to destroy
1180 * all channels that are still open.
1181 *
1182 * @param cls the `struct GNUNET_CADET_Handle`
1183 * @param cid chanenl ID
1184 * @param value a `struct GNUNET_CADET_Channel` to destroy
1185 * @return #GNUNET_OK (continue to iterate)
1186 */
1187static int
1188destroy_channel_cb (void *cls,
1189 uint32_t cid,
1190 void *value)
1191{
1192 /* struct GNUNET_CADET_Handle *handle = cls; */
1193 struct GNUNET_CADET_Channel *ch = value;
1194
1195 (void) cls;
1196 (void) cid;
1197 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1198 "Destroying channel due to GNUNET_CADET_disconnect()\n");
1199 destroy_channel (ch);
1200 return GNUNET_OK;
1201} 1183}
1202 1184
1203 1185
@@ -1219,6 +1201,7 @@ destroy_port_cb (void *cls,
1219 struct GNUNET_CADET_Port *port = value; 1201 struct GNUNET_CADET_Port *port = value;
1220 1202
1221 (void) cls; 1203 (void) cls;
1204 (void) id;
1222 /* This is a warning, the app should have cleanly closed all open ports */ 1205 /* This is a warning, the app should have cleanly closed all open ports */
1223 GNUNET_break (0); 1206 GNUNET_break (0);
1224 GNUNET_CADET_close_port (port); 1207 GNUNET_CADET_close_port (port);
@@ -1270,18 +1253,21 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1270void 1253void
1271GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) 1254GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
1272{ 1255{
1273 struct GNUNET_CADET_PortMessage *msg;
1274 struct GNUNET_MQ_Envelope *env;
1275
1276 GNUNET_assert (GNUNET_YES == 1256 GNUNET_assert (GNUNET_YES ==
1277 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, 1257 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports,
1278 &p->id, 1258 &p->id,
1279 p)); 1259 p));
1280 env = GNUNET_MQ_msg (msg, 1260 if (NULL != p->cadet->mq)
1281 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); 1261 {
1282 msg->port = p->id; 1262 struct GNUNET_CADET_PortMessage *msg;
1283 GNUNET_MQ_send (p->cadet->mq, 1263 struct GNUNET_MQ_Envelope *env;
1284 env); 1264
1265 env = GNUNET_MQ_msg (msg,
1266 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE);
1267 msg->port = p->id;
1268 GNUNET_MQ_send (p->cadet->mq,
1269 env);
1270 }
1285 GNUNET_free_non_null (p->handlers); 1271 GNUNET_free_non_null (p->handlers);
1286 GNUNET_free (p); 1272 GNUNET_free (p);
1287} 1273}
@@ -1633,9 +1619,6 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
1633 return NULL; 1619 return NULL;
1634 } 1620 }
1635 h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 1621 h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1636 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1637 h->reconnect_task = NULL;
1638
1639 return h; 1622 return h;
1640} 1623}
1641 1624
@@ -1661,8 +1644,6 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1661 GNUNET_CADET_DisconnectEventHandler disconnects, 1644 GNUNET_CADET_DisconnectEventHandler disconnects,
1662 const struct GNUNET_MQ_MessageHandler *handlers) 1645 const struct GNUNET_MQ_MessageHandler *handlers)
1663{ 1646{
1664 struct GNUNET_CADET_PortMessage *msg;
1665 struct GNUNET_MQ_Envelope *env;
1666 struct GNUNET_CADET_Port *p; 1647 struct GNUNET_CADET_Port *p;
1667 1648
1668 GNUNET_assert (NULL != connects); 1649 GNUNET_assert (NULL != connects);
@@ -1688,13 +1669,11 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1688 p->window_changes = window_changes; 1669 p->window_changes = window_changes;
1689 p->disconnects = disconnects; 1670 p->disconnects = disconnects;
1690 p->handlers = GNUNET_MQ_copy_handlers (handlers); 1671 p->handlers = GNUNET_MQ_copy_handlers (handlers);
1691 1672
1692 1673 GNUNET_assert (GNUNET_OK ==
1693 env = GNUNET_MQ_msg (msg, 1674 open_port_cb (h,
1694 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); 1675 &p->id,
1695 msg->port = p->id; 1676 p));
1696 GNUNET_MQ_send (h->mq,
1697 env);
1698 return p; 1677 return p;
1699} 1678}
1700 1679
@@ -1753,7 +1732,8 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1753 handlers, 1732 handlers,
1754 &cadet_mq_error_handler, 1733 &cadet_mq_error_handler,
1755 ch); 1734 ch);
1756 GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls); 1735 GNUNET_MQ_set_handlers_closure (ch->mq,
1736 channel_cls);
1757 1737
1758 /* Request channel creation to service */ 1738 /* Request channel creation to service */
1759 env = GNUNET_MQ_msg (msg, 1739 env = GNUNET_MQ_msg (msg,
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index b22881907..13b04b885 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -231,7 +231,7 @@ shutdown_task (void *cls)
231 } 231 }
232} 232}
233 233
234void * 234void
235mq_cb(void *cls) 235mq_cb(void *cls)
236{ 236{
237 listen_stdio (); 237 listen_stdio ();
@@ -577,9 +577,9 @@ peer_callback (void *cls,
577 }else{ 577 }else{
578 p = paths; 578 p = paths;
579 FPRINTF (stdout, 579 FPRINTF (stdout,
580 "Path with offset %u: ", 580 "Indirekt path with offset %u: ",
581 offset); 581 offset);
582 for (i = 0; i < offset && NULL != p;) 582 for (i = 0; i <= offset && NULL != p;)
583 { 583 {
584 FPRINTF (stdout, 584 FPRINTF (stdout,
585 "%s ", 585 "%s ",
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index dd693731f..4568d2733 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -881,7 +881,7 @@ path_info_iterator (void *cls,
881 unsigned int path_length; 881 unsigned int path_length;
882 882
883 path_length = GCPP_get_length (path); 883 path_length = GCPP_get_length (path);
884 path_size = sizeof (struct GNUNET_PeerIdentity) * (path_length - 1); 884 path_size = sizeof (struct GNUNET_PeerIdentity) * path_length;
885 if (sizeof (*resp) + path_size > UINT16_MAX) 885 if (sizeof (*resp) + path_size > UINT16_MAX)
886 { 886 {
887 LOG (GNUNET_ERROR_TYPE_WARNING, 887 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -902,9 +902,9 @@ path_info_iterator (void *cls,
902 /* Don't copy first peer. First peer is always the local one. Last 902 /* Don't copy first peer. First peer is always the local one. Last
903 * peer is always the destination (leave as 0, EOL). 903 * peer is always the destination (leave as 0, EOL).
904 */ 904 */
905 for (i = 0; i < off; i++) 905 for (i = 0; i <= off; i++)
906 id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, 906 id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path,
907 i + 1)); 907 i));
908 GNUNET_MQ_send (mq, 908 GNUNET_MQ_send (mq,
909 env); 909 env);
910 return GNUNET_YES; 910 return GNUNET_YES;
@@ -927,29 +927,23 @@ get_peer_info (void *cls,
927 struct CadetClient *c = cls; 927 struct CadetClient *c = cls;
928 struct GNUNET_MQ_Envelope *env; 928 struct GNUNET_MQ_Envelope *env;
929 struct GNUNET_CADET_LocalInfoPeer *msg; 929 struct GNUNET_CADET_LocalInfoPeer *msg;
930
931 930
932 env = GNUNET_MQ_msg (msg, 931 env = GNUNET_MQ_msg (msg,
933 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); 932 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
934
935 msg->offset = htons(0); 933 msg->offset = htons(0);
936 msg->destination = *peer; 934 msg->destination = *peer;
937 msg->paths = htons (GCP_count_paths (p)); 935 msg->paths = htons (GCP_count_paths (p));
938 msg->tunnel = htons (NULL != GCP_get_tunnel (p, 936 msg->tunnel = htons (NULL != GCP_get_tunnel (p,
939 GNUNET_NO)); 937 GNUNET_NO));
940 msg->finished_with_paths = htons(0); 938 msg->finished_with_paths = htons(0);
941
942 GNUNET_MQ_send (c->mq, 939 GNUNET_MQ_send (c->mq,
943 env); 940 env);
944 941 GCP_iterate_indirect_paths (p,
945 GCP_iterate_indirect_paths(p, 942 &path_info_iterator,
946 &path_info_iterator, 943 c->mq);
947 c->mq);
948
949} 944}
950 945
951 946
952
953/** 947/**
954 * Handler for client's SHOW_PEER request. 948 * Handler for client's SHOW_PEER request.
955 * 949 *
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index ac1ee59de..b375d51ca 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -243,16 +243,16 @@ GCP_2s (const struct CadetPeer *cp)
243 static char buf[5]; 243 static char buf[5];
244 char *ret; 244 char *ret;
245 245
246 if (NULL == cp || 246 if ((NULL == cp) ||
247 NULL == &cp->pid.public_key){ 247 (NULL == &cp->pid.public_key))
248 return "NULL"; 248 return "NULL";
249 } 249
250 250
251 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key); 251 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key);
252 252
253 if (NULL == ret){ 253 if (NULL == ret)
254 return "NULL"; 254 return "NULL";
255 } 255
256 256
257 strncpy (buf, 257 strncpy (buf,
258 ret, 258 ret,
@@ -1217,6 +1217,8 @@ GCP_iterate_paths (struct CadetPeer *cp,
1217 (NULL == cp->core_mq) ? "" : " including direct link"); 1217 (NULL == cp->core_mq) ? "" : " including direct link");
1218 if (NULL != cp->core_mq) 1218 if (NULL != cp->core_mq)
1219 { 1219 {
1220 /* FIXME: this branch seems to duplicate the
1221 i=0 case below (direct link). Leave out!??? -CG */
1220 struct CadetPeerPath *path; 1222 struct CadetPeerPath *path;
1221 1223
1222 path = GCPP_get_path_from_route (1, 1224 path = GCPP_get_path_from_route (1,