aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 20:54:16 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 20:54:24 +0200
commit2cce8be6b8fcb2baa0d7abde4bbe486cbcb3f983 (patch)
tree28bde1eaa1de1f569404d879689a411d9cdbe678 /src
parent18c183d3cb8f12790ed55333519b53a535a5c906 (diff)
downloadgnunet-2cce8be6b8fcb2baa0d7abde4bbe486cbcb3f983.tar.gz
gnunet-2cce8be6b8fcb2baa0d7abde4bbe486cbcb3f983.zip
misc bugfixes
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c1
-rw-r--r--src/identity/gnunet-identity.c2
-rw-r--r--src/json/test_json_mhd.c1
-rw-r--r--src/transport/gnunet-communicator-tcp.c9
-rw-r--r--src/transport/gnunet-communicator-udp.c77
-rw-r--r--src/transport/gnunet-communicator-unix.c4
-rw-r--r--src/transport/gnunet-service-tng.c35
-rw-r--r--src/transport/test_transport_address_switch.c176
8 files changed, 140 insertions, 165 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index bd95428be..a1f6e37c2 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -1472,6 +1472,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1472 1, 1472 1,
1473 GNUNET_NO); 1473 GNUNET_NO);
1474 drop = ccc->head_recv; 1474 drop = ccc->head_recv;
1475 GNUNET_assert (NULL != drop);
1475 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1476 GNUNET_CONTAINER_DLL_remove (ccc->head_recv,
1476 ccc->tail_recv, 1477 ccc->tail_recv,
1477 drop); 1478 drop);
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index e22ac9106..4d6b1db3f 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -291,7 +291,7 @@ print_ego (void *cls,
291 } 291 }
292 if (! (list | monitor)) 292 if (! (list | monitor))
293 return; 293 return;
294 if (NULL == ego) 294 if ( (NULL == ego) || (NULL == identifier) )
295 return; 295 return;
296 if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) 296 if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego)))
297 return; 297 return;
diff --git a/src/json/test_json_mhd.c b/src/json/test_json_mhd.c
index 13338b32c..73efc4d97 100644
--- a/src/json/test_json_mhd.c
+++ b/src/json/test_json_mhd.c
@@ -144,7 +144,6 @@ main (int argc, const char *const argv[])
144 { 144 {
145 GNUNET_break (0); 145 GNUNET_break (0);
146 MHD_stop_daemon (daemon); 146 MHD_stop_daemon (daemon);
147 GNUNET_free (url);
148 json_decref (bigj); 147 json_decref (bigj);
149 GNUNET_free (post_data); 148 GNUNET_free (post_data);
150 GNUNET_free (str); 149 GNUNET_free (str);
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 8ab99700c..50264cf45 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1909,15 +1909,6 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1909 queue->sock, 1909 queue->sock,
1910 &queue_read_kx, 1910 &queue_read_kx,
1911 queue); 1911 queue);
1912 if (NULL == queue)
1913 {
1914 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1915 "Failed to setup queue to %s at `%s'\n",
1916 GNUNET_i2s (peer),
1917 path);
1918 GNUNET_NETWORK_socket_close (sock);
1919 return GNUNET_NO;
1920 }
1921 start_initial_kx_out (queue); 1912 start_initial_kx_out (queue);
1922 return GNUNET_OK; 1913 return GNUNET_OK;
1923} 1914}
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 1c2063d58..6193b9225 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1043,7 +1043,7 @@ check_timeouts (void *cls)
1043 st = GNUNET_TIME_UNIT_FOREVER_REL; 1043 st = GNUNET_TIME_UNIT_FOREVER_REL;
1044 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap))) 1044 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1045 { 1045 {
1046 st = GNUNET_TIME_absolute_get_remaining (receiver->timeout); 1046 st = GNUNET_TIME_absolute_get_remaining (sender->timeout);
1047 if (0 != st.rel_value_us) 1047 if (0 != st.rel_value_us)
1048 break; 1048 break;
1049 sender_destroy (sender); 1049 sender_destroy (sender);
@@ -2113,51 +2113,6 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
2113 2113
2114 2114
2115/** 2115/**
2116 * Setup a receiver for transmission. Setup the MQ processing and
2117 * inform transport that the queue is ready.
2118 *
2119 * @param target which peer are we talking to
2120 * @param address address of the peer
2121 * @param address_len number of bytes in @a address
2122 * @return handle for the address
2123 */
2124static struct ReceiverAddress *
2125receiver_setup (const struct GNUNET_PeerIdentity *target,
2126 const struct sockaddr *address,
2127 socklen_t address_len)
2128{
2129 struct ReceiverAddress *receiver;
2130
2131 receiver = GNUNET_new (struct ReceiverAddress);
2132 receiver->address = GNUNET_memdup (address, address_len);
2133 receiver->address_len = address_len;
2134 receiver->target = *target;
2135 receiver->nt = GNUNET_NT_scanner_get_type (is, address, address_len);
2136 (void) GNUNET_CONTAINER_multipeermap_put (
2137 receivers,
2138 &receiver->target,
2139 receiver,
2140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2141 receiver->timeout =
2142 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2143 receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
2144 receiver,
2145 receiver->timeout.abs_value_us);
2146 GNUNET_STATISTICS_set (stats,
2147 "# receivers active",
2148 GNUNET_CONTAINER_multipeermap_size (receivers),
2149 GNUNET_NO);
2150 receiver->foreign_addr =
2151 sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2152 setup_receiver_mq (receiver);
2153
2154 if (NULL == timeout_task)
2155 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
2156 return receiver;
2157}
2158
2159
2160/**
2161 * Function called by the transport service to initialize a 2116 * Function called by the transport service to initialize a
2162 * message queue given address information about another peer. 2117 * message queue given address information about another peer.
2163 * If and when the communication channel is established, the 2118 * If and when the communication channel is established, the
@@ -2192,8 +2147,30 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2192 } 2147 }
2193 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 2148 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
2194 in = udp_address_to_sockaddr (path, &in_len); 2149 in = udp_address_to_sockaddr (path, &in_len);
2195 receiver = receiver_setup (peer, in, in_len); 2150
2196 (void) receiver; 2151 receiver = GNUNET_new (struct ReceiverAddress);
2152 receiver->address = in;
2153 receiver->address_len = in_len;
2154 receiver->target = *peer;
2155 receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
2156 (void) GNUNET_CONTAINER_multipeermap_put (receivers,
2157 &receiver->target,
2158 receiver,
2159 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2160 receiver->timeout =
2161 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2162 receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
2163 receiver,
2164 receiver->timeout.abs_value_us);
2165 GNUNET_STATISTICS_set (stats,
2166 "# receivers active",
2167 GNUNET_CONTAINER_multipeermap_size (receivers),
2168 GNUNET_NO);
2169 receiver->foreign_addr =
2170 sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
2171 setup_receiver_mq (receiver);
2172 if (NULL == timeout_task)
2173 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
2197 return GNUNET_OK; 2174 return GNUNET_OK;
2198} 2175}
2199 2176
@@ -2489,14 +2466,14 @@ iface_proc (void *cls,
2489 2466
2490 (void) cls; 2467 (void) cls;
2491 (void) netmask; 2468 (void) netmask;
2469 if (NULL == addr)
2470 return GNUNET_YES; /* need to know our address! */
2492 network = GNUNET_NT_scanner_get_type (is, addr, addrlen); 2471 network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
2493 if (GNUNET_NT_LOOPBACK == network) 2472 if (GNUNET_NT_LOOPBACK == network)
2494 { 2473 {
2495 /* Broadcasting on loopback does not make sense */ 2474 /* Broadcasting on loopback does not make sense */
2496 return GNUNET_YES; 2475 return GNUNET_YES;
2497 } 2476 }
2498 if (NULL == addr)
2499 return GNUNET_YES; /* need to know our address! */
2500 for (bi = bi_head; NULL != bi; bi = bi->next) 2477 for (bi = bi_head; NULL != bi; bi = bi->next)
2501 { 2478 {
2502 if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen))) 2479 if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index 642703f29..9bbc02c65 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -417,6 +417,7 @@ select_write_cb (void *cls)
417 struct Queue *queue = queue_tail; 417 struct Queue *queue = queue_tail;
418 const struct GNUNET_MessageHeader *msg = queue->msg; 418 const struct GNUNET_MessageHeader *msg = queue->msg;
419 size_t msg_size = ntohs (msg->size); 419 size_t msg_size = ntohs (msg->size);
420 const void *msg;
420 ssize_t sent; 421 ssize_t sent;
421 422
422 /* take queue of the ready list */ 423 /* take queue of the ready list */
@@ -432,12 +433,13 @@ select_write_cb (void *cls)
432 NULL); 433 NULL);
433 434
434 /* send 'msg' */ 435 /* send 'msg' */
436 msg = queue->msg;
435 queue->msg = NULL; 437 queue->msg = NULL;
436 GNUNET_MQ_impl_send_continue (queue->mq); 438 GNUNET_MQ_impl_send_continue (queue->mq);
437 resend: 439 resend:
438 /* Send the data */ 440 /* Send the data */
439 sent = GNUNET_NETWORK_socket_sendto (unix_sock, 441 sent = GNUNET_NETWORK_socket_sendto (unix_sock,
440 queue->msg, 442 msg,
441 msg_size, 443 msg_size,
442 (const struct sockaddr *) queue->address, 444 (const struct sockaddr *) queue->address,
443 queue->address_len); 445 queue->address_len);
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 7cc9f193c..9262e5e97 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -2980,7 +2980,8 @@ free_virtual_link (struct VirtualLink *vl)
2980 2980
2981 while (NULL != (pm = vl->pending_msg_head)) 2981 while (NULL != (pm = vl->pending_msg_head))
2982 free_pending_message (pm); 2982 free_pending_message (pm);
2983 GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl); 2983 GNUNET_assert (GNUNET_YES ==
2984 GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl));
2984 if (NULL != vl->visibility_task) 2985 if (NULL != vl->visibility_task)
2985 { 2986 {
2986 GNUNET_SCHEDULER_cancel (vl->visibility_task); 2987 GNUNET_SCHEDULER_cancel (vl->visibility_task);
@@ -3006,7 +3007,9 @@ free_virtual_link (struct VirtualLink *vl)
3006static void 3007static void
3007free_validation_state (struct ValidationState *vs) 3008free_validation_state (struct ValidationState *vs)
3008{ 3009{
3009 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs); 3010 GNUNET_assert (
3011 GNUNET_YES ==
3012 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs));
3010 GNUNET_CONTAINER_heap_remove_node (vs->hn); 3013 GNUNET_CONTAINER_heap_remove_node (vs->hn);
3011 vs->hn = NULL; 3014 vs->hn = NULL;
3012 if (NULL != vs->sc) 3015 if (NULL != vs->sc)
@@ -4650,6 +4653,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4650 struct DistanceVector *dv; 4653 struct DistanceVector *dv;
4651 4654
4652 vl = lookup_virtual_link (target); 4655 vl = lookup_virtual_link (target);
4656 GNUNET_assert (NULL != vl);
4653 n = vl->n; 4657 n = vl->n;
4654 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4658 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4655 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4659 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
@@ -5101,6 +5105,7 @@ handle_del_address (void *cls,
5101 const struct GNUNET_TRANSPORT_DelAddressMessage *dam) 5105 const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
5102{ 5106{
5103 struct TransportClient *tc = cls; 5107 struct TransportClient *tc = cls;
5108 struct AddressListEntry *alen;
5104 5109
5105 if (CT_COMMUNICATOR != tc->type) 5110 if (CT_COMMUNICATOR != tc->type)
5106 { 5111 {
@@ -5110,8 +5115,9 @@ handle_del_address (void *cls,
5110 } 5115 }
5111 for (struct AddressListEntry *ale = tc->details.communicator.addr_head; 5116 for (struct AddressListEntry *ale = tc->details.communicator.addr_head;
5112 NULL != ale; 5117 NULL != ale;
5113 ale = ale->next) 5118 ale = alen)
5114 { 5119 {
5120 alen = ale->next;
5115 if (dam->aid != ale->aid) 5121 if (dam->aid != ale->aid)
5116 continue; 5122 continue;
5117 GNUNET_assert (ale->tc == tc); 5123 GNUNET_assert (ale->tc == tc);
@@ -5515,10 +5521,10 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5515 msize = ntohs (fb->msg_size); 5521 msize = ntohs (fb->msg_size);
5516 fc.message_uuid = fb->msg_uuid; 5522 fc.message_uuid = fb->msg_uuid;
5517 fc.rc = NULL; 5523 fc.rc = NULL;
5518 GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map, 5524 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map,
5519 fb->msg_uuid.uuid, 5525 fb->msg_uuid.uuid,
5520 &find_by_message_uuid, 5526 &find_by_message_uuid,
5521 &fc); 5527 &fc);
5522 if (NULL == (rc = fc.rc)) 5528 if (NULL == (rc = fc.rc))
5523 { 5529 {
5524 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ 5530 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */
@@ -7756,6 +7762,7 @@ handle_validation_challenge (
7756 struct GNUNET_TIME_RelativeNBO validity_duration; 7762 struct GNUNET_TIME_RelativeNBO validity_duration;
7757 struct IncomingRequest *ir; 7763 struct IncomingRequest *ir;
7758 struct Neighbour *n; 7764 struct Neighbour *n;
7765 struct GNUNET_PeerIdentity sender;
7759 7766
7760 /* DV-routed messages are not allowed for validation challenges */ 7767 /* DV-routed messages are not allowed for validation challenges */
7761 if (cmc->total_hops > 0) 7768 if (cmc->total_hops > 0)
@@ -7794,9 +7801,9 @@ handle_validation_challenge (
7794 route_control_message_without_fc (&cmc->im.sender, 7801 route_control_message_without_fc (&cmc->im.sender,
7795 &tvr.header, 7802 &tvr.header,
7796 RMO_ANYTHING_GOES | RMO_REDUNDANT); 7803 RMO_ANYTHING_GOES | RMO_REDUNDANT);
7804 sender = cmc->im.sender;
7797 finish_cmc_handling (cmc); 7805 finish_cmc_handling (cmc);
7798 7806 vl = lookup_virtual_link (&sender);
7799 vl = lookup_virtual_link (&cmc->im.sender);
7800 if (NULL != vl) 7807 if (NULL != vl)
7801 return; 7808 return;
7802 7809
@@ -7805,17 +7812,17 @@ handle_validation_challenge (
7805 CORE), so we must try to bring the link up! */ 7812 CORE), so we must try to bring the link up! */
7806 7813
7807 /* (1) Check existing queues, if any, we may be lucky! */ 7814 /* (1) Check existing queues, if any, we may be lucky! */
7808 n = lookup_neighbour (&cmc->im.sender); 7815 n = lookup_neighbour (&sender);
7809 if (NULL != n) 7816 if (NULL != n)
7810 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 7817 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
7811 start_address_validation (&cmc->im.sender, q->address); 7818 start_address_validation (&sender, q->address);
7812 /* (2) Also try to see if we have addresses in PEERSTORE for this peer 7819 /* (2) Also try to see if we have addresses in PEERSTORE for this peer
7813 we could use */ 7820 we could use */
7814 for (ir = ir_head; NULL != ir; ir = ir->next) 7821 for (ir = ir_head; NULL != ir; ir = ir->next)
7815 if (0 == GNUNET_memcmp (&ir->pid, &cmc->im.sender)) 7822 if (0 == GNUNET_memcmp (&ir->pid, &sender))
7816 return; /* we are already trying */ 7823 return; /* we are already trying */
7817 ir = GNUNET_new (struct IncomingRequest); 7824 ir = GNUNET_new (struct IncomingRequest);
7818 ir->pid = cmc->im.sender; 7825 ir->pid = sender;
7819 GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); 7826 GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir);
7820 ir->wc = GNUNET_PEERSTORE_watch (peerstore, 7827 ir->wc = GNUNET_PEERSTORE_watch (peerstore,
7821 "transport", 7828 "transport",
@@ -9190,6 +9197,7 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9190 "Cannot connect to %s at `%s', no matching communicator present\n", 9197 "Cannot connect to %s at `%s', no matching communicator present\n",
9191 GNUNET_i2s (pid), 9198 GNUNET_i2s (pid),
9192 address); 9199 address);
9200 GNUNET_free (prefix);
9193 return; 9201 return;
9194 } 9202 }
9195 /* forward suggestion for queue creation to communicator */ 9203 /* forward suggestion for queue creation to communicator */
@@ -9198,6 +9206,7 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9198 (unsigned int) idgen, 9206 (unsigned int) idgen,
9199 prefix, 9207 prefix,
9200 address); 9208 address);
9209 GNUNET_free (prefix);
9201 alen = strlen (address) + 1; 9210 alen = strlen (address) + 1;
9202 env = 9211 env =
9203 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 9212 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index fa977a364..98f1170ff 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -93,9 +93,7 @@ stat_start_attempt_cb (void *cls,
93 struct PeerStats *stat = cls; 93 struct PeerStats *stat = cls;
94 94
95 stat->switch_attempts++; 95 stat->switch_attempts++;
96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat);
97 "Switch attempted (%p)",
98 stat);
99 bytes_recv_after_switch = 0; 97 bytes_recv_after_switch = 0;
100 bytes_sent_after_switch = 0; 98 bytes_sent_after_switch = 0;
101 99
@@ -113,9 +111,7 @@ stat_success_attempt_cb (void *cls,
113 struct PeerStats *stat = cls; 111 struct PeerStats *stat = cls;
114 112
115 stat->switch_success++; 113 stat->switch_success++;
116 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 114 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat);
117 "Switch succeeded (%p)",
118 stat);
119 return GNUNET_OK; 115 return GNUNET_OK;
120} 116}
121 117
@@ -133,9 +129,7 @@ stat_fail_attempt_cb (void *cls,
133 return GNUNET_OK; 129 return GNUNET_OK;
134 130
135 stat->switch_fail++; 131 stat->switch_fail++;
136 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat);
137 "Switch failed (%p)",
138 stat);
139 return GNUNET_OK; 133 return GNUNET_OK;
140} 134}
141 135
@@ -157,7 +151,8 @@ stat_addresses_available (void *cls,
157/** 151/**
158 * List of statistics entries we care about. 152 * List of statistics entries we care about.
159 */ 153 */
160static struct WatchEntry { 154static struct WatchEntry
155{
161 156
162 /** 157 /**
163 * Name of the statistic we watch. 158 * Name of the statistic we watch.
@@ -168,15 +163,17 @@ static struct WatchEntry {
168 * Handler to register; 163 * Handler to register;
169 */ 164 */
170 GNUNET_STATISTICS_Iterator stat_handler; 165 GNUNET_STATISTICS_Iterator stat_handler;
171} watches[] = { 166} watches[] =
172 { "# Attempts to switch addresses", &stat_start_attempt_cb }, 167 {{"# Attempts to switch addresses", &stat_start_attempt_cb},
173 { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, 168 {"# Successful attempts to switch addresses", &stat_success_attempt_cb},
174 { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", &stat_fail_attempt_cb }, 169 {"# Failed attempts to switch addresses (failed to send CONNECT CONT)",
175 { "# Failed attempts to switch addresses (failed to send CONNECT)", &stat_fail_attempt_cb }, 170 &stat_fail_attempt_cb},
176 { "# Failed attempts to switch addresses (no response)", &stat_fail_attempt_cb }, 171 {"# Failed attempts to switch addresses (failed to send CONNECT)",
177 { "# transport addresses", &stat_addresses_available }, 172 &stat_fail_attempt_cb},
178 { NULL, NULL } 173 {"# Failed attempts to switch addresses (no response)",
179}; 174 &stat_fail_attempt_cb},
175 {"# transport addresses", &stat_addresses_available},
176 {NULL, NULL}};
180 177
181 178
182static void 179static void
@@ -203,19 +200,18 @@ custom_shutdown (void *cls)
203 } 200 }
204 201
205 /* stop statistics */ 202 /* stop statistics */
206 for (unsigned int i=0;i<2;i++) 203 for (unsigned int i = 0; i < 2; i++)
207 { 204 {
208 if (NULL != stats[i].stat) 205 if (NULL != stats[i].stat)
209 { 206 {
210 for (unsigned int j=0;NULL != watches[j].stat_name; j++) 207 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
211 GNUNET_STATISTICS_watch_cancel (stats[i].stat, 208 GNUNET_assert (GNUNET_OK ==
212 "transport", 209 GNUNET_STATISTICS_watch_cancel (stats[i].stat,
213 watches[j].stat_name, 210 "transport",
214 watches[j].stat_handler, 211 watches[j].stat_name,
215 &stats[i]); 212 watches[j].stat_handler,
216 213 &stats[i]));
217 GNUNET_STATISTICS_destroy (stats[i].stat, 214 GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO);
218 GNUNET_NO);
219 stats[i].stat = NULL; 215 stats[i].stat = NULL;
220 } 216 }
221 } 217 }
@@ -224,15 +220,16 @@ custom_shutdown (void *cls)
224 FPRINTF (stderr, "\n"); 220 FPRINTF (stderr, "\n");
225 if (stats[0].switch_attempts > 0) 221 if (stats[0].switch_attempts > 0)
226 { 222 {
227 FPRINTF (stderr, 223 FPRINTF (
228 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", 224 stderr,
229 stats[0].switch_attempts, 225 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
230 stats[0].switch_success, 226 stats[0].switch_attempts,
231 stats[0].switch_fail); 227 stats[0].switch_success,
228 stats[0].switch_fail);
232 if (stats[0].switch_success != stats[0].switch_attempts) 229 if (stats[0].switch_success != stats[0].switch_attempts)
233 { 230 {
234 GNUNET_break (0); 231 GNUNET_break (0);
235 result ++; 232 result++;
236 } 233 }
237 } 234 }
238 else if (stats[0].addresses_avail > 1) 235 else if (stats[0].addresses_avail > 1)
@@ -243,11 +240,12 @@ custom_shutdown (void *cls)
243 } 240 }
244 if (stats[1].switch_attempts > 0) 241 if (stats[1].switch_attempts > 0)
245 { 242 {
246 FPRINTF (stderr, 243 FPRINTF (
247 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", 244 stderr,
248 stats[1].switch_attempts, 245 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
249 stats[1].switch_success, 246 stats[1].switch_attempts,
250 stats[1].switch_fail); 247 stats[1].switch_success,
248 stats[1].switch_fail);
251 if (stats[1].switch_success != stats[1].switch_attempts) 249 if (stats[1].switch_success != stats[1].switch_attempts)
252 { 250 {
253 GNUNET_break (0); 251 GNUNET_break (0);
@@ -261,19 +259,17 @@ custom_shutdown (void *cls)
261 stats[1].addresses_avail); 259 stats[1].addresses_avail);
262 } 260 }
263 261
264 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 262 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
265 (bytes_sent_after_switch == 0) ) 263 (bytes_sent_after_switch == 0))
266 { 264 {
267 FPRINTF (stderr, 265 FPRINTF (stderr, "No data sent after switching!\n");
268 "No data sent after switching!\n");
269 GNUNET_break (0); 266 GNUNET_break (0);
270 result++; 267 result++;
271 } 268 }
272 if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 269 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
273 (bytes_recv_after_switch == 0) ) 270 (bytes_recv_after_switch == 0))
274 { 271 {
275 FPRINTF (stderr, 272 FPRINTF (stderr, "No data received after switching!\n");
276 "No data received after switching!\n");
277 GNUNET_break (0); 273 GNUNET_break (0);
278 result++; 274 result++;
279 } 275 }
@@ -306,13 +302,14 @@ notify_receive (void *cls,
306 GNUNET_i2s (sender)); 302 GNUNET_i2s (sender));
307 GNUNET_free (ps); 303 GNUNET_free (ps);
308 } 304 }
309 if ( ((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && 305 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
310 (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && 306 (stats[0].switch_attempts ==
311 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) 307 stats[0].switch_fail + stats[0].switch_success) &&
308 (stats[1].switch_attempts ==
309 stats[1].switch_fail + stats[1].switch_success))
312 { 310 {
313 bytes_recv_after_switch += ntohs(hdr->header.size); 311 bytes_recv_after_switch += ntohs (hdr->header.size);
314 if ( (bytes_sent_after_switch > 0) && 312 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
315 (bytes_recv_after_switch > 0) )
316 { 313 {
317 /* A peer switched addresses and sent and received data after the 314 /* A peer switched addresses and sent and received data after the
318 * switch operations */ 315 * switch operations */
@@ -327,21 +324,22 @@ notify_send (void *cls)
327{ 324{
328 static uint32_t cnt; 325 static uint32_t cnt;
329 326
330 GNUNET_assert (GNUNET_OK == 327 GNUNET_assert (
331 GNUNET_TRANSPORT_TESTING_send (ccc->p[1], 328 GNUNET_OK ==
332 ccc->p[0], 329 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
333 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 330 ccc->p[0],
334 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 331 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
335 ++cnt, 332 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
336 &notify_send, 333 ++cnt,
337 NULL)); 334 &notify_send,
338 if ( ( (stats[0].switch_attempts >= 1) || 335 NULL));
339 (stats[1].switch_attempts >= 1) ) && 336 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
340 (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && 337 (stats[0].switch_attempts ==
341 (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) 338 stats[0].switch_fail + stats[0].switch_success) &&
339 (stats[1].switch_attempts ==
340 stats[1].switch_fail + stats[1].switch_success))
342 { 341 {
343 bytes_sent_after_switch 342 bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
344 += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
345 } 343 }
346} 344}
347 345
@@ -370,10 +368,9 @@ progress_indicator (void *cls)
370static void 368static void
371connected_cb (void *cls) 369connected_cb (void *cls)
372{ 370{
373 for (unsigned int i=0;i<2;i++) 371 for (unsigned int i = 0; i < 2; i++)
374 { 372 {
375 stats[i].stat = GNUNET_STATISTICS_create ("transport", 373 stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg);
376 ccc->p[i]->cfg);
377 if (NULL == stats[i].stat) 374 if (NULL == stats[i].stat)
378 { 375 {
379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -382,7 +379,7 @@ connected_cb (void *cls)
382 GNUNET_SCHEDULER_shutdown (); 379 GNUNET_SCHEDULER_shutdown ();
383 return; 380 return;
384 } 381 }
385 for (unsigned int j=0;NULL != watches[j].stat_name; j++) 382 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
386 { 383 {
387 GNUNET_STATISTICS_watch (stats[i].stat, 384 GNUNET_STATISTICS_watch (stats[i].stat,
388 "transport", 385 "transport",
@@ -397,29 +394,28 @@ connected_cb (void *cls)
397 &progress_indicator, 394 &progress_indicator,
398 NULL); 395 NULL);
399 /* Peers are connected, start transmit test messages */ 396 /* Peers are connected, start transmit test messages */
400 GNUNET_assert (GNUNET_OK == 397 GNUNET_assert (
401 GNUNET_TRANSPORT_TESTING_send (ccc->p[1], 398 GNUNET_OK ==
402 ccc->p[0], 399 GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
403 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 400 ccc->p[0],
404 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 401 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
405 0, 402 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
406 &notify_send, 403 0,
407 NULL)); 404 &notify_send,
405 NULL));
408} 406}
409 407
410 408
411int 409int
412main (int argc, 410main (int argc, char *argv[])
413 char *argv[])
414{ 411{
415 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 412 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc =
416 .connect_continuation = &connected_cb, 413 {.connect_continuation = &connected_cb,
417 .config_file = "test_transport_api_data.conf", 414 .config_file = "test_transport_api_data.conf",
418 .rec = &notify_receive, 415 .rec = &notify_receive,
419 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 416 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
420 .shutdown_task = &custom_shutdown, 417 .shutdown_task = &custom_shutdown,
421 .timeout = TIMEOUT 418 .timeout = TIMEOUT};
422 };
423 ccc = &my_ccc; 419 ccc = &my_ccc;
424 int ret; 420 int ret;
425 421