aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-10 10:59:00 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-10 10:59:00 +0000
commit107b3a706cf4d2f0276fb7534a846de5d36a73a9 (patch)
tree755562cc41715e13946a09b2aad4ba2086f05981 /src/ats/ats_api.c
parent98aa0c158ee5cf82097432eff4cd15da2993198d (diff)
downloadgnunet-107b3a706cf4d2f0276fb7534a846de5d36a73a9.tar.gz
gnunet-107b3a706cf4d2f0276fb7534a846de5d36a73a9.zip
adding change preference API to ATS
Diffstat (limited to 'src/ats/ats_api.c')
-rw-r--r--src/ats/ats_api.c115
1 files changed, 13 insertions, 102 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index ce598c4e3..48f15a73f 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -32,67 +32,22 @@
32 */ 32 */
33#include "platform.h" 33#include "platform.h"
34#include "gnunet_ats_service.h" 34#include "gnunet_ats_service.h"
35#include "ats_api.h"
35 36
36#define DEBUG_ATS GNUNET_EXTRA_LOGGING 37#define DEBUG_ATS GNUNET_EXTRA_LOGGING
37 38
39/**
40 * Receive and send buffer windows grow over time. For
41 * how long can 'unused' bandwidth accumulate before we
42 * need to cap it? (specified in seconds).
43 */
44#define MAX_WINDOW_TIME_S (5 * 60)
45
38// NOTE: this implementation is simply supposed 46// NOTE: this implementation is simply supposed
39// to implement a simplistic strategy in-process; 47// to implement a simplistic strategy in-process;
40// in the future, we plan to replace it with a real 48// in the future, we plan to replace it with a real
41// service implementation 49// service implementation
42 50
43/**
44 * Allocation record for a peer's address.
45 */
46struct AllocationRecord
47{
48
49 /**
50 * Performance information associated with this address (array).
51 */
52 struct GNUNET_TRANSPORT_ATS_Information *ats;
53
54 /**
55 * Name of the plugin
56 */
57 char *plugin_name;
58
59 /**
60 * Address this record represents, allocated at the end of this struct.
61 */
62 const void *plugin_addr;
63
64 /**
65 * Session associated with this record.
66 */
67 struct Session *session;
68
69 /**
70 * Number of bytes in plugin_addr.
71 */
72 size_t plugin_addr_len;
73
74 /**
75 * Number of entries in 'ats'.
76 */
77 uint32_t ats_count;
78
79 /**
80 * Inbound bandwidth assigned to this address right now, 0 for none.
81 */
82 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
83
84 /**
85 * Outbound bandwidth assigned to this address right now, 0 for none.
86 */
87 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
88
89 /**
90 * Set to GNUNET_YES if this is the connected address of a connected peer.
91 */
92 int connected;
93
94};
95
96 51
97/** 52/**
98 * Opaque handle to obtain address suggestions. 53 * Opaque handle to obtain address suggestions.
@@ -124,55 +79,6 @@ struct GNUNET_ATS_SuggestionContext
124 79
125 80
126/** 81/**
127 * Handle to the ATS subsystem.
128 */
129struct GNUNET_ATS_Handle
130{
131 /**
132 * Configuration.
133 */
134 const struct GNUNET_CONFIGURATION_Handle *cfg;
135
136 /**
137 * Function to call when the allocation changes.
138 */
139 GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb;
140
141 /**
142 * Closure for 'alloc_cb'.
143 */
144 void *alloc_cb_cls;
145
146 /**
147 * Information about all connected peers. Maps peer identities
148 * to one or more 'struct AllocationRecord' values.
149 */
150 struct GNUNET_CONTAINER_MultiHashMap *peers;
151
152 /**
153 * Map of PeerIdentities to 'struct GNUNET_ATS_SuggestionContext's.
154 */
155 struct GNUNET_CONTAINER_MultiHashMap *notify_map;
156
157
158 /**
159 * Task scheduled to update our bandwidth assignment.
160 */
161 GNUNET_SCHEDULER_TaskIdentifier ba_task;
162
163 /**
164 * Total inbound bandwidth per configuration.
165 */
166 unsigned long long total_bps_in;
167
168 /**
169 * Total outbound bandwidth per configuration.
170 */
171 unsigned long long total_bps_out;
172};
173
174
175/**
176 * Count number of connected records. 82 * Count number of connected records.
177 * 83 *
178 * @param cls pointer to counter 84 * @param cls pointer to counter
@@ -232,6 +138,8 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
232 { 138 {
233 ar->bandwidth_in = sbc->bw_in; 139 ar->bandwidth_in = sbc->bw_in;
234 ar->bandwidth_out = sbc->bw_out; 140 ar->bandwidth_out = sbc->bw_out;
141 GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window,
142 ar->bandwidth_in);
235 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 143 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
236 (const struct GNUNET_PeerIdentity *) key, 144 (const struct GNUNET_PeerIdentity *) key,
237 ar->plugin_name, ar->session, ar->plugin_addr, 145 ar->plugin_name, ar->session, ar->plugin_addr,
@@ -609,6 +517,9 @@ create_allocation_record (const char *plugin_name, struct Session *session,
609 memcpy (&ar[1], plugin_addr, plugin_addr_len); 517 memcpy (&ar[1], plugin_addr, plugin_addr_len);
610 ar->session = session; 518 ar->session = session;
611 ar->plugin_addr_len = plugin_addr_len; 519 ar->plugin_addr_len = plugin_addr_len;
520 GNUNET_BANDWIDTH_tracker_init (&ar->available_recv_window,
521 ar->bandwidth_in,
522 MAX_WINDOW_TIME_S);
612 GNUNET_assert (ats_count > 0); 523 GNUNET_assert (ats_count > 0);
613 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); 524 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
614 memcpy (ar->ats, ats, 525 memcpy (ar->ats, ats,