aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport_ats.c67
-rw-r--r--src/transport/plugin_transport_tcp.c38
-rw-r--r--src/transport/plugin_transport_udp.c41
3 files changed, 110 insertions, 36 deletions
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index f862f8c47..430c00ba6 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -140,6 +140,56 @@ find_ai (const struct GNUNET_HELLO_Address *address,
140 140
141 141
142/** 142/**
143 * Find matching address info, ignoring sessions.
144 *
145 * @param cls the `struct FindClosure`
146 * @param key which peer is this about
147 * @param value the `struct AddressInfo`
148 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
149 */
150static int
151find_ai_no_session_cb (void *cls,
152 const struct GNUNET_PeerIdentity *key,
153 void *value)
154{
155 struct FindClosure *fc = cls;
156 struct AddressInfo *ai = value;
157
158 if (0 ==
159 GNUNET_HELLO_address_cmp (fc->address,
160 ai->address))
161 {
162 fc->ret = ai;
163 return GNUNET_NO;
164 }
165 return GNUNET_YES;
166}
167
168
169/**
170 * Find the address information struct for the
171 * given address (ignoring sessions)
172 *
173 * @param address address to look for
174 * @return NULL if this combination is unknown
175 */
176static struct AddressInfo *
177find_ai_no_session (const struct GNUNET_HELLO_Address *address)
178{
179 struct FindClosure fc;
180
181 fc.address = address;
182 fc.session = NULL;
183 fc.ret = NULL;
184 GNUNET_CONTAINER_multipeermap_get_multiple (p2a,
185 &address->peer,
186 &find_ai_no_session_cb,
187 &fc);
188 return fc.ret;
189}
190
191
192/**
143 * Test if ATS knows about this address. 193 * Test if ATS knows about this address.
144 * 194 *
145 * @param address the address 195 * @param address the address
@@ -187,11 +237,22 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
187 { 237 {
188 GNUNET_break (NULL != session); 238 GNUNET_break (NULL != session);
189 } 239 }
190 ai = find_ai (address, session); 240 ai = (NULL == session)
241 ? find_ai_no_session (address)
242 : find_ai (address, session);
191 if (NULL != ai) 243 if (NULL != ai)
192 {
193 GNUNET_break (0);
194 return; 244 return;
245 if (NULL != session)
246 {
247 /* in this case, we must not find an existing
248 session-less address, as the caller should
249 have checked for this case if it were possible. */
250 ai = find_ai (address, NULL);
251 if (NULL != ai)
252 {
253 GNUNET_assert (0);
254 return;
255 }
195 } 256 }
196 if (NULL == (papi = GST_plugins_find (address->transport_name))) 257 if (NULL == (papi = GST_plugins_find (address->transport_name)))
197 { 258 {
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 770525f21..89d270cc8 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1529,20 +1529,22 @@ tcp_plugin_get_session (void *cls,
1529#endif 1529#endif
1530 1530
1531 addrlen = address->address_length; 1531 addrlen = address->address_length;
1532 LOG(GNUNET_ERROR_TYPE_DEBUG, 1532 LOG (GNUNET_ERROR_TYPE_DEBUG,
1533 "Trying to get session for `%s' address of peer `%s'\n", 1533 "Trying to get session for `%s' address of peer `%s'\n",
1534 tcp_plugin_address_to_string(NULL, address->address, address->address_length), 1534 tcp_plugin_address_to_string(NULL, address->address, address->address_length),
1535 GNUNET_i2s (&address->peer)); 1535 GNUNET_i2s (&address->peer));
1536 1536
1537 if (GNUNET_HELLO_address_check_option(address, GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1537 if (GNUNET_HELLO_address_check_option (address,
1538 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1538 { 1539 {
1539 GNUNET_break (0); 1540 GNUNET_break (0);
1540 return NULL; 1541 return NULL;
1541 } 1542 }
1542 1543
1543 /* look for existing session */ 1544 /* look for existing session */
1544 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, 1545 if (GNUNET_YES ==
1545 &address->peer)) 1546 GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
1547 &address->peer))
1546 { 1548 {
1547 struct SessionItCtx si_ctx; 1549 struct SessionItCtx si_ctx;
1548 1550
@@ -1550,15 +1552,18 @@ tcp_plugin_get_session (void *cls,
1550 si_ctx.result = NULL; 1552 si_ctx.result = NULL;
1551 1553
1552 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, 1554 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
1553 &address->peer, &session_lookup_it, &si_ctx); 1555 &address->peer,
1554 if (si_ctx.result != NULL) 1556 &session_lookup_it, &si_ctx);
1557 if (NULL != si_ctx.result)
1555 { 1558 {
1556 session = si_ctx.result; 1559 session = si_ctx.result;
1557 LOG(GNUNET_ERROR_TYPE_DEBUG, 1560 LOG (GNUNET_ERROR_TYPE_DEBUG,
1558 "Found existing session for `%s' address `%s' session %p\n", 1561 "Found existing session for `%s' address `%s' session %p\n",
1559 GNUNET_i2s (&address->peer), 1562 GNUNET_i2s (&address->peer),
1560 tcp_plugin_address_to_string(NULL, address->address, address->address_length), 1563 tcp_plugin_address_to_string (NULL,
1561 session); 1564 address->address,
1565 address->address_length),
1566 session);
1562 return session; 1567 return session;
1563 } 1568 }
1564 LOG (GNUNET_ERROR_TYPE_DEBUG, 1569 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1637,8 +1642,9 @@ tcp_plugin_get_session (void *cls,
1637 } 1642 }
1638 1643
1639 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && 1644 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
1640 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, 1645 (GNUNET_NO ==
1641 &address->peer))) 1646 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
1647 &address->peer)))
1642 { 1648 {
1643 LOG (GNUNET_ERROR_TYPE_DEBUG, 1649 LOG (GNUNET_ERROR_TYPE_DEBUG,
1644 "Found valid IPv4 NAT address (creating session)!\n"); 1650 "Found valid IPv4 NAT address (creating session)!\n");
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 3a482c486..0589a24bd 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1687,9 +1687,11 @@ udp_plugin_lookup_session (void *cls,
1687 "Looking for existing session for peer `%s' `%s' \n", 1687 "Looking for existing session for peer `%s' `%s' \n",
1688 GNUNET_i2s (&address->peer), 1688 GNUNET_i2s (&address->peer),
1689 udp_address_to_string(NULL, address->address, address->address_length)); 1689 udp_address_to_string(NULL, address->address, address->address_length));
1690 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, &address->peer, 1690 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
1691 session_cmp_it, &cctx); 1691 &address->peer,
1692 if (cctx.res != NULL ) 1692 session_cmp_it,
1693 &cctx);
1694 if (NULL != cctx.res)
1693 { 1695 {
1694 LOG (GNUNET_ERROR_TYPE_DEBUG, 1696 LOG (GNUNET_ERROR_TYPE_DEBUG,
1695 "Found existing session %p\n", 1697 "Found existing session %p\n",
@@ -1836,14 +1838,18 @@ udp_plugin_create_session (void *cls,
1836 if (NULL == s) 1838 if (NULL == s)
1837 return NULL; /* protocol not supported or address invalid */ 1839 return NULL; /* protocol not supported or address invalid */
1838 LOG(GNUNET_ERROR_TYPE_DEBUG, 1840 LOG(GNUNET_ERROR_TYPE_DEBUG,
1839 "Creating new %s session %p for peer `%s' address `%s'\n", 1841 "Creating new session %p for peer `%s' address `%s'\n",
1840 GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound",
1841 s, GNUNET_i2s (&address->peer), 1842 s, GNUNET_i2s (&address->peer),
1842 udp_address_to_string( NULL,address->address,address->address_length)); 1843 udp_address_to_string( NULL,address->address,address->address_length));
1843 GNUNET_assert( 1844 GNUNET_assert(GNUNET_OK ==
1844 GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1845 GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
1845 GNUNET_STATISTICS_set (plugin->env->stats, "# UDP sessions active", 1846 &s->target,
1846 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); 1847 s,
1848 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1849 GNUNET_STATISTICS_set (plugin->env->stats,
1850 "# UDP sessions active",
1851 GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
1852 GNUNET_NO);
1847 return s; 1853 return s;
1848} 1854}
1849 1855
@@ -2330,18 +2336,19 @@ process_udp_message (struct Plugin *plugin,
2330 GNUNET_break(0); 2336 GNUNET_break(0);
2331 return; 2337 return;
2332 } 2338 }
2333 LOG(GNUNET_ERROR_TYPE_DEBUG, 2339 LOG (GNUNET_ERROR_TYPE_DEBUG,
2334 "Received message with %u bytes from peer `%s' at `%s'\n", 2340 "Received message with %u bytes from peer `%s' at `%s'\n",
2335 (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), 2341 (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
2336 GNUNET_a2s (sender_addr, sender_addr_len)); 2342 GNUNET_a2s (sender_addr, sender_addr_len));
2337 2343
2338 address = GNUNET_HELLO_address_allocate ( &msg->sender, PLUGIN_NAME, 2344 address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME,
2339 arg, args, 2345 arg, args,
2340 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 2346 GNUNET_HELLO_ADDRESS_INFO_NONE);
2341 if (NULL == (s = udp_plugin_lookup_session (plugin, address))) 2347 if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
2342 { 2348 {
2343 s = udp_plugin_create_session (plugin, address); 2349 s = udp_plugin_create_session (plugin, address);
2344 plugin->env->session_start (NULL, address, s, NULL, 0); 2350 plugin->env->session_start (plugin->env->cls,
2351 address, s, NULL, 0);
2345 notify_session_monitor (s->plugin, 2352 notify_session_monitor (s->plugin,
2346 s, 2353 s,
2347 GNUNET_TRANSPORT_SS_INIT); 2354 GNUNET_TRANSPORT_SS_INIT);