summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-25 22:59:22 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-25 22:59:22 +0000
commit200c39244ad165f003ec810320b415dda6ec7542 (patch)
tree38afe94b2dba79818585cc3e19c32b7907bc3811 /src
parentc3f7f2380e5509d26537d090a227e46ddd1bd165 (diff)
-correct a few overly optimistic assumptions about what can legitimately happen...
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,
/**
+ * Find matching address info, ignoring sessions.
+ *
+ * @param cls the `struct FindClosure`
+ * @param key which peer is this about
+ * @param value the `struct AddressInfo`
+ * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
+ */
+static int
+find_ai_no_session_cb (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
+{
+ struct FindClosure *fc = cls;
+ struct AddressInfo *ai = value;
+
+ if (0 ==
+ GNUNET_HELLO_address_cmp (fc->address,
+ ai->address))
+ {
+ fc->ret = ai;
+ return GNUNET_NO;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Find the address information struct for the
+ * given address (ignoring sessions)
+ *
+ * @param address address to look for
+ * @return NULL if this combination is unknown
+ */
+static struct AddressInfo *
+find_ai_no_session (const struct GNUNET_HELLO_Address *address)
+{
+ struct FindClosure fc;
+
+ fc.address = address;
+ fc.session = NULL;
+ fc.ret = NULL;
+ GNUNET_CONTAINER_multipeermap_get_multiple (p2a,
+ &address->peer,
+ &find_ai_no_session_cb,
+ &fc);
+ return fc.ret;
+}
+
+
+/**
* Test if ATS knows about this address.
*
* @param address the address
@@ -187,11 +237,22 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
{
GNUNET_break (NULL != session);
}
- ai = find_ai (address, session);
+ ai = (NULL == session)
+ ? find_ai_no_session (address)
+ : find_ai (address, session);
if (NULL != ai)
- {
- GNUNET_break (0);
return;
+ if (NULL != session)
+ {
+ /* in this case, we must not find an existing
+ session-less address, as the caller should
+ have checked for this case if it were possible. */
+ ai = find_ai (address, NULL);
+ if (NULL != ai)
+ {
+ GNUNET_assert (0);
+ return;
+ }
}
if (NULL == (papi = GST_plugins_find (address->transport_name)))
{
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,
#endif
addrlen = address->address_length;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Trying to get session for `%s' address of peer `%s'\n",
- tcp_plugin_address_to_string(NULL, address->address, address->address_length),
- GNUNET_i2s (&address->peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to get session for `%s' address of peer `%s'\n",
+ tcp_plugin_address_to_string(NULL, address->address, address->address_length),
+ GNUNET_i2s (&address->peer));
- if (GNUNET_HELLO_address_check_option(address, GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ if (GNUNET_HELLO_address_check_option (address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND))
{
GNUNET_break (0);
return NULL;
}
/* look for existing session */
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
- &address->peer))
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
+ &address->peer))
{
struct SessionItCtx si_ctx;
@@ -1550,15 +1552,18 @@ tcp_plugin_get_session (void *cls,
si_ctx.result = NULL;
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
- &address->peer, &session_lookup_it, &si_ctx);
- if (si_ctx.result != NULL)
+ &address->peer,
+ &session_lookup_it, &si_ctx);
+ if (NULL != si_ctx.result)
{
session = si_ctx.result;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Found existing session for `%s' address `%s' session %p\n",
- GNUNET_i2s (&address->peer),
- tcp_plugin_address_to_string(NULL, address->address, address->address_length),
- session);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Found existing session for `%s' address `%s' session %p\n",
+ GNUNET_i2s (&address->peer),
+ tcp_plugin_address_to_string (NULL,
+ address->address,
+ address->address_length),
+ session);
return session;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1637,8 +1642,9 @@ tcp_plugin_get_session (void *cls,
}
if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
- (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
- &address->peer)))
+ (GNUNET_NO ==
+ GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
+ &address->peer)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"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,
"Looking for existing session for peer `%s' `%s' \n",
GNUNET_i2s (&address->peer),
udp_address_to_string(NULL, address->address, address->address_length));
- GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, &address->peer,
- session_cmp_it, &cctx);
- if (cctx.res != NULL )
+ GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
+ &address->peer,
+ session_cmp_it,
+ &cctx);
+ if (NULL != cctx.res)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found existing session %p\n",
@@ -1836,14 +1838,18 @@ udp_plugin_create_session (void *cls,
if (NULL == s)
return NULL; /* protocol not supported or address invalid */
LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating new %s session %p for peer `%s' address `%s'\n",
- GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound",
+ "Creating new session %p for peer `%s' address `%s'\n",
s, GNUNET_i2s (&address->peer),
udp_address_to_string( NULL,address->address,address->address_length));
- GNUNET_assert(
- GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- GNUNET_STATISTICS_set (plugin->env->stats, "# UDP sessions active",
- GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO);
+ GNUNET_assert(GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
+ &s->target,
+ s,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_STATISTICS_set (plugin->env->stats,
+ "# UDP sessions active",
+ GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
+ GNUNET_NO);
return s;
}
@@ -2330,18 +2336,19 @@ process_udp_message (struct Plugin *plugin,
GNUNET_break(0);
return;
}
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received message with %u bytes from peer `%s' at `%s'\n",
- (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
- GNUNET_a2s (sender_addr, sender_addr_len));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message with %u bytes from peer `%s' at `%s'\n",
+ (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
+ GNUNET_a2s (sender_addr, sender_addr_len));
- address = GNUNET_HELLO_address_allocate ( &msg->sender, PLUGIN_NAME,
- arg, args,
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME,
+ arg, args,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
{
s = udp_plugin_create_session (plugin, address);
- plugin->env->session_start (NULL, address, s, NULL, 0);
+ plugin->env->session_start (plugin->env->cls,
+ address, s, NULL, 0);
notify_session_monitor (s->plugin,
s,
GNUNET_TRANSPORT_SS_INIT);