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.c92
1 files changed, 84 insertions, 8 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index d05e88824..fce1ba7d3 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -175,6 +175,12 @@ struct ForeignAddressList
175 const void *addr; 175 const void *addr;
176 176
177 /** 177 /**
178 * Session (or NULL if no valid session currently exists or if the
179 * plugin does not use sessions).
180 */
181 struct Session *session;
182
183 /**
178 * What was the last latency observed for this address, plugin and peer? 184 * What was the last latency observed for this address, plugin and peer?
179 */ 185 */
180 struct GNUNET_TIME_Relative latency; 186 struct GNUNET_TIME_Relative latency;
@@ -1347,6 +1353,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
1347 mq->message_buf_size, 1353 mq->message_buf_size,
1348 mq->priority, 1354 mq->priority,
1349 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1355 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1356 mq->specific_address->session,
1350 mq->specific_address->addr, 1357 mq->specific_address->addr,
1351 mq->specific_address->addrlen, 1358 mq->specific_address->addrlen,
1352 force_address, 1359 force_address,
@@ -1624,6 +1631,61 @@ expire_address_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1624 1631
1625 1632
1626/** 1633/**
1634 * Function that will be called whenever the plugin internally
1635 * cleans up a session pointer and hence the service needs to
1636 * discard all of those sessions as well. Plugins that do not
1637 * use sessions can simply omit calling this function and always
1638 * use NULL wherever a session pointer is needed.
1639 *
1640 * @param cls closure
1641 * @param peer which peer was the session for
1642 * @param session which session is being destoyed
1643 */
1644static void
1645plugin_env_session_end (void *cls,
1646 const struct GNUNET_PeerIdentity *peer,
1647 struct Session *session)
1648{
1649 struct TransportPlugin *p = cls;
1650 struct NeighbourList *nl;
1651 struct ReadyList *rl;
1652 struct ForeignAddressList *pos;
1653 struct ForeignAddressList *prev;
1654
1655 nl = find_neighbour (peer);
1656 if (nl == NULL)
1657 return;
1658 rl = nl->plugins;
1659 while (rl != NULL)
1660 {
1661 if (rl->plugin == p)
1662 break;
1663 rl = rl->next;
1664 }
1665 if (rl == NULL)
1666 return;
1667 prev = NULL;
1668 pos = rl->addresses;
1669 while ( (pos != NULL) &&
1670 (pos->session != session) )
1671 {
1672 prev = pos;
1673 pos = pos->next;
1674 }
1675 if (pos == NULL)
1676 return;
1677 pos->session = NULL;
1678 if (pos->addrlen != 0)
1679 return;
1680 if (prev == NULL)
1681 rl->addresses = pos->next;
1682 else
1683 prev->next = pos->next;
1684 GNUNET_free (pos);
1685}
1686
1687
1688/**
1627 * Function that must be called by each plugin to notify the 1689 * Function that must be called by each plugin to notify the
1628 * transport service about the addresses under which the transport 1690 * transport service about the addresses under which the transport
1629 * provided by the plugin can be reached. 1691 * provided by the plugin can be reached.
@@ -1743,6 +1805,8 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1743 * 1805 *
1744 * @param neighbour which peer we care about 1806 * @param neighbour which peer we care about
1745 * @param tname name of the transport plugin 1807 * @param tname name of the transport plugin
1808 * @param session session to look for, NULL for 'any'; otherwise
1809 * can be used for the service to "learn" this session ID
1746 * @param addr binary address 1810 * @param addr binary address
1747 * @param addrlen length of addr 1811 * @param addrlen length of addr
1748 * @return NULL if no such entry exists 1812 * @return NULL if no such entry exists
@@ -1750,6 +1814,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1750static struct ForeignAddressList * 1814static struct ForeignAddressList *
1751find_peer_address(struct NeighbourList *neighbour, 1815find_peer_address(struct NeighbourList *neighbour,
1752 const char *tname, 1816 const char *tname,
1817 struct Session *session,
1753 const char *addr, 1818 const char *addr,
1754 size_t addrlen) 1819 size_t addrlen)
1755{ 1820{
@@ -1771,6 +1836,8 @@ find_peer_address(struct NeighbourList *neighbour,
1771 ( (address_head->addrlen != addrlen) || 1836 ( (address_head->addrlen != addrlen) ||
1772 (memcmp(address_head->addr, addr, addrlen) != 0) ) ) 1837 (memcmp(address_head->addr, addr, addrlen) != 0) ) )
1773 address_head = address_head->next; 1838 address_head = address_head->next;
1839 if (session != NULL)
1840 address_head->session = session; /* learn it! */
1774 return address_head; 1841 return address_head;
1775} 1842}
1776 1843
@@ -1781,6 +1848,7 @@ find_peer_address(struct NeighbourList *neighbour,
1781 * 1848 *
1782 * @param neighbour which peer we care about 1849 * @param neighbour which peer we care about
1783 * @param tname name of the transport plugin 1850 * @param tname name of the transport plugin
1851 * @param session session of the plugin, or NULL for none
1784 * @param addr binary address 1852 * @param addr binary address
1785 * @param addrlen length of addr 1853 * @param addrlen length of addr
1786 * @return NULL if we do not have a transport plugin for 'tname' 1854 * @return NULL if we do not have a transport plugin for 'tname'
@@ -1788,13 +1856,14 @@ find_peer_address(struct NeighbourList *neighbour,
1788static struct ForeignAddressList * 1856static struct ForeignAddressList *
1789add_peer_address (struct NeighbourList *neighbour, 1857add_peer_address (struct NeighbourList *neighbour,
1790 const char *tname, 1858 const char *tname,
1859 struct Session *session,
1791 const char *addr, 1860 const char *addr,
1792 size_t addrlen) 1861 size_t addrlen)
1793{ 1862{
1794 struct ReadyList *head; 1863 struct ReadyList *head;
1795 struct ForeignAddressList *ret; 1864 struct ForeignAddressList *ret;
1796 1865
1797 ret = find_peer_address (neighbour, tname, addr, addrlen); 1866 ret = find_peer_address (neighbour, tname, session, addr, addrlen);
1798 if (ret != NULL) 1867 if (ret != NULL)
1799 return ret; 1868 return ret;
1800 head = neighbour->plugins; 1869 head = neighbour->plugins;
@@ -1807,6 +1876,7 @@ add_peer_address (struct NeighbourList *neighbour,
1807 if (head == NULL) 1876 if (head == NULL)
1808 return NULL; 1877 return NULL;
1809 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen); 1878 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen);
1879 ret->session = session;
1810 ret->addr = (const char*) &ret[1]; 1880 ret->addr = (const char*) &ret[1];
1811 memcpy (&ret[1], addr, addrlen); 1881 memcpy (&ret[1], addr, addrlen);
1812 ret->addrlen = addrlen; 1882 ret->addrlen = addrlen;
@@ -2014,7 +2084,7 @@ add_to_foreign_address_list (void *cls,
2014 1, 2084 1,
2015 GNUNET_NO); 2085 GNUNET_NO);
2016 try = GNUNET_NO; 2086 try = GNUNET_NO;
2017 fal = find_peer_address (n, tname, addr, addrlen); 2087 fal = find_peer_address (n, tname, NULL, addr, addrlen);
2018 if (fal == NULL) 2088 if (fal == NULL)
2019 { 2089 {
2020#if DEBUG_TRANSPORT 2090#if DEBUG_TRANSPORT
@@ -2025,7 +2095,7 @@ add_to_foreign_address_list (void *cls,
2025 GNUNET_i2s (&n->id), 2095 GNUNET_i2s (&n->id),
2026 expiration.value); 2096 expiration.value);
2027#endif 2097#endif
2028 fal = add_peer_address (n, tname, addr, addrlen); 2098 fal = add_peer_address (n, tname, NULL, addr, addrlen);
2029 if (fal == NULL) 2099 if (fal == NULL)
2030 { 2100 {
2031 GNUNET_STATISTICS_update (stats, 2101 GNUNET_STATISTICS_update (stats,
@@ -2392,6 +2462,7 @@ check_pending_validation (void *cls,
2392 n->public_key_valid = GNUNET_YES; 2462 n->public_key_valid = GNUNET_YES;
2393 fal = add_peer_address (n, 2463 fal = add_peer_address (n,
2394 ve->transport_name, 2464 ve->transport_name,
2465 NULL,
2395 ve->addr, 2466 ve->addr,
2396 ve->addrlen); 2467 ve->addrlen);
2397 GNUNET_assert (fal != NULL); 2468 GNUNET_assert (fal != NULL);
@@ -2604,7 +2675,7 @@ run_validation (void *cls,
2604 neighbour = setup_new_neighbour(&id); 2675 neighbour = setup_new_neighbour(&id);
2605 neighbour->publicKey = va->publicKey; 2676 neighbour->publicKey = va->publicKey;
2606 neighbour->public_key_valid = GNUNET_YES; 2677 neighbour->public_key_valid = GNUNET_YES;
2607 peer_address = add_peer_address(neighbour, tname, addr, addrlen); 2678 peer_address = add_peer_address(neighbour, tname, NULL, addr, addrlen);
2608 GNUNET_assert(peer_address != NULL); 2679 GNUNET_assert(peer_address != NULL);
2609 hello_size = GNUNET_HELLO_size(our_hello); 2680 hello_size = GNUNET_HELLO_size(our_hello);
2610 tsize = sizeof(struct TransportPingMessage) + hello_size; 2681 tsize = sizeof(struct TransportPingMessage) + hello_size;
@@ -3018,8 +3089,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3018 GNUNET_CRYPTO_rsa_sign (my_private_key, 3089 GNUNET_CRYPTO_rsa_sign (my_private_key,
3019 &pong->purpose, &pong->signature)); 3090 &pong->purpose, &pong->signature));
3020 n = find_neighbour(peer); 3091 n = find_neighbour(peer);
3021 if (n == NULL) 3092 GNUNET_assert (n != NULL);
3022 n = setup_new_neighbour(peer);
3023 /* first try reliable response transmission */ 3093 /* first try reliable response transmission */
3024 rl = n->plugins; 3094 rl = n->plugins;
3025 while (rl != NULL) 3095 while (rl != NULL)
@@ -3033,6 +3103,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3033 ntohs (pong->header.size), 3103 ntohs (pong->header.size),
3034 TRANSPORT_PONG_PRIORITY, 3104 TRANSPORT_PONG_PRIORITY,
3035 HELLO_VERIFICATION_TIMEOUT, 3105 HELLO_VERIFICATION_TIMEOUT,
3106 fal->session,
3036 fal->addr, 3107 fal->addr,
3037 fal->addrlen, 3108 fal->addrlen,
3038 GNUNET_SYSERR, 3109 GNUNET_SYSERR,
@@ -3088,6 +3159,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3088 * @param message the message, NULL if we only care about 3159 * @param message the message, NULL if we only care about
3089 * learning about the delay until we should receive again 3160 * learning about the delay until we should receive again
3090 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL) 3161 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL)
3162 * @param session identifier used for this session (can be NULL)
3091 * @param sender_address binary address of the sender (if observed) 3163 * @param sender_address binary address of the sender (if observed)
3092 * @param sender_address_len number of bytes in sender_address 3164 * @param sender_address_len number of bytes in sender_address
3093 * @return how long the plugin should wait until receiving more data 3165 * @return how long the plugin should wait until receiving more data
@@ -3096,11 +3168,13 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3096static struct GNUNET_TIME_Relative 3168static struct GNUNET_TIME_Relative
3097plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 3169plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
3098 const struct GNUNET_MessageHeader *message, 3170 const struct GNUNET_MessageHeader *message,
3099 unsigned int distance, const char *sender_address, 3171 unsigned int distance,
3172 struct Session *session,
3173 const char *sender_address,
3100 size_t sender_address_len) 3174 size_t sender_address_len)
3101{ 3175{
3102 struct ReadyList *service_context;
3103 struct TransportPlugin *plugin = cls; 3176 struct TransportPlugin *plugin = cls;
3177 struct ReadyList *service_context;
3104 struct TransportClient *cpos; 3178 struct TransportClient *cpos;
3105 struct InboundMessage *im; 3179 struct InboundMessage *im;
3106 struct ForeignAddressList *peer_address; 3180 struct ForeignAddressList *peer_address;
@@ -3119,6 +3193,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
3119 { 3193 {
3120 peer_address = add_peer_address(n, 3194 peer_address = add_peer_address(n,
3121 plugin->short_name, 3195 plugin->short_name,
3196 session,
3122 sender_address, 3197 sender_address,
3123 sender_address_len); 3198 sender_address_len);
3124 if (peer_address != NULL) 3199 if (peer_address != NULL)
@@ -3577,6 +3652,7 @@ create_environment (struct TransportPlugin *plug)
3577 plug->env.cls = plug; 3652 plug->env.cls = plug;
3578 plug->env.receive = &plugin_env_receive; 3653 plug->env.receive = &plugin_env_receive;
3579 plug->env.notify_address = &plugin_env_notify_address; 3654 plug->env.notify_address = &plugin_env_notify_address;
3655 plug->env.session_end = &plugin_env_session_end;
3580 plug->env.max_connections = max_connect_per_transport; 3656 plug->env.max_connections = max_connect_per_transport;
3581 plug->env.stats = stats; 3657 plug->env.stats = stats;
3582} 3658}