#include "platform.h"
#include "gnunet_ats_service.h"
#include "gnunet-service-transport_ats.h"
-#include "gnunet-service-transport_blacklist.h"
-#include "gnunet-service-transport_clients.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_manipulation.h"
#include "gnunet-service-transport_plugins.h"
}
+/**
+ * Send information about a new outbound quota to our clients.
+ * Note that the outbound quota is enforced client-side (i.e.
+ * in libgnunettransport).
+ *
+ * @param n affected peer
+ */
+static void
+send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
+{
+ struct QuotaSetMessage q_msg;
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
+
+ if (! GNUNET_TRANSPORT_is_connected (n->state))
+ return;
+#if IGNORE_INBOUND_QUOTA
+ bandwidth_min = n->primary_address.bandwidth_out;
+#else
+ bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
+ n->neighbour_receive_quota);
+#endif
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
+ ntohl (bandwidth_min.value__),
+ GNUNET_i2s (&n->id));
+ q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
+ q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
+ q_msg.quota = bandwidth_min;
+ q_msg.peer = n->id;
+ GST_clients_broadcast (&q_msg.header,
+ GNUNET_NO);
+}
+
+
/**
* Notify our clients that another peer connected to us.
*
}
-/**
- * Send information about a new outbound quota to our clients.
- * Note that the outbound quota is enforced client-side (i.e.
- * in libgnunettransport).
- *
- * @param n affected peer
- */
-static void
-send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
-{
- struct QuotaSetMessage q_msg;
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
-
- if (! GNUNET_TRANSPORT_is_connected (n->state))
- return;
-#if IGNORE_INBOUND_QUOTA
- bandwidth_min = n->primary_address.bandwidth_out;
-#else
- bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
- n->neighbour_receive_quota);
-#endif
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
- ntohl (bandwidth_min.value__),
- GNUNET_i2s (&n->id));
- q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
- q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
- q_msg.quota = bandwidth_min;
- q_msg.peer = n->id;
- GST_clients_broadcast (&q_msg.header, GNUNET_NO);
-}
-
-
/**
* We don't need a given neighbour address any more.
* Release its resources and give appropriate notifications
{
/* new timeout is earlier, reschedule master task */
GNUNET_SCHEDULER_cancel (n->task);
- n->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (timeout),
- &master_task,
- n);
+ n->task = GNUNET_SCHEDULER_add_at (timeout,
+ &master_task,
+ n);
}
n->timeout = timeout;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
sqm.header.size = htons (sizeof (struct GNUNET_ATS_SessionQuotaMessage));
sqm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA);
sqm.quota = quota.value__;
- (void) send_with_session (n,
- &sqm,
- sizeof (sqm),
- UINT32_MAX - 1,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- NULL, NULL);
+ if (NULL != n->primary_address.session)
+ (void) send_with_session (n,
+ &sqm,
+ sizeof (sqm),
+ UINT32_MAX - 1,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO,
+ NULL, NULL);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Disconnecting peer `%4s' due to SET_QUOTA\n",
+ "Disconnecting peer `%s' due to SET_QUOTA\n",
GNUNET_i2s (&n->id));
if (GNUNET_YES == test_connected (n))
GNUNET_STATISTICS_update (GST_stats,
if (bytes_in_send_queue < mq->message_buf_size)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n",
+ "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n",
bytes_in_send_queue,
- mq->message_buf_size,
+ (unsigned int) mq->message_buf_size,
(GNUNET_OK == success) ? "OK" : "FAIL",
- size_payload,
- physical);
+ (unsigned int) size_payload,
+ (unsigned int) physical);
GNUNET_break (0);
}
"Sending message to `%s' of type %u with %u bytes was a %s\n",
GNUNET_i2s (receiver),
ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
- mq->message_buf_size,
+ (unsigned int) mq->message_buf_size,
(success == GNUNET_OK) ? "success" : "FAILURE");
if (NULL != mq->cont)
mq->cont (mq->cont_cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Giving message with %u bytes to plugin session %p\n",
- mq->message_buf_size,
+ (unsigned int) mq->message_buf_size,
n->primary_address.session);
(void) send_with_session (n,
mq->message_buf,
mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
mq->cont = cont;
mq->cont_cls = cont_cls;
- memcpy (&mq[1], msg, msg_size);
+ GNUNET_memcpy (&mq[1], msg, msg_size);
mq->message_buf = (const char *) &mq[1];
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,
+ (unsigned int) msg_size,
GNUNET_i2s (target));
GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
n->messages_tail,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New inbound delay for peer `%s' is %llu ms\n",
GNUNET_i2s (&n->id),
- delay.rel_value_us / 1000);
+ (unsigned long long) delay.rel_value_us / 1000LL);
papi->update_inbound_delay (papi->cls,
&n->id,
n->primary_address.session,
{
struct NeighbourMapEntry *n;
+ if (0 ==
+ memcmp (&GST_my_identity,
+ peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cowardly refusing to consider myself my neighbour!\n");
+ return NULL;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating new neighbour entry for `%s'\n",
GNUNET_i2s (peer));
- GNUNET_assert (0 !=
- memcmp (&GST_my_identity,
- peer,
- sizeof (struct GNUNET_PeerIdentity)));
n = GNUNET_new (struct NeighbourMapEntry);
n->id = *peer;
n->ack_state = ACK_UNDEFINED;
scm = (const struct TransportSynMessage *) message;
GNUNET_break_op (0 == ntohl (scm->reserved));
ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
+ if (0 ==
+ memcmp (&GST_my_identity,
+ peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* loopback connection-to-self, ignore */
+ return GNUNET_SYSERR;
+ }
n = lookup_neighbour (peer);
if (NULL == n)
{
/* This is a new neighbour and set to not connected */
n = setup_neighbour (peer);
+ GNUNET_assert (NULL != n);
}
/* Remember this SYN message in neighbour */
/* Get rid of remains and re-try */
free_neighbour (n);
n = setup_neighbour (peer);
+ GNUNET_assert (NULL != n);
/* Remember the SYN time stamp for ACK message */
n->ack_state = ACK_SEND_SYN_ACK;
n->connect_ack_timestamp = ts;
if (NULL == (n = lookup_neighbour (peer)))
{
n = setup_neighbour (peer);
+ if (NULL == n)
+ {
+ /* not sure how this can happen... */
+ GNUNET_break (0);
+ goto cleanup;
+ }
n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
}
/* The session used to send the SYN terminated:
* this implies a connect error*/
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to send SYN in %s with `%s' %p: session terminated\n",
- "CONNECT_SENT",
+ "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n",
GST_plugins_a2s (n->primary_address.address),
- n->primary_address.session,
- GNUNET_i2s (peer));
+ n->primary_address.session);
/* Destroy the address since it cannot be used */
unset_primary_address (n);
break;
case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to send SYN in %s with `%s' %p: session terminated\n",
- "RECONNECT_SENT",
+ "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n",
GST_plugins_a2s (n->primary_address.address),
- n->primary_address.session,
- GNUNET_i2s (peer));
+ n->primary_address.session);
/* Destroy the address since it cannot be used */
unset_primary_address (n);
set_state_and_timeout (n,