/*
- This file is part of GNUnet
- (C) 2002--2013 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ This file is part of GNUnet
+ (C) 2002--2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
*/
/**
* @file transport/plugin_transport_tcp.c
* @return string representing the same address
*/
static const char *
-tcp_address_to_string (void *cls, const void *addr, size_t addrlen);
+tcp_address_to_string (void *cls,
+ const void *addr,
+ size_t addrlen);
+
/**
* Function to check if an inbound connection is acceptable.
*/
static int
plugin_tcp_access_check (void *cls,
- const struct GNUNET_CONNECTION_Credentials *ucred,
- const struct sockaddr *addr, socklen_t addrlen)
+ const struct GNUNET_CONNECTION_Credentials *ucred,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct Plugin *plugin = cls;
LOG(GNUNET_ERROR_TYPE_DEBUG,
return GNUNET_YES;
}
+
/**
* Our external IP address/port mapping has changed.
*
- * @param cls closure, the 'struct Plugin'
+ * @param cls closure, the `struct Plugin`
* @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
* the previous (now invalid) one
* @param addr either the previous or the new public IP address
- * @param addrlen actual lenght of the address
+ * @param addrlen actual length of @a addr
*/
static void
-tcp_nat_port_map_callback (void *cls, int add_remove,
- const struct sockaddr *addr, socklen_t addrlen)
+tcp_nat_port_map_callback (void *cls,
+ int add_remove,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct Plugin *plugin = cls;
struct GNUNET_HELLO_Address *address;
GNUNET_HELLO_address_free(address);
}
+
/**
* Function called for a quick conversion of the binary address to
* a numeric address. Note that the caller must not free the
*
* @param cls closure (`struct Plugin*`)
* @param addr binary address
- * @param addrlen length of the address
+ * @param addrlen length of @a addr
* @return string representing the same address
*/
static const char *
-tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
+tcp_address_to_string (void *cls,
+ const void *addr,
+ size_t addrlen)
{
static char rbuf[INET6_ADDRSTRLEN + 12];
char buf[INET6_ADDRSTRLEN];
sb = &a4;
break;
default:
- LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"),
- (unsigned int ) addrlen);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Unexpected address length: %u bytes\n"),
+ (unsigned int ) addrlen);
return NULL ;
}
if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
{
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "inet_ntop");
return NULL ;
}
GNUNET_snprintf (rbuf, sizeof(rbuf),
- (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options,
- buf, port);
+ (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
+ PLUGIN_NAME,
+ options,
+ buf,
+ port);
return rbuf;
}
+
/**
* Function called to convert a string address to
* a binary address.
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
static int
-tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
- void **buf, size_t *added)
+tcp_string_to_address (void *cls,
+ const char *addr,
+ uint16_t addrlen,
+ void **buf,
+ size_t *added)
{
struct sockaddr_storage socket_address;
char *address;
}
}
+
/**
* Closure for #session_lookup_by_client_it().
*/
struct Session *ret;
};
+
static int
-session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key,
- void *value)
+session_lookup_by_client_it (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct SessionClientCtx *sc_ctx = cls;
struct Session *s = value;
return GNUNET_YES;
}
+
/**
* Find the session handle for the given client.
* Currently uses both the hashmap and the client
*/
static struct Session *
lookup_session_by_client (struct Plugin *plugin,
- struct GNUNET_SERVER_Client *client)
+ struct GNUNET_SERVER_Client *client)
{
struct Session *ret;
struct SessionClientCtx sc_ctx;
return sc_ctx.ret;
}
+
/**
* Functions with this signature are called whenever we need
* to close a session due to a disconnect or failure to
* @return #GNUNET_OK on success
*/
static int
-tcp_disconnect_session (void *cls, struct Session *session)
+tcp_disconnect_session (void *cls,
+ struct Session *session)
{
struct Plugin *plugin = cls;
struct PendingMessage *pm;
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting session of peer `%s' address `%s'\n",
GNUNET_i2s (&session->target),
- tcp_address_to_string (NULL, session->address->address, session->address->address_length));
+ tcp_address_to_string (NULL,
+ session->address->address,
+ session->address->address_length));
if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task)
{
}
else
{
- GNUNET_assert(
- GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session));
+ GNUNET_assert(GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
+ &session->target,
+ session));
}
if (NULL != session->client)
- GNUNET_SERVER_client_set_user_context(session->client, (void *) NULL);
+ GNUNET_SERVER_client_set_user_context (session->client,
+ (void *) NULL);
/* clean up state */
if (NULL != session->transmit_handle)
while (NULL != (pm = session->pending_messages_head))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- pm->transmit_cont != NULL ? "Could not deliver message to `%4s'.\n" : "Could not deliver message to `%4s', notifying.\n",
- GNUNET_i2s (&session->target));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ (NULL != pm->transmit_cont)
+ ? "Could not deliver message to `%4s'.\n"
+ : "Could not deliver message to `%4s', notifying.\n",
+ GNUNET_i2s (&session->target));
GNUNET_STATISTICS_update (session->plugin->env->stats,
gettext_noop ("# bytes currently in TCP buffers"),
-(int64_t) pm->message_size, GNUNET_NO);
return GNUNET_OK;
}
+
/**
* Function that is called to get the keepalive factor.
- * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
+ * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
* calculate the interval between keepalive packets.
*
* @param cls closure with the `struct Plugin`
return 3;
}
+
/**
* Session was idle, so disconnect it
*
* @param tc scheduler context
*/
static void
-session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+session_timeout (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Session *s = cls;
s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Session %p was idle for %s, disconnecting\n", s,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES));
+ "Session %p was idle for %s, disconnecting\n", s,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ GNUNET_YES));
/* call session destroy function */
tcp_disconnect_session (s->plugin, s);
}
+
/**
* Increment session timeout due to activity
*
else
GNUNET_assert(NULL == client);
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n",
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Creating new session for peer `%4s'\n",
GNUNET_i2s (&address->peer));
session = GNUNET_new (struct Session);
session->last_activity = GNUNET_TIME_absolute_get ();
return session;
}
+
/**
* If we have pending messages, ask the server to
* transmit them (schedule the respective tasks, etc.)
static void
process_pending_messages (struct Session *session);
+
/**
* Function called to notify a client about the socket
* being ready to queue more data. "buf" will be
* writing in the meantime.
*
* @param cls closure
- * @param size number of bytes available in buf
+ * @param size number of bytes available in @a buf
* @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
*/
static size_t
do_transmit (void *cls, size_t size, void *buf)
return ret;
}
+
/**
* If we have pending messages, ask the server to
* transmit them (schedule the respective tasks, etc.)
int res;
};
+
/**
* Function called to check if a session is in our maps.
*
}
#endif
+
/**
* Function that can be used by the transport service to transmit
* a message using the plugin. Note that in the case of a
};
+
/**
* Look for a session by address.
*
* @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session
*/
static int
-session_lookup_it (void *cls, const struct GNUNET_PeerIdentity *key,
- void *value)
+session_lookup_it (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct SessionItCtx * si_ctx = cls;
struct Session * session = value;
{
struct Plugin *plugin = cls;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s'\n",
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting peer `%4s'\n",
GNUNET_i2s (target));
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, target,
&session_disconnect_it, plugin);
static struct PrettyPrinterContext *ppc_dll_tail;
/**
- * Context for address to string conversion.
+ * Context for address to string conversion, closure
+ * for #append_port().
*/
struct PrettyPrinterContext
{
GNUNET_TRANSPORT_AddressStringCallback asc;
/**
- * Clsoure for 'asc'.
+ * Clsoure for @e asc.
*/
void *asc_cls;
uint32_t options;
};
-static void
-ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct PrettyPrinterContext *ppc = cls;
-
- ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (NULL != ppc->resolver_handle)
- {
- GNUNET_RESOLVER_request_cancel (ppc->resolver_handle);
- ppc->resolver_handle = NULL;
- }
- GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
- GNUNET_free(ppc);
-}
/**
* Append our port and forward the result.
*
- * @param cls the 'struct PrettyPrinterContext*'
+ * @param cls the `struct PrettyPrinterContext *`
* @param hostname hostname part of the address
*/
static void
-append_port (void *cls, const char *hostname)
+append_port (void *cls,
+ const char *hostname)
{
struct PrettyPrinterContext *ppc = cls;
- struct PrettyPrinterContext *cur;
char *ret;
if (NULL == hostname)
{
- ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */
- GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc);
- GNUNET_SCHEDULER_cancel (ppc->timeout_task);
- ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ /* Final call, done */
ppc->resolver_handle = NULL;
- GNUNET_free(ppc);
- return;
- }
- for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
- if (cur == ppc)
- break;
- if (NULL == cur)
- {
- ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
- GNUNET_break(0);
+ GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
+ ppc_dll_tail,
+ ppc);
+ ppc->asc (ppc->asc_cls,
+ NULL,
+ GNUNET_OK);
+ GNUNET_free (ppc);
return;
}
-
if (GNUNET_YES == ppc->ipv6)
- GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname,
- ppc->port);
+ GNUNET_asprintf (&ret,
+ "%s.%u.[%s]:%d",
+ PLUGIN_NAME,
+ ppc->options,
+ hostname,
+ ppc->port);
else
- GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname,
- ppc->port);
- ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
- GNUNET_free(ret);
+ GNUNET_asprintf (&ret,
+ "%s.%u.%s:%d",
+ PLUGIN_NAME,
+ ppc->options,
+ hostname,
+ ppc->port);
+ ppc->asc (ppc->asc_cls,
+ ret,
+ GNUNET_OK);
+ GNUNET_free (ret);
}
+
/**
* Convert the transports address to a nice, human-readable
* format.
* @param type name of the transport that generated the address
* @param addr one of the addresses of the host, NULL for the last address
* the specific address format depends on the transport
- * @param addrlen length of the address
+ * @param addrlen length of the @a addr
* @param numeric should (IP) addresses be displayed in numeric form?
* @param timeout after how long should we give up?
* @param asc function to call on each string
- * @param asc_cls closure for asc
- *
+ * @param asc_cls closure for @a asc
*/
static void
-tcp_plugin_address_pretty_printer (void *cls, const char *type,
- const void *addr, size_t addrlen, int numeric,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
+tcp_plugin_address_pretty_printer (void *cls,
+ const char *type,
+ const void *addr,
+ size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc,
+ void *asc_cls)
{
struct PrettyPrinterContext *ppc;
const void *sb;
uint16_t port;
uint32_t options;
- if (addrlen == sizeof(struct IPv6TcpAddress))
+ if (sizeof(struct IPv6TcpAddress) == addrlen)
{
t6 = addr;
memset (&a6, 0, sizeof(a6));
sb = &a6;
sbs = sizeof(a6);
}
- else if (addrlen == sizeof(struct IPv4TcpAddress))
+ else if (sizeof(struct IPv4TcpAddress) == addrlen)
{
t4 = addr;
memset (&a4, 0, sizeof(a4));
ppc->asc_cls = asc_cls;
ppc->port = port;
ppc->options = options;
- ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc);
- ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric,
- timeout, &append_port, ppc);
- if (NULL != ppc->resolver_handle)
+ ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
+ sbs,
+ ! numeric,
+ timeout,
+ &append_port, ppc);
+ if (NULL == ppc->resolver_handle)
{
- GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc);
- }
- else
- {
- GNUNET_break(0);
- GNUNET_free(ppc);
+ GNUNET_break (0);
+ GNUNET_free (ppc);
+ return;
}
+ GNUNET_CONTAINER_DLL_insert (ppc_dll_head,
+ ppc_dll_tail,
+ ppc);
}
+
/**
* Check if the given port is plausible (must be either our listen
* port or our advertised port), or any port if we are behind NAT
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
- LOG(GNUNET_ERROR_TYPE_WARNING,
+ LOG(GNUNET_ERROR_TYPE_INFO,
"Received %s message from my own identity `%4s' on address `%s'\n",
"WELCOME", GNUNET_i2s (&wm->clientIdentity),
GNUNET_a2s (vaddr, alen));
GNUNET_free(vaddr);
}
- GNUNET_break_op(0);
return;
}
}
else
{
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Throttling receiving from `%s' for %s\n",
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Throttling receiving from `%s' for %s\n",
GNUNET_i2s (&session->target),
GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
GNUNET_SERVER_disable_receive_done_warning (client);
struct Plugin *plugin = cls;
struct Session *session;
- if (client == NULL )
+ if (NULL == client)
return;
session = lookup_session_by_client (plugin, client);
- if (session == NULL )
+ if (NULL == session)
return; /* unknown, nothing to do */
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Destroying session of `%4s' with %s due to network-level disconnect.\n",
* @param cls closure, a struct TCPProbeContext
* @param size max size to copy
* @param buf buffer to copy message to
- * @return number of bytes copied into buf
+ * @return number of bytes copied into @a buf
*/
static size_t
-notify_send_probe (void *cls, size_t size, void *buf)
+notify_send_probe (void *cls,
+ size_t size,
+ void *buf)
{
struct TCPProbeContext *tcp_probe_ctx = cls;
struct Plugin *plugin = tcp_probe_ctx->plugin;
return ret;
}
+
/**
* Function called by the NAT subsystem suggesting another peer wants
* to connect to us via connection reversal. Try to connect back to the
* @param addrlen number of bytes in @a addr
*/
static void
-try_connection_reversal (void *cls, const struct sockaddr *addr,
- socklen_t addrlen)
+try_connection_reversal (void *cls,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct Plugin *plugin = cls;
struct GNUNET_CONNECTION_Handle *sock;
}
+
/**
* Function obtain the network type for a session
*
* @return the network type in HBO or #GNUNET_SYSERR
*/
static enum GNUNET_ATS_Network_Type
-tcp_get_network (void *cls, struct Session *session)
+tcp_get_network (void *cls,
+ struct Session *session)
{
struct Plugin * plugin = cls;
+
GNUNET_assert (NULL != plugin);
GNUNET_assert (NULL != session);
if (GNUNET_SYSERR == find_session (plugin,session))
return session->ats_address_network_type;
}
+
/**
* Entry point for the plugin.
*
void *
libgnunet_plugin_transport_tcp_init (void *cls)
{
- static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { {
- &handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
- sizeof(struct WelcomeMessage) }, { &handle_tcp_nat_probe, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
- sizeof(struct TCP_NAT_ProbeMessage) }, { &handle_tcp_data, NULL,
- GNUNET_MESSAGE_TYPE_ALL, 0 }, { NULL, NULL, 0, 0 } };
+ static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
+ { &handle_tcp_welcome, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, sizeof(struct WelcomeMessage) },
+ { &handle_tcp_nat_probe, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, sizeof(struct TCP_NAT_ProbeMessage) },
+ { &handle_tcp_data, NULL,
+ GNUNET_MESSAGE_TYPE_ALL, 0 },
+ { NULL, NULL, 0, 0 }
+ };
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
return api;
}
- GNUNET_assert(NULL != env->cfg);
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
- "MAX_CONNECTIONS", &max_connections))
+ GNUNET_assert (NULL != env->cfg);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "MAX_CONNECTIONS",
+ &max_connections))
max_connections = 128;
aport = 0;
aport = 0;
if (bport != 0)
{
- service = GNUNET_SERVICE_start ("transport-tcp", env->cfg,
- GNUNET_SERVICE_OPTION_NONE);
- if (service == NULL )
+ service = GNUNET_SERVICE_start ("transport-tcp",
+ env->cfg,
+ GNUNET_SERVICE_OPTION_NONE);
+ if (service == NULL)
{
- LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n"));
- return NULL ;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to start service.\n"));
+ return NULL;
}
}
else
plugin->adv_port = aport;
plugin->env = env;
plugin->lsock = NULL;
- if ((service != NULL )&&
- (GNUNET_SYSERR !=
- (ret_s =
- GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs,
- &addrlens)))){
- for (ret = ret_s-1; ret >= 0; ret--)
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Binding to address `%s'\n",
- GNUNET_a2s (addrs[ret], addrlens[ret]));
- plugin->nat =
- GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s,
- (const struct sockaddr **) addrs, addrlens,
- &tcp_nat_port_map_callback,
- &try_connection_reversal, plugin);
- for (ret = ret_s -1; ret >= 0; ret--)
- {
- GNUNET_assert (addrs[ret] != NULL);
- GNUNET_free (addrs[ret]);
- }
- GNUNET_free_non_null (addrs);
- GNUNET_free_non_null (addrlens);
-}
-else
-{
- plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
- GNUNET_YES, 0, 0, NULL, NULL, NULL,
- &try_connection_reversal, plugin);
-}
+ if ( (service != NULL) &&
+ (GNUNET_SYSERR !=
+ (ret_s =
+ GNUNET_SERVICE_get_server_addresses ("transport-tcp",
+ env->cfg,
+ &addrs,
+ &addrlens))))
+ {
+ for (ret = ret_s-1; ret >= 0; ret--)
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Binding to address `%s'\n",
+ GNUNET_a2s (addrs[ret], addrlens[ret]));
+ plugin->nat
+ = GNUNET_NAT_register (env->cfg,
+ GNUNET_YES,
+ aport,
+ (unsigned int) ret_s,
+ (const struct sockaddr **) addrs, addrlens,
+ &tcp_nat_port_map_callback,
+ &try_connection_reversal,
+ plugin);
+ for (ret = ret_s -1; ret >= 0; ret--)
+ GNUNET_free (addrs[ret]);
+ GNUNET_free_non_null (addrs);
+ GNUNET_free_non_null (addrlens);
+ }
+ else
+ {
+ plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
+ GNUNET_YES, 0, 0, NULL, NULL, NULL,
+ &try_connection_reversal, plugin);
+ }
api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
api->cls = plugin;
api->send = &tcp_plugin_send;
api->get_session = &tcp_plugin_get_session;
-
api->disconnect_session = &tcp_disconnect_session;
api->query_keepalive_factor = &tcp_query_keepalive_factor;
api->disconnect_peer = &tcp_plugin_disconnect;
}
else
{
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp",
- "TIMEOUT", &idle_timeout))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (env->cfg,
+ "transport-tcp",
+ "TIMEOUT",
+ &idle_timeout))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "transport-tcp",
- "TIMEOUT");
- if (plugin->nat != NULL )
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "transport-tcp",
+ "TIMEOUT");
+ if (NULL != plugin->nat)
GNUNET_NAT_unregister (plugin->nat);
GNUNET_free(plugin);
GNUNET_free(api);
- return NULL ;
+ return NULL;
}
- plugin->server = GNUNET_SERVER_create_with_sockets (
- &plugin_tcp_access_check, plugin, NULL, idle_timeout, GNUNET_YES);
+ plugin->server
+ = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check,
+ plugin, NULL,
+ idle_timeout, GNUNET_YES);
}
plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
memcpy (plugin->handlers, my_handlers, sizeof(my_handlers));
- for (i = 0;
- i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);
- i++)
+ for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++)
plugin->handlers[i].callback_cls = plugin;
GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_YES);
- if (bport != 0)
- LOG(GNUNET_ERROR_TYPE_INFO, _("TCP transport listening on port %llu\n"),
- bport);
+ GNUNET_YES);
+ if (0 != bport)
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("TCP transport listening on port %llu\n"),
+ bport);
else
- LOG(GNUNET_ERROR_TYPE_INFO,
- _("TCP transport not listening on any port (client only)\n"));
- if (aport != bport)
- LOG(GNUNET_ERROR_TYPE_INFO,
- _("TCP transport advertises itself as being on port %llu\n"), aport);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("TCP transport not listening on any port (client only)\n"));
+ if ( (aport != bport) &&
+ (0 != bport) )
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("TCP transport advertises itself as being on port %llu\n"),
+ aport);
/* Initially set connections to 0 */
GNUNET_assert(NULL != plugin->env->stats);
GNUNET_STATISTICS_set (plugin->env->stats,
return api;
}
+
/**
* Exit point from the plugin.
*
GNUNET_free(api);
return NULL ;
}
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down TCP plugin\n");
/* Removing leftover sessions */
GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
- &session_disconnect_it, plugin);
+ &session_disconnect_it,
+ plugin);
/* Removing leftover NAT sessions */
GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns,
- &session_disconnect_it, plugin);
+ &session_disconnect_it,
+ plugin);
next = ppc_dll_head;
for (cur = next; NULL != cur; cur = next)
{
+ GNUNET_break (0);
next = cur->next;
- GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur);
- if (NULL != cur->resolver_handle)
- GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
- GNUNET_SCHEDULER_cancel (cur->timeout_task);
- GNUNET_free(cur);
- GNUNET_break(0);
+ GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
+ ppc_dll_tail,
+ cur);
+ GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
+ GNUNET_free (cur);
}
- if (plugin->service != NULL )
+ if (NULL != plugin->service)
GNUNET_SERVICE_stop (plugin->service);
else
GNUNET_SERVER_destroy (plugin->server);
GNUNET_free(plugin->handlers);
- if (plugin->nat != NULL )
+ if (NULL != plugin->nat)
GNUNET_NAT_unregister (plugin->nat);
while (NULL != (tcp_probe = plugin->probe_head))
{
GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
GNUNET_free(plugin);
GNUNET_free(api);
- return NULL ;
+ return NULL;
}
/* end of plugin_transport_tcp.c */