summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-10 16:45:26 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-10 16:45:26 +0000
commit75264ef067a70a1b0c01dcab46264d4f31217a5f (patch)
tree690c7ade80810c6cb33bd83e1562d30ca2a0fd06 /src
parent6cf96e80986552390556f36bd6e464d48c1a4b88 (diff)
-fixing some memory leaks from #3667, also reindentation and code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport.c59
-rw-r--r--src/transport/gnunet-service-transport.h5
-rw-r--r--src/transport/gnunet-service-transport_ats.c6
-rw-r--r--src/transport/gnunet-service-transport_clients.c28
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c402
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c31
-rw-r--r--src/transport/gnunet-service-transport_plugins.c57
-rw-r--r--src/transport/gnunet-service-transport_plugins.h4
-rw-r--r--src/transport/gnunet-service-transport_validation.c5
-rw-r--r--src/transport/plugin_transport_http_client.c22
-rw-r--r--src/transport/plugin_transport_tcp.c231
-rw-r--r--src/transport/plugin_transport_udp.c18
12 files changed, 500 insertions, 368 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index fcd2a492d..5840eec5e 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -176,7 +176,7 @@ static struct SessionKiller *sk_tail;
/**
* Interface scanner determines our LAN address range(s).
*/
-static struct GNUNET_ATS_InterfaceScanner *is;
+struct GNUNET_ATS_InterfaceScanner *GST_is;
/**
* Head of DLL of blacklist checks we have pending for
@@ -697,53 +697,6 @@ plugin_env_session_end (void *cls,
/**
- * Function that will be called to figure if an address is an loopback,
- * LAN, WAN etc. address
- *
- * @param cls closure
- * @param addr binary address
- * @param addrlen length of the @a addr
- * @return type of the network @a addr belongs to
- */
-static enum GNUNET_ATS_Network_Type
-plugin_env_address_to_type (void *cls,
- const struct sockaddr *addr,
- size_t addrlen)
-{
- if (NULL == GST_ats)
- {
- GNUNET_break(0);
- return GNUNET_ATS_NET_UNSPECIFIED;
- }
- return GNUNET_ATS_scanner_address_get_type (is,
- addr,
- addrlen);
-}
-
-
-/**
- * Function that will be called to update metrics for an address
- *
- * @param cls closure
- * @param address address to update metrics for
- * @param session the session
- * @param ats the ats information to update
- * @param ats_count the number of @a ats elements
- */
-static void
-plugin_env_update_metrics (void *cls,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
-{
- GST_ats_update_metrics (address,
- session,
- ats, ats_count);
-}
-
-
-/**
* Black list check result from blacklist check triggered when a
* plugin gave us a new session in #plugin_env_session_start(). If
* connection to the peer is disallowed, kill the session.
@@ -940,8 +893,8 @@ shutdown_task (void *cls,
GST_ats = NULL;
GNUNET_ATS_connectivity_done (GST_ats_connect);
GST_ats_connect = NULL;
- GNUNET_ATS_scanner_done (is);
- is = NULL;
+ GNUNET_ATS_scanner_done (GST_is);
+ GST_is = NULL;
GST_clients_stop ();
GST_blacklist_stop ();
GST_hello_stop ();
@@ -1075,7 +1028,7 @@ run (void *cls,
GST_blacklist_start (GST_server,
GST_cfg,
&GST_my_identity);
- is = GNUNET_ATS_scanner_init ();
+ GST_is = GNUNET_ATS_scanner_init ();
GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
&ats_request_address_change,
@@ -1085,9 +1038,7 @@ run (void *cls,
GST_plugins_load (&GST_manipulation_recv,
&plugin_env_address_change_notification,
&plugin_env_session_start,
- &plugin_env_session_end,
- &plugin_env_address_to_type,
- &plugin_env_update_metrics);
+ &plugin_env_session_end);
GST_neighbours_start ((max_fd / 3) * 2);
GST_clients_start (GST_server);
GST_validation_start ((max_fd / 3));
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index afceca3df..21a9ee2bc 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -68,6 +68,11 @@ extern struct GNUNET_ATS_SchedulingHandle *GST_ats;
*/
extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
+/**
+ * Interface scanner determines our LAN address range(s).
+ */
+extern struct GNUNET_ATS_InterfaceScanner *GST_is;
+
/**
* Function to call when a peer's address has changed
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index 5abc0531b..cb05e2fef 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -575,9 +575,9 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address,
and if we get metrics for those, they were never known to
ATS which means we end up here (however, in this
case, the address must be an outbound address). */
- GNUNET_assert (GNUNET_YES !=
- GNUNET_HELLO_address_check_option (address,
- GNUNET_HELLO_ADDRESS_INFO_INBOUND));
+ GNUNET_break (GNUNET_YES !=
+ GNUNET_HELLO_address_check_option (address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND));
return;
}
/* Call to manipulation to manipulate ATS information */
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index db863ae65..87bc0699b 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -747,7 +747,8 @@ clients_handle_send (void *cls,
{
/* client asked for transmission before 'START' */
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
@@ -756,7 +757,8 @@ clients_handle_send (void *cls,
sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
obm = (const struct OutboundMessage *) message;
@@ -765,7 +767,8 @@ clients_handle_send (void *cls,
if (msize < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
@@ -779,23 +782,27 @@ clients_handle_send (void *cls,
gettext_noop
("# bytes payload dropped (other peer was not connected)"),
msize, GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
- "SEND",
+ "Received SEND request for `%s' and first message of type %u and total size %u\n",
GNUNET_i2s (&obm->peer),
ntohs (obmm->type),
msize);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
stcc = GNUNET_new (struct SendTransmitContinuationContext);
stcc->target = obm->peer;
stcc->client = client;
GNUNET_SERVER_client_keep (client);
- GST_manipulation_send (&obm->peer, obmm, msize,
+ GST_manipulation_send (&obm->peer,
+ obmm,
+ msize,
GNUNET_TIME_relative_ntoh (obm->timeout),
- &handle_send_transmit_continuation, stcc);
+ &handle_send_transmit_continuation,
+ stcc);
}
@@ -824,7 +831,8 @@ clients_handle_request_connect (void *cls,
sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index 31b8a3a29..f52634edc 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -195,6 +195,7 @@ struct DelayQueueEntry *generic_dqe_tail;
*/
struct GNUNET_SCHEDULER_Task * generic_send_delay_task;
+
static void
set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value)
{
@@ -228,9 +229,9 @@ set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value)
default:
break;
}
-
}
+
static uint32_t
find_metric(struct TM_Peer *dest, uint32_t type, int direction)
{
@@ -245,10 +246,10 @@ find_metric(struct TM_Peer *dest, uint32_t type, int direction)
return UINT32_MAX;
}
+
/**
* Clean up metrics for a peer
*/
-
static void
free_metric(struct TM_Peer *dest)
{
@@ -263,6 +264,7 @@ free_metric(struct TM_Peer *dest)
}
}
+
/**
* Set traffic metric to manipulate
*
@@ -349,6 +351,7 @@ GST_manipulation_set_metric(void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_receive_done(client, GNUNET_OK);
}
+
static void
send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -359,11 +362,18 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (NULL != tmp)
{
- GNUNET_break(GNUNET_YES == GST_neighbours_test_connected (&dqe->id));
+ GNUNET_break (GNUNET_YES ==
+ GST_neighbours_test_connected (&dqe->id));
tmp->send_delay_task = NULL;
- GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe);
- GST_neighbours_send(&dqe->id, dqe->msg, dqe->msg_size, dqe->timeout,
- dqe->cont, dqe->cont_cls);
+ GNUNET_CONTAINER_DLL_remove (tmp->send_head,
+ tmp->send_tail,
+ dqe);
+ GST_neighbours_send (&dqe->id,
+ dqe->msg,
+ dqe->msg_size,
+ dqe->timeout,
+ dqe->cont,
+ dqe->cont_cls);
next = tmp->send_head;
if (NULL != next)
@@ -394,90 +404,114 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_free(dqe);
}
+
/**
- * Adapter function between transport's send function and transport plugins
+ * Adapter function between transport's send function and transport plugins.
+ * Delays message transmission if an artificial delay is configured.
*
* @param target the peer the message to send to
* @param msg the message received
* @param msg_size message size
* @param timeout timeout
* @param cont the continuation to call after sending
- * @param cont_cls cls for continuation
+ * @param cont_cls cls for @a cont
*/
void
-GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg,
- size_t msg_size, struct GNUNET_TIME_Relative timeout,
- GST_NeighbourSendContinuation cont, void *cont_cls)
+GST_manipulation_send (const struct GNUNET_PeerIdentity *target,
+ const void *msg,
+ size_t msg_size,
+ struct GNUNET_TIME_Relative timeout,
+ GST_NeighbourSendContinuation cont,
+ void *cont_cls)
{
struct TM_Peer *tmp;
struct DelayQueueEntry *dqe;
struct GNUNET_TIME_Relative delay;
+ int do_delay;
- if (NULL
- != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, target)))
- {
- GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target));
- /* Manipulate here */
- /* Delay */
- if (UINT32_MAX != find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND))
- {
- /* We have a delay */
- delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY,
- TM_SEND);
- dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size);
- dqe->id = *target;
- dqe->tmp = tmp;
- dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- delay);
- dqe->cont = cont;
- dqe->cont_cls = cont_cls;
- dqe->msg = &dqe[1];
- dqe->msg_size = msg_size;
- dqe->timeout = timeout;
- memcpy(dqe->msg, msg, msg_size);
- GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head, tmp->send_tail, dqe);
- if (NULL == tmp->send_delay_task)
- tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
- &send_delayed, dqe);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Delaying %u byte message to peer `%s' with generic delay for %ms\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- return;
- }
- }
- else if (UINT32_MAX
- != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY,
- TM_SEND))
+ do_delay = GNUNET_NO;
+ if (NULL != (tmp =
+ GNUNET_CONTAINER_multipeermap_get (man_handle.peers,
+ target)))
+ {
+ GNUNET_break (GNUNET_YES ==
+ GST_neighbours_test_connected(target));
+ /* check for peer-specific delay */
+ if (UINT32_MAX !=
+ find_metric (tmp,
+ GNUNET_ATS_QUALITY_NET_DELAY,
+ TM_SEND))
{
- GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target));
/* We have a delay */
- delay.rel_value_us = find_metric(&man_handle.general,
- GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND);
- dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size);
- dqe->id = *target;
- dqe->tmp = NULL;
- dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- delay);
- dqe->cont = cont;
- dqe->cont_cls = cont_cls;
- dqe->msg = &dqe[1];
- dqe->msg_size = msg_size;
- dqe->timeout = timeout;
- memcpy(dqe->msg, msg, msg_size);
- GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head, generic_dqe_tail, dqe);
- if (NULL == generic_send_delay_task)
- {
- generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
- &send_delayed, dqe);
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- return;
+ delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY,
+ TM_SEND);
+ do_delay = GNUNET_YES;
}
-
- /* Normal sending */
- GST_neighbours_send(target, msg, msg_size, timeout, cont, cont_cls);
+ }
+ else if (UINT32_MAX !=
+ find_metric(&man_handle.general,
+ GNUNET_ATS_QUALITY_NET_DELAY,
+ TM_SEND))
+ {
+ GNUNET_break (GNUNET_YES ==
+ GST_neighbours_test_connected (target));
+ /* We have a delay */
+ delay.rel_value_us = find_metric (&man_handle.general,
+ GNUNET_ATS_QUALITY_NET_DELAY,
+ TM_SEND);
+ do_delay = GNUNET_YES;
+ }
+ if (GNUNET_NO == do_delay)
+ {
+ /* Normal sending */
+ GST_neighbours_send (target,
+ msg,
+ msg_size,
+ timeout,
+ cont, cont_cls);
+ return;
+ }
+ dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size);
+ dqe->id = *target;
+ dqe->tmp = tmp;
+ dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay);
+ dqe->cont = cont;
+ dqe->cont_cls = cont_cls;
+ dqe->msg = &dqe[1];
+ dqe->msg_size = msg_size;
+ dqe->timeout = timeout;
+ memcpy (dqe->msg,
+ msg,
+ msg_size);
+ if (NULL == tmp)
+ {
+ GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head,
+ generic_dqe_tail,
+ dqe);
+ if (NULL == generic_send_delay_task)
+ generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &send_delayed,
+ dqe);
+ }
+ else
+ {
+ GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head,
+ tmp->send_tail,
+ dqe);
+ if (NULL == tmp->send_delay_task)
+ tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &send_delayed,
+ dqe);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Delaying %u byte message to peer `%s' with peer specific delay for %s\n",
+ msg_size,
+ GNUNET_i2s (target),
+ GNUNET_STRINGS_relative_time_to_string (delay,
+ GNUNET_YES));
}
+
/**
* Function that will be called to manipulate ATS information according to
* current manipulation settings
@@ -489,10 +523,10 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg,
* @param ats_count the number of ats information
*/
struct GNUNET_ATS_Information *
-GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
const struct GNUNET_PeerIdentity *peer = &address->peer;
struct GNUNET_ATS_Information *ats_new;
@@ -510,8 +544,11 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
ats_new[d] = ats[d];
m_tmp = UINT32_MAX;
if (NULL != tmp)
- m_tmp = find_metric(tmp, ntohl(ats[d].type), TM_RECEIVE);
- g_tmp = find_metric(&man_handle.general, ntohl(ats[d].type), TM_RECEIVE);
+ m_tmp = find_metric (tmp, ntohl(ats[d].type),
+ TM_RECEIVE);
+ g_tmp = find_metric (&man_handle.general,
+ ntohl(ats[d].type),
+ TM_RECEIVE);
if (UINT32_MAX != g_tmp)
ats_new[d].value = htonl(g_tmp);
@@ -565,14 +602,15 @@ GST_manipulation_recv (void *cls,
if (quota_delay.rel_value_us > m_delay.rel_value_us)
m_delay = quota_delay;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Delaying next receive for peer `%s' for %s\n",
- GNUNET_i2s (&address->peer),
- GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Delaying next receive for peer `%s' for %s\n",
+ GNUNET_i2s (&address->peer),
+ GNUNET_STRINGS_relative_time_to_string (m_delay,
+ GNUNET_YES));
return m_delay;
-
}
+
/**
* Initialize traffic manipulation
*
@@ -584,15 +622,21 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg)
unsigned long long tmp;
struct GNUNET_TIME_Relative delay;
- if ((GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport",
- "MANIPULATE_DISTANCE_IN", &tmp)) && (tmp > 0))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Setting inbound distance_in to %llu\n", (unsigned long long) tmp);
- set_metric(&man_handle.general, TM_RECEIVE,
- GNUNET_ATS_QUALITY_NET_DISTANCE, tmp);
- }
+ if ( (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number(GST_cfg,
+ "transport",
+ "MANIPULATE_DISTANCE_IN",
+ &tmp)) &&
+ (tmp > 0) )
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Setting inbound distance_in to %llu\n",
+ (unsigned long long) tmp);
+ set_metric (&man_handle.general,
+ TM_RECEIVE,
+ GNUNET_ATS_QUALITY_NET_DISTANCE,
+ tmp);
+ }
if ((GNUNET_OK
== GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport",
@@ -625,92 +669,106 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg)
man_handle.peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
}
+
static int
-free_tmps(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
+free_tmps (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
+ struct TM_Peer *tmp = value;
struct DelayQueueEntry *dqe;
- struct DelayQueueEntry *next;
- if (NULL != value)
- {
- struct TM_Peer *tmp = (struct TM_Peer *) value;
-
- if (GNUNET_YES
- != GNUNET_CONTAINER_multipeermap_remove(man_handle.peers, key, value))
- GNUNET_break(0);
- free_metric(tmp);
- next = tmp->send_head;
- while (NULL != (dqe = next))
- {
- next = dqe->next;
- GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe);
- if (NULL != dqe->cont)
- dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0);
- GNUNET_free(dqe);
- }
- if (NULL != tmp->send_delay_task)
- {
- GNUNET_SCHEDULER_cancel(tmp->send_delay_task);
- tmp->send_delay_task = NULL;
- }
- GNUNET_free(tmp);
- }
+ if (NULL == tmp)
+ return GNUNET_OK;
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (man_handle.peers,
+ key,
+ value));
+ free_metric (tmp);
+ while (NULL != (dqe = tmp->send_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (tmp->send_head,
+ tmp->send_tail,
+ dqe);
+ if (NULL != dqe->cont)
+ dqe->cont (dqe->cont_cls,
+ GNUNET_SYSERR,
+ dqe->msg_size,
+ 0);
+ GNUNET_free (dqe);
+ }
+ if (NULL != tmp->send_delay_task)
+ {
+ GNUNET_SCHEDULER_cancel(tmp->send_delay_task);
+ tmp->send_delay_task = NULL;
+ }
+ GNUNET_free(tmp);
return GNUNET_OK;
}
+
/**
* Notify manipulation about disconnect so it can discard queued messages
*
* @param peer the disconnecting peer
*/
void
-GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer)
+GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer)
{
struct TM_Peer *tmp;
struct DelayQueueEntry *dqe;
struct DelayQueueEntry *next;
if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer)))
+ {
+ while (NULL != (dqe = tmp->send_head))
{
- next = tmp->send_head;
- while (NULL != (dqe = next))
- {
- next = dqe->next;
- GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe);
- if (NULL != dqe->cont)
- dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0);
- GNUNET_free(dqe);
- }
+ GNUNET_CONTAINER_DLL_remove (tmp->send_head,
+ tmp->send_tail,
+ dqe);
+ if (NULL != dqe->cont)
+ dqe->cont (dqe->cont_cls,
+ GNUNET_SYSERR,
+ dqe->msg_size,
+ 0);
+ GNUNET_free(dqe);
}
- else if (UINT32_MAX
- != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY,
- TM_SEND))
+ }
+ else if (UINT32_MAX != find_metric (&man_handle.general,
+ GNUNET_ATS_QUALITY_NET_DELAY,
+ TM_SEND))
+ {
+ next = generic_dqe_head;
+ while (NULL != (dqe = next))
{
- next = generic_dqe_head;
- while (NULL != (dqe = next))
- {
- next = dqe->next;
- if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id)))
- {
- GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail,
- dqe);
- if (NULL != dqe->cont)
- dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0);
- GNUNET_free(dqe);
- }
- }
- if (NULL != generic_send_delay_task)
- {
- GNUNET_SCHEDULER_cancel(generic_send_delay_task);
- generic_send_delay_task = NULL;
- if (NULL != generic_dqe_head)
- generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at),
- &send_delayed, generic_dqe_head);
- }
+ next = dqe->next;
+ if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id)))
+ {
+ GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
+ generic_dqe_tail,
+ dqe);
+ if (NULL != dqe->cont)
+ dqe->cont (dqe->cont_cls,
+ GNUNET_SYSERR,
+ dqe->msg_size,
+ 0);
+ GNUNET_free(dqe);
+ }
+ }
+ if (NULL != generic_send_delay_task)
+ {
+ GNUNET_SCHEDULER_cancel (generic_send_delay_task);
+ generic_send_delay_task = NULL;
+ if (NULL != generic_dqe_head)
+ generic_send_delay_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at),
+ &send_delayed,
+ generic_dqe_head);
}
+ }
}
+
/**
* Stop traffic manipulation
*/
@@ -718,26 +776,30 @@ void
GST_manipulation_stop()
{
struct DelayQueueEntry *cur;
- struct DelayQueueEntry *next;
- GNUNET_CONTAINER_multipeermap_iterate(man_handle.peers, &free_tmps, NULL);
- GNUNET_CONTAINER_multipeermap_destroy(man_handle.peers);
- next = generic_dqe_head;
- while (NULL != (cur = next))
- {
- next = cur->next;
- GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail, cur);
- if (NULL != cur->cont)
- cur->cont(cur->cont_cls, GNUNET_SYSERR, cur->msg_size, 0);
- GNUNET_free(cur);
- }
- if (NULL != generic_send_delay_task)
- {
- GNUNET_SCHEDULER_cancel(generic_send_delay_task);
- generic_send_delay_task = NULL;
- }
+ GNUNET_CONTAINER_multipeermap_iterate (man_handle.peers,
+ &free_tmps,
+ NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (man_handle.peers);
- free_metric(&man_handle.general);
+ while (NULL != (cur = generic_dqe_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
+ generic_dqe_tail,
+ cur);
+ if (NULL != cur->cont)
+ cur->cont (cur->cont_cls,
+ GNUNET_SYSERR,
+ cur->msg_size,
+ 0);
+ GNUNET_free (cur);
+ }
+ if (NULL != generic_send_delay_task)
+ {
+ GNUNET_SCHEDULER_cancel (generic_send_delay_task);
+ generic_send_delay_task = NULL;
+ }
+ free_metric (&man_handle.general);
man_handle.peers = NULL;
}
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 9316169a1..5cfb5ed6d 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1034,7 +1034,7 @@ send_with_session (struct NeighbourMapEntry *n,
struct GNUNET_TRANSPORT_PluginFunctions *papi;
struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_assert (n->primary_address.session != NULL);
+ GNUNET_assert (NULL != n->primary_address.session);
if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) ||
(-1 == papi->send (papi->cls,
n->primary_address.session,
@@ -1561,7 +1561,8 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
: (uint32_t) latency.rel_value_us );
GST_ats_update_metrics (n->primary_address.address,
n->primary_address.session,
- &ats, 1);
+ &ats,
+ 1);
}
@@ -1680,14 +1681,20 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
{
GNUNET_break (0);
if (NULL != cont)
- cont (cont_cls, GNUNET_SYSERR, msg_size, 0);
+ cont (cont_cls,
+ GNUNET_SYSERR,
+ msg_size,
+ 0);
return;
}
if (GNUNET_YES != test_connected (n))
{
GNUNET_break (0);
if (NULL != cont)
- cont (cont_cls, GNUNET_SYSERR, msg_size, 0);
+ cont (cont_cls,
+ GNUNET_SYSERR,
+ msg_size,
+ 0);
return;
}
bytes_in_send_queue += msg_size;
@@ -1703,10 +1710,13 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
mq->message_buf_size = msg_size;
mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enqueueing %u bytes to send to peer %s\n",
- msg_size, GNUNET_i2s (target));
-
- GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Enqueueing %u bytes to send to peer %s\n",
+ msg_size,
+ GNUNET_i2s (target));
+ GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
+ n->messages_tail,
+ mq);
if (NULL != n->task)
GNUNET_SCHEDULER_cancel (n->task);
n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
@@ -2814,7 +2824,7 @@ send_utilization_data (void *cls,
void *value)
{
struct NeighbourMapEntry *n = value;
- struct GNUNET_ATS_Information atsi[4];
+ struct GNUNET_ATS_Information atsi[2];
uint32_t bps_in;
uint32_t bps_out;
struct GNUNET_TIME_Relative delta;
@@ -2842,7 +2852,8 @@ send_utilization_data (void *cls,
atsi[1].value = htonl (bps_in);
GST_ats_update_metrics (n->primary_address.address,
n->primary_address.session,
- atsi, 2);
+ atsi,
+ 2);
n->util_total_bytes_recv = 0;
n->util_total_bytes_sent = 0;
n->last_util_transmission = GNUNET_TIME_absolute_get ();
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index 79f7f4ddd..1571cee71 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet-service-transport.h"
#include "gnunet-service-transport_hello.h"
+#include "gnunet-service-transport_ats.h"
#include "gnunet-service-transport_plugins.h"
/**
@@ -79,6 +80,53 @@ static struct TransportPlugin *plugins_tail;
/**
+ * Function that will be called to update metrics for an address
+ *
+ * @param cls closure
+ * @param address address to update metrics for
+ * @param session the session
+ * @param ats the ats information to update
+ * @param ats_count the number of @a ats elements
+ */
+static void
+plugin_env_update_metrics (void *cls,
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
+{
+ GST_ats_update_metrics (address,
+ session,
+ ats, ats_count);
+}
+
+
+/**
+ * Function that will be called to figure if an address is an loopback,
+ * LAN, WAN etc. address
+ *
+ * @param cls closure
+ * @param addr binary address
+ * @param addrlen length of the @a addr
+ * @return type of the network @a addr belongs to
+ */
+static enum GNUNET_ATS_Network_Type
+plugin_env_address_to_type (void *cls,
+ const struct sockaddr *addr,
+ size_t addrlen)
+{
+ if (NULL == GST_is)
+ {
+ GNUNET_break(0);
+ return GNUNET_ATS_NET_UNSPECIFIED;
+ }
+ return GNUNET_ATS_scanner_address_get_type (GST_is,
+ addr,
+ addrlen);
+}
+
+
+/**
* Load and initialize all plugins. The respective functions will be
* invoked by the plugins when the respective events happen. The
* closure will be set to a 'const char*' containing the name of the
@@ -89,15 +137,12 @@ static struct TransportPlugin *plugins_tail;
* @param session_start_cb function to call when a session was created
* @param session_end_cb function to call when a session was terminated
* @param address_type_cb function to call when a address type is requested
- * @param metric_update_cb function to call when address metrics change
*/
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
GNUNET_TRANSPORT_SessionStart session_start_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb,
- GNUNET_TRANSPORT_AddressToType address_type_cb,
- GNUNET_TRANSPORT_UpdateAddressMetrics metric_update_cb)
+ GNUNET_TRANSPORT_SessionEnd session_end_cb)
{
struct TransportPlugin *plug;
struct TransportPlugin *next;
@@ -145,8 +190,8 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
plug->env.notify_address = address_cb;
plug->env.session_start = session_start_cb;
plug->env.session_end = session_end_cb;
- plug->env.get_address_type = address_type_cb;
- plug->env.update_address_metrics = metric_update_cb;
+ plug->env.get_address_type = &plugin_env_address_to_type;
+ plug->env.update_address_metrics = &plugin_env_update_metrics;
plug->env.max_connections = tneigh;
plug->env.stats = GST_stats;
GNUNET_CONTAINER_DLL_insert (plugins_head,
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index 461394f7e..006945678 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -52,9 +52,7 @@ void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
GNUNET_TRANSPORT_SessionStart session_start_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb,
- GNUNET_TRANSPORT_AddressToType address_type_cb,
- GNUNET_TRANSPORT_UpdateAddressMetrics metric_update_cb);
+ GNUNET_TRANSPORT_SessionEnd session_end_cb);
/**
* Unload all plugins
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index cd5a87696..d8966f1a4 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1473,7 +1473,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
ats[1].value = htonl ((uint32_t) ve->network);
if (GNUNET_YES == ve->known_to_ats)
{
- GST_ats_update_metrics (ve->address, NULL, ats, 2);
+ GST_ats_update_metrics (ve->address,
+ NULL,
+ ats,
+ 2);
}
else
{
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 9dc2d114f..6e994d467 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -1884,13 +1884,13 @@ client_connect (struct Session *s)
return GNUNET_SYSERR;
}
- GNUNET_asprintf(&s->url,
- "%s/%s;%u",
- http_common_plugin_address_to_url(NULL,
- s->address->address,
- s->address->address_length),
- GNUNET_i2s_full (plugin->env->my_identity),
- plugin->last_tag);
+ GNUNET_asprintf (&s->url,
+ "%s/%s;%u",
+ http_common_plugin_address_to_url (NULL,
+ s->address->address,
+ s->address->address_length),
+ GNUNET_i2s_full (plugin->env->my_identity),
+ plugin->last_tag);
plugin->last_tag++;
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1911,21 +1911,23 @@ client_connect (struct Session *s)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: connected with GET %p and PUT %p\n",
- s, s->get.easyhandle, s->put.easyhandle);
+ s, s->get.easyhandle,
+ s->put.easyhandle);
/* Perform connect */
GNUNET_STATISTICS_set (plugin->env->stats,
HTTP_STAT_STR_CONNECTIONS,
plugin->cur_requests,
GNUNET_NO);
/* Re-schedule since handles have changed */
- if (plugin->client_perform_task != NULL)
+ if (NULL != plugin->client_perform_task)
{
GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
plugin->client_perform_task = NULL;
}
/* Schedule task to run immediately */
- plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin);
+ plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run,
+ plugin);
return res;
}
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index f95e11f80..5396d5247 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -269,7 +269,7 @@ struct Session
/**
* Task cleaning up a NAT client connection establishment attempt;
*/
- struct GNUNET_SCHEDULER_Task * nat_connection_timeout;
+ struct GNUNET_SCHEDULER_Task *nat_connection_timeout;
/**
* Messages currently pending for transmission
@@ -296,12 +296,12 @@ struct Session
/**
* ID of task used to delay receiving more to throttle sender.
*/
- struct GNUNET_SCHEDULER_Task * receive_delay_task;
+ struct GNUNET_SCHEDULER_Task *receive_delay_task;
/**
* Session timeout task
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* When will this session time out?
@@ -891,7 +891,7 @@ tcp_plugin_disconnect_session (void *cls,
session,
GNUNET_TRANSPORT_SS_DONE);
- if (session->receive_delay_task != NULL)
+ if (NULL != session->receive_delay_task)
{
GNUNET_SCHEDULER_cancel (session->receive_delay_task);
if (NULL != session->client)
@@ -1101,8 +1101,8 @@ do_transmit (void *cls, size_t size, void *buf)
tl = NULL;
ret = 0;
now = GNUNET_TIME_absolute_get ();
- while ((NULL != (pos = session->pending_messages_head))
- && (pos->timeout.abs_value_us <= now.abs_value_us))
+ while ( (NULL != (pos = session->pending_messages_head)) &&
+ (pos->timeout.abs_value_us <= now.abs_value_us) )
{
GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
session->pending_messages_tail,
@@ -1116,7 +1116,10 @@ do_transmit (void *cls, size_t size, void *buf)
pos->message_size,
GNUNET_i2s (&session->target));
ret += pos->message_size;
- GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
+ GNUNET_CONTAINER_DLL_insert_after (hd,
+ tl,
+ tl,
+ pos);
}
/* do this call before callbacks (so that if callbacks destroy
* session, they have a chance to cancel actions done by this
@@ -1127,12 +1130,15 @@ do_transmit (void *cls, size_t size, void *buf)
* the callbacks may abort the session */
while (NULL != (pos = hd))
{
- GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
- if (pos->transmit_cont != NULL)
+ GNUNET_CONTAINER_DLL_remove (hd,
+ tl,
+ pos);
+ if (NULL != pos->transmit_cont)
pos->transmit_cont (pos->transmit_cont_cls,
&pid,
GNUNET_SYSERR,
- pos->message_size, 0);
+ pos->message_size,
+ 0);
GNUNET_free (pos);
}
GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1165,19 +1171,23 @@ do_transmit (void *cls, size_t size, void *buf)
GNUNET_assert (pos->message_size <= session->bytes_in_queue);
session->bytes_in_queue -= pos->message_size;
GNUNET_assert(size >= pos->message_size);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message of type %u size %u to %s\n",
- ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
- pos->message_size,
- tcp_plugin_address_to_string (session->plugin,
- session->address->address,
- session->address->address_length));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting message of type %u size %u to %s\n",
+ ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
+ pos->message_size,
+ tcp_plugin_address_to_string (session->plugin,
+ session->address->address,
+ session->address->address_length));
/* FIXME: this memcpy can be up to 7% of our total runtime */
- memcpy (cbuf, pos->msg, pos->message_size);
+ memcpy (cbuf,
+ pos->msg,
+ pos->message_size);
cbuf += pos->message_size;
ret += pos->message_size;
size -= pos->message_size;
- GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
+ GNUNET_CONTAINER_DLL_insert_tail (hd,
+ tl,
+ pos);
}
notify_session_monitor (session->plugin,
session,
@@ -1193,19 +1203,19 @@ do_transmit (void *cls, size_t size, void *buf)
while (NULL != (pos = hd))
{
GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
- if (pos->transmit_cont != NULL)
+ if (NULL != pos->transmit_cont)
pos->transmit_cont (pos->transmit_cont_cls,
&pid,
GNUNET_OK,
pos->message_size,
pos->message_size); /* FIXME: include TCP overhead */
- GNUNET_free(pos);
+ GNUNET_free (pos);
}
GNUNET_assert (NULL == hd);
GNUNET_assert (NULL == tl);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u bytes\n",
- ret);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting %u bytes\n",
+ ret);
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# bytes currently in TCP buffers"),
- (int64_t) ret,
@@ -1294,7 +1304,8 @@ tcp_plugin_send (void *cls,
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Asked to transmit %u bytes to `%s', added message to list.\n",
- msgbuf_size, GNUNET_i2s (&session->target));
+ msgbuf_size,
+ GNUNET_i2s (&session->target));
if (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
@@ -1303,10 +1314,11 @@ tcp_plugin_send (void *cls,
{
GNUNET_assert (NULL != session->client);
GNUNET_SERVER_client_set_timeout (session->client,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size,
- GNUNET_NO);
+ gettext_noop ("# bytes currently in TCP buffers"),
+ msgbuf_size,
+ GNUNET_NO);
/* append pm to pending_messages list */
GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
@@ -1320,10 +1332,10 @@ tcp_plugin_send (void *cls,
process_pending_messages (session);
return msgbuf_size;
}
- else if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns,
- &session->target,
- session))
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns,
+ &session->target,
+ session))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"This NAT WAIT session for peer `%s' is not yet ready!\n",
@@ -1342,23 +1354,21 @@ tcp_plugin_send (void *cls,
GNUNET_TRANSPORT_SS_HANDSHAKE);
return msgbuf_size;
}
- else
- {
- LOG(GNUNET_ERROR_TYPE_ERROR,
- "Invalid session %p\n",
- session);
- if (NULL != cont)
- cont (cont_cls,
- &session->target,
- GNUNET_SYSERR,
- pm->message_size,
- 0);
- GNUNET_break (0);
- GNUNET_free (pm);
- return GNUNET_SYSERR; /* session does not exist here */
- }
+ LOG(GNUNET_ERROR_TYPE_ERROR,
+ "Invalid session %p\n",
+ session);
+ if (NULL != cont)
+ cont (cont_cls,
+ &session->target,
+ GNUNET_SYSERR,
+ pm->message_size,
+ 0);
+ GNUNET_break (0);
+ GNUNET_free (pm);
+ return GNUNET_SYSERR; /* session does not exist here */
}
+
/**
* Closure for #session_lookup_it().
*/
@@ -1390,12 +1400,13 @@ session_lookup_it (void *cls,
const struct GNUNET_PeerIdentity *key,
void *value)
{
- struct SessionItCtx * si_ctx = cls;
- struct Session * session = value;
+ struct SessionItCtx *si_ctx = cls;
+ struct Session *session = value;
- if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address))
+ if (0 !=
+ GNUNET_HELLO_address_cmp (si_ctx->address,
+ session->address))
return GNUNET_YES;
- /* Found existing session */
si_ctx->result = session;
return GNUNET_NO;
}
@@ -2273,12 +2284,16 @@ handle_tcp_welcome (void *cls,
sizeof(struct GNUNET_PeerIdentity)))
{
/* refuse connections from ourselves */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
+ if (GNUNET_OK ==
+ GNUNET_SERVER_client_get_address (client,
+ &vaddr,
+ &alen))
{
LOG (GNUNET_ERROR_TYPE_INFO,
- "Received %s message from my own identity `%4s' on address `%s'\n",
- "WELCOME", GNUNET_i2s (&wm->clientIdentity),
+ "Received WELCOME message from my own identity `%4s' on address `%s'\n",
+ GNUNET_i2s (&wm->clientIdentity),
GNUNET_a2s (vaddr, alen));
GNUNET_free(vaddr);
}
@@ -2286,9 +2301,9 @@ handle_tcp_welcome (void *cls,
}
LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received %s message from `%4s' %p\n",
- "WELCOME",
- GNUNET_i2s (&wm->clientIdentity), client);
+ "Received WELCOME message from `%4s' %p\n",
+ GNUNET_i2s (&wm->clientIdentity),
+ client);
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# TCP WELCOME messages received"),
1,
@@ -2296,7 +2311,8 @@ handle_tcp_welcome (void *cls,
session = lookup_session_by_client (plugin, client);
if (NULL != session)
{
- if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ if (GNUNET_OK ==
+ GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found existing session %p for peer `%s'\n",
@@ -2313,7 +2329,8 @@ handle_tcp_welcome (void *cls,
if (plugin->cur_connections == plugin->max_connections)
GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */
- if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ if (GNUNET_OK ==
+ GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
if (alen == sizeof(struct sockaddr_in))
{
@@ -2336,8 +2353,10 @@ handle_tcp_welcome (void *cls,
t6.t6_port = s6->sin6_port;
memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
- PLUGIN_NAME, &t6, sizeof (t6),
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ PLUGIN_NAME,
+ &t6,
+ sizeof (t6),
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND);
}
else
{
@@ -2345,9 +2364,15 @@ handle_tcp_welcome (void *cls,
GNUNET_free_non_null (vaddr);
return;
}
- session = create_session (plugin, address, client, GNUNET_NO);
+ session = create_session (plugin,
+ address,
+ client,
+ GNUNET_NO);
GNUNET_HELLO_address_free (address);
- session->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, vaddr, alen);
+ session->ats_address_network_type
+ = plugin->env->get_address_type (plugin->env->cls,
+ vaddr,
+ alen);
ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
ats.value = htonl (session->ats_address_network_type);
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2418,13 +2443,15 @@ handle_tcp_data (void *cls,
struct Session *session;
struct GNUNET_TIME_Relative delay;
uint16_t type;
+ struct GNUNET_ATS_Information distance;
type = ntohs (message->type);
- if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type)
- || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
+ if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
+ (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) )
{
/* We don't want to propagate WELCOME and NAT Probe messages up! */
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
return;
}
session = lookup_session_by_client (plugin, client);
@@ -2434,14 +2461,19 @@ handle_tcp_data (void *cls,
void *vaddr;
size_t alen;
- GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
- LOG(GNUNET_ERROR_TYPE_ERROR,
- "Received unexpected %u bytes of type %u from `%s'\n",
- (unsigned int) ntohs (message->size),
- (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen));
+ GNUNET_SERVER_client_get_address (client,
+ &vaddr,
+ &alen);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Received unexpected %u bytes of type %u from `%s'\n",
+ (unsigned int) ntohs (message->size),
+ (unsigned int) ntohs (message->type),
+ GNUNET_a2s (vaddr,
+ alen));
GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free_non_null(vaddr);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
+ GNUNET_free_non_null (vaddr);
return;
}
else if (GNUNET_YES == session->expecting_welcome)
@@ -2451,35 +2483,37 @@ handle_tcp_data (void *cls,
size_t alen;
GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
- LOG(GNUNET_ERROR_TYPE_ERROR,
- "Received unexpected %u bytes of type %u from `%s'\n",
- (unsigned int) ntohs (message->size),
- (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Received unexpected %u bytes of type %u from `%s'\n",
+ (unsigned int) ntohs (message->size),
+ (unsigned int) ntohs (message->type),
+ GNUNET_a2s (vaddr, alen));
GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free_non_null(vaddr);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
+ GNUNET_free_non_null (vaddr);
return;
}
session->last_activity = GNUNET_TIME_absolute_get ();
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Passing %u bytes of type %u from `%4s' to transport service.\n",
- (unsigned int) ntohs (message->size),
- (unsigned int) ntohs (message->type), GNUNET_i2s (&session->target));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Passing %u bytes of type %u from `%4s' to transport service.\n",
+ (unsigned int) ntohs (message->size),
+ (unsigned int) ntohs (message->type),
+ GNUNET_i2s (&session->target));
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes received via TCP"), ntohs (message->size),
- GNUNET_NO);
- struct GNUNET_ATS_Information distance;
+ gettext_noop ("# bytes received via TCP"),
+ ntohs (message->size),
+ GNUNET_NO);
distance.type = htonl (GNUNET_ATS_NETWORK_TYPE);
distance.value = htonl ((uint32_t) session->ats_address_network_type);
- GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
-
- GNUNET_assert(GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
- &session->target,
- session));
+ GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
+ GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
+ &session->target,
+ session));
delay = plugin->env->receive (plugin->env->cls,
session->address,
session,
@@ -2722,9 +2756,11 @@ 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) },
+ 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) },
+ 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 }
@@ -2936,8 +2972,11 @@ libgnunet_plugin_transport_tcp_init (void *cls)
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);
+ 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 (0 != bport)
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 0a8c3cab4..f185c8738 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -2265,13 +2265,17 @@ process_udp_message (struct Plugin *plugin,
udp_addr,
udp_addr_len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
+ if (NULL ==
+ (s = udp_plugin_lookup_session (plugin, address)))
{
s = udp_plugin_create_session (plugin,
address,
network_type);
plugin->env->session_start (plugin->env->cls,
- address, s, NULL, 0);
+ address,
+ s,
+ NULL,
+ 0);
notify_session_monitor (s->plugin,
s,
GNUNET_TRANSPORT_SS_INIT);
@@ -3566,9 +3570,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
p->defrag_ctxs = GNUNET_CONTAINER_heap_create (
GNUNET_CONTAINER_HEAP_ORDER_MIN);
- p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p);
- GNUNET_BANDWIDTH_tracker_init (&p->tracker, NULL, NULL,
- GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30);
+ p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
+ p);
+ GNUNET_BANDWIDTH_tracker_init (&p->tracker,
+ NULL,
+ NULL,
+ GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps),
+ 30);
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Setting up sockets\n");
res = setup_sockets (p,