aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-12-15 07:18:32 +0000
committerBart Polot <bart@net.in.tum.de>2014-12-15 07:18:32 +0000
commit6b9a9a88ba0f2201f7b1a759b75292ab05e36588 (patch)
tree38000b3733929540ab8c4b187ee851fe08fcfc28 /src/cadet
parent1c5e8bd4c25b6bbb6a71d33f4c784ede4b41bf77 (diff)
downloadgnunet-6b9a9a88ba0f2201f7b1a759b75292ab05e36588.tar.gz
gnunet-6b9a9a88ba0f2201f7b1a759b75292ab05e36588.zip
Only allow one EPHM/PONG in the queue.
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c95
1 files changed, 82 insertions, 13 deletions
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index a5d4ea9ce..7c420843e 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -203,6 +203,16 @@ struct CadetTunnel
203 * Task to trim connections if too many are present. 203 * Task to trim connections if too many are present.
204 */ 204 */
205 GNUNET_SCHEDULER_TaskIdentifier trim_connections_task; 205 GNUNET_SCHEDULER_TaskIdentifier trim_connections_task;
206
207 /**
208 * Ephemeral message in the queue (to avoid queueing more than one).
209 */
210 struct CadetConnectionQueue *ephm_h;
211
212 /**
213 * Pong message in the queue.
214 */
215 struct CadetConnectionQueue *pong_h;
206}; 216};
207 217
208 218
@@ -1279,13 +1289,56 @@ send_queued_data (struct CadetTunnel *t)
1279 1289
1280 1290
1281/** 1291/**
1292 * Callback called when a queued message is sent.
1293 *
1294 * @param cls Closure.
1295 * @param c Connection this message was on.
1296 * @param type Type of message sent.
1297 * @param fwd Was this a FWD going message?
1298 * @param size Size of the message.
1299 */
1300static void
1301ephm_sent (void *cls,
1302 struct CadetConnection *c,
1303 struct CadetConnectionQueue *q,
1304 uint16_t type, int fwd, size_t size)
1305{
1306 struct CadetTunnel *t = cls;
1307 LOG (GNUNET_ERROR_TYPE_DEBUG, "ephm_sent %s\n", GC_m2s (type));
1308 t->ephm_h = NULL;
1309}
1310
1311/**
1312 * Callback called when a queued message is sent.
1313 *
1314 * @param cls Closure.
1315 * @param c Connection this message was on.
1316 * @param type Type of message sent.
1317 * @param fwd Was this a FWD going message?
1318 * @param size Size of the message.
1319 */
1320static void
1321pong_sent (void *cls,
1322 struct CadetConnection *c,
1323 struct CadetConnectionQueue *q,
1324 uint16_t type, int fwd, size_t size)
1325{
1326 struct CadetTunnel *t = cls;
1327 LOG (GNUNET_ERROR_TYPE_DEBUG, "pong_sent %s\n", GC_m2s (type));
1328
1329 t->pong_h = NULL;
1330}
1331
1332/**
1282 * Sends key exchange message on a tunnel, choosing the best connection. 1333 * Sends key exchange message on a tunnel, choosing the best connection.
1283 * Should not be called on loopback tunnels. 1334 * Should not be called on loopback tunnels.
1284 * 1335 *
1285 * @param t Tunnel on which this message is transmitted. 1336 * @param t Tunnel on which this message is transmitted.
1286 * @param message Message to send. Function modifies it. 1337 * @param message Message to send. Function modifies it.
1338 *
1339 * @return Handle to the message in the connection queue.
1287 */ 1340 */
1288static void 1341static struct CadetConnectionQueue *
1289send_kx (struct CadetTunnel *t, 1342send_kx (struct CadetTunnel *t,
1290 const struct GNUNET_MessageHeader *message) 1343 const struct GNUNET_MessageHeader *message)
1291{ 1344{
@@ -1295,6 +1348,7 @@ send_kx (struct CadetTunnel *t,
1295 char cbuf[sizeof (struct GNUNET_CADET_KX) + size]; 1348 char cbuf[sizeof (struct GNUNET_CADET_KX) + size];
1296 uint16_t type; 1349 uint16_t type;
1297 int fwd; 1350 int fwd;
1351 GCC_sent cont;
1298 1352
1299 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT KX on Tunnel %s\n", GCT_2s (t)); 1353 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT KX on Tunnel %s\n", GCT_2s (t));
1300 1354
@@ -1303,7 +1357,7 @@ send_kx (struct CadetTunnel *t,
1303 { 1357 {
1304 LOG (GNUNET_ERROR_TYPE_DEBUG, " loopback!\n"); 1358 LOG (GNUNET_ERROR_TYPE_DEBUG, " loopback!\n");
1305 GNUNET_break (0); 1359 GNUNET_break (0);
1306 return; 1360 return NULL;
1307 } 1361 }
1308 type = ntohs (message->type); 1362 type = ntohs (message->type);
1309 1363
@@ -1324,7 +1378,7 @@ send_kx (struct CadetTunnel *t,
1324 GCP_debug (t->peer, GNUNET_ERROR_TYPE_ERROR); 1378 GCP_debug (t->peer, GNUNET_ERROR_TYPE_ERROR);
1325 LOG (GNUNET_ERROR_TYPE_ERROR, "\n\n\n"); 1379 LOG (GNUNET_ERROR_TYPE_ERROR, "\n\n\n");
1326 } 1380 }
1327 return; 1381 return NULL;
1328 } 1382 }
1329 1383
1330 msg = (struct GNUNET_CADET_KX *) cbuf; 1384 msg = (struct GNUNET_CADET_KX *) cbuf;
@@ -1339,26 +1393,31 @@ send_kx (struct CadetTunnel *t,
1339 GNUNET_break (0); 1393 GNUNET_break (0);
1340 GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); 1394 GCT_debug (t, GNUNET_ERROR_TYPE_ERROR);
1341 } 1395 }
1342 return; 1396 return NULL;
1343 } 1397 }
1344 switch (type) 1398 switch (type)
1345 { 1399 {
1346 case GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL: 1400 case GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL:
1401 GNUNET_assert (NULL == t->ephm_h);
1402 cont = &ephm_sent;
1403 memcpy (&msg[1], message, size);
1404 break;
1347 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG: 1405 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG:
1406 GNUNET_assert (NULL == t->pong_h);
1407 cont = &pong_sent;
1348 memcpy (&msg[1], message, size); 1408 memcpy (&msg[1], message, size);
1349 break; 1409 break;
1350 1410
1351 default: 1411 default:
1352 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", 1412 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", GC_m2s (type));
1353 GC_m2s (type)); 1413 GNUNET_assert (0);
1354 GNUNET_break (0);
1355 } 1414 }
1356 1415
1357 fwd = GCC_is_origin (t->connection_head->c, GNUNET_YES); 1416 fwd = GCC_is_origin (t->connection_head->c, GNUNET_YES);
1358 /* TODO save handle and cancel in case of a unneeded retransmission */ 1417
1359 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg->header, type, 0, c, 1418 return GCC_send_prebuilt_message (&msg->header, type, 0, c,
1360 fwd, GNUNET_YES, 1419 fwd, GNUNET_YES,
1361 NULL, NULL)); 1420 cont, t);
1362} 1421}
1363 1422
1364 1423
@@ -1371,6 +1430,11 @@ static void
1371send_ephemeral (struct CadetTunnel *t) 1430send_ephemeral (struct CadetTunnel *t)
1372{ 1431{
1373 LOG (GNUNET_ERROR_TYPE_INFO, "===> EPHM for %s\n", GCT_2s (t)); 1432 LOG (GNUNET_ERROR_TYPE_INFO, "===> EPHM for %s\n", GCT_2s (t));
1433 if (NULL != t->ephm_h)
1434 {
1435 LOG (GNUNET_ERROR_TYPE_INFO, " already queued\n");
1436 return;
1437 }
1374 1438
1375 kx_msg.sender_status = htonl (t->estate); 1439 kx_msg.sender_status = htonl (t->estate);
1376 kx_msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1440 kx_msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
@@ -1379,7 +1443,7 @@ send_ephemeral (struct CadetTunnel *t)
1379 t_encrypt (t, &kx_msg.nonce, &kx_msg.nonce, 1443 t_encrypt (t, &kx_msg.nonce, &kx_msg.nonce,
1380 ping_encryption_size(), kx_msg.iv, GNUNET_YES); 1444 ping_encryption_size(), kx_msg.iv, GNUNET_YES);
1381 LOG (GNUNET_ERROR_TYPE_DEBUG, " send nonce e %u\n", kx_msg.nonce); 1445 LOG (GNUNET_ERROR_TYPE_DEBUG, " send nonce e %u\n", kx_msg.nonce);
1382 send_kx (t, &kx_msg.header); 1446 t->ephm_h = send_kx (t, &kx_msg.header);
1383} 1447}
1384 1448
1385 1449
@@ -1395,6 +1459,11 @@ send_pong (struct CadetTunnel *t, uint32_t challenge)
1395 struct GNUNET_CADET_KX_Pong msg; 1459 struct GNUNET_CADET_KX_Pong msg;
1396 1460
1397 LOG (GNUNET_ERROR_TYPE_INFO, "===> PONG for %s\n", GCT_2s (t)); 1461 LOG (GNUNET_ERROR_TYPE_INFO, "===> PONG for %s\n", GCT_2s (t));
1462 if (NULL != t->pong_h)
1463 {
1464 LOG (GNUNET_ERROR_TYPE_INFO, " already queued\n");
1465 return;
1466 }
1398 msg.header.size = htons (sizeof (msg)); 1467 msg.header.size = htons (sizeof (msg));
1399 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX_PONG); 1468 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX_PONG);
1400 msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1469 msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
@@ -1404,7 +1473,7 @@ send_pong (struct CadetTunnel *t, uint32_t challenge)
1404 sizeof (msg.nonce), msg.iv, GNUNET_YES); 1473 sizeof (msg.nonce), msg.iv, GNUNET_YES);
1405 LOG (GNUNET_ERROR_TYPE_DEBUG, " e sending %u\n", msg.nonce); 1474 LOG (GNUNET_ERROR_TYPE_DEBUG, " e sending %u\n", msg.nonce);
1406 1475
1407 send_kx (t, &msg.header); 1476 t->pong_h = send_kx (t, &msg.header);
1408} 1477}
1409 1478
1410 1479