aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-17 15:18:29 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-17 15:18:29 +0000
commitb77c3c0220c8b1945ee6c4173151847ad2fc4941 (patch)
treed809be6ab00540d0ab058d29d912429a4eeb2e25 /src
parent3546e3b90ad958eb9fd3d372c7bd53400853b698 (diff)
downloadgnunet-b77c3c0220c8b1945ee6c4173151847ad2fc4941.tar.gz
gnunet-b77c3c0220c8b1945ee6c4173151847ad2fc4941.zip
- refactor
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c112
1 files changed, 58 insertions, 54 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index e966e7192..b57470339 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -490,6 +490,34 @@ get_hop (struct MeshConnection *c, int fwd)
490 490
491 491
492/** 492/**
493 * Is traffic coming from this sender 'FWD' traffic?
494 *
495 * @param c Connection to check.
496 * @param sender Peer identity of neighbor.
497 *
498 * @return GNUNET_YES in case the sender is the 'prev' hop and therefore
499 * the traffic is 'FWD'. GNUNET_NO for BCK. GNUNET_SYSERR for errors.
500 */
501static int
502is_fwd (const struct MeshConnection *c,
503 const struct GNUNET_PeerIdentity *sender)
504{
505 GNUNET_PEER_Id id;
506
507 id = GNUNET_PEER_search (sender);
508 if (GMP_get_short_id (get_prev_hop (c)) == id)
509 return GNUNET_YES;
510
511 if (GMP_get_short_id (get_next_hop (c)) == id)
512 return GNUNET_NO;
513
514 GNUNET_break (0);
515 return GNUNET_SYSERR;
516}
517
518
519
520/**
493 * Send an ACK informing the predecessor about the available buffer space. 521 * Send an ACK informing the predecessor about the available buffer space.
494 * 522 *
495 * Note that for fwd ack, the FWD mean forward *traffic* (root->dest), 523 * Note that for fwd ack, the FWD mean forward *traffic* (root->dest),
@@ -500,7 +528,7 @@ get_hop (struct MeshConnection *c, int fwd)
500 * @param fwd Is this FWD ACK? (Going dest->owner) 528 * @param fwd Is this FWD ACK? (Going dest->owner)
501 */ 529 */
502static void 530static void
503connection_send_ack (struct MeshConnection *c, unsigned int buffer, int fwd) 531send_ack (struct MeshConnection *c, unsigned int buffer, int fwd)
504{ 532{
505 struct MeshFlowControl *next_fc; 533 struct MeshFlowControl *next_fc;
506 struct MeshFlowControl *prev_fc; 534 struct MeshFlowControl *prev_fc;
@@ -574,10 +602,37 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
574 GMT_change_state (t, MESH_TUNNEL3_WAITING); 602 GMT_change_state (t, MESH_TUNNEL3_WAITING);
575 if (MESH_CONNECTION_READY != connection->state) 603 if (MESH_CONNECTION_READY != connection->state)
576 connection_change_state (connection, MESH_CONNECTION_SENT); 604 connection_change_state (connection, MESH_CONNECTION_SENT);
605
577} 606}
578 607
579 608
580/** 609/**
610 * Send a notification that a connection is broken.
611 *
612 * @param c Connection that is broken.
613 * @param id1 Peer that has disconnected.
614 * @param id2 Peer that has disconnected.
615 * @param fwd Direction towards which to send it.
616 */
617static void
618send_broken (struct MeshConnection *c,
619 const struct GNUNET_PeerIdentity *id1,
620 const struct GNUNET_PeerIdentity *id2,
621 int fwd)
622{
623 struct GNUNET_MESH_ConnectionBroken msg;
624
625 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
626 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
627 msg.cid = c->id;
628 msg.peer1 = *id1;
629 msg.peer2 = *id2;
630 GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
631}
632
633
634
635/**
581 * Send keepalive packets for a connection. 636 * Send keepalive packets for a connection.
582 * 637 *
583 * @param c Connection to keep alive.. 638 * @param c Connection to keep alive..
@@ -1177,33 +1232,6 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1177 1232
1178 1233
1179/** 1234/**
1180 * Is traffic coming from this sender 'FWD' traffic?
1181 *
1182 * @param c Connection to check.
1183 * @param sender Peer identity of neighbor.
1184 *
1185 * @return GNUNET_YES in case the sender is the 'prev' hop and therefore
1186 * the traffic is 'FWD'. GNUNET_NO for BCK. GNUNET_SYSERR for errors.
1187 */
1188int
1189is_fwd (const struct MeshConnection *c,
1190 const struct GNUNET_PeerIdentity *sender)
1191{
1192 GNUNET_PEER_Id id;
1193
1194 id = GNUNET_PEER_search (sender);
1195 if (GMP_get_short_id (get_prev_hop (c)) == id)
1196 return GNUNET_YES;
1197
1198 if (GMP_get_short_id (get_next_hop (c)) == id)
1199 return GNUNET_NO;
1200
1201 GNUNET_break (0);
1202 return GNUNET_SYSERR;
1203}
1204
1205
1206/**
1207 * Core handler for notifications of broken paths 1235 * Core handler for notifications of broken paths
1208 * 1236 *
1209 * @param cls Closure (unused). 1237 * @param cls Closure (unused).
@@ -1707,7 +1735,7 @@ GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
1707 else 1735 else
1708 { 1736 {
1709 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n"); 1737 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
1710 connection_send_ack (c, buffer, fwd); 1738 send_ack (c, buffer, fwd);
1711 } 1739 }
1712} 1740}
1713 1741
@@ -1956,35 +1984,11 @@ GMC_get_qn (struct MeshConnection *c, int fwd)
1956void 1984void
1957GMC_allow (struct MeshConnection *c, unsigned int buffer, int fwd) 1985GMC_allow (struct MeshConnection *c, unsigned int buffer, int fwd)
1958{ 1986{
1959 connection_send_ack (c, buffer, fwd); 1987 send_ack (c, buffer, fwd);
1960} 1988}
1961 1989
1962 1990
1963/** 1991/**
1964 * Send a notification that a connection is broken.
1965 *
1966 * @param c Connection that is broken.
1967 * @param id1 Peer that has disconnected.
1968 * @param id2 Peer that has disconnected.
1969 * @param fwd Direction towards which to send it.
1970 */
1971static void
1972send_broken (struct MeshConnection *c,
1973 const struct GNUNET_PeerIdentity *id1,
1974 const struct GNUNET_PeerIdentity *id2,
1975 int fwd)
1976{
1977 struct GNUNET_MESH_ConnectionBroken msg;
1978
1979 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
1980 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
1981 msg.cid = c->id;
1982 msg.peer1 = *id1;
1983 msg.peer2 = *id2;
1984 GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
1985}
1986
1987/**
1988 * Notify other peers on a connection of a broken link. Mark connections 1992 * Notify other peers on a connection of a broken link. Mark connections
1989 * to destroy after all traffic has been sent. 1993 * to destroy after all traffic has been sent.
1990 * 1994 *