aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_performance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r--src/ats/gnunet-service-ats_performance.c233
1 files changed, 118 insertions, 115 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 16d0777de..441c6610e 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -63,64 +63,64 @@ static struct GNUNET_NotificationContext *nc_pic;
63 * @param bandwidth_in assigned inbound bandwidth 63 * @param bandwidth_in assigned inbound bandwidth
64 */ 64 */
65static void 65static void
66notify_client(struct GNUNET_SERVICE_Client *client, 66notify_client (struct GNUNET_SERVICE_Client *client,
67 const struct GNUNET_PeerIdentity *peer, 67 const struct GNUNET_PeerIdentity *peer,
68 const char *plugin_name, 68 const char *plugin_name,
69 const void *plugin_addr, 69 const void *plugin_addr,
70 size_t plugin_addr_len, 70 size_t plugin_addr_len,
71 int active, 71 int active,
72 const struct GNUNET_ATS_Properties *prop, 72 const struct GNUNET_ATS_Properties *prop,
73 enum GNUNET_HELLO_AddressInfo local_address_info, 73 enum GNUNET_HELLO_AddressInfo local_address_info,
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
76{ 76{
77 struct PeerInformationMessage *msg; 77 struct PeerInformationMessage *msg;
78 size_t plugin_name_length = strlen(plugin_name) + 1; 78 size_t plugin_name_length = strlen (plugin_name) + 1;
79 size_t msize = 79 size_t msize =
80 sizeof(struct PeerInformationMessage) + 80 sizeof(struct PeerInformationMessage)
81 plugin_addr_len + 81 + plugin_addr_len
82 plugin_name_length; 82 + plugin_name_length;
83 char buf[msize] GNUNET_ALIGN; 83 char buf[msize] GNUNET_ALIGN;
84 char *addrp; 84 char *addrp;
85 85
86 if (NULL != prop) 86 if (NULL != prop)
87 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 87 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
88 GNUNET_assert(msize < GNUNET_MAX_MESSAGE_SIZE); 88 GNUNET_assert (msize < GNUNET_MAX_MESSAGE_SIZE);
89 msg = (struct PeerInformationMessage *)buf; 89 msg = (struct PeerInformationMessage *) buf;
90 msg->header.size = htons(msize); 90 msg->header.size = htons (msize);
91 msg->header.type = htons(GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); 91 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
92 msg->id = htonl(0); 92 msg->id = htonl (0);
93 msg->peer = *peer; 93 msg->peer = *peer;
94 msg->address_length = htons(plugin_addr_len); 94 msg->address_length = htons (plugin_addr_len);
95 msg->address_active = ntohl((uint32_t)active); 95 msg->address_active = ntohl ((uint32_t) active);
96 msg->plugin_name_length = htons(plugin_name_length); 96 msg->plugin_name_length = htons (plugin_name_length);
97 msg->bandwidth_out = bandwidth_out; 97 msg->bandwidth_out = bandwidth_out;
98 msg->bandwidth_in = bandwidth_in; 98 msg->bandwidth_in = bandwidth_in;
99 if (NULL != prop) 99 if (NULL != prop)
100 GNUNET_ATS_properties_hton(&msg->properties, 100 GNUNET_ATS_properties_hton (&msg->properties,
101 prop); 101 prop);
102 else 102 else
103 memset(&msg->properties, 103 memset (&msg->properties,
104 0, 104 0,
105 sizeof(struct GNUNET_ATS_Properties)); 105 sizeof(struct GNUNET_ATS_Properties));
106 msg->address_local_info = htonl(local_address_info); 106 msg->address_local_info = htonl (local_address_info);
107 addrp = (char *)&msg[1]; 107 addrp = (char *) &msg[1];
108 GNUNET_memcpy(addrp, plugin_addr, plugin_addr_len); 108 GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len);
109 strcpy(&addrp[plugin_addr_len], plugin_name); 109 strcpy (&addrp[plugin_addr_len], plugin_name);
110 if (NULL == client) 110 if (NULL == client)
111 { 111 {
112 GNUNET_notification_context_broadcast(nc_pic, 112 GNUNET_notification_context_broadcast (nc_pic,
113 &msg->header, 113 &msg->header,
114 GNUNET_YES); 114 GNUNET_YES);
115 } 115 }
116 else 116 else
117 { 117 {
118 struct GNUNET_MQ_Envelope *env; 118 struct GNUNET_MQ_Envelope *env;
119 119
120 env = GNUNET_MQ_msg_copy(&msg->header); 120 env = GNUNET_MQ_msg_copy (&msg->header);
121 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 121 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
122 env); 122 env);
123 } 123 }
124} 124}
125 125
126 126
@@ -142,32 +142,35 @@ notify_client(struct GNUNET_SERVICE_Client *client,
142 * @param bandwidth_in assigned inbound bandwidth 142 * @param bandwidth_in assigned inbound bandwidth
143 */ 143 */
144void 144void
145GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, 145GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
146 const char *plugin_name, 146 const char *plugin_name,
147 const void *plugin_addr, 147 const void *plugin_addr,
148 size_t plugin_addr_len, 148 size_t plugin_addr_len,
149 int active, 149 int active,
150 const struct GNUNET_ATS_Properties *prop, 150 const struct GNUNET_ATS_Properties *prop,
151 enum GNUNET_HELLO_AddressInfo local_address_info, 151 enum GNUNET_HELLO_AddressInfo
152 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 152 local_address_info,
153 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 153 struct GNUNET_BANDWIDTH_Value32NBO
154 bandwidth_out,
155 struct GNUNET_BANDWIDTH_Value32NBO
156 bandwidth_in)
154{ 157{
155 GNUNET_break((NULL == prop) || 158 GNUNET_break ((NULL == prop) ||
156 (GNUNET_NT_UNSPECIFIED != prop->scope)); 159 (GNUNET_NT_UNSPECIFIED != prop->scope));
157 notify_client(NULL, 160 notify_client (NULL,
158 peer, 161 peer,
159 plugin_name, 162 plugin_name,
160 plugin_addr, 163 plugin_addr,
161 plugin_addr_len, 164 plugin_addr_len,
162 active, 165 active,
163 prop, 166 prop,
164 local_address_info, 167 local_address_info,
165 bandwidth_out, 168 bandwidth_out,
166 bandwidth_in); 169 bandwidth_in);
167 GNUNET_STATISTICS_update(GSA_stats, 170 GNUNET_STATISTICS_update (GSA_stats,
168 "# performance updates given to clients", 171 "# performance updates given to clients",
169 1, 172 1,
170 GNUNET_NO); 173 GNUNET_NO);
171} 174}
172 175
173 176
@@ -186,38 +189,38 @@ GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer,
186 * @param bandwidth_in current inbound bandwidth assigned to address 189 * @param bandwidth_in current inbound bandwidth assigned to address
187 */ 190 */
188static void 191static void
189peerinfo_it(void *cls, 192peerinfo_it (void *cls,
190 const struct GNUNET_PeerIdentity *id, 193 const struct GNUNET_PeerIdentity *id,
191 const char *plugin_name, 194 const char *plugin_name,
192 const void *plugin_addr, 195 const void *plugin_addr,
193 size_t plugin_addr_len, 196 size_t plugin_addr_len,
194 int active, 197 int active,
195 const struct GNUNET_ATS_Properties *prop, 198 const struct GNUNET_ATS_Properties *prop,
196 enum GNUNET_HELLO_AddressInfo local_address_info, 199 enum GNUNET_HELLO_AddressInfo local_address_info,
197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 200 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 201 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
199{ 202{
200 struct GNUNET_SERVICE_Client *client = cls; 203 struct GNUNET_SERVICE_Client *client = cls;
201 204
202 if (NULL == id) 205 if (NULL == id)
203 return; 206 return;
204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n", 208 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
206 GNUNET_i2s(id), 209 GNUNET_i2s (id),
207 plugin_name, 210 plugin_name,
208 (unsigned int)ntohl(bandwidth_out.value__), 211 (unsigned int) ntohl (bandwidth_out.value__),
209 (unsigned int)ntohl(bandwidth_in.value__)); 212 (unsigned int) ntohl (bandwidth_in.value__));
210 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 213 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
211 notify_client(client, 214 notify_client (client,
212 id, 215 id,
213 plugin_name, 216 plugin_name,
214 plugin_addr, 217 plugin_addr,
215 plugin_addr_len, 218 plugin_addr_len,
216 active, 219 active,
217 prop, 220 prop,
218 local_address_info, 221 local_address_info,
219 bandwidth_out, 222 bandwidth_out,
220 bandwidth_in); 223 bandwidth_in);
221} 224}
222 225
223 226
@@ -228,25 +231,25 @@ peerinfo_it(void *cls,
228 * @param flag flag specifying the type of the client 231 * @param flag flag specifying the type of the client
229 */ 232 */
230void 233void
231GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, 234GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
232 enum StartFlag flag) 235 enum StartFlag flag)
233{ 236{
234 struct GNUNET_MQ_Handle *mq; 237 struct GNUNET_MQ_Handle *mq;
235 238
236 mq = GNUNET_SERVICE_client_get_mq(client); 239 mq = GNUNET_SERVICE_client_get_mq (client);
237 if (START_FLAG_PERFORMANCE_WITH_PIC == flag) 240 if (START_FLAG_PERFORMANCE_WITH_PIC == flag)
238 { 241 {
239 GNUNET_notification_context_add(nc_pic, 242 GNUNET_notification_context_add (nc_pic,
240 mq); 243 mq);
241 GAS_addresses_get_peer_info(NULL, 244 GAS_addresses_get_peer_info (NULL,
242 &peerinfo_it, 245 &peerinfo_it,
243 client); 246 client);
244 } 247 }
245 else 248 else
246 { 249 {
247 GNUNET_notification_context_add(nc_no_pic, 250 GNUNET_notification_context_add (nc_no_pic,
248 mq); 251 mq);
249 } 252 }
250} 253}
251 254
252 255
@@ -256,10 +259,10 @@ GAS_performance_add_client(struct GNUNET_SERVICE_Client *client,
256 * @param server handle to our server 259 * @param server handle to our server
257 */ 260 */
258void 261void
259GAS_performance_init() 262GAS_performance_init ()
260{ 263{
261 nc_no_pic = GNUNET_notification_context_create(32); 264 nc_no_pic = GNUNET_notification_context_create (32);
262 nc_pic = GNUNET_notification_context_create(32); 265 nc_pic = GNUNET_notification_context_create (32);
263} 266}
264 267
265 268
@@ -267,11 +270,11 @@ GAS_performance_init()
267 * Shutdown performance subsystem. 270 * Shutdown performance subsystem.
268 */ 271 */
269void 272void
270GAS_performance_done() 273GAS_performance_done ()
271{ 274{
272 GNUNET_notification_context_destroy(nc_no_pic); 275 GNUNET_notification_context_destroy (nc_no_pic);
273 nc_no_pic = NULL; 276 nc_no_pic = NULL;
274 GNUNET_notification_context_destroy(nc_pic); 277 GNUNET_notification_context_destroy (nc_pic);
275 nc_pic = NULL; 278 nc_pic = NULL;
276} 279}
277 280