diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-03-02 00:05:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-03-02 00:05:42 +0000 |
commit | 87d015d6fb1a435d5d5b6ff62983fce6ba4cf2ef (patch) | |
tree | 8eae192cf4281ab6687d437a7f18053a8944df6c /src/transport/gnunet-service-transport_neighbours.c | |
parent | 4bee6d11ba8ac5554e906d60b0fce0ed2a737a97 (diff) | |
download | gnunet-87d015d6fb1a435d5d5b6ff62983fce6ba4cf2ef.tar.gz gnunet-87d015d6fb1a435d5d5b6ff62983fce6ba4cf2ef.zip |
define quota message to transmit quota requests, towards addressing #3652
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 78 |
1 files changed, 74 insertions, 4 deletions
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 | |||
157 | uint32_t nonce GNUNET_PACKED; | 157 | uint32_t nonce GNUNET_PACKED; |
158 | }; | 158 | }; |
159 | 159 | ||
160 | |||
161 | /** | ||
162 | * Message a peer sends to another when connected to indicate that | ||
163 | * the other peer should limit transmissions to the indicated | ||
164 | * quota. | ||
165 | */ | ||
166 | struct SessionQuotaMessage | ||
167 | { | ||
168 | /** | ||
169 | * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA. | ||
170 | */ | ||
171 | struct GNUNET_MessageHeader header; | ||
172 | |||
173 | /** | ||
174 | * Quota to use (for sending), in bytes per second. | ||
175 | */ | ||
176 | uint32_t quota GNUNET_PACKED; | ||
177 | }; | ||
178 | |||
179 | |||
160 | /** | 180 | /** |
161 | * Message we send to the other peer to notify him that we intentionally | 181 | * Message we send to the other peer to notify him that we intentionally |
162 | * are disconnecting (to reduce timeouts). This is just a friendly | 182 | * are disconnecting (to reduce timeouts). This is just a friendly |
@@ -336,7 +356,7 @@ struct NeighbourMapEntry | |||
336 | 356 | ||
337 | /** | 357 | /** |
338 | * Main task that drives this peer (timeouts, keepalives, etc.). | 358 | * Main task that drives this peer (timeouts, keepalives, etc.). |
339 | * Always runs the 'master_task'. | 359 | * Always runs the #master_task(). |
340 | */ | 360 | */ |
341 | struct GNUNET_SCHEDULER_Task *task; | 361 | struct GNUNET_SCHEDULER_Task *task; |
342 | 362 | ||
@@ -388,6 +408,14 @@ struct NeighbourMapEntry | |||
388 | unsigned int quota_violation_count; | 408 | unsigned int quota_violation_count; |
389 | 409 | ||
390 | /** | 410 | /** |
411 | * Latest quota the other peer send us in bytes per second. | ||
412 | * We should not send more, least the other peer throttle | ||
413 | * receiving our traffic. | ||
414 | * FIXME: Not used (#3652). | ||
415 | */ | ||
416 | unsigned int neighbour_receive_quota; | ||
417 | |||
418 | /** | ||
391 | * The current state of the peer. | 419 | * The current state of the peer. |
392 | */ | 420 | */ |
393 | enum GNUNET_TRANSPORT_PeerState state; | 421 | enum GNUNET_TRANSPORT_PeerState state; |
@@ -2296,7 +2324,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
2296 | * We received a 'SYN' message from the other peer. | 2324 | * We received a 'SYN' message from the other peer. |
2297 | * Consider switching to it. | 2325 | * Consider switching to it. |
2298 | * | 2326 | * |
2299 | * @param message possibly a 'struct TransportSynMessage' (check format) | 2327 | * @param message possibly a `struct TransportSynMessage` (check format) |
2300 | * @param peer identity of the peer to switch the address for | 2328 | * @param peer identity of the peer to switch the address for |
2301 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error | 2329 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error |
2302 | */ | 2330 | */ |
@@ -3589,6 +3617,47 @@ delayed_disconnect (void *cls, | |||
3589 | 3617 | ||
3590 | 3618 | ||
3591 | /** | 3619 | /** |
3620 | * We received a quoat message from the given peer, | ||
3621 | * validate and process. | ||
3622 | * | ||
3623 | * @param peer sender of the message | ||
3624 | * @param msg the quota message | ||
3625 | */ | ||
3626 | void | ||
3627 | GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, | ||
3628 | const struct GNUNET_MessageHeader *msg) | ||
3629 | { | ||
3630 | struct NeighbourMapEntry *n; | ||
3631 | const struct SessionQuotaMessage *sqm; | ||
3632 | |||
3633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3634 | "Received QUOTA message from peer `%s'\n", | ||
3635 | GNUNET_i2s (peer)); | ||
3636 | if (ntohs (msg->size) != sizeof (struct SessionQuotaMessage)) | ||
3637 | { | ||
3638 | GNUNET_break_op (0); | ||
3639 | GNUNET_STATISTICS_update (GST_stats, | ||
3640 | gettext_noop ("# quota messages ignored (malformed)"), | ||
3641 | 1, | ||
3642 | GNUNET_NO); | ||
3643 | return; | ||
3644 | } | ||
3645 | GNUNET_STATISTICS_update (GST_stats, | ||
3646 | gettext_noop | ||
3647 | ("# QUOTA messages received"), | ||
3648 | 1, GNUNET_NO); | ||
3649 | sqm = (const struct SessionQuotaMessage *) msg; | ||
3650 | if (NULL == (n = lookup_neighbour (peer))) | ||
3651 | { | ||
3652 | /* gone already */ | ||
3653 | return; | ||
3654 | } | ||
3655 | n->neighbour_receive_quota = ntohl (sqm->quota); | ||
3656 | /* FIXME: tell someone? (#3652) */ | ||
3657 | } | ||
3658 | |||
3659 | |||
3660 | /** | ||
3592 | * We received a disconnect message from the given peer, | 3661 | * We received a disconnect message from the given peer, |
3593 | * validate and process. | 3662 | * validate and process. |
3594 | * | 3663 | * |
@@ -3602,7 +3671,7 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer | |||
3602 | struct NeighbourMapEntry *n; | 3671 | struct NeighbourMapEntry *n; |
3603 | const struct SessionDisconnectMessage *sdm; | 3672 | const struct SessionDisconnectMessage *sdm; |
3604 | 3673 | ||
3605 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3606 | "Received DISCONNECT message from peer `%s'\n", | 3675 | "Received DISCONNECT message from peer `%s'\n", |
3607 | GNUNET_i2s (peer)); | 3676 | GNUNET_i2s (peer)); |
3608 | if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) | 3677 | if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) |
@@ -3610,7 +3679,8 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer | |||
3610 | GNUNET_break_op (0); | 3679 | GNUNET_break_op (0); |
3611 | GNUNET_STATISTICS_update (GST_stats, | 3680 | GNUNET_STATISTICS_update (GST_stats, |
3612 | gettext_noop | 3681 | gettext_noop |
3613 | ("# disconnect messages ignored (malformed)"), 1, | 3682 | ("# disconnect messages ignored (malformed)"), |
3683 | 1, | ||
3614 | GNUNET_NO); | 3684 | GNUNET_NO); |
3615 | return; | 3685 | return; |
3616 | } | 3686 | } |