summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-07 15:26:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-07 15:26:06 +0000
commit013cf64f56c0a529f0c11597e912b39e4a0a896c (patch)
tree763624e31708ea0d0b7b8f11f5c1308e220c0b94
parent900c1831440d1b6f9fdb35d39334bca2e94bdefb (diff)
first round of simplification to change preference API
-rw-r--r--src/core/Makefile.am3
-rw-r--r--src/core/core_api.c21
-rw-r--r--src/core/gnunet-service-core_sessions.c128
-rw-r--r--src/core/test_core_api_preferences.c10
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c9
-rw-r--r--src/fs/gnunet-service-fs_cp.c20
-rw-r--r--src/include/gnunet_core_service.h19
7 files changed, 71 insertions, 139 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 2ea90c9ff..65883d537 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -43,7 +43,8 @@ gnunet_service_core_new_SOURCES = \
gnunet-service-core_clients.c gnunet-service-core_clients.h \
gnunet-service-core_neighbours.c gnunet-service-core_neighbours.h \
gnunet-service-core_kx.c gnunet-service-core_kx.h \
- gnunet-service-core_sessions.c gnunet-service-core_sessions.h
+ gnunet-service-core_sessions.c gnunet-service-core_sessions.h \
+ gnunet-service-core_typemap.c gnunet-service-core_typemap.h
gnunet_service_core_new_LDADD = \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 24013b7cf..91368ffc3 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -421,7 +421,6 @@ static int
disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
void *value)
{
- static struct GNUNET_BANDWIDTH_Value32NBO zero;
struct GNUNET_CORE_Handle *h = cls;
struct GNUNET_CORE_TransmitHandle *th;
struct PeerRecord *pr = value;
@@ -449,7 +448,7 @@ disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
GNUNET_break (0);
pcic_cls = pr->pcic_cls;
GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
- pcic (pcic_cls, &pr->peer, zero, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0);
+ pcic (pcic_cls, &pr->peer, 0, GNUNET_TIME_UNIT_FOREVER_REL);
}
while (NULL != (th = pr->pending_head))
{
@@ -1230,9 +1229,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
GNUNET_free_non_null (pr->pcic_ptr);
pr->pcic_ptr = NULL;
if (pcic != NULL)
- pcic (pr->pcic_cls, &pr->peer, cim->bw_out, ntohl (cim->reserved_amount),
- GNUNET_TIME_relative_ntoh (cim->reserve_delay),
- GNUNET_ntohll (cim->preference));
+ pcic (pr->pcic_cls, &pr->peer, ntohl (cim->reserved_amount),
+ GNUNET_TIME_relative_ntoh (cim->reserve_delay));
break;
default:
reconnect_later (h);
@@ -1677,15 +1675,6 @@ change_preference_send_continuation (void *cls, int success)
*
* @param h core handle
* @param peer identifies the peer
- * @param timeout after how long should we give up (and call "info" with NULL
- * for "peer" to signal an error)?
- * @param bw_out set to the current bandwidth limit (sending) for this peer,
- * caller should set "bw_out" to "-1" to avoid changing
- * the current value; otherwise "bw_out" will be lowered to
- * the specified value; passing a pointer to "0" can be used to force
- * us to disconnect from the peer; "bw_out" might not increase
- * as specified since the upper bound is generally
- * determined by the other peer!
* @param amount reserve N bytes for receiving, negative
* amounts can be used to undo a (recent) reservation;
* @param preference increase incoming traffic share preference by this amount;
@@ -1699,8 +1688,6 @@ change_preference_send_continuation (void *cls, int success)
struct GNUNET_CORE_InformationRequestContext *
GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bw_out,
int32_t amount, uint64_t preference,
GNUNET_CORE_PeerConfigurationInfoCallback
info, void *info_cls)
@@ -1735,7 +1722,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
rim->header.size = htons (sizeof (struct RequestInfoMessage));
rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++);
- rim->limit_outbound = bw_out;
+ rim->limit_outbound = GNUNET_BANDWIDTH_VALUE_MAX; // FIXME: remove entirely soon...
rim->reserve_inbound = htonl (amount);
rim->preference_change = GNUNET_htonll (preference);
rim->peer = *peer;
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index b379c3ac7..6e1494373 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -710,102 +710,86 @@ void
GSC_SESSIONS_handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
-#if 0
- // FIXME!
const struct RequestInfoMessage *rcm;
- struct GSC_Client *pos;
- struct Neighbour *n;
+ struct Session *session;
struct ConfigurationInfoMessage cim;
int32_t want_reserv;
int32_t got_reserv;
- unsigned long long old_preference;
struct GNUNET_TIME_Relative rdelay;
rdelay = GNUNET_TIME_UNIT_ZERO;
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core service receives `%s' request.\n",
"REQUEST_INFO");
#endif
rcm = (const struct RequestInfoMessage *) message;
- n = find_neighbour (&rcm->peer);
- memset (&cim, 0, sizeof (cim));
- if ((n != NULL) && (GNUNET_YES == n->is_connected))
- {
- want_reserv = ntohl (rcm->reserve_inbound);
- if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
- {
- n->bw_out_internal_limit = rcm->limit_outbound;
- if (n->bw_out.value__ !=
- GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
- n->bw_out_external_limit).value__)
- {
- n->bw_out =
- GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
- n->bw_out_external_limit);
- GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
- n->bw_out);
- GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
- handle_peer_status_change (n);
- }
- }
- if (want_reserv < 0)
- {
- got_reserv = want_reserv;
- }
- else if (want_reserv > 0)
- {
- rdelay =
- GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
- want_reserv);
- if (rdelay.rel_value == 0)
- got_reserv = want_reserv;
- else
- got_reserv = 0; /* all or nothing */
- }
- else
- got_reserv = 0;
- GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv);
- old_preference = n->current_preference;
- n->current_preference += GNUNET_ntohll (rcm->preference_change);
- if (old_preference > n->current_preference)
- {
- /* overflow; cap at maximum value */
- n->current_preference = ULLONG_MAX;
- }
- update_preference_sum (n->current_preference - old_preference);
-#if DEBUG_CORE_QUOTA
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
- (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv,
- (unsigned long long) rdelay.rel_value);
-#endif
- cim.reserved_amount = htonl (got_reserv);
- cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
- cim.bw_out = n->bw_out;
- cim.preference = n->current_preference;
- }
- else
+ session = find_session (&rcm->peer);
+ if (NULL == session)
{
/* Technically, this COULD happen (due to asynchronous behavior),
* but it should be rare, so we should generate an info event
* to help diagnosis of serious errors that might be masked by this */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Client asked for preference change with peer `%s', which is not connected!\n"),
+ _("Client asked for preference change with peer `%s', which is not connected!\n"),
GNUNET_i2s (&rcm->peer));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
+
+ want_reserv = ntohl (rcm->reserve_inbound);
+ if (session->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
+ {
+ session->bw_out_internal_limit = rcm->limit_outbound;
+ if (session->bw_out.value__ !=
+ GNUNET_BANDWIDTH_value_min (session->bw_out_internal_limit,
+ session->bw_out_external_limit).value__)
+ {
+ session->bw_out =
+ GNUNET_BANDWIDTH_value_min (session->bw_out_internal_limit,
+ session->bw_out_external_limit);
+ GNUNET_BANDWIDTH_tracker_update_quota (&session->available_recv_window,
+ session->bw_out);
+#if 0
+ // FIXME: who does this?
+ GNUNET_TRANSPORT_set_quota (transport, &session->peer,
+ session->bw_in,
+ session->bw_out);
+#endif
+ }
+ }
+ if (want_reserv < 0)
+ {
+ got_reserv = want_reserv;
+ }
+ else if (want_reserv > 0)
+ {
+ rdelay =
+ GNUNET_BANDWIDTH_tracker_get_delay (&session->available_recv_window,
+ want_reserv);
+ if (rdelay.rel_value == 0)
+ got_reserv = want_reserv;
+ else
+ got_reserv = 0; /* all or nothing */
+ }
+ else
+ got_reserv = 0;
+ GNUNET_BANDWIDTH_tracker_consume (&session->available_recv_window, got_reserv);
+#if DEBUG_CORE_QUOTA
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
+ (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv,
+ (unsigned long long) rdelay.rel_value);
+#endif
cim.header.size = htons (sizeof (struct ConfigurationInfoMessage));
cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO);
- cim.peer = rcm->peer;
+ cim.reserved_amount = htonl (got_reserv);
+ cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
cim.rim_id = rcm->rim_id;
-#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
- "CONFIGURATION_INFO");
-#endif
+ cim.bw_out = session->bw_out;
+ cim.preference = 0; /* FIXME: remove */
+ cim.peer = rcm->peer;
GSC_CLIENTS_send_to_client (client, &cim.header, GNUNET_NO);
-#endif
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c
index 19d51ef60..6d7f52953 100644
--- a/src/core/test_core_api_preferences.c
+++ b/src/core/test_core_api_preferences.c
@@ -154,8 +154,8 @@ transmit_ready (void *cls, size_t size, void *buf)
static void
preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount,
- struct GNUNET_TIME_Relative res_delay, uint64_t preference);
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay);
static void
do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -173,16 +173,14 @@ do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
"Requesting reservatin of 32k from core in 1s!\n");
irc =
GNUNET_CORE_peer_change_preference (p1.ch, &p2.id,
- GNUNET_TIME_UNIT_SECONDS,
- GNUNET_BANDWIDTH_VALUE_MAX,
1000000 /* bandwidth for 1s */ ,
0, &preference_cb, pc);
}
static void
preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount,
- struct GNUNET_TIME_Relative res_delay, uint64_t preference)
+ int32_t amount,
+ struct GNUNET_TIME_Relative res_delay)
{
struct PeerContext *pc = cls;
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 9d4885b78..0623c0cb1 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -452,20 +452,16 @@ update_core_preference (void *cls,
*
* @param cls closure
* @param peer identifies the peer
- * @param bpm_out set to the current bandwidth limit (sending) for this peer
* @param amount set to the amount that was actually reserved or unreserved;
* either the full requested amount or zero (no partial reservations)
* @param res_delay if the reservation could not be satisfied (amount was 0), how
* long should the client wait until re-trying?
- * @param preference current traffic preference for the given peer
*/
static void
update_core_preference_finish (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bpm_out,
int32_t amount,
- struct GNUNET_TIME_Relative res_delay,
- uint64_t preference)
+ struct GNUNET_TIME_Relative res_delay)
{
struct PeerInfo *peer_info = cls;
@@ -519,8 +515,7 @@ update_core_preference (void *cls,
GNUNET_NO);
peer->info_ctx =
GNUNET_CORE_peer_change_preference (coreAPI, &peer->id,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX, 0,
+ 0,
preference,
&update_core_preference_finish, peer);
}
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 49b01724f..ed855c42e 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -388,25 +388,19 @@ static size_t
peer_transmit_ready_cb (void *cls, size_t size, void *buf);
-
-
/**
* Function called by core upon success or failure of our bandwidth reservation request.
*
* @param cls the 'struct GSF_ConnectedPeer' of the peer for which we made the request
* @param peer identifies the peer
- * @param bandwidth_out available amount of outbound bandwidth
* @param amount set to the amount that was actually reserved or unreserved;
* either the full requested amount or zero (no partial reservations)
* @param res_delay if the reservation could not be satisfied (amount was 0), how
* long should the client wait until re-trying?
- * @param preference current traffic preference for the given peer
*/
static void
core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount, struct GNUNET_TIME_Relative res_delay,
- uint64_t preference);
+ int32_t amount, struct GNUNET_TIME_Relative res_delay);
/**
@@ -439,8 +433,6 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
cp->inc_preference = 0;
cp->irc =
GNUNET_CORE_peer_change_preference (GSF_core, &target,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
DBLOCK_SIZE, ip,
&core_reserve_callback, cp);
}
@@ -527,8 +519,6 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
cp->inc_preference = 0;
cp->irc =
GNUNET_CORE_peer_change_preference (GSF_core, &target,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
DBLOCK_SIZE, ip,
&core_reserve_callback, cp);
}
@@ -539,18 +529,14 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
*
* @param cls the 'struct GSF_ConnectedPeer' of the peer for which we made the request
* @param peer identifies the peer
- * @param bandwidth_out available amount of outbound bandwidth
* @param amount set to the amount that was actually reserved or unreserved;
* either the full requested amount or zero (no partial reservations)
* @param res_delay if the reservation could not be satisfied (amount was 0), how
* long should the client wait until re-trying?
- * @param preference current traffic preference for the given peer
*/
static void
core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- int32_t amount, struct GNUNET_TIME_Relative res_delay,
- uint64_t preference)
+ int32_t amount, struct GNUNET_TIME_Relative res_delay)
{
struct GSF_ConnectedPeer *cp = cls;
struct GSF_PeerTransmitHandle *pth;
@@ -599,8 +585,6 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
cp->irc =
GNUNET_CORE_peer_change_preference (GSF_core, peer,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BANDWIDTH_VALUE_MAX,
DBLOCK_SIZE, 0,
&core_reserve_callback, cp);
fn = get_trust_filename (peer);
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index f33a78926..4eddda41f 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -244,25 +244,19 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
*
* @param cls closure
* @param peer identifies the peer
- * @param bandwidth_out available amount of outbound bandwidth
* @param amount set to the amount that was actually reserved or unreserved;
* either the full requested amount or zero (no partial reservations)
* @param res_delay if the reservation could not be satisfied (amount was 0), how
* long should the client wait until re-trying?
- * @param preference current traffic preference for the given peer
*/
typedef void (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls,
const struct
GNUNET_PeerIdentity *
peer,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
int32_t amount,
struct
GNUNET_TIME_Relative
- res_delay,
- uint64_t preference);
+ res_delay);
@@ -278,15 +272,6 @@ struct GNUNET_CORE_InformationRequestContext;
*
* @param h core handle
* @param peer identifies the peer
- * @param timeout after how long should we give up (and call "info" with NULL
- * for "peer" to signal an error)?
- * @param bw_out set to the current bandwidth limit (sending) for this peer,
- * caller should set "bpm_out" to "GNUNET_BANDWIDTH_VALUE_MAX" to avoid changing
- * the current value; otherwise "bw_out" will be lowered to
- * the specified value; passing a pointer to "0" can be used to force
- * us to disconnect from the peer; "bw_out" might not increase
- * as specified since the upper bound is generally
- * determined by the other peer!
* @param amount reserve N bytes for receiving, negative
* amounts can be used to undo a (recent) reservation;
* @param preference increase incoming traffic share preference by this amount;
@@ -300,8 +285,6 @@ struct GNUNET_CORE_InformationRequestContext;
struct GNUNET_CORE_InformationRequestContext *
GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bw_out,
int32_t amount, uint64_t preference,
GNUNET_CORE_PeerConfigurationInfoCallback
info, void *info_cls);