/**
* Number of bytes in plugin_addr.
*/
- size_t plugin_addr_len;
+ size_t plugin_addr_len;
/**
* Number of entries in 'ats'.
/**
* Global ATS handle.
- */
+ */
struct GNUNET_ATS_Handle *atc;
/**
* Which peer are we monitoring?
- */
+ */
struct GNUNET_PeerIdentity target;
};
* @return GNUNET_YES (continue iteration)
*/
static int
-count_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+count_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
unsigned int *ac = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
(*ac)++;
return GNUNET_YES;
* @return GNUNET_YES (continue iteration)
*/
static int
-set_bw_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SetBandwidthContext *sbc = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
- {
- ar->bandwidth = sbc->bw;
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
- else if (ntohl(ar->bandwidth.value__) > 0)
- {
- ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
+ {
+ ar->bandwidth = sbc->bw;
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
+ else if (ntohl (ar->bandwidth.value__) > 0)
+ {
+ ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
return GNUNET_YES;
}
*
* @param cls the 'struct GNUNET_ATS_Handle'
* @param tc scheduler context
- */
+ */
static void
-update_bandwidth_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_ATS_Handle *atc = cls;
unsigned int ac;
atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
/* FIXME: update calculations NICELY; what follows is a naive version */
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &count_connections,
- &ac);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &count_connections, &ac);
bwc.atc = atc;
bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &set_bw_connections,
- &bwc);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
}
*/
static void
update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
- struct AllocationRecord *change)
+ struct AllocationRecord *change)
{
/* FIXME: based on the 'change', update the LP-problem... */
if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
- atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task,
- atc);
+ atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, atc);
}
* @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet
*/
static int
-suggest_address (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_SuggestionContext *asc = cls;
struct AllocationRecord *ar = value;
-
+
/* trivial strategy: pick first available address... */
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
asc->cb = NULL;
return GNUNET_NO;
}
*/
struct GNUNET_ATS_SuggestionContext *
GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- GNUNET_ATS_AddressSuggestionCallback cb,
- void *cb_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_ATS_AddressSuggestionCallback cb,
+ void *cb_cls)
{
struct GNUNET_ATS_SuggestionContext *asc;
asc->target = *peer;
GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
&peer->hashPubKey,
- &suggest_address,
- asc);
+ &suggest_address, asc);
if (NULL == asc->cb)
- {
- GNUNET_free (asc);
- return NULL;
- }
+ {
+ GNUNET_free (asc);
+ return NULL;
+ }
GNUNET_CONTAINER_multihashmap_put (atc->notify_map,
- &peer->hashPubKey,
- asc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &peer->hashPubKey,
+ asc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return asc;
}
GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
{
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
- &asc->target.hashPubKey,
- asc));
+ GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
+ &asc->target.hashPubKey,
+ asc));
GNUNET_free (asc);
}
*/
struct GNUNET_ATS_Handle *
GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
- void *alloc_cb_cls)
+ GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
+ void *alloc_cb_cls)
{
struct GNUNET_ATS_Handle *atc;
atc->alloc_cb_cls = alloc_cb_cls;
atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
GNUNET_CONFIGURATION_get_value_number (cfg,
- "core",
- "TOTAL_QUOTA_OUT",
- &atc->total_bps);
+ "core",
+ "TOTAL_QUOTA_OUT", &atc->total_bps);
return atc;
}
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_allocation_record (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = value;
GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
{
if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
- {
- GNUNET_SCHEDULER_cancel (atc->ba_task);
- atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (atc->ba_task);
+ atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_allocation_record,
- NULL);
+ &destroy_allocation_record, NULL);
GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
* GNUNET_NO if the record do match and 'old' was updated
*/
static int
-update_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct UpdateSessionContext *usc = cls;
struct AllocationRecord *arnew = usc->arnew;
if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
return GNUNET_YES;
- if ( (arnew->session == arold->session) ||
- ( (arold->session == NULL) &&
- (arold->plugin_addr_len == arnew->plugin_addr_len) &&
- (0 == memcmp (arold->plugin_addr,
- arnew->plugin_addr,
- arnew->plugin_addr_len)) ) )
+ if ((arnew->session == arold->session) ||
+ ((arold->session == NULL) &&
+ (arold->plugin_addr_len == arnew->plugin_addr_len) &&
+ (0 == memcmp (arold->plugin_addr,
+ arnew->plugin_addr, arnew->plugin_addr_len))))
+ {
+ change = GNUNET_NO;
+ /* records match */
+ if (arnew->session != arold->session)
+ {
+ arold->session = arnew->session;
+ change = GNUNET_YES;
+ }
+ if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
{
- change = GNUNET_NO;
- /* records match */
- if (arnew->session != arold->session)
- {
- arold->session = arnew->session;
- change = GNUNET_YES;
- }
- if ( (arnew->connected == GNUNET_YES) &&
- (arold->connected == GNUNET_NO) )
- {
- arold->connected = GNUNET_YES;
- change = GNUNET_YES;
- }
- // FIXME: merge ats arrays of (arold, arnew);
-
- if (GNUNET_YES == change)
- update_bandwidth_assignment (usc->atc, arold);
- return GNUNET_NO;
+ arold->connected = GNUNET_YES;
+ change = GNUNET_YES;
}
+ // FIXME: merge ats arrays of (arold, arnew);
+
+ if (GNUNET_YES == change)
+ update_bandwidth_assignment (usc->atc, arold);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
*/
static struct AllocationRecord *
create_allocation_record (const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
memcpy (&ar[1], plugin_addr, plugin_addr_len);
ar->session = session;
ar->plugin_addr_len = plugin_addr_len;
- GNUNET_array_grow (ar->ats,
- ar->ats_count,
- ats_count);
- memcpy (ar->ats,
- ats,
- ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
+ memcpy (ar->ats,
+ ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
return ar;
}
* @return GNUNET_OK (continue to iterate)
*/
static int
-disconnect_peer (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_Handle *atc = cls;
struct AllocationRecord *ar = value;
if (GNUNET_YES == ar->connected)
- {
- ar->connected = GNUNET_NO;
- update_bandwidth_assignment (atc, ar);
- }
+ {
+ ar->connected = GNUNET_NO;
+ update_bandwidth_assignment (atc, ar);
+ }
return GNUNET_OK;
}
*/
void
GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &disconnect_peer,
- atc);
+ &disconnect_peer, atc);
ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
ar->connected = GNUNET_YES;
usc.atc = atc;
usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}
*/
void
GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer)
{
(void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
- &peer->hashPubKey,
- &disconnect_peer,
- atc);
+ &peer->hashPubKey,
+ &disconnect_peer, atc);
}
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SessionDestroyContext *sdc = cls;
struct AllocationRecord *ar = value;
if (ar->plugin_addr != NULL)
return GNUNET_OK;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
- key,
- ar));
- if (GNUNET_YES == ar->connected);
- {
- /* FIXME: is this supposed to be allowed? What to do then? */
- GNUNET_break (0);
- }
+ GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
+ key, ar));
+ if (GNUNET_YES == ar->connected) ;
+ {
+ /* FIXME: is this supposed to be allowed? What to do then? */
+ GNUNET_break (0);
+ }
destroy_allocation_record (NULL, key, ar);
return GNUNET_OK;
}
*/
void
GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const struct Session *session)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct Session *session)
{
struct SessionDestroyContext sdc;
sdc.atc = atc;
sdc.session = session;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_session,
- &sdc);
+ &destroy_session, &sdc);
}
* @return GNUNET_YES (continue to iterate)
*/
static int
-notify_valid (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = cls;
struct GNUNET_ATS_SuggestionContext *asc = value;
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
GNUNET_ATS_suggest_address_cancel (asc);
return GNUNET_OK;
}
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Absolute valid_until,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Absolute valid_until,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
- ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ ar = create_allocation_record (plugin_name,
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
usc.atc = atc;
- usc.arnew = ar;
+ usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
- &peer->hashPubKey,
- ¬ify_valid,
- ar);
+ &peer->hashPubKey,
+ ¬ify_valid, ar);
}
/* end of file gnunet-service-transport_ats.c */