aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-12 13:45:44 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-12 13:45:44 +0000
commite1b1446ff25ce0e5cb7871a16b24e88517d10803 (patch)
treee055256d7bc6063c0c1979be356a7d821c0bf55e /src/transport
parent47d4bf2182b2142272cb2a5283ae929a80e1292c (diff)
downloadgnunet-e1b1446ff25ce0e5cb7871a16b24e88517d10803.tar.gz
gnunet-e1b1446ff25ce0e5cb7871a16b24e88517d10803.zip
-some minor code cleanup
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_udp.c153
1 files changed, 71 insertions, 82 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index cb95a5a00..46804ba1d 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -78,25 +78,25 @@ static struct PrettyPrinterContext *ppc_dll_tail;
78 */ 78 */
79struct PrettyPrinterContext 79struct PrettyPrinterContext
80{ 80{
81 /** 81 /**
82 * DLL 82 * DLL
83 */ 83 */
84 struct PrettyPrinterContext *next; 84 struct PrettyPrinterContext *next;
85 85
86 /** 86 /**
87 * DLL 87 * DLL
88 */ 88 */
89 struct PrettyPrinterContext *prev; 89 struct PrettyPrinterContext *prev;
90 90
91 /** 91 /**
92 * Timeout task 92 * Timeout task
93 */ 93 */
94 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 94 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
95 95
96 /** 96 /**
97 * Resolver handle 97 * Resolver handle
98 */ 98 */
99 struct GNUNET_RESOLVER_RequestHandle *resolver_handle; 99 struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
100 100
101 /** 101 /**
102 * Function to call with the result. 102 * Function to call with the result.
@@ -464,22 +464,23 @@ udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
464 464
465 465
466/** 466/**
467 * Start session timeout 467 * Cancel timeout
468 */ 468 */
469static void 469static void
470start_session_timeout (struct Session *s); 470stop_session_timeout (struct Session *s)
471{
472 GNUNET_assert (NULL != s);
471 473
472/** 474 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
473 * Increment session timeout due to activity 475 {
474 */ 476 GNUNET_SCHEDULER_cancel (s->timeout_task);
475static void 477 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
476reschedule_session_timeout (struct Session *s); 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Timeout stopped for session %p canceled\n",
480 s);
481 }
482}
477 483
478/**
479 * Cancel timeout
480 */
481static void
482stop_session_timeout (struct Session *s);
483 484
484/** 485/**
485 * (re)schedule select tasks for this plugin. 486 * (re)schedule select tasks for this plugin.
@@ -578,17 +579,18 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
578 sb = &a4; 579 sb = &a4;
579 } 580 }
580 else if (addrlen == 0) 581 else if (addrlen == 0)
581 { 582 {
582 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s", TRANSPORT_SESSION_INBOUND_STRING); 583 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s", TRANSPORT_SESSION_INBOUND_STRING);
583 return rbuf; 584 return rbuf;
584 } 585 }
585 else 586 else
586 { 587 {
587 return NULL; 588 return NULL;
588 } 589 }
589 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 590 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
590 591
591 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 592 GNUNET_snprintf (rbuf, sizeof (rbuf),
593 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
592 PLUGIN_NAME, options, buf, port); 594 PLUGIN_NAME, options, buf, port);
593 return rbuf; 595 return rbuf;
594} 596}
@@ -701,7 +703,7 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
701} 703}
702 704
703 705
704void 706static void
705ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 707ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
706{ 708{
707 struct PrettyPrinterContext *ppc = cls; 709 struct PrettyPrinterContext *ppc = cls;
@@ -1140,6 +1142,7 @@ dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw)
1140 plugin->ipv6_queue_tail, udpw); 1142 plugin->ipv6_queue_tail, udpw);
1141} 1143}
1142 1144
1145
1143static void 1146static void
1144fragmented_message_done (struct UDP_FragmentationContext *fc, int result) 1147fragmented_message_done (struct UDP_FragmentationContext *fc, int result)
1145{ 1148{
@@ -1148,7 +1151,10 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result)
1148 struct UDP_MessageWrapper dummy; 1151 struct UDP_MessageWrapper dummy;
1149 struct Session *s = fc->session; 1152 struct Session *s = fc->session;
1150 1153
1151 LOG (GNUNET_ERROR_TYPE_DEBUG, "%p : Fragmented message removed with result %s\n", fc, (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); 1154 LOG (GNUNET_ERROR_TYPE_DEBUG,
1155 "%p : Fragmented message removed with result %s\n",
1156 fc,
1157 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1152 1158
1153 /* Call continuation for fragmented message */ 1159 /* Call continuation for fragmented message */
1154 memset (&dummy, 0, sizeof (dummy)); 1160 memset (&dummy, 0, sizeof (dummy));
@@ -1377,25 +1383,6 @@ reschedule_session_timeout (struct Session *s)
1377} 1383}
1378 1384
1379 1385
1380/**
1381 * Cancel timeout
1382 */
1383static void
1384stop_session_timeout (struct Session *s)
1385{
1386 GNUNET_assert (NULL != s);
1387
1388 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1389 {
1390 GNUNET_SCHEDULER_cancel (s->timeout_task);
1391 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1393 "Timeout stopped for session %p canceled\n",
1394 s);
1395 }
1396}
1397
1398
1399static struct Session * 1386static struct Session *
1400create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 1387create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
1401 const void *addr, size_t addrlen, 1388 const void *addr, size_t addrlen,
@@ -1441,8 +1428,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
1441 return NULL; 1428 return NULL;
1442 } 1429 }
1443 t6 = addr; 1430 t6 = addr;
1444 s = 1431 s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
1445 GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
1446 len = sizeof (struct sockaddr_in6); 1432 len = sizeof (struct sockaddr_in6);
1447 v6 = (struct sockaddr_in6 *) &s[1]; 1433 v6 = (struct sockaddr_in6 *) &s[1];
1448 v6->sin6_family = AF_INET6; 1434 v6->sin6_family = AF_INET6;
@@ -1485,9 +1471,11 @@ session_cmp_it (void *cls,
1485 1471
1486 socklen_t s_addrlen = s->addrlen; 1472 socklen_t s_addrlen = s->addrlen;
1487 1473
1488 LOG (GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n", 1474 LOG (GNUNET_ERROR_TYPE_DEBUG,
1489 udp_address_to_string (NULL, (void *) address->address, address->address_length), 1475 "Comparing address %s <-> %s\n",
1490 GNUNET_a2s (s->sock_addr, s->addrlen)); 1476 udp_address_to_string (NULL, (void *) address->address,
1477 address->address_length),
1478 GNUNET_a2s (s->sock_addr, s->addrlen));
1491 if ((address->address_length == sizeof (struct IPv4UdpAddress)) && 1479 if ((address->address_length == sizeof (struct IPv4UdpAddress)) &&
1492 (s_addrlen == sizeof (struct sockaddr_in))) 1480 (s_addrlen == sizeof (struct sockaddr_in)))
1493 { 1481 {
@@ -1544,7 +1532,7 @@ udp_get_network (void *cls,
1544 */ 1532 */
1545static struct Session * 1533static struct Session *
1546udp_plugin_lookup_session (void *cls, 1534udp_plugin_lookup_session (void *cls,
1547 const struct GNUNET_HELLO_Address *address) 1535 const struct GNUNET_HELLO_Address *address)
1548{ 1536{
1549 struct Plugin * plugin = cls; 1537 struct Plugin * plugin = cls;
1550 struct IPv6UdpAddress * udp_a6; 1538 struct IPv6UdpAddress * udp_a6;
@@ -1601,20 +1589,20 @@ udp_plugin_lookup_session (void *cls,
1601 return NULL; 1589 return NULL;
1602} 1590}
1603 1591
1592
1604static struct Session * 1593static struct Session *
1605udp_plugin_create_session (void *cls, 1594udp_plugin_create_session (void *cls,
1606 const struct GNUNET_HELLO_Address *address) 1595 const struct GNUNET_HELLO_Address *address)
1607{ 1596{
1608 struct Session * s = NULL; 1597 struct Session *s;
1609 1598
1610 /* otherwise create new */
1611 s = create_session (plugin, 1599 s = create_session (plugin,
1612 &address->peer, 1600 &address->peer,
1613 address->address, 1601 address->address,
1614 address->address_length, 1602 address->address_length,
1615 NULL, NULL); 1603 NULL, NULL);
1616 if (NULL == s) 1604 if (NULL == s)
1617 return NULL; /* protocol not supported or address invalid */ 1605 return NULL; /* protocol not supported or address invalid */
1618 LOG (GNUNET_ERROR_TYPE_DEBUG, 1606 LOG (GNUNET_ERROR_TYPE_DEBUG,
1619 "Creating new session %p for peer `%s' address `%s'\n", 1607 "Creating new session %p for peer `%s' address `%s'\n",
1620 s, 1608 s,
@@ -1633,7 +1621,6 @@ udp_plugin_create_session (void *cls,
1633} 1621}
1634 1622
1635 1623
1636
1637/** 1624/**
1638 * Creates a new outbound session the transport service will use to send data to the 1625 * Creates a new outbound session the transport service will use to send data to the
1639 * peer 1626 * peer
@@ -1644,24 +1631,23 @@ udp_plugin_create_session (void *cls,
1644 */ 1631 */
1645static struct Session * 1632static struct Session *
1646udp_plugin_get_session (void *cls, 1633udp_plugin_get_session (void *cls,
1647 const struct GNUNET_HELLO_Address *address) 1634 const struct GNUNET_HELLO_Address *address)
1648{ 1635{
1649 struct Session * s = NULL; 1636 struct Session *s;
1650 1637
1651 if (NULL == address) 1638 if (NULL == address)
1652 { 1639 {
1653 GNUNET_break (0); 1640 GNUNET_break (0);
1654 return NULL; 1641 return NULL;
1655 } 1642 }
1656 if ((address->address_length != sizeof (struct IPv4UdpAddress)) && 1643 if ((address->address_length != sizeof (struct IPv4UdpAddress)) &&
1657 (address->address_length != sizeof (struct IPv6UdpAddress))) 1644 (address->address_length != sizeof (struct IPv6UdpAddress)))
1658 return NULL; 1645 return NULL;
1659 1646
1660 /* otherwise create new */ 1647 /* otherwise create new */
1661 if (NULL != (s = udp_plugin_lookup_session(cls, address))) 1648 if (NULL != (s = udp_plugin_lookup_session (cls, address)))
1662 return s; 1649 return s;
1663 else 1650 return udp_plugin_create_session (cls, address);
1664 return udp_plugin_create_session (cls, address);
1665} 1651}
1666 1652
1667 1653
@@ -1706,6 +1692,7 @@ send_next_fragment (void *cls,
1706 int result, size_t payload, size_t physical) 1692 int result, size_t payload, size_t physical)
1707{ 1693{
1708 struct UDP_MessageWrapper *udpw = cls; 1694 struct UDP_MessageWrapper *udpw = cls;
1695
1709 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); 1696 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag);
1710} 1697}
1711 1698
@@ -2455,6 +2442,7 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2455 } 2442 }
2456} 2443}
2457 2444
2445
2458static struct UDP_MessageWrapper * 2446static struct UDP_MessageWrapper *
2459remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, 2447remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
2460 struct GNUNET_NETWORK_Handle *sock) 2448 struct GNUNET_NETWORK_Handle *sock)
@@ -2622,6 +2610,7 @@ analyze_send_error (struct Plugin *plugin,
2622 } 2610 }
2623} 2611}
2624 2612
2613
2625static size_t 2614static size_t
2626udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) 2615udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
2627{ 2616{