aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-26 12:12:46 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-26 12:12:46 +0000
commita7624bca11271b46efadd7c7ea989aec9c673a90 (patch)
tree5e57e09f2fd6d42852e6af352b6980145f496407 /src/transport
parent9a07ba196afb7c09422b0fa33071c4c42079f487 (diff)
downloadgnunet-a7624bca11271b46efadd7c7ea989aec9c673a90.tar.gz
gnunet-a7624bca11271b46efadd7c7ea989aec9c673a90.zip
3 way handshake works
fixing now sending and quotas
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_neighbours_fsm.c255
1 files changed, 160 insertions, 95 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours_fsm.c b/src/transport/gnunet-service-transport_neighbours_fsm.c
index ca5eb959d..8759eff08 100644
--- a/src/transport/gnunet-service-transport_neighbours_fsm.c
+++ b/src/transport/gnunet-service-transport_neighbours_fsm.c
@@ -384,7 +384,7 @@ change (struct NeighbourMapEntry * n, int state, int line)
384 old = "S_CONNECT_SENT"; 384 old = "S_CONNECT_SENT";
385 break; 385 break;
386 case S_DISCONNECT: 386 case S_DISCONNECT:
387 old = "S_DISCONNECTED"; 387 old = "S_DISCONNECT";
388 break; 388 break;
389 case S_NOT_CONNECTED: 389 case S_NOT_CONNECTED:
390 old = "S_NOT_CONNECTED"; 390 old = "S_NOT_CONNECTED";
@@ -408,7 +408,7 @@ change (struct NeighbourMapEntry * n, int state, int line)
408 new = "S_CONNECT_SENT"; 408 new = "S_CONNECT_SENT";
409 break; 409 break;
410 case S_DISCONNECT: 410 case S_DISCONNECT:
411 new = "S_DISCONNECTED"; 411 new = "S_DISCONNECT";
412 break; 412 break;
413 case S_NOT_CONNECTED: 413 case S_NOT_CONNECTED:
414 new = "S_NOT_CONNECTED"; 414 new = "S_NOT_CONNECTED";
@@ -429,27 +429,34 @@ change (struct NeighbourMapEntry * n, int state, int line)
429 } 429 }
430 break; 430 break;
431 case S_CONNECT_RECV: 431 case S_CONNECT_RECV:
432 if ((state == S_CONNECT_RECV_ACK_SENT) || (state == S_NOT_CONNECTED)) 432 if ((state == S_CONNECT_RECV_ACK_SENT) || (state == S_NOT_CONNECTED) ||
433 (state == S_DISCONNECT) || (state == S_CONNECTED))
433 { 434 {
434 allowed = GNUNET_YES; 435 allowed = GNUNET_YES;
435 break; 436 break;
436 } 437 }
437 break; 438 break;
438 case S_CONNECT_SENT: 439 case S_CONNECT_SENT:
439 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED)) 440 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) ||
441 (state == S_DISCONNECT))
440 { 442 {
441 allowed = GNUNET_YES; 443 allowed = GNUNET_YES;
442 break; 444 break;
443 } 445 }
444 break; 446 break;
445 case S_CONNECTED: 447 case S_CONNECTED:
446 if (state == S_NOT_CONNECTED) 448 if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT))
447 { 449 {
448 allowed = GNUNET_YES; 450 allowed = GNUNET_YES;
449 break; 451 break;
450 } 452 }
451 break; 453 break;
452 case S_DISCONNECT: 454 case S_DISCONNECT:
455 if (state == S_NOT_CONNECTED)
456 {
457 allowed = GNUNET_YES;
458 break;
459 }
453 break; 460 break;
454 default: 461 default:
455 GNUNET_break (0); 462 GNUNET_break (0);
@@ -492,7 +499,12 @@ send_with_plugin (void *cls,
492 size_t ret = GNUNET_SYSERR; 499 size_t ret = GNUNET_SYSERR;
493 500
494 papi = GST_plugins_find (plugin_name); 501 papi = GST_plugins_find (plugin_name);
495 GNUNET_assert (papi != NULL); 502 if (papi == NULL)
503 {
504 if (cont != NULL)
505 cont (cont_cls, target, GNUNET_SYSERR);
506 return GNUNET_SYSERR;
507 }
496 508
497 ret = papi->send (papi->cls, 509 ret = papi->send (papi->cls,
498 target, 510 target,
@@ -506,11 +518,8 @@ send_with_plugin (void *cls,
506 518
507 if (ret == -1) 519 if (ret == -1)
508 { 520 {
509 cont (cont_cls, target, GNUNET_SYSERR); 521 if (cont != NULL)
510 } 522 cont (cont_cls, target, GNUNET_SYSERR);
511 else
512 {
513 cont (cont_cls, target, GNUNET_OK);
514 } 523 }
515 return ret; 524 return ret;
516} 525}
@@ -670,6 +679,43 @@ GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
670} 679}
671 680
672 681
682static int
683send_disconnect (struct NeighbourMapEntry *n)
684{
685 size_t ret;
686 struct SessionDisconnectMessage disconnect_msg;
687
688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending DISCONNECT to peer `%4s'\n",
689 GNUNET_i2s (&n->id));
690
691 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
692 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
693 disconnect_msg.reserved = htonl (0);
694 disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
695 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
696 sizeof (struct GNUNET_TIME_AbsoluteNBO) );
697 disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
698 disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
699 disconnect_msg.public_key = GST_my_public_key;
700 GNUNET_assert (GNUNET_OK ==
701 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
702 &disconnect_msg.purpose,
703 &disconnect_msg.signature));
704
705 ret = send_with_plugin(NULL, &n->id,
706 (const char *) &disconnect_msg, sizeof (disconnect_msg),
707 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen,
708 GNUNET_YES, NULL, n);
709
710 if (ret == GNUNET_SYSERR)
711 return GNUNET_SYSERR;
712
713 GNUNET_STATISTICS_update (GST_stats,
714 gettext_noop ("# peers disconnected due to external request"), 1,
715 GNUNET_NO);
716 return GNUNET_OK;
717}
718
673/** 719/**
674 * Disconnect from the given neighbour, clean up the record. 720 * Disconnect from the given neighbour, clean up the record.
675 * 721 *
@@ -679,6 +725,7 @@ static void
679disconnect_neighbour (struct NeighbourMapEntry *n) 725disconnect_neighbour (struct NeighbourMapEntry *n)
680{ 726{
681 struct MessageQueue *mq; 727 struct MessageQueue *mq;
728 int was_connected = is_connected(n);
682 729
683 if (is_disconnecting(n) == GNUNET_YES) 730 if (is_disconnecting(n) == GNUNET_YES)
684 return; 731 return;
@@ -686,7 +733,18 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
686 /* send DISCONNECT MESSAGE */ 733 /* send DISCONNECT MESSAGE */
687 if (is_connected(n) || is_connecting(n)) 734 if (is_connected(n) || is_connecting(n))
688 { 735 {
689 change_state (n, S_DISCONNECT); 736 if (GNUNET_OK == send_disconnect(n))
737 {
738 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent DISCONNECT_MSG to `%s'\n",
739 GNUNET_i2s (&n->id));
740 change_state (n, S_DISCONNECT);
741 }
742 else
743 {
744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not send DISCONNECT_MSG to `%s'\n",
745 GNUNET_i2s (&n->id));
746 change_state (n, S_NOT_CONNECTED);
747 }
690 } 748 }
691 749
692 if (GNUNET_YES == n->in_disconnect) 750 if (GNUNET_YES == n->in_disconnect)
@@ -704,9 +762,10 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
704 n->is_active->n = NULL; 762 n->is_active->n = NULL;
705 n->is_active = NULL; 763 n->is_active = NULL;
706 } 764 }
707 if (is_connected (n)) 765 if (was_connected)
708 { 766 {
709 change_state (n, S_NOT_CONNECTED); 767 if (n->state != S_NOT_CONNECTED)
768 change_state (n, S_NOT_CONNECTED);
710 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); 769 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
711 GNUNET_SCHEDULER_cancel (n->keepalive_task); 770 GNUNET_SCHEDULER_cancel (n->keepalive_task);
712 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; 771 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
@@ -816,7 +875,7 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n", 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
817 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 876 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
818#endif 877#endif
819 if (n->state == S_CONNECTED) 878 if (is_connected(n))
820 GNUNET_STATISTICS_update (GST_stats, 879 GNUNET_STATISTICS_update (GST_stats,
821 gettext_noop ("# peers disconnected due to global disconnect"), 1, 880 gettext_noop ("# peers disconnected due to global disconnect"), 1,
822 GNUNET_NO); 881 GNUNET_NO);
@@ -986,11 +1045,10 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
986 struct NeighbourMapEntry *n; 1045 struct NeighbourMapEntry *n;
987 1046
988#if DEBUG_TRANSPORT 1047#if DEBUG_TRANSPORT
989#endif 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
990 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
991 "Unknown peer `%s', creating new neighbour\n", 1049 "Unknown peer `%s', creating new neighbour\n",
992 GNUNET_i2s (peer)); 1050 GNUNET_i2s (peer));
993 1051#endif
994 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 1052 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
995 n->id = *peer; 1053 n->id = *peer;
996 n->state = S_NOT_CONNECTED; 1054 n->state = S_NOT_CONNECTED;
@@ -1020,19 +1078,15 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1020 1078
1021 GNUNET_assert (neighbours != NULL); 1079 GNUNET_assert (neighbours != NULL);
1022#if DEBUG_TRANSPORT 1080#if DEBUG_TRANSPORT
1023#endif 1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n",
1024 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Trying to connect to peer `%s'\n",
1025 GNUNET_i2s (target)); 1082 GNUNET_i2s (target));
1026 1083#endif
1027 GNUNET_assert (0 != 1084 GNUNET_assert (0 !=
1028 memcmp (target, &GST_my_identity, 1085 memcmp (target, &GST_my_identity,
1029 sizeof (struct GNUNET_PeerIdentity))); 1086 sizeof (struct GNUNET_PeerIdentity)));
1030 n = lookup_neighbour (target); 1087 n = lookup_neighbour (target);
1031 if ((NULL != n) && (n->state > S_CONNECTED)) 1088 if ((NULL != n) && (n->state != S_NOT_CONNECTED) )
1032 return; /* already connected */ 1089 return; /* already connecting or connected */
1033
1034 if ((NULL != n) && (n->state > S_NOT_CONNECTED))
1035 return; /* already connecting */
1036 1090
1037 if (n == NULL) 1091 if (n == NULL)
1038 n = setup_neighbour (target); 1092 n = setup_neighbour (target);
@@ -1060,7 +1114,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
1060 1114
1061 n = lookup_neighbour (target); 1115 n = lookup_neighbour (target);
1062 1116
1063 if ((NULL == n) || (n->state != S_CONNECTED)) 1117 if ((NULL == n) || (!is_connected(n)))
1064 return GNUNET_NO; /* not connected */ 1118 return GNUNET_NO; /* not connected */
1065 return GNUNET_YES; 1119 return GNUNET_YES;
1066} 1120}
@@ -1126,11 +1180,11 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1126{ 1180{
1127 struct NeighbourMapEntry *n; 1181 struct NeighbourMapEntry *n;
1128 struct MessageQueue *mq; 1182 struct MessageQueue *mq;
1129 1183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GST_neighbours_send %u\n", __LINE__);
1130 GNUNET_assert (neighbours != NULL); 1184 GNUNET_assert (neighbours != NULL);
1131 1185
1132 n = lookup_neighbour (target); 1186 n = lookup_neighbour (target);
1133 if ((n == NULL) || (n->state != S_CONNECTED)) 1187 if ((n == NULL) || (!is_connected(n)))
1134 { 1188 {
1135 GNUNET_STATISTICS_update (GST_stats, 1189 GNUNET_STATISTICS_update (GST_stats,
1136 gettext_noop 1190 gettext_noop
@@ -1139,9 +1193,9 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1139#if DEBUG_TRANSPORT 1193#if DEBUG_TRANSPORT
1140 if (n == NULL) 1194 if (n == NULL)
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 "Could not send message to peer `%s': unknown neighbor", 1196 "Could not send message to peer `%s': unknown neighbour",
1143 GNUNET_i2s (target)); 1197 GNUNET_i2s (target));
1144 else if (n->state != S_CONNECTED) 1198 else if (!is_connected(n))
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1146 "Could not send message to peer `%s': not connected\n", 1200 "Could not send message to peer `%s': not connected\n",
1147 GNUNET_i2s (target)); 1201 GNUNET_i2s (target));
@@ -1150,7 +1204,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1150 cont (cont_cls, GNUNET_SYSERR); 1204 cont (cont_cls, GNUNET_SYSERR);
1151 return; 1205 return;
1152 } 1206 }
1153 1207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GST_neighbours_send %u %X %s\n", __LINE__ , n->session, GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen));
1154 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0)) 1208 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0))
1155 { 1209 {
1156 GNUNET_STATISTICS_update (GST_stats, 1210 GNUNET_STATISTICS_update (GST_stats,
@@ -1167,6 +1221,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1167 cont (cont_cls, GNUNET_SYSERR); 1221 cont (cont_cls, GNUNET_SYSERR);
1168 return; 1222 return;
1169 } 1223 }
1224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GST_neighbours_send %u\n", __LINE__);
1170 GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader)); 1225 GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader));
1171 GNUNET_STATISTICS_update (GST_stats, 1226 GNUNET_STATISTICS_update (GST_stats,
1172 gettext_noop 1227 gettext_noop
@@ -1408,39 +1463,6 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
1408 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic); 1463 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic);
1409} 1464}
1410 1465
1411static void
1412send_disconnect (struct NeighbourMapEntry *n)
1413{
1414 size_t ret;
1415 struct SessionDisconnectMessage disconnect_msg;
1416
1417 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
1418 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1419 disconnect_msg.reserved = htonl (0);
1420 disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1421 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1422 sizeof (struct GNUNET_TIME_AbsoluteNBO) );
1423 disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1424 disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1425 disconnect_msg.public_key = GST_my_public_key;
1426 GNUNET_assert (GNUNET_OK ==
1427 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
1428 &disconnect_msg.purpose,
1429 &disconnect_msg.signature));
1430
1431 ret = send_with_plugin(NULL, &n->id,
1432 (const char *) &disconnect_msg, sizeof (disconnect_msg),
1433 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen,
1434 GNUNET_YES, NULL, NULL);
1435
1436 GNUNET_STATISTICS_update (GST_stats,
1437 gettext_noop ("# peers disconnected due to external request"), 1,
1438 GNUNET_NO);
1439
1440 if (n->state != S_DISCONNECT)
1441 change_state (n, S_DISCONNECT);
1442}
1443
1444/** 1466/**
1445 * If we have an active connection to the given target, it must be shutdown. 1467 * If we have an active connection to the given target, it must be shutdown.
1446 * 1468 *
@@ -1456,7 +1478,7 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1456 n = lookup_neighbour (target); 1478 n = lookup_neighbour (target);
1457 if (NULL == n) 1479 if (NULL == n)
1458 return; /* not active */ 1480 return; /* not active */
1459 if (n->state == S_CONNECTED) 1481 if (is_connected(n))
1460 { 1482 {
1461 send_disconnect(n); 1483 send_disconnect(n);
1462 1484
@@ -1535,37 +1557,38 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1535 1557
1536static void neighbour_connected (struct NeighbourMapEntry *n, 1558static void neighbour_connected (struct NeighbourMapEntry *n,
1537 const struct GNUNET_ATS_Information *ats, 1559 const struct GNUNET_ATS_Information *ats,
1538 uint32_t ats_count) 1560 uint32_t ats_count, int send_connect_ack)
1539{ 1561{
1540 struct GNUNET_MessageHeader msg; 1562 struct GNUNET_MessageHeader msg;
1541 size_t msg_len; 1563 size_t msg_len;
1542 int ret; 1564 int ret;
1543 1565
1544 if (n->state == S_CONNECTED) 1566 if (is_connected(n))
1545 return; 1567 return;
1546 1568
1547 change_state (n, S_CONNECTED); 1569 change_state (n, S_CONNECTED);
1548
1549 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 1570 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
1550 &neighbour_keepalive_task, 1571 &neighbour_keepalive_task,
1551 n); 1572 n);
1552 1573
1553 /* send CONNECT_ACK (SYN_ACK)*/ 1574 if (send_connect_ack)
1554 msg_len = sizeof (msg); 1575 {
1555 msg.size = htons (msg_len); 1576 /* send CONNECT_ACK (SYN_ACK)*/
1556 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 1577 msg_len = sizeof (msg);
1557 1578 msg.size = htons (msg_len);
1558 ret = send_with_plugin (NULL, &n->id, (const char *) &msg, msg_len, 0, 1579 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
1559 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL, NULL); 1580
1560 if (ret == GNUNET_SYSERR) 1581 ret = send_with_plugin (NULL, &n->id, (const char *) &msg, msg_len, 0,
1561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1582 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
1562 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", 1583 if (ret == GNUNET_SYSERR)
1563 GNUNET_i2s (&n->id), n->plugin_name, 1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1564 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1585 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n",
1565 n->addr, 1586 GNUNET_i2s (&n->id), n->plugin_name,
1566 n->addrlen), 1587 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
1567 n->session); 1588 n->addr,
1568 1589 n->addrlen),
1590 n->session);
1591 }
1569 neighbours_connected++; 1592 neighbours_connected++;
1570 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 1593 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
1571 GNUNET_NO); 1594 GNUNET_NO);
@@ -1600,7 +1623,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1600 struct GNUNET_TIME_Absolute ts; 1623 struct GNUNET_TIME_Absolute ts;
1601 struct NeighbourMapEntry *n; 1624 struct NeighbourMapEntry *n;
1602 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1625 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1603 "GST_neighbours_handle_connect_ack\n"); 1626 "GST_neighbours_handle_connect_ack SYN/ACK\n");
1604 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 1627 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
1605 { 1628 {
1606 GNUNET_break_op (0); 1629 GNUNET_break_op (0);
@@ -1617,9 +1640,48 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1617 if (n->state != S_CONNECT_SENT) 1640 if (n->state != S_CONNECT_SENT)
1618 { 1641 {
1619 GNUNET_break (0); 1642 GNUNET_break (0);
1643 send_disconnect(n);
1620 return; 1644 return;
1621 } 1645 }
1622 neighbour_connected (n, ats, ats_count); 1646 neighbour_connected (n, ats, ats_count, GNUNET_YES);
1647}
1648
1649void
1650GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
1651 const struct GNUNET_PeerIdentity *peer,
1652 const char *plugin_name,
1653 const char *sender_address, uint16_t sender_address_len,
1654 struct Session *session,
1655 const struct GNUNET_ATS_Information *ats,
1656 uint32_t ats_count)
1657{
1658 struct NeighbourMapEntry *n;
1659 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1660 "GST_neighbours_handle_ack ACK\n");
1661 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
1662 {
1663 GNUNET_break_op (0);
1664 return;
1665 }
1666
1667 n = lookup_neighbour (peer);
1668 if (NULL == n)
1669 {
1670 send_disconnect(n);
1671 GNUNET_break (0);
1672 }
1673
1674 if (n->state != S_CONNECT_RECV)
1675 {
1676 send_disconnect(n);
1677 GNUNET_break (0);
1678 return;
1679 }
1680
1681 if (is_connected(n))
1682 return;
1683
1684 neighbour_connected (n, ats, ats_count, GNUNET_NO);
1623} 1685}
1624 1686
1625 1687
@@ -1650,9 +1712,10 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
1650 struct GNUNET_TIME_Absolute ts; 1712 struct GNUNET_TIME_Absolute ts;
1651 struct NeighbourMapEntry *n; 1713 struct NeighbourMapEntry *n;
1652 struct SessionConnectMessage connect_msg; 1714 struct SessionConnectMessage connect_msg;
1653 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1715 size_t msg_len;
1654 int ret; 1716 int ret;
1655 1717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1718 "GST_neighbours_handle_connect SYN\n");
1656 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 1719 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
1657 { 1720 {
1658 GNUNET_break_op (0); 1721 GNUNET_break_op (0);
@@ -1671,18 +1734,20 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
1671 change_state (n, S_CONNECT_RECV); 1734 change_state (n, S_CONNECT_RECV);
1672 1735
1673 /* send CONNECT_ACK (SYN_ACK)*/ 1736 /* send CONNECT_ACK (SYN_ACK)*/
1674 connect_msg.header.size = htons (sizeof (struct SessionConnectMessage)); 1737 msg_len = sizeof (struct SessionConnectMessage);
1738 connect_msg.header.size = htons (msg_len);
1675 connect_msg.header.type = 1739 connect_msg.header.type =
1676 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); 1740 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK);
1677 connect_msg.reserved = htonl (0); 1741 connect_msg.reserved = htonl (0);
1678 connect_msg.timestamp = 1742 connect_msg.timestamp =
1679 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1743 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1680 1744
1681 papi = GST_plugins_find (plugin_name); 1745 ret = send_with_plugin(NULL, &n->id, (const void *) &connect_msg,
1682 ret = papi->send (papi->cls, &n->id, (const char *) &connect_msg, sizeof (struct SessionConnectMessage), 1746 msg_len,
1683 0, 1747 0,
1684 GNUNET_TIME_UNIT_FOREVER_REL, NULL, sender_address, sender_address_len, GNUNET_YES, 1748 GNUNET_TIME_UNIT_FOREVER_REL,
1685 NULL, NULL); 1749 session, plugin_name, sender_address, sender_address_len,
1750 GNUNET_YES, NULL, NULL);
1686 1751
1687 if (ret == GNUNET_SYSERR) 1752 if (ret == GNUNET_SYSERR)
1688 { 1753 {