aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-07-21 00:15:22 +0000
committerBart Polot <bart@net.in.tum.de>2014-07-21 00:15:22 +0000
commit2c0aed48a0c9507ea50b1683b7dc1cced822713d (patch)
tree9b17d1568c50724746f731cbdb45dd9584f41f5e /src/cadet
parentcd806ab8dc55774a64ed25b453757f2d9569535f (diff)
downloadgnunet-2c0aed48a0c9507ea50b1683b7dc1cced822713d.tar.gz
gnunet-2c0aed48a0c9507ea50b1683b7dc1cced822713d.zip
- notify about deleted messages when popping messages from a connection, allowing to keep a count and make sure the connection is destroyed
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c21
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c16
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h11
3 files changed, 37 insertions, 11 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index eff147a29..5425e258a 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -379,6 +379,8 @@ GCC_state2s (enum CadetConnectionState s)
379 case CADET_CONNECTION_DESTROYED: 379 case CADET_CONNECTION_DESTROYED:
380 return "CADET_CONNECTION_DESTROYED"; 380 return "CADET_CONNECTION_DESTROYED";
381 default: 381 default:
382 GNUNET_break (0);
383 LOG (GNUNET_ERROR_TYPE_ERROR, " conn state %u unknown!\n", s);
382 return "CADET_CONNECTION_STATE_ERROR"; 384 return "CADET_CONNECTION_STATE_ERROR";
383 } 385 }
384} 386}
@@ -1406,7 +1408,7 @@ unregister_neighbors (struct CadetConnection *c)
1406 if (GNUNET_OK != GCP_remove_connection (peer, c)) 1408 if (GNUNET_OK != GCP_remove_connection (peer, c))
1407 { 1409 {
1408 GNUNET_assert (CADET_CONNECTION_NEW == c->state 1410 GNUNET_assert (CADET_CONNECTION_NEW == c->state
1409 || CADET_CONNECTION_DESTROYED == c->state); 1411 || CADET_CONNECTION_DESTROYED == c->state);
1410 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate: %u\n", c->state); 1412 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate: %u\n", c->state);
1411 if (NULL != c->t) GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG); 1413 if (NULL != c->t) GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
1412 } 1414 }
@@ -1415,7 +1417,7 @@ unregister_neighbors (struct CadetConnection *c)
1415 if (GNUNET_OK != GCP_remove_connection (peer, c)) 1417 if (GNUNET_OK != GCP_remove_connection (peer, c))
1416 { 1418 {
1417 GNUNET_assert (CADET_CONNECTION_NEW == c->state 1419 GNUNET_assert (CADET_CONNECTION_NEW == c->state
1418 || CADET_CONNECTION_DESTROYED == c->state); 1420 || CADET_CONNECTION_DESTROYED == c->state);
1419 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate: %u\n", c->state); 1421 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate: %u\n", c->state);
1420 if (NULL != c->t) GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG); 1422 if (NULL != c->t) GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
1421 } 1423 }
@@ -1795,6 +1797,8 @@ GCC_handle_broken (void* cls,
1795 struct GNUNET_CADET_ConnectionBroken *msg; 1797 struct GNUNET_CADET_ConnectionBroken *msg;
1796 struct CadetConnection *c; 1798 struct CadetConnection *c;
1797 struct CadetTunnel *t; 1799 struct CadetTunnel *t;
1800 unsigned int del;
1801 int pending;
1798 int fwd; 1802 int fwd;
1799 1803
1800 msg = (struct GNUNET_CADET_ConnectionBroken *) message; 1804 msg = (struct GNUNET_CADET_ConnectionBroken *) message;
@@ -1831,15 +1835,26 @@ GCC_handle_broken (void* cls,
1831 c->state = CADET_CONNECTION_DESTROYED; 1835 c->state = CADET_CONNECTION_DESTROYED;
1832 GCT_remove_connection (t, c); 1836 GCT_remove_connection (t, c);
1833 c->t = NULL; 1837 c->t = NULL;
1838 pending = c->pending_messages;
1834 1839
1835 /* GCP_connection_pop will destroy the connection when the last message 1840 /* GCP_connection_pop will destroy the connection when the last message
1836 * is popped! Do not use 'c' after the call. */ 1841 * is popped! Do not use 'c' after the call. */
1837 while (NULL != (out_msg = GCP_connection_pop (neighbor, c))) 1842 while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &del)))
1838 { 1843 {
1844 pending -= del + 1;
1839 GCT_resend_message (out_msg, t); 1845 GCT_resend_message (out_msg, t);
1840 } 1846 }
1841 /* All pending messages should have been popped, 1847 /* All pending messages should have been popped,
1842 * and the connection destroyed by the continuation. */ 1848 * and the connection destroyed by the continuation. */
1849 if (0 < pending)
1850 {
1851 GNUNET_break (0);
1852 GCC_destroy (c);
1853 }
1854 else
1855 {
1856 GNUNET_break (0 == pending_msgs); /* If negative: counter error! */
1857 }
1843 } 1858 }
1844 else 1859 else
1845 { 1860 {
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index fdd79abcd..c037c6171 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -1133,11 +1133,10 @@ GCP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls,
1133 struct CadetPeer *peer; 1133 struct CadetPeer *peer;
1134 1134
1135 peer = queue->peer; 1135 peer = queue->peer;
1136 1136 LOG (GNUNET_ERROR_TYPE_DEBUG, "queue destroy %s\n", GC_m2s (queue->type));
1137 if (GNUNET_YES == clear_cls) 1137 if (GNUNET_YES == clear_cls)
1138 { 1138 {
1139 LOG (GNUNET_ERROR_TYPE_DEBUG, "queue destroy type %s\n", 1139 LOG (GNUNET_ERROR_TYPE_DEBUG, " free cls\n");
1140 GC_m2s (queue->type));
1141 switch (queue->type) 1140 switch (queue->type)
1142 { 1141 {
1143 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: 1142 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
@@ -1384,18 +1383,26 @@ connection_get_first_message (struct CadetPeer *peer, struct CadetConnection *c)
1384/** 1383/**
1385 * Get the first message for a connection and unqueue it. 1384 * Get the first message for a connection and unqueue it.
1386 * 1385 *
1386 * Only tunnel (or higher) level messages are unqueued. Connection specific
1387 * messages are destroyed and the count given to the caller.
1388 *
1387 * @param peer Neighboring peer. 1389 * @param peer Neighboring peer.
1388 * @param c Connection. 1390 * @param c Connection.
1391 * @param del[out] How many messages have been deleted without returning.
1392 * Can be NULL.
1389 * 1393 *
1390 * @return First message for this connection. 1394 * @return First message for this connection.
1391 */ 1395 */
1392struct GNUNET_MessageHeader * 1396struct GNUNET_MessageHeader *
1393GCP_connection_pop (struct CadetPeer *peer, struct CadetConnection *c) 1397GCP_connection_pop (struct CadetPeer *peer,
1398 struct CadetConnection *c,
1399 unsigned int *del)
1394{ 1400{
1395 struct CadetPeerQueue *q; 1401 struct CadetPeerQueue *q;
1396 struct CadetPeerQueue *next; 1402 struct CadetPeerQueue *next;
1397 struct GNUNET_MessageHeader *msg; 1403 struct GNUNET_MessageHeader *msg;
1398 1404
1405 if (NULL != del) *del = 0;
1399 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection pop on connection %p\n", c); 1406 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection pop on connection %p\n", c);
1400 for (q = peer->queue_head; NULL != q; q = next) 1407 for (q = peer->queue_head; NULL != q; q = next)
1401 { 1408 {
@@ -1411,6 +1418,7 @@ GCP_connection_pop (struct CadetPeer *peer, struct CadetConnection *c)
1411 case GNUNET_MESSAGE_TYPE_CADET_ACK: 1418 case GNUNET_MESSAGE_TYPE_CADET_ACK:
1412 case GNUNET_MESSAGE_TYPE_CADET_POLL: 1419 case GNUNET_MESSAGE_TYPE_CADET_POLL:
1413 GCP_queue_destroy (q, GNUNET_YES, GNUNET_NO, 0); 1420 GCP_queue_destroy (q, GNUNET_YES, GNUNET_NO, 0);
1421 if (NULL != del) *del = *del + 1;
1414 continue; 1422 continue;
1415 1423
1416 case GNUNET_MESSAGE_TYPE_CADET_KX: 1424 case GNUNET_MESSAGE_TYPE_CADET_KX:
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index b7297d101..e581685fa 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -169,17 +169,20 @@ GCP_queue_cancel (struct CadetPeer *peer, struct CadetConnection *c);
169/** 169/**
170 * Get the first message for a connection and unqueue it. 170 * Get the first message for a connection and unqueue it.
171 * 171 *
172 * If the message was the last in the connection and the destruction flag 172 * Only tunnel (or higher) level messages are unqueued. Connection specific
173 * was set, the connection will be freed by the continuation called by this 173 * messages are destroyed and the count given to the caller.
174 * function, and @c c will be INVALID after the call.
175 * 174 *
176 * @param peer Neighboring peer. 175 * @param peer Neighboring peer.
177 * @param c Connection. 176 * @param c Connection.
177 * @param del[out] How many messages have been deleted without returning.
178 * Can be NULL.
178 * 179 *
179 * @return First message for this connection. 180 * @return First message for this connection.
180 */ 181 */
181struct GNUNET_MessageHeader * 182struct GNUNET_MessageHeader *
182GCP_connection_pop (struct CadetPeer *peer, struct CadetConnection *c); 183GCP_connection_pop (struct CadetPeer *peer,
184 struct CadetConnection *c,
185 unsigned int *del);
183 186
184/** 187/**
185 * Unlock a possibly locked queue for a connection. 188 * Unlock a possibly locked queue for a connection.