const struct GNUNET_PeerIdentity *target);
-/**
- * Set the share of incoming/outgoing bandwidth for the given
- * peer to the specified amount.
- *
- * @param handle connection to transport service
- * @param target who's bandwidth quota is being changed
- * @param quota_in incoming bandwidth quota
- * @param quota_out outgoing bandwidth quota
- */
-void
-GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target,
- struct GNUNET_BANDWIDTH_Value32NBO quota_in,
- struct GNUNET_BANDWIDTH_Value32NBO quota_out);
-
-
/**
* Opaque handle for a transmission-ready request.
*/
}
-/**
- * Client asked for a quota change for a particular peer. Process the request.
- *
- * @param cls unused
- * @param client the client
- * @param message the quota changing message
- */
-static void
-clients_handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct QuotaSetMessage *qsm;
-
- qsm = (const struct QuotaSetMessage *) message;
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# SET QUOTA messages received"), 1,
- GNUNET_NO);
-#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' request (new quota %u) from client for peer `%4s'\n",
- "SET_QUOTA", (unsigned int) ntohl (qsm->quota.value__),
- GNUNET_i2s (&qsm->peer));
-#endif
- GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
/**
* Take the given address and append it to the set of results sent back to
* the client.
{&clients_handle_request_connect, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
sizeof (struct TransportRequestConnectMessage)},
- {&clients_handle_set_quota, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
{&clients_handle_address_lookup, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
{&clients_handle_peer_address_lookup, NULL,
}
-/**
- * Closure for 'send_set_quota'.
- */
-struct SetQuotaContext
-{
-
- /**
- * Identity of the peer impacted by the quota change.
- */
- struct GNUNET_PeerIdentity target;
-
- /**
- * Quota to transmit.
- */
- struct GNUNET_BANDWIDTH_Value32NBO quota_in;
-};
-
-
-/**
- * Send SET_QUOTA message to the service.
- *
- * @param cls the 'struct SetQuotaContext'
- * @param size number of bytes available in buf
- * @param buf where to copy the message
- * @return number of bytes copied to buf
- */
-static size_t
-send_set_quota (void *cls, size_t size, void *buf)
-{
- struct SetQuotaContext *sqc = cls;
- struct QuotaSetMessage msg;
-
- if (buf == NULL)
- {
- GNUNET_free (sqc);
- return 0;
- }
-#if DEBUG_TRANSPORT_API
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request with respect to `%4s'.\n", "SET_QUOTA",
- GNUNET_i2s (&sqc->target));
-#endif
- GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
- msg.header.size = htons (sizeof (struct QuotaSetMessage));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
- msg.quota = sqc->quota_in;
- msg.peer = sqc->target;
- memcpy (buf, &msg, sizeof (msg));
- GNUNET_free (sqc);
- return sizeof (struct QuotaSetMessage);
-}
-
-
-/**
- * Set the share of incoming bandwidth for the given
- * peer to the specified amount.
- *
- * @param handle connection to transport service
- * @param target who's bandwidth quota is being changed
- * @param quota_in incoming bandwidth quota in bytes per ms
- * @param quota_out outgoing bandwidth quota in bytes per ms
- */
-void
-GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target,
- struct GNUNET_BANDWIDTH_Value32NBO quota_in,
- struct GNUNET_BANDWIDTH_Value32NBO quota_out)
-{
- struct Neighbour *n;
- struct SetQuotaContext *sqc;
-
- n = neighbour_find (handle, target);
- if (NULL == n)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Quota changed to %u for peer `%s', but I have no such neighbour!\n",
- (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
- return;
- }
- GNUNET_assert (NULL != handle->client);
-#if DEBUG_TRANSPORT_API
- if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota changed from %u to %u for peer `%s'\n",
- (unsigned int) n->out_tracker.available_bytes_per_s__,
- (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
- else
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota remains at %u for peer `%s'\n",
- (unsigned int) n->out_tracker.available_bytes_per_s__,
- GNUNET_i2s (target));
-#endif
- GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, quota_out);
- sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
- sqc->target = *target;
- sqc->quota_in = quota_in;
- schedule_control_transmit (handle, sizeof (struct QuotaSetMessage),
- &send_set_quota, sqc);
-}
-
-
/**
* Send REQUEST_CONNECT message to the service.
*