aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-20 13:52:02 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-20 13:52:02 +0000
commitf71fb2816cee37e823abcaa9d79c149ba90ff4cd (patch)
treed1727ba1a62ab1bd9fcf3dc7a5bdd071160dd582 /src/transport
parent12bda91777d20fff1fb016d89db08075d45204ab (diff)
downloadgnunet-f71fb2816cee37e823abcaa9d79c149ba90ff4cd.tar.gz
gnunet-f71fb2816cee37e823abcaa9d79c149ba90ff4cd.zip
-eliminate duplicate all_zeros globals, eliminated dead 'latency' field in SendOKMessage
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_clients.c99
-rw-r--r--src/transport/transport.h5
2 files changed, 54 insertions, 50 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 9fc167985..310121268 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -233,9 +233,15 @@ static struct GNUNET_SERVER_NotificationContext *plugin_nc;
233 */ 233 */
234static struct GNUNET_SERVER_Client *sync_client; 234static struct GNUNET_SERVER_Client *sync_client;
235 235
236/**
237 * Peer identity that is all zeros, used as a way to indicate
238 * "all peers". Used for comparissons.
239 */
240static struct GNUNET_PeerIdentity all_zeros;
241
236 242
237/** 243/**
238 * Find the internal handle associated with the given client handle 244 * Find the internal handle associated with the given client handle.
239 * 245 *
240 * @param client server's client handle to look up 246 * @param client server's client handle to look up
241 * @return internal client handle 247 * @return internal client handle
@@ -243,17 +249,13 @@ static struct GNUNET_SERVER_Client *sync_client;
243static struct TransportClient * 249static struct TransportClient *
244lookup_client (struct GNUNET_SERVER_Client *client) 250lookup_client (struct GNUNET_SERVER_Client *client)
245{ 251{
246 struct TransportClient *tc; 252 return GNUNET_SERVER_client_get_user_context (client,
247 253 struct TransportClient);
248 for (tc = clients_head; NULL != tc; tc = tc->next)
249 if (tc->client == client)
250 return tc;
251 return NULL;
252} 254}
253 255
254 256
255/** 257/**
256 * Create the internal handle for the given server client handle 258 * Create the internal handle for the given server client handle.
257 * 259 *
258 * @param client server's client handle to create our internal handle for 260 * @param client server's client handle to create our internal handle for
259 * @return fresh internal client handle 261 * @return fresh internal client handle
@@ -266,6 +268,10 @@ setup_client (struct GNUNET_SERVER_Client *client)
266 GNUNET_assert (NULL == lookup_client (client)); 268 GNUNET_assert (NULL == lookup_client (client));
267 tc = GNUNET_new (struct TransportClient); 269 tc = GNUNET_new (struct TransportClient);
268 tc->client = client; 270 tc->client = client;
271 GNUNET_SERVER_client_set_user_context (client, tc);
272 GNUNET_CONTAINER_DLL_insert (clients_head,
273 clients_tail,
274 tc);
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Client %p connected\n", 276 "Client %p connected\n",
271 tc); 277 tc);
@@ -275,7 +281,7 @@ setup_client (struct GNUNET_SERVER_Client *client)
275 281
276/** 282/**
277 * Find the handle to the monitoring client associated with the given 283 * Find the handle to the monitoring client associated with the given
278 * client handle 284 * client handle.
279 * 285 *
280 * @param head the head of the client queue to look in 286 * @param head the head of the client queue to look in
281 * @param client server's client handle to look up 287 * @param client server's client handle to look up
@@ -308,7 +314,6 @@ setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client,
308 const struct GNUNET_PeerIdentity *peer) 314 const struct GNUNET_PeerIdentity *peer)
309{ 315{
310 struct MonitoringClient *mc; 316 struct MonitoringClient *mc;
311 static struct GNUNET_PeerIdentity all_zeros;
312 317
313 GNUNET_assert (NULL == 318 GNUNET_assert (NULL ==
314 lookup_monitoring_client (peer_monitoring_clients_head, 319 lookup_monitoring_client (peer_monitoring_clients_head,
@@ -320,15 +325,17 @@ setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client,
320 peer_monitoring_clients_tail, 325 peer_monitoring_clients_tail,
321 mc); 326 mc);
322 GNUNET_SERVER_client_mark_monitor (client); 327 GNUNET_SERVER_client_mark_monitor (client);
323 GNUNET_SERVER_notification_context_add (peer_nc, client); 328 GNUNET_SERVER_notification_context_add (peer_nc,
324 329 client);
325 if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) 330 if (0 != memcmp (peer,
326 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 331 &all_zeros,
332 sizeof (struct GNUNET_PeerIdentity)))
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Client %p started monitoring of the peer `%s'\n", 334 "Client %p started monitoring of the peer `%s'\n",
328 mc, 335 mc,
329 GNUNET_i2s (peer)); 336 GNUNET_i2s (peer));
330 else 337 else
331 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Client %p started monitoring all peers\n", 339 "Client %p started monitoring all peers\n",
333 mc); 340 mc);
334 return mc; 341 return mc;
@@ -349,7 +356,6 @@ setup_val_monitoring_client (struct GNUNET_SERVER_Client *client,
349 struct GNUNET_PeerIdentity *peer) 356 struct GNUNET_PeerIdentity *peer)
350{ 357{
351 struct MonitoringClient *mc; 358 struct MonitoringClient *mc;
352 static struct GNUNET_PeerIdentity all_zeros;
353 359
354 GNUNET_assert (NULL == 360 GNUNET_assert (NULL ==
355 lookup_monitoring_client (val_monitoring_clients_head, 361 lookup_monitoring_client (val_monitoring_clients_head,
@@ -365,19 +371,19 @@ setup_val_monitoring_client (struct GNUNET_SERVER_Client *client,
365 if (0 != memcmp (peer, 371 if (0 != memcmp (peer,
366 &all_zeros, 372 &all_zeros,
367 sizeof (struct GNUNET_PeerIdentity))) 373 sizeof (struct GNUNET_PeerIdentity)))
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "Client %p started monitoring of the peer `%s'\n", 375 "Client %p started monitoring of the peer `%s'\n",
370 mc, GNUNET_i2s (peer)); 376 mc, GNUNET_i2s (peer));
371 else 377 else
372 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Client %p started monitoring all peers\n", mc); 379 "Client %p started monitoring all peers\n", mc);
374 return mc; 380 return mc;
375} 381}
376 382
377 383
378/** 384/**
379 * Function called to notify a client about the socket being ready to 385 * Function called to notify a client about the socket being ready to
380 * queue more data. "buf" will be NULL and "size" zero if the socket 386 * queue more data. @a buf will be NULL and @a size zero if the socket
381 * was closed for writing in the meantime. 387 * was closed for writing in the meantime.
382 * 388 *
383 * @param cls closure 389 * @param cls closure
@@ -414,7 +420,8 @@ transmit_to_client_callback (void *cls,
414 break; 420 break;
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
416 "Transmitting message of type %u to client %p.\n", 422 "Transmitting message of type %u to client %p.\n",
417 ntohs (msg->type), tc); 423 ntohs (msg->type),
424 tc);
418 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 425 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
419 tc->message_queue_tail, 426 tc->message_queue_tail,
420 q); 427 q);
@@ -456,8 +463,8 @@ unicast (struct TransportClient *tc,
456 GNUNET_break (0); 463 GNUNET_break (0);
457 return; 464 return;
458 } 465 }
459 466 if ( (tc->message_count >= MAX_PENDING) &&
460 if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop)) 467 (GNUNET_YES == may_drop) )
461 { 468 {
462 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 469 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
463 _("Dropping message of type %u and size %u, have %u/%u messages pending\n"), 470 _("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
@@ -476,7 +483,8 @@ unicast (struct TransportClient *tc,
476 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); 483 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
477 memcpy (&q[1], msg, msize); 484 memcpy (&q[1], msg, msize);
478 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head, 485 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
479 tc->message_queue_tail, q); 486 tc->message_queue_tail,
487 q);
480 tc->message_count++; 488 tc->message_count++;
481 if (NULL != tc->th) 489 if (NULL != tc->th)
482 return; 490 return;
@@ -492,7 +500,7 @@ unicast (struct TransportClient *tc,
492 * Called whenever a client is disconnected. Frees our 500 * Called whenever a client is disconnected. Frees our
493 * resources associated with that client. 501 * resources associated with that client.
494 * 502 *
495 * @param cls closure 503 * @param cls closure, NULL
496 * @param client identification of the client 504 * @param client identification of the client
497 */ 505 */
498static void 506static void
@@ -503,11 +511,11 @@ client_disconnect_notification (void *cls,
503 struct MonitoringClient *mc; 511 struct MonitoringClient *mc;
504 struct ClientMessageQueueEntry *mqe; 512 struct ClientMessageQueueEntry *mqe;
505 513
506 if (client == NULL) 514 if (NULL == client)
507 return; 515 return;
508 mc = lookup_monitoring_client (peer_monitoring_clients_head, 516 mc = lookup_monitoring_client (peer_monitoring_clients_head,
509 client); 517 client);
510 if (mc != NULL) 518 if (NULL != mc)
511 { 519 {
512 GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head, 520 GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head,
513 peer_monitoring_clients_tail, 521 peer_monitoring_clients_tail,
@@ -516,7 +524,7 @@ client_disconnect_notification (void *cls,
516 } 524 }
517 mc = lookup_monitoring_client (val_monitoring_clients_head, 525 mc = lookup_monitoring_client (val_monitoring_clients_head,
518 client); 526 client);
519 if (mc != NULL) 527 if (NULL != mc)
520 { 528 {
521 GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, 529 GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head,
522 val_monitoring_clients_tail, 530 val_monitoring_clients_tail,
@@ -524,7 +532,7 @@ client_disconnect_notification (void *cls,
524 GNUNET_free (mc); 532 GNUNET_free (mc);
525 } 533 }
526 tc = lookup_client (client); 534 tc = lookup_client (client);
527 if (tc == NULL) 535 if (NULL == tc)
528 return; 536 return;
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
530 "Client %p disconnected, cleaning up.\n", tc); 538 "Client %p disconnected, cleaning up.\n", tc);
@@ -536,7 +544,8 @@ client_disconnect_notification (void *cls,
536 GNUNET_free (mqe); 544 GNUNET_free (mqe);
537 } 545 }
538 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); 546 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
539 if (tc->th != NULL) 547 GNUNET_SERVER_client_set_user_context (client, NULL);
548 if (NULL != tc->th)
540 { 549 {
541 GNUNET_SERVER_notify_transmit_ready_cancel (tc->th); 550 GNUNET_SERVER_notify_transmit_ready_cancel (tc->th);
542 tc->th = NULL; 551 tc->th = NULL;
@@ -634,9 +643,10 @@ clients_handle_start (void *cls,
634 } 643 }
635 tc = setup_client (client); 644 tc = setup_client (client);
636 tc->send_payload = (0 != (2 & options)); 645 tc->send_payload = (0 != (2 & options));
637 unicast (tc, GST_hello_get (), GNUNET_NO); 646 unicast (tc,
647 GST_hello_get (),
648 GNUNET_NO);
638 GST_neighbours_iterate (&notify_client_about_neighbour, tc); 649 GST_neighbours_iterate (&notify_client_about_neighbour, tc);
639 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
640 GNUNET_SERVER_receive_done (client, GNUNET_OK); 650 GNUNET_SERVER_receive_done (client, GNUNET_OK);
641} 651}
642 652
@@ -684,7 +694,8 @@ struct SendTransmitContinuationContext
684 * @param bytes_on_wire bytes sent on wire 694 * @param bytes_on_wire bytes sent on wire
685 */ 695 */
686static void 696static void
687handle_send_transmit_continuation (void *cls, int success, 697handle_send_transmit_continuation (void *cls,
698 int success,
688 size_t bytes_payload, 699 size_t bytes_payload,
689 size_t bytes_on_wire) 700 size_t bytes_on_wire)
690{ 701{
@@ -692,17 +703,17 @@ handle_send_transmit_continuation (void *cls, int success,
692 struct SendOkMessage send_ok_msg; 703 struct SendOkMessage send_ok_msg;
693 704
694 if (GNUNET_OK == success) 705 if (GNUNET_OK == success)
695 GST_neighbours_notify_payload_sent (&stcc->target, bytes_payload); 706 GST_neighbours_notify_payload_sent (&stcc->target,
696 707 bytes_payload);
697 send_ok_msg.header.size = htons (sizeof (send_ok_msg)); 708 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
698 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 709 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
699 send_ok_msg.bytes_msg = htonl (bytes_payload); 710 send_ok_msg.bytes_msg = htonl (bytes_payload);
700 send_ok_msg.bytes_physical = htonl (bytes_on_wire); 711 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
701 send_ok_msg.success = htonl (success); 712 send_ok_msg.success = htonl (success);
702 send_ok_msg.latency =
703 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
704 send_ok_msg.peer = stcc->target; 713 send_ok_msg.peer = stcc->target;
705 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO); 714 GST_clients_unicast (stcc->client,
715 &send_ok_msg.header,
716 GNUNET_NO);
706 GNUNET_SERVER_client_drop (stcc->client); 717 GNUNET_SERVER_client_drop (stcc->client);
707 GNUNET_free (stcc); 718 GNUNET_free (stcc);
708} 719}
@@ -1254,14 +1265,14 @@ clients_handle_monitor_peers (void *cls,
1254 struct GNUNET_SERVER_Client *client, 1265 struct GNUNET_SERVER_Client *client,
1255 const struct GNUNET_MessageHeader *message) 1266 const struct GNUNET_MessageHeader *message)
1256{ 1267{
1257 static struct GNUNET_PeerIdentity all_zeros;
1258 struct GNUNET_SERVER_TransmitContext *tc; 1268 struct GNUNET_SERVER_TransmitContext *tc;
1259 const struct PeerMonitorMessage *msg; 1269 const struct PeerMonitorMessage *msg;
1260 struct IterationContext pc; 1270 struct IterationContext pc;
1261 1271
1262 msg = (const struct PeerMonitorMessage *) message; 1272 msg = (const struct PeerMonitorMessage *) message;
1263 if ( (GNUNET_YES != ntohl (msg->one_shot)) && 1273 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
1264 (NULL != lookup_monitoring_client (peer_monitoring_clients_head, client)) ) 1274 (NULL != lookup_monitoring_client (peer_monitoring_clients_head,
1275 client)) )
1265 { 1276 {
1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 1277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1267 "ServerClient %p tried to start monitoring twice\n", 1278 "ServerClient %p tried to start monitoring twice\n",
@@ -1316,7 +1327,6 @@ clients_handle_monitor_validation (void *cls,
1316 struct GNUNET_SERVER_Client *client, 1327 struct GNUNET_SERVER_Client *client,
1317 const struct GNUNET_MessageHeader *message) 1328 const struct GNUNET_MessageHeader *message)
1318{ 1329{
1319 static struct GNUNET_PeerIdentity all_zeros;
1320 struct GNUNET_SERVER_TransmitContext *tc; 1330 struct GNUNET_SERVER_TransmitContext *tc;
1321 struct PeerMonitorMessage *msg; 1331 struct PeerMonitorMessage *msg;
1322 struct IterationContext pc; 1332 struct IterationContext pc;
@@ -1582,8 +1592,9 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1582 1592
1583 for (tc = clients_head; NULL != tc; tc = tc->next) 1593 for (tc = clients_head; NULL != tc; tc = tc->next)
1584 { 1594 {
1585 if ((GNUNET_YES == may_drop) && (GNUNET_YES != tc->send_payload)) 1595 if ( (GNUNET_YES == may_drop) &&
1586 continue; /* skip, this client does not care about payload */ 1596 (GNUNET_YES != tc->send_payload) )
1597 continue; /* skip, this client does not care about payload */
1587 unicast (tc, msg, may_drop); 1598 unicast (tc, msg, may_drop);
1588 } 1599 }
1589} 1600}
@@ -1624,7 +1635,6 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1624 enum GNUNET_TRANSPORT_PeerState state, 1635 enum GNUNET_TRANSPORT_PeerState state,
1625 struct GNUNET_TIME_Absolute state_timeout) 1636 struct GNUNET_TIME_Absolute state_timeout)
1626{ 1637{
1627 static struct GNUNET_PeerIdentity all_zeros;
1628 struct PeerIterateResponseMessage *msg; 1638 struct PeerIterateResponseMessage *msg;
1629 struct MonitoringClient *mc; 1639 struct MonitoringClient *mc;
1630 1640
@@ -1668,7 +1678,6 @@ GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity
1668{ 1678{
1669 struct ValidationIterateResponseMessage *msg; 1679 struct ValidationIterateResponseMessage *msg;
1670 struct MonitoringClient *mc; 1680 struct MonitoringClient *mc;
1671 static struct GNUNET_PeerIdentity all_zeros;
1672 1681
1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1674 "Sending information about for validation entry for peer `%s' using address `%s'\n", 1683 "Sending information about for validation entry for peer `%s' using address `%s'\n",
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 6fea9201c..01d1b1722 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -265,11 +265,6 @@ struct SendOkMessage
265 uint32_t bytes_physical GNUNET_PACKED; 265 uint32_t bytes_physical GNUNET_PACKED;
266 266
267 /** 267 /**
268 * Latency estimate.
269 */
270 struct GNUNET_TIME_RelativeNBO latency;
271
272 /**
273 * Which peer can send more now? 268 * Which peer can send more now?
274 */ 269 */
275 struct GNUNET_PeerIdentity peer; 270 struct GNUNET_PeerIdentity peer;