summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-02 00:05:42 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-02 00:05:42 +0000
commit87d015d6fb1a435d5d5b6ff62983fce6ba4cf2ef (patch)
tree8eae192cf4281ab6687d437a7f18053a8944df6c
parent4bee6d11ba8ac5554e906d60b0fce0ed2a737a97 (diff)
define quota message to transmit quota requests, towards addressing #3652
-rw-r--r--src/include/gnunet_protocols.h7
-rw-r--r--src/transport/gnunet-service-transport.c4
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c78
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h12
4 files changed, 97 insertions, 4 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 37e08f1c2..8553e6ab7 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1286,6 +1286,13 @@ extern "C"
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 378
/**
+ * Message exchanged between transport services to
+ * indicate that the sender should limit its transmission
+ * rate to the indicated quota.
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA 379
+
+/**
* Request to monitor addresses used by a peer or all peers.
*/
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST 380
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 96f1489da..49a6d9abd 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -462,6 +462,10 @@ GST_receive_callback (void *cls,
GST_neighbours_handle_disconnect_message (&address->peer,
message);
break;
+ case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
+ GST_neighbours_handle_quota_message (&address->peer,
+ message);
+ break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
GST_neighbours_keepalive (&address->peer,
message);
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 17e30c0b7..9ce06d1b5 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -157,6 +157,26 @@ struct SessionKeepAliveMessage
uint32_t nonce GNUNET_PACKED;
};
+
+/**
+ * Message a peer sends to another when connected to indicate that
+ * the other peer should limit transmissions to the indicated
+ * quota.
+ */
+struct SessionQuotaMessage
+{
+ /**
+ * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Quota to use (for sending), in bytes per second.
+ */
+ uint32_t quota GNUNET_PACKED;
+};
+
+
/**
* Message we send to the other peer to notify him that we intentionally
* are disconnecting (to reduce timeouts). This is just a friendly
@@ -336,7 +356,7 @@ struct NeighbourMapEntry
/**
* Main task that drives this peer (timeouts, keepalives, etc.).
- * Always runs the 'master_task'.
+ * Always runs the #master_task().
*/
struct GNUNET_SCHEDULER_Task *task;
@@ -388,6 +408,14 @@ struct NeighbourMapEntry
unsigned int quota_violation_count;
/**
+ * Latest quota the other peer send us in bytes per second.
+ * We should not send more, least the other peer throttle
+ * receiving our traffic.
+ * FIXME: Not used (#3652).
+ */
+ unsigned int neighbour_receive_quota;
+
+ /**
* The current state of the peer.
*/
enum GNUNET_TRANSPORT_PeerState state;
@@ -2296,7 +2324,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
* We received a 'SYN' message from the other peer.
* Consider switching to it.
*
- * @param message possibly a 'struct TransportSynMessage' (check format)
+ * @param message possibly a `struct TransportSynMessage` (check format)
* @param peer identity of the peer to switch the address for
* @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
@@ -3589,6 +3617,47 @@ delayed_disconnect (void *cls,
/**
+ * We received a quoat message from the given peer,
+ * validate and process.
+ *
+ * @param peer sender of the message
+ * @param msg the quota message
+ */
+void
+GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *msg)
+{
+ struct NeighbourMapEntry *n;
+ const struct SessionQuotaMessage *sqm;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received QUOTA message from peer `%s'\n",
+ GNUNET_i2s (peer));
+ if (ntohs (msg->size) != sizeof (struct SessionQuotaMessage))
+ {
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop ("# quota messages ignored (malformed)"),
+ 1,
+ GNUNET_NO);
+ return;
+ }
+ GNUNET_STATISTICS_update (GST_stats,
+ gettext_noop
+ ("# QUOTA messages received"),
+ 1, GNUNET_NO);
+ sqm = (const struct SessionQuotaMessage *) msg;
+ if (NULL == (n = lookup_neighbour (peer)))
+ {
+ /* gone already */
+ return;
+ }
+ n->neighbour_receive_quota = ntohl (sqm->quota);
+ /* FIXME: tell someone? (#3652) */
+}
+
+
+/**
* We received a disconnect message from the given peer,
* validate and process.
*
@@ -3602,7 +3671,7 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
struct NeighbourMapEntry *n;
const struct SessionDisconnectMessage *sdm;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received DISCONNECT message from peer `%s'\n",
GNUNET_i2s (peer));
if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
@@ -3610,7 +3679,8 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
GNUNET_break_op (0);
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
- ("# disconnect messages ignored (malformed)"), 1,
+ ("# disconnect messages ignored (malformed)"),
+ 1,
GNUNET_NO);
return;
}
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 070ee01a9..c92209d81 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -307,6 +307,18 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
/**
+ * We received a quoat message from the given peer,
+ * validate and process.
+ *
+ * @param peer sender of the message
+ * @param msg the quota message
+ */
+void
+GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *msg);
+
+
+/**
* We received a disconnect message from the given peer,
* validate and process.
*