aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c244
1 files changed, 111 insertions, 133 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index e2616f078..854eef773 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -197,6 +197,12 @@ struct ForeignAddressList
197 */ 197 */
198 unsigned int connect_attempts; 198 unsigned int connect_attempts;
199 199
200 /**
201 * DV distance to this peer (1 if no DV is used).
202 * FIXME: need to set this from transport plugins!
203 */
204 uint32_t distance;
205
200}; 206};
201 207
202 208
@@ -446,6 +452,11 @@ struct NeighborList
446 struct GNUNET_TIME_Relative latency; 452 struct GNUNET_TIME_Relative latency;
447 453
448 /** 454 /**
455 * DV distance to this peer (1 if no DV is used).
456 */
457 uint32_t distance;
458
459 /**
449 * How many bytes have we received since the "last_quota_update" 460 * How many bytes have we received since the "last_quota_update"
450 * timestamp? 461 * timestamp?
451 */ 462 */
@@ -465,9 +476,8 @@ struct NeighborList
465 unsigned int quota_violation_count; 476 unsigned int quota_violation_count;
466 477
467 /** 478 /**
468 * Have we seen an ACK from this neighbor in the past? 479 * Have we seen an PONG from this neighbor in the past (and
469 * (used to make up a fake ACK for clients connecting after 480 * not had a disconnect since)?
470 * the neighbor connected to us).
471 */ 481 */
472 int received_pong; 482 int received_pong;
473 483
@@ -771,7 +781,6 @@ static struct CheckHelloValidatedContext *chvc_tail;
771static struct GNUNET_CONTAINER_MultiHashMap *validation_map; 781static struct GNUNET_CONTAINER_MultiHashMap *validation_map;
772 782
773 783
774
775/** 784/**
776 * The peer specified by the given neighbor has timed-out or a plugin 785 * The peer specified by the given neighbor has timed-out or a plugin
777 * has disconnected. We may either need to do nothing (other plugins 786 * has disconnected. We may either need to do nothing (other plugins
@@ -1000,6 +1009,30 @@ transmit_to_client (struct TransportClient *client,
1000 1009
1001 1010
1002/** 1011/**
1012 * Transmit a 'SEND_OK' notification to the given client for the
1013 * given neighbor.
1014 *
1015 * @param client who to notify
1016 * @param n neighbor to notify about
1017 * @param result status code for the transmission request
1018 */
1019static void
1020transmit_send_ok (struct TransportClient *client,
1021 struct NeighborList *n,
1022 int result)
1023{
1024 struct SendOkMessage send_ok_msg;
1025
1026 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
1027 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
1028 send_ok_msg.success = htonl (result);
1029 send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency);
1030 send_ok_msg.peer = n->id;
1031 transmit_to_client (client, &send_ok_msg.header, GNUNET_NO);
1032}
1033
1034
1035/**
1003 * Function called by the GNUNET_TRANSPORT_TransmitFunction 1036 * Function called by the GNUNET_TRANSPORT_TransmitFunction
1004 * upon "completion" of a send request. This tells the API 1037 * upon "completion" of a send request. This tells the API
1005 * that it is now legal to send another message to the given 1038 * that it is now legal to send another message to the given
@@ -1019,60 +1052,32 @@ transmit_send_continuation (void *cls,
1019 int result) 1052 int result)
1020{ 1053{
1021 struct MessageQueue *mq = cls; 1054 struct MessageQueue *mq = cls;
1022 /*struct ReadyList *rl;*/ /* We no longer use the ReadyList for anything here, safe to remove? */
1023 struct SendOkMessage send_ok_msg;
1024 struct NeighborList *n; 1055 struct NeighborList *n;
1025 1056
1026 GNUNET_assert (mq != NULL);
1027 n = find_neighbor(&mq->neighbor_id); 1057 n = find_neighbor(&mq->neighbor_id);
1028 if (n == NULL) /* Neighbor must have been removed asynchronously! */ 1058 GNUNET_assert (n != NULL);
1029 return; 1059 if (mq->specific_address != NULL)
1030
1031 /* Otherwise, let's make sure we've got the right peer */
1032 GNUNET_assert (0 ==
1033 memcmp (&n->id, target,
1034 sizeof (struct GNUNET_PeerIdentity)));
1035
1036 if (result == GNUNET_OK)
1037 { 1060 {
1038 if (mq->specific_address != NULL) 1061 if (result == GNUNET_OK)
1039 { 1062 {
1040 mq->specific_address->timeout = 1063 mq->specific_address->timeout =
1041 GNUNET_TIME_relative_to_absolute 1064 GNUNET_TIME_relative_to_absolute
1042 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1065 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1043 mq->specific_address->connected = GNUNET_YES; 1066 mq->specific_address->connected = GNUNET_YES;
1044 } 1067 }
1045 } 1068 else
1046 else 1069 {
1047 { 1070 mq->specific_address->connected = GNUNET_NO;
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1071 }
1049 "Transmission to peer `%s' failed, marking connection as down.\n", 1072 if (! mq->internal_msg)
1050 GNUNET_i2s (target)); 1073 mq->specific_address->in_transmit = GNUNET_NO;
1051 if (mq->specific_address != NULL)
1052 mq->specific_address->connected = GNUNET_NO;
1053 } 1074 }
1054 if ( (! mq->internal_msg) &&
1055 (mq->specific_address != NULL) )
1056 mq->specific_address->in_transmit = GNUNET_NO;
1057
1058 if (mq->client != NULL) 1075 if (mq->client != NULL)
1059 { 1076 transmit_send_ok (mq->client, n, result);
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061 "Notifying client %p about transmission to peer `%4s'.\n",
1062 mq->client, GNUNET_i2s (target));
1063 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
1064 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
1065 send_ok_msg.success = htonl (result);
1066 send_ok_msg.peer = n->id;
1067 transmit_to_client (mq->client, &send_ok_msg.header, GNUNET_NO);
1068 }
1069 GNUNET_free (mq); 1077 GNUNET_free (mq);
1070 /* one plugin just became ready again, try transmitting 1078 try_transmission_to_peer (n);
1071 another message (if available) */ 1079 if (result != GNUNET_OK)
1072 if (result == GNUNET_OK) 1080 disconnect_neighbor (n, GNUNET_YES);
1073 try_transmission_to_peer (n);
1074 else
1075 disconnect_neighbor (n, GNUNET_YES);
1076} 1081}
1077 1082
1078 1083
@@ -1159,8 +1164,12 @@ try_transmission_to_peer (struct NeighborList *neighbor)
1159 min_latency = GNUNET_TIME_UNIT_FOREVER_REL; 1164 min_latency = GNUNET_TIME_UNIT_FOREVER_REL;
1160 rl = NULL; 1165 rl = NULL;
1161 mq = neighbor->messages_head; 1166 mq = neighbor->messages_head;
1167 /* FIXME: support bi-directional use of TCP */
1162 if (mq->specific_address == NULL) 1168 if (mq->specific_address == NULL)
1163 mq->specific_address = find_ready_address(neighbor); 1169 mq->specific_address = find_ready_address(neighbor);
1170 GNUNET_CONTAINER_DLL_remove (neighbor->messages_head,
1171 neighbor->messages_tail,
1172 mq);
1164 if (mq->specific_address == NULL) 1173 if (mq->specific_address == NULL)
1165 { 1174 {
1166#if DEBUG_TRANSPORT 1175#if DEBUG_TRANSPORT
@@ -1169,14 +1178,14 @@ try_transmission_to_peer (struct NeighborList *neighbor)
1169 mq->message_buf_size, 1178 mq->message_buf_size,
1170 GNUNET_i2s (&mq->neighbor_id)); 1179 GNUNET_i2s (&mq->neighbor_id));
1171#endif 1180#endif
1181 if (mq->client != NULL)
1182 transmit_send_ok (mq->client, neighbor, GNUNET_NO);
1183 GNUNET_free (mq);
1172 return; /* nobody ready */ 1184 return; /* nobody ready */
1173 } 1185 }
1174 if (mq->specific_address->connected == GNUNET_NO) 1186 if (mq->specific_address->connected == GNUNET_NO)
1175 mq->specific_address->connect_attempts++; 1187 mq->specific_address->connect_attempts++;
1176 rl = mq->specific_address->ready_list; 1188 rl = mq->specific_address->ready_list;
1177 GNUNET_CONTAINER_DLL_remove (neighbor->messages_head,
1178 neighbor->messages_tail,
1179 mq);
1180 mq->plugin = rl->plugin; 1189 mq->plugin = rl->plugin;
1181 if (!mq->internal_msg) 1190 if (!mq->internal_msg)
1182 mq->specific_address->in_transmit = GNUNET_YES; 1191 mq->specific_address->in_transmit = GNUNET_YES;
@@ -1251,7 +1260,6 @@ transmit_to_peer (struct TransportClient *client,
1251 memcpy(&mq->neighbor_id, &neighbor->id, sizeof(struct GNUNET_PeerIdentity)); 1260 memcpy(&mq->neighbor_id, &neighbor->id, sizeof(struct GNUNET_PeerIdentity));
1252 mq->internal_msg = is_internal; 1261 mq->internal_msg = is_internal;
1253 mq->priority = priority; 1262 mq->priority = priority;
1254
1255 if (is_internal) 1263 if (is_internal)
1256 GNUNET_CONTAINER_DLL_insert (neighbor->messages_head, 1264 GNUNET_CONTAINER_DLL_insert (neighbor->messages_head,
1257 neighbor->messages_tail, 1265 neighbor->messages_tail,
@@ -1495,14 +1503,20 @@ plugin_env_notify_address (void *cls,
1495 */ 1503 */
1496static void 1504static void
1497notify_clients_connect (const struct GNUNET_PeerIdentity *peer, 1505notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
1498 struct GNUNET_TIME_Relative latency) 1506 struct GNUNET_TIME_Relative latency,
1507 uint32_t distance)
1499{ 1508{
1500 struct ConnectInfoMessage cim; 1509 struct ConnectInfoMessage cim;
1501 struct TransportClient *cpos; 1510 struct TransportClient *cpos;
1502 1511
1512#if DEBUG_TRANSPORT
1513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1514 "Notifying clients about connection from `%s'\n",
1515 GNUNET_i2s (peer));
1516#endif
1503 cim.header.size = htons (sizeof (struct ConnectInfoMessage)); 1517 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
1504 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 1518 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
1505 cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000)); 1519 cim.distance = htonl (distance);
1506 cim.latency = GNUNET_TIME_relative_hton (latency); 1520 cim.latency = GNUNET_TIME_relative_hton (latency);
1507 memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity)); 1521 memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity));
1508 cpos = clients; 1522 cpos = clients;
@@ -1523,6 +1537,11 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1523 struct DisconnectInfoMessage dim; 1537 struct DisconnectInfoMessage dim;
1524 struct TransportClient *cpos; 1538 struct TransportClient *cpos;
1525 1539
1540#if DEBUG_TRANSPORT
1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1542 "Notifying clients about lost connection to `%s'\n",
1543 GNUNET_i2s (peer));
1544#endif
1526 dim.header.size = htons (sizeof (struct DisconnectInfoMessage)); 1545 dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
1527 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 1546 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1528 dim.reserved = htonl (0); 1547 dim.reserved = htonl (0);
@@ -1612,6 +1631,7 @@ add_peer_address(struct NeighborList *neighbor,
1612 ret->expires = GNUNET_TIME_relative_to_absolute 1631 ret->expires = GNUNET_TIME_relative_to_absolute
1613 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1632 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1614 ret->latency = GNUNET_TIME_relative_get_forever(); 1633 ret->latency = GNUNET_TIME_relative_get_forever();
1634 ret->distance = -1;
1615 ret->timeout = GNUNET_TIME_relative_to_absolute 1635 ret->timeout = GNUNET_TIME_relative_to_absolute
1616 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1636 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1617 ret->ready_list = head; 1637 ret->ready_list = head;
@@ -1731,6 +1751,12 @@ check_pending_validation (void *cls,
1731 n->latency = fal->latency; 1751 n->latency = fal->latency;
1732 else 1752 else
1733 n->latency.value = (fal->latency.value + n->latency.value) / 2; 1753 n->latency.value = (fal->latency.value + n->latency.value) / 2;
1754 n->distance = fal->distance;
1755 if (GNUNET_NO == n->received_pong)
1756 {
1757 notify_clients_connect (&target, n->latency, n->distance);
1758 n->received_pong = GNUNET_YES;
1759 }
1734 } 1760 }
1735 1761
1736 /* clean up validation entry */ 1762 /* clean up validation entry */
@@ -1795,6 +1821,7 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
1795#endif 1821#endif
1796 return; 1822 return;
1797 } 1823 }
1824
1798#if 0 1825#if 0
1799 /* FIXME: add given address to potential pool of our addresses 1826 /* FIXME: add given address to potential pool of our addresses
1800 (for voting) */ 1827 (for voting) */
@@ -1809,7 +1836,7 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
1809 1836
1810static void 1837static void
1811neighbor_timeout_task (void *cls, 1838neighbor_timeout_task (void *cls,
1812 const struct GNUNET_SCHEDULER_TaskContext *tc) 1839 const struct GNUNET_SCHEDULER_TaskContext *tc)
1813{ 1840{
1814 struct NeighborList *n = cls; 1841 struct NeighborList *n = cls;
1815 1842
@@ -1861,13 +1888,13 @@ setup_new_neighbor (const struct GNUNET_PeerIdentity *peer)
1861 tp = tp->next; 1888 tp = tp->next;
1862 } 1889 }
1863 n->latency = GNUNET_TIME_UNIT_FOREVER_REL; 1890 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
1891 n->distance = -1;
1864 n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, 1892 n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
1865 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1893 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1866 &neighbor_timeout_task, n); 1894 &neighbor_timeout_task, n);
1867 transmit_to_peer (NULL, NULL, 0, 1895 transmit_to_peer (NULL, NULL, 0,
1868 (const char *) our_hello, GNUNET_HELLO_size(our_hello), 1896 (const char *) our_hello, GNUNET_HELLO_size(our_hello),
1869 GNUNET_NO, n); 1897 GNUNET_NO, n);
1870 notify_clients_connect (peer, GNUNET_TIME_UNIT_FOREVER_REL);
1871 return n; 1898 return n;
1872} 1899}
1873 1900
@@ -2266,28 +2293,15 @@ process_hello (struct TransportPlugin *plugin,
2266 * disconnect? 2293 * disconnect?
2267 */ 2294 */
2268static void 2295static void
2269disconnect_neighbor (struct NeighborList *current_handle, int check) 2296disconnect_neighbor (struct NeighborList *n, int check)
2270{ 2297{
2271 struct ReadyList *rpos; 2298 struct ReadyList *rpos;
2272 struct NeighborList *npos; 2299 struct NeighborList *npos;
2273 struct NeighborList *nprev; 2300 struct NeighborList *nprev;
2274 struct NeighborList *n;
2275 struct MessageQueue *mq; 2301 struct MessageQueue *mq;
2276 struct ForeignAddressList *peer_addresses; 2302 struct ForeignAddressList *peer_addresses;
2277 struct ForeignAddressList *peer_pos; 2303 struct ForeignAddressList *peer_pos;
2278 2304
2279 if (neighbors == NULL)
2280 return; /* We don't have any neighbors, so client has an already removed handle! */
2281
2282 npos = neighbors;
2283 while ((npos != NULL) && (current_handle != npos))
2284 npos = npos->next;
2285
2286 if (npos == NULL)
2287 return; /* Couldn't find neighbor in existing list, must have been already removed! */
2288 else
2289 n = npos;
2290
2291 if (GNUNET_YES == check) 2305 if (GNUNET_YES == check)
2292 { 2306 {
2293 rpos = n->plugins; 2307 rpos = n->plugins;
@@ -2303,10 +2317,10 @@ disconnect_neighbor (struct NeighborList *current_handle, int check)
2303 rpos = rpos->next; 2317 rpos = rpos->next;
2304 } 2318 }
2305 } 2319 }
2306
2307#if DEBUG_TRANSPORT 2320#if DEBUG_TRANSPORT
2308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2309 "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id)); 2322 "Disconnecting from `%4s'\n",
2323 GNUNET_i2s (&n->id));
2310#endif 2324#endif
2311 /* remove n from neighbors list */ 2325 /* remove n from neighbors list */
2312 nprev = NULL; 2326 nprev = NULL;
@@ -2323,7 +2337,8 @@ disconnect_neighbor (struct NeighborList *current_handle, int check)
2323 nprev->next = n->next; 2337 nprev->next = n->next;
2324 2338
2325 /* notify all clients about disconnect */ 2339 /* notify all clients about disconnect */
2326 notify_clients_disconnect (&n->id); 2340 if (GNUNET_YES == n->received_pong)
2341 notify_clients_disconnect (&n->id);
2327 2342
2328 /* clean up all plugins, cancel connections and pending transmissions */ 2343 /* clean up all plugins, cancel connections and pending transmissions */
2329 while (NULL != (rpos = n->plugins)) 2344 while (NULL != (rpos = n->plugins))
@@ -2352,7 +2367,10 @@ disconnect_neighbor (struct NeighborList *current_handle, int check)
2352 GNUNET_free (mq); 2367 GNUNET_free (mq);
2353 } 2368 }
2354 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2369 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2355 GNUNET_SCHEDULER_cancel (sched, n->timeout_task); 2370 {
2371 GNUNET_SCHEDULER_cancel (sched, n->timeout_task);
2372 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2373 }
2356 /* finally, free n itself */ 2374 /* finally, free n itself */
2357 GNUNET_free (n); 2375 GNUNET_free (n);
2358} 2376}
@@ -2504,9 +2522,10 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
2504 peer_address = add_peer_address(n, 2522 peer_address = add_peer_address(n,
2505 plugin->short_name, 2523 plugin->short_name,
2506 sender_address, 2524 sender_address,
2507 sender_address_len); 2525 sender_address_len);
2508 if (peer_address != NULL) 2526 if (peer_address != NULL)
2509 { 2527 {
2528 peer_address->distance = distance;
2510 if (peer_address->connected == GNUNET_NO) 2529 if (peer_address->connected == GNUNET_NO)
2511 { 2530 {
2512 peer_address->connected = GNUNET_YES; 2531 peer_address->connected = GNUNET_YES;
@@ -2520,10 +2539,12 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
2520 /* update traffic received amount ... */ 2539 /* update traffic received amount ... */
2521 msize = ntohs (message->size); 2540 msize = ntohs (message->size);
2522 n->last_received += msize; 2541 n->last_received += msize;
2523 GNUNET_SCHEDULER_cancel (sched, n->timeout_task); 2542 n->distance = distance;
2524 n->peer_timeout = 2543 n->peer_timeout =
2525 GNUNET_TIME_relative_to_absolute 2544 GNUNET_TIME_relative_to_absolute
2526 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2545 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2546 GNUNET_SCHEDULER_cancel (sched,
2547 n->timeout_task);
2527 n->timeout_task = 2548 n->timeout_task =
2528 GNUNET_SCHEDULER_add_delayed (sched, 2549 GNUNET_SCHEDULER_add_delayed (sched,
2529 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2550 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
@@ -2551,6 +2572,11 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
2551 handle_pong(plugin, message, peer, sender_address, sender_address_len); 2572 handle_pong(plugin, message, peer, sender_address, sender_address_len);
2552 break; 2573 break;
2553 default: 2574 default:
2575 if (! n->received_pong)
2576 {
2577 GNUNET_break_op (0);
2578 break;
2579 }
2554#if DEBUG_TRANSPORT 2580#if DEBUG_TRANSPORT
2555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2556 "Received message of type %u from `%4s', sending to all clients.\n", 2582 "Received message of type %u from `%4s', sending to all clients.\n",
@@ -2591,8 +2617,6 @@ handle_start (void *cls,
2591 struct TransportClient *c; 2617 struct TransportClient *c;
2592 struct ConnectInfoMessage cim; 2618 struct ConnectInfoMessage cim;
2593 struct NeighborList *n; 2619 struct NeighborList *n;
2594 struct InboundMessage *im;
2595 struct GNUNET_MessageHeader *ack;
2596 2620
2597#if DEBUG_TRANSPORT 2621#if DEBUG_TRANSPORT
2598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2626,34 +2650,18 @@ handle_start (void *cls,
2626 /* tell new client about all existing connections */ 2650 /* tell new client about all existing connections */
2627 cim.header.size = htons (sizeof (struct ConnectInfoMessage)); 2651 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
2628 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 2652 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2629 cim.quota_out = 2653 n = neighbors;
2630 htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000)); 2654 while (n != NULL)
2631 /* FIXME: this ACK stuff is not nice! */ 2655 {
2632 im = GNUNET_malloc (sizeof (struct InboundMessage) + 2656 if (GNUNET_YES == n->received_pong)
2633 sizeof (struct GNUNET_MessageHeader)); 2657 {
2634 im->header.size = htons (sizeof (struct InboundMessage) + 2658 cim.id = n->id;
2635 sizeof (struct GNUNET_MessageHeader)); 2659 cim.latency = GNUNET_TIME_relative_hton (n->latency);
2636 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 2660 cim.distance = htonl (n->distance);
2637 im->latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); 2661 transmit_to_client (c, &cim.header, GNUNET_NO);
2638 ack = (struct GNUNET_MessageHeader *) &im[1];
2639 ack->size = htons (sizeof (struct GNUNET_MessageHeader));
2640 ack->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK);
2641 for (n = neighbors; n != NULL; n = n->next)
2642 {
2643 cim.id = n->id;
2644 cim.latency = GNUNET_TIME_relative_hton (n->latency);
2645 transmit_to_client (c, &cim.header, GNUNET_NO);
2646 if (n->received_pong)
2647 {
2648 im->peer = n->id;
2649 transmit_to_client (c, &im->header, GNUNET_NO);
2650 } 2662 }
2663 n = n->next;
2651 } 2664 }
2652 GNUNET_free (im);
2653 }
2654 else
2655 {
2656 fprintf(stderr, "Our hello is NULL!\n");
2657 } 2665 }
2658 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2666 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2659} 2667}
@@ -2725,7 +2733,7 @@ handle_send (void *cls,
2725 } 2733 }
2726 n = find_neighbor (&obm->peer); 2734 n = find_neighbor (&obm->peer);
2727 if (n == NULL) 2735 if (n == NULL)
2728 n = setup_new_neighbor (&obm->peer); /* But won't ever add address, we have none! */ 2736 n = setup_new_neighbor (&obm->peer);
2729 tc = clients; 2737 tc = clients;
2730 while ((tc != NULL) && (tc->client != client)) 2738 while ((tc != NULL) && (tc->client != client))
2731 tc = tc->next; 2739 tc = tc->next;
@@ -2789,33 +2797,6 @@ handle_set_quota (void *cls,
2789} 2797}
2790 2798
2791 2799
2792/**
2793 * Handle TRY_CONNECT-message.
2794 *
2795 * @param cls closure (always NULL)
2796 * @param client identification of the client
2797 * @param message the actual message
2798 */
2799static void
2800handle_try_connect (void *cls,
2801 struct GNUNET_SERVER_Client *client,
2802 const struct GNUNET_MessageHeader *message)
2803{
2804 const struct TryConnectMessage *tcm;
2805 struct NeighborList *neighbor;
2806 tcm = (const struct TryConnectMessage *) message;
2807#if DEBUG_TRANSPORT
2808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2809 "Received `%s' request from client %p asking to connect to `%4s'\n",
2810 "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer));
2811#endif
2812 neighbor = find_neighbor(&tcm->peer);
2813 if (neighbor == NULL)
2814 setup_new_neighbor (&tcm->peer);
2815 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2816}
2817
2818
2819static void 2800static void
2820transmit_address_to_client (void *cls, const char *address) 2801transmit_address_to_client (void *cls, const char *address)
2821{ 2802{
@@ -2909,9 +2890,6 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = {
2909 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0}, 2890 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
2910 {&handle_set_quota, NULL, 2891 {&handle_set_quota, NULL,
2911 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)}, 2892 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
2912 {&handle_try_connect, NULL,
2913 GNUNET_MESSAGE_TYPE_TRANSPORT_TRY_CONNECT,
2914 sizeof (struct TryConnectMessage)},
2915 {&handle_address_lookup, NULL, 2893 {&handle_address_lookup, NULL,
2916 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 2894 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP,
2917 0}, 2895 0},