aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet-new_tunnels.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-29 12:40:40 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-29 12:40:40 +0100
commitf61c5da9a44126edcbdfd66712ae1879e39a623d (patch)
treee59a41fab7713e7c9f86d0540ca38dd1eb0ebf13 /src/cadet/gnunet-service-cadet-new_tunnels.c
parentd50ef7d2d9631f56be7ad0d74d21fd78ed9d4cc2 (diff)
downloadgnunet-f61c5da9a44126edcbdfd66712ae1879e39a623d.tar.gz
gnunet-f61c5da9a44126edcbdfd66712ae1879e39a623d.zip
when applicable, do connection selection outside of send_kx*
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_tunnels.c')
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index f98f46b9b..c08a01f1a 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -1275,35 +1275,38 @@ GCT_change_estate (struct CadetTunnel *t,
1275/** 1275/**
1276 * Send a KX message. 1276 * Send a KX message.
1277 * 1277 *
1278 * @param t Tunnel on which to send it. 1278 * @param t tunnel on which to send the KX_AUTH
1279 * @param ct Tunnel and connection on which to send the KX_AUTH, NULL if
1280 * we are to find one that is ready.
1279 * @param ax axolotl key context to use 1281 * @param ax axolotl key context to use
1280 */ 1282 */
1281static void 1283static void
1282send_kx (struct CadetTunnel *t, 1284send_kx (struct CadetTunnel *t,
1285 struct CadetTConnection *ct,
1283 struct CadetTunnelAxolotl *ax) 1286 struct CadetTunnelAxolotl *ax)
1284{ 1287{
1285 struct CadetTConnection *ct;
1286 struct CadetConnection *cc; 1288 struct CadetConnection *cc;
1287 struct GNUNET_MQ_Envelope *env; 1289 struct GNUNET_MQ_Envelope *env;
1288 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; 1290 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
1289 enum GNUNET_CADET_KX_Flags flags; 1291 enum GNUNET_CADET_KX_Flags flags;
1290 1292
1291 ct = get_ready_connection (t); 1293 if (NULL == ct)
1294 ct = get_ready_connection (t);
1292 if (NULL == ct) 1295 if (NULL == ct)
1293 { 1296 {
1294 LOG (GNUNET_ERROR_TYPE_DEBUG, 1297 LOG (GNUNET_ERROR_TYPE_DEBUG,
1295 "Wanted to send KX on %s, but no connection is ready, deferring\n", 1298 "Wanted to send %s in state %s, but no connection is ready, deferring\n",
1296 GCT_2s (t)); 1299 GCT_2s (t),
1300 estate2s (t->estate));
1297 t->next_kx_attempt = GNUNET_TIME_absolute_get (); 1301 t->next_kx_attempt = GNUNET_TIME_absolute_get ();
1298 return; 1302 return;
1299 } 1303 }
1300 cc = ct->cc; 1304 cc = ct->cc;
1301 LOG (GNUNET_ERROR_TYPE_DEBUG, 1305 LOG (GNUNET_ERROR_TYPE_DEBUG,
1302 "Sending KX on %s using %s in state %s\n", 1306 "Sending KX on %s via %s using %s in state %s\n",
1303 GCT_2s (t), 1307 GCT_2s (t),
1304 GCC_2s (ct->cc), 1308 GCC_2s (cc),
1305 estate2s (t->estate)); 1309 estate2s (t->estate));
1306
1307 env = GNUNET_MQ_msg (msg, 1310 env = GNUNET_MQ_msg (msg,
1308 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX); 1311 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX);
1309 flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */ 1312 flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */
@@ -1330,23 +1333,27 @@ send_kx (struct CadetTunnel *t,
1330/** 1333/**
1331 * Send a KX_AUTH message. 1334 * Send a KX_AUTH message.
1332 * 1335 *
1333 * @param t Tunnel on which to send it. 1336 * @param t tunnel on which to send the KX_AUTH
1337 * @param ct Tunnel and connection on which to send the KX_AUTH, NULL if
1338 * we are to find one that is ready.
1334 * @param ax axolotl key context to use 1339 * @param ax axolotl key context to use
1335 * @param force_reply Force the other peer to reply with a KX_AUTH message 1340 * @param force_reply Force the other peer to reply with a KX_AUTH message
1336 * (set if we would like to transmit right now, but cannot) 1341 * (set if we would like to transmit right now, but cannot)
1337 */ 1342 */
1338static void 1343static void
1339send_kx_auth (struct CadetTunnel *t, 1344send_kx_auth (struct CadetTunnel *t,
1345 struct CadetTConnection *ct,
1340 struct CadetTunnelAxolotl *ax, 1346 struct CadetTunnelAxolotl *ax,
1341 int force_reply) 1347 int force_reply)
1342{ 1348{
1343 struct CadetTConnection *ct;
1344 struct CadetConnection *cc; 1349 struct CadetConnection *cc;
1345 struct GNUNET_MQ_Envelope *env; 1350 struct GNUNET_MQ_Envelope *env;
1346 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg; 1351 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg;
1347 enum GNUNET_CADET_KX_Flags flags; 1352 enum GNUNET_CADET_KX_Flags flags;
1348 1353
1349 ct = get_ready_connection (t); 1354 if ( (NULL == ct) ||
1355 (GNUNET_NO == ct->is_ready) )
1356 ct = get_ready_connection (t);
1350 if (NULL == ct) 1357 if (NULL == ct)
1351 { 1358 {
1352 LOG (GNUNET_ERROR_TYPE_DEBUG, 1359 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1560,6 +1567,7 @@ retry_kx (void *cls)
1560 case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */ 1567 case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */
1561 case CADET_TUNNEL_KEY_AX_SENT: /* trying again */ 1568 case CADET_TUNNEL_KEY_AX_SENT: /* trying again */
1562 send_kx (t, 1569 send_kx (t,
1570 NULL,
1563 &t->ax); 1571 &t->ax);
1564 break; 1572 break;
1565 case CADET_TUNNEL_KEY_AX_RECV: 1573 case CADET_TUNNEL_KEY_AX_RECV:
@@ -1578,6 +1586,7 @@ retry_kx (void *cls)
1578 ax = &t->ax; 1586 ax = &t->ax;
1579 } 1587 }
1580 send_kx_auth (t, 1588 send_kx_auth (t,
1589 NULL,
1581 ax, 1590 ax,
1582 (0 == GCT_count_channels (t)) 1591 (0 == GCT_count_channels (t))
1583 ? GNUNET_NO 1592 ? GNUNET_NO
@@ -1598,6 +1607,7 @@ retry_kx (void *cls)
1598 ax = &t->ax; 1607 ax = &t->ax;
1599 } 1608 }
1600 send_kx_auth (t, 1609 send_kx_auth (t,
1610 NULL,
1601 ax, 1611 ax,
1602 (0 == GCT_count_channels (t)) 1612 (0 == GCT_count_channels (t))
1603 ? GNUNET_NO 1613 ? GNUNET_NO
@@ -1617,6 +1627,7 @@ retry_kx (void *cls)
1617 ax = &t->ax; 1627 ax = &t->ax;
1618 } 1628 }
1619 send_kx_auth (t, 1629 send_kx_auth (t,
1630 NULL,
1620 ax, 1631 ax,
1621 GNUNET_NO); 1632 GNUNET_NO);
1622 break; 1633 break;
@@ -1648,6 +1659,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
1648 LOG (GNUNET_ERROR_TYPE_DEBUG, 1659 LOG (GNUNET_ERROR_TYPE_DEBUG,
1649 "Got duplicate KX. Firing back KX_AUTH.\n"); 1660 "Got duplicate KX. Firing back KX_AUTH.\n");
1650 send_kx_auth (t, 1661 send_kx_auth (t,
1662 ct,
1651 &t->ax, 1663 &t->ax,
1652 GNUNET_NO); 1664 GNUNET_NO);
1653 return; 1665 return;
@@ -1666,6 +1678,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
1666 "Got duplicate unverified KX on %s. Fire back KX_AUTH again.\n", 1678 "Got duplicate unverified KX on %s. Fire back KX_AUTH again.\n",
1667 GCT_2s (t)); 1679 GCT_2s (t));
1668 send_kx_auth (t, 1680 send_kx_auth (t,
1681 ct,
1669 t->unverified_ax, 1682 t->unverified_ax,
1670 GNUNET_NO); 1683 GNUNET_NO);
1671 return; 1684 return;
@@ -2145,6 +2158,7 @@ connection_ready_cb (void *cls,
2145 t->kx_task = NULL; 2158 t->kx_task = NULL;
2146 } 2159 }
2147 send_kx (t, 2160 send_kx (t,
2161 ct,
2148 &t->ax); 2162 &t->ax);
2149 break; 2163 break;
2150 case CADET_TUNNEL_KEY_AX_RECV: 2164 case CADET_TUNNEL_KEY_AX_RECV:
@@ -2167,6 +2181,7 @@ connection_ready_cb (void *cls,
2167 t->kx_task = NULL; 2181 t->kx_task = NULL;
2168 } 2182 }
2169 send_kx_auth (t, 2183 send_kx_auth (t,
2184 ct,
2170 &t->ax, 2185 &t->ax,
2171 GNUNET_NO); 2186 GNUNET_NO);
2172 return; 2187 return;
@@ -2776,6 +2791,7 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
2776 t->kx_task = NULL; 2791 t->kx_task = NULL;
2777 } 2792 }
2778 send_kx_auth (t, 2793 send_kx_auth (t,
2794 ct,
2779 &t->ax, 2795 &t->ax,
2780 GNUNET_YES); 2796 GNUNET_YES);
2781 return; 2797 return;
@@ -2792,6 +2808,7 @@ GCT_handle_encrypted (struct CadetTConnection *ct,
2792 t->kx_task = NULL; 2808 t->kx_task = NULL;
2793 } 2809 }
2794 send_kx (t, 2810 send_kx (t,
2811 ct,
2795 &t->ax); 2812 &t->ax);
2796 return; 2813 return;
2797 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 2814 case CADET_TUNNEL_KEY_AX_AUTH_SENT: