diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/mesh_api_new.c | 90 |
1 files changed, 54 insertions, 36 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 17b4caced..658696df6 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -579,6 +579,55 @@ reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
579 | 579 | ||
580 | 580 | ||
581 | /** | 581 | /** |
582 | * Send a connect packet to the service with the applications and types | ||
583 | * requested by the user. | ||
584 | * | ||
585 | * @param h The mesh handle. | ||
586 | * | ||
587 | */ | ||
588 | static void | ||
589 | send_connect (struct GNUNET_MESH_Handle *h) | ||
590 | { | ||
591 | size_t size; | ||
592 | |||
593 | size = sizeof (struct GNUNET_MESH_ClientConnect); | ||
594 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); | ||
595 | size += h->n_handlers * sizeof (uint16_t); | ||
596 | { | ||
597 | char buf[size]; | ||
598 | struct GNUNET_MESH_ClientConnect *msg; | ||
599 | GNUNET_MESH_ApplicationType *apps; | ||
600 | uint16_t napps; | ||
601 | uint16_t *types; | ||
602 | uint16_t ntypes; | ||
603 | |||
604 | /* build connection packet */ | ||
605 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | ||
606 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | ||
607 | msg->header.size = htons (size); | ||
608 | apps = (GNUNET_MESH_ApplicationType *) &msg[1]; | ||
609 | for (napps = 0; napps < h->n_applications; napps++) | ||
610 | { | ||
611 | apps[napps] = htonl (h->applications[napps]); | ||
612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", | ||
613 | h->applications[napps]); | ||
614 | } | ||
615 | types = (uint16_t *) & apps[napps]; | ||
616 | for (ntypes = 0; ntypes < h->n_handlers; ntypes++) | ||
617 | types[ntypes] = htons (h->message_handlers[ntypes].type); | ||
618 | msg->applications = htons (napps); | ||
619 | msg->types = htons (ntypes); | ||
620 | #if DEBUG | ||
621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
622 | "mesh: Sending %lu bytes long message %d types and %d apps\n", | ||
623 | ntohs (msg->header.size), ntypes, napps); | ||
624 | #endif | ||
625 | send_packet (h, &msg->header); | ||
626 | } | ||
627 | } | ||
628 | |||
629 | |||
630 | /** | ||
582 | * Reconnect to the service, retransmit all infomation to try to restore the | 631 | * Reconnect to the service, retransmit all infomation to try to restore the |
583 | * original state. | 632 | * original state. |
584 | * | 633 | * |
@@ -617,6 +666,9 @@ reconnect (struct GNUNET_MESH_Handle *h) | |||
617 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, | 666 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, |
618 | GNUNET_TIME_relative_multiply | 667 | GNUNET_TIME_relative_multiply |
619 | (h->reconnect_time, 2)); | 668 | (h->reconnect_time, 2)); |
669 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
670 | "mesh: Next retry in %sms\n", | ||
671 | GNUNET_TIME_relative_to_string(h->reconnect_time)); | ||
620 | GNUNET_break (0); | 672 | GNUNET_break (0); |
621 | return GNUNET_NO; | 673 | return GNUNET_NO; |
622 | } | 674 | } |
@@ -624,6 +676,7 @@ reconnect (struct GNUNET_MESH_Handle *h) | |||
624 | { | 676 | { |
625 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | 677 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; |
626 | } | 678 | } |
679 | send_connect(h); | ||
627 | /* Rebuild all tunnels */ | 680 | /* Rebuild all tunnels */ |
628 | for (t = h->tunnels_head; NULL != t; t = t->next) | 681 | for (t = h->tunnels_head; NULL != t; t = t->next) |
629 | { | 682 | { |
@@ -1122,12 +1175,6 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1122 | const GNUNET_MESH_ApplicationType *stypes) | 1175 | const GNUNET_MESH_ApplicationType *stypes) |
1123 | { | 1176 | { |
1124 | struct GNUNET_MESH_Handle *h; | 1177 | struct GNUNET_MESH_Handle *h; |
1125 | struct GNUNET_MESH_ClientConnect *msg; | ||
1126 | GNUNET_MESH_ApplicationType *apps; | ||
1127 | uint16_t napps; | ||
1128 | uint16_t *types; | ||
1129 | uint16_t ntypes; | ||
1130 | size_t size; | ||
1131 | 1178 | ||
1132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); | 1179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); |
1133 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | 1180 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); |
@@ -1152,36 +1199,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1152 | /* count handlers and apps, calculate size */ | 1199 | /* count handlers and apps, calculate size */ |
1153 | for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; | 1200 | for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; |
1154 | for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; | 1201 | for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; |
1155 | size = sizeof (struct GNUNET_MESH_ClientConnect); | 1202 | send_connect(h); |
1156 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); | ||
1157 | size += h->n_handlers * sizeof (uint16_t); | ||
1158 | |||
1159 | { | ||
1160 | char buf[size]; | ||
1161 | |||
1162 | /* build connection packet */ | ||
1163 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | ||
1164 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | ||
1165 | msg->header.size = htons (size); | ||
1166 | apps = (GNUNET_MESH_ApplicationType *) &msg[1]; | ||
1167 | for (napps = 0; napps < h->n_applications; napps++) | ||
1168 | { | ||
1169 | apps[napps] = htonl (h->applications[napps]); | ||
1170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", | ||
1171 | h->applications[napps]); | ||
1172 | } | ||
1173 | types = (uint16_t *) & apps[napps]; | ||
1174 | for (ntypes = 0; ntypes < h->n_handlers; ntypes++) | ||
1175 | types[ntypes] = htons (h->message_handlers[ntypes].type); | ||
1176 | msg->applications = htons (napps); | ||
1177 | msg->types = htons (ntypes); | ||
1178 | #if DEBUG | ||
1179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1180 | "mesh: Sending %lu bytes long message %d types and %d apps\n", | ||
1181 | ntohs (msg->header.size), ntypes, napps); | ||
1182 | #endif | ||
1183 | send_packet (h, &msg->header); | ||
1184 | } | ||
1185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n"); | 1203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n"); |
1186 | return h; | 1204 | return h; |
1187 | } | 1205 | } |