aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
commit1c323bd4cbb388a9e7515a1f733a3062bf093aee (patch)
tree7cc525d79149d44840b9f7a0040aaf3e69ecd665 /src/dv
parentaedaaed687db1ff20b447378f01ad7306921450c (diff)
downloadgnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.tar.gz
gnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.zip
fixing #3657 (replace ATS_Information with struct), but WIHTOUT fixing ATS testcases yet
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/gnunet-service-dv.c52
-rw-r--r--src/dv/plugin_transport_dv.c59
2 files changed, 34 insertions, 77 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 93cc0628f..7ea4a300e 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -1159,46 +1159,6 @@ schedule_refresh_routes ()
1159 1159
1160 1160
1161/** 1161/**
1162 * Get distance information from 'atsi'.
1163 *
1164 * @param atsi performance data
1165 * @param atsi_count number of entries in atsi
1166 * @return connected transport distance
1167 */
1168static uint32_t
1169get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
1170 uint32_t atsi_count)
1171{
1172 uint32_t i;
1173
1174 for (i = 0; i < atsi_count; i++)
1175 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
1176 return (0 == ntohl (atsi[i].value)) ? DIRECT_NEIGHBOR_COST : ntohl (atsi[i].value); // FIXME: 0 check should not be required once ATS is fixed!
1177 /* If we do not have explicit distance data, assume direct neighbor. */
1178 return DIRECT_NEIGHBOR_COST;
1179}
1180
1181
1182/**
1183 * Get network information from 'atsi'.
1184 *
1185 * @param atsi performance data
1186 * @param atsi_count number of entries in atsi
1187 * @return connected transport network
1188 */
1189static enum GNUNET_ATS_Network_Type
1190get_atsi_network (const struct GNUNET_ATS_Information *atsi,
1191 uint32_t atsi_count)
1192{
1193 uint32_t i;
1194
1195 for (i = 0; i < atsi_count; i++)
1196 if (ntohl (atsi[i].type) == GNUNET_ATS_NETWORK_TYPE)
1197 return (enum GNUNET_ATS_Network_Type) ntohl (atsi[i].value);
1198 return GNUNET_ATS_NET_UNSPECIFIED;
1199}
1200
1201/**
1202 * Multipeermap iterator for freeing routes that go via a particular 1162 * Multipeermap iterator for freeing routes that go via a particular
1203 * neighbor that disconnected and is thus no longer available. 1163 * neighbor that disconnected and is thus no longer available.
1204 * 1164 *
@@ -1308,8 +1268,7 @@ handle_direct_disconnect (struct DirectNeighbor *neighbor)
1308 * #GNUNET_SYSERR if this address is no longer available for ATS 1268 * #GNUNET_SYSERR if this address is no longer available for ATS
1309 * @param bandwidth_out assigned outbound bandwidth for the connection 1269 * @param bandwidth_out assigned outbound bandwidth for the connection
1310 * @param bandwidth_in assigned inbound bandwidth for the connection 1270 * @param bandwidth_in assigned inbound bandwidth for the connection
1311 * @param ats performance data for the address (as far as known) 1271 * @param prop performance data for the address (as far as known)
1312 * @param ats_count number of performance records in @a ats
1313 */ 1272 */
1314static void 1273static void
1315handle_ats_update (void *cls, 1274handle_ats_update (void *cls,
@@ -1317,12 +1276,11 @@ handle_ats_update (void *cls,
1317 int active, 1276 int active,
1318 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1277 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1319 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1278 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1320 const struct GNUNET_ATS_Information *ats, 1279 const struct GNUNET_ATS_Properties *prop)
1321 uint32_t ats_count)
1322{ 1280{
1323 struct DirectNeighbor *neighbor; 1281 struct DirectNeighbor *neighbor;
1324 uint32_t distance; 1282 uint32_t distance;
1325 enum GNUNET_ATS_Network_Type network = GNUNET_ATS_NET_UNSPECIFIED; 1283 enum GNUNET_ATS_Network_Type network;
1326 1284
1327 if (NULL == address) 1285 if (NULL == address)
1328 { 1286 {
@@ -1335,8 +1293,8 @@ handle_ats_update (void *cls,
1335 // FIXME: handle disconnect/inactive case too! 1293 // FIXME: handle disconnect/inactive case too!
1336 return; 1294 return;
1337 } 1295 }
1338 distance = get_atsi_distance (ats, ats_count); 1296 distance = prop->distance;
1339 network = get_atsi_network (ats, ats_count); 1297 network = prop->scope;
1340 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network); 1298 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
1341 /* check if entry exists */ 1299 /* check if entry exists */
1342 neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, 1300 neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 382e57596..f84c4a1b6 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -234,14 +234,12 @@ static void
234notify_distance_change (struct Session *session) 234notify_distance_change (struct Session *session)
235{ 235{
236 struct Plugin *plugin = session->plugin; 236 struct Plugin *plugin = session->plugin;
237 struct GNUNET_ATS_Information ats;
238 237
239 if (GNUNET_YES != session->active) 238 if (GNUNET_YES != session->active)
240 return; 239 return;
241 ats.type = htonl ((uint32_t) GNUNET_ATS_QUALITY_NET_DISTANCE); 240 plugin->env->update_address_distance (plugin->env->cls,
242 ats.value = htonl (session->distance); 241 session->address,
243 plugin->env->update_address_metrics (plugin->env->cls, 242 session->distance);
244 session->address, session, &ats, 1);
245} 243}
246 244
247 245
@@ -260,21 +258,20 @@ unbox_cb (void *cls,
260{ 258{
261 struct Plugin *plugin = cls; 259 struct Plugin *plugin = cls;
262 struct Session *session = client; 260 struct Session *session = client;
263 struct GNUNET_ATS_Information ats;
264 261
265 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
266 ats.value = htonl (session->distance);
267 session->active = GNUNET_YES; 262 session->active = GNUNET_YES;
268 LOG (GNUNET_ERROR_TYPE_DEBUG, 263 LOG (GNUNET_ERROR_TYPE_DEBUG,
269 "Delivering message of type %u with %u bytes from peer `%s'\n", 264 "Delivering message of type %u with %u bytes from peer `%s'\n",
270 ntohs (message->type), 265 ntohs (message->type),
271 ntohs (message->size), 266 ntohs (message->size),
272 GNUNET_i2s (&session->sender)); 267 GNUNET_i2s (&session->sender));
273 268 plugin->env->receive (plugin->env->cls,
274 plugin->env->receive (plugin->env->cls, session->address, session, 269 session->address,
270 session,
275 message); 271 message);
276 plugin->env->update_address_metrics (plugin->env->cls, 272 plugin->env->update_address_distance (plugin->env->cls,
277 session->address, session, &ats, 1); 273 session->address,
274 session->distance);
278 return GNUNET_OK; 275 return GNUNET_OK;
279} 276}
280 277
@@ -294,12 +291,12 @@ handle_dv_message_received (void *cls,
294 const struct GNUNET_MessageHeader *msg) 291 const struct GNUNET_MessageHeader *msg)
295{ 292{
296 struct Plugin *plugin = cls; 293 struct Plugin *plugin = cls;
297 struct GNUNET_ATS_Information ats;
298 struct Session *session; 294 struct Session *session;
299 295
300 LOG (GNUNET_ERROR_TYPE_DEBUG, 296 LOG (GNUNET_ERROR_TYPE_DEBUG,
301 "Received DV_MESSAGE_RECEIVED message for peer `%s': new distance %u\n", 297 "Received DV_MESSAGE_RECEIVED message for peer `%s': new distance %u\n",
302 GNUNET_i2s (sender), distance); 298 GNUNET_i2s (sender),
299 distance);
303 session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, 300 session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions,
304 sender); 301 sender);
305 if (NULL == session) 302 if (NULL == session)
@@ -320,17 +317,19 @@ handle_dv_message_received (void *cls,
320 GNUNET_NO); 317 GNUNET_NO);
321 return; 318 return;
322 } 319 }
323 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
324 ats.value = htonl (distance);
325 session->active = GNUNET_YES; 320 session->active = GNUNET_YES;
326 LOG (GNUNET_ERROR_TYPE_DEBUG, 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
327 "Delivering message of type %u with %u bytes from peer `%s'\n", 322 "Delivering message of type %u with %u bytes from peer `%s'\n",
328 ntohs (msg->type), 323 ntohs (msg->type),
329 ntohs (msg->size), 324 ntohs (msg->size),
330 GNUNET_i2s (sender)); 325 GNUNET_i2s (sender));
331 plugin->env->receive (plugin->env->cls, session->address, session, msg); 326 plugin->env->receive (plugin->env->cls,
332 plugin->env->update_address_metrics (plugin->env->cls, 327 session->address,
333 session->address, session, &ats, 1); 328 session,
329 msg);
330 plugin->env->update_address_distance (plugin->env->cls,
331 session->address,
332 session->distance);
334} 333}
335 334
336 335
@@ -350,7 +349,6 @@ handle_dv_connect (void *cls,
350{ 349{
351 struct Plugin *plugin = cls; 350 struct Plugin *plugin = cls;
352 struct Session *session; 351 struct Session *session;
353 struct GNUNET_ATS_Information ats[2];
354 352
355 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network); 353 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
356 /** 354 /**
@@ -358,8 +356,7 @@ handle_dv_connect (void *cls,
358 * If you remove it, also remove libgnunetats linkage from Makefile.am 356 * If you remove it, also remove libgnunetats linkage from Makefile.am
359 */ 357 */
360 LOG (GNUNET_ERROR_TYPE_DEBUG, 358 LOG (GNUNET_ERROR_TYPE_DEBUG,
361 "Received `%s' message for peer `%s' with next hop in network %s\n", 359 "Received DV_CONNECT message for peer `%s' with next hop in network %s\n",
362 "DV_CONNECT",
363 GNUNET_i2s (peer), 360 GNUNET_i2s (peer),
364 GNUNET_ATS_print_network_type (network)); 361 GNUNET_ATS_print_network_type (network));
365 362
@@ -375,7 +372,8 @@ handle_dv_connect (void *cls,
375 372
376 session = GNUNET_new (struct Session); 373 session = GNUNET_new (struct Session);
377 session->address = GNUNET_HELLO_address_allocate (peer, "dv", 374 session->address = GNUNET_HELLO_address_allocate (peer, "dv",
378 NULL, 0, GNUNET_HELLO_ADDRESS_INFO_NONE); 375 NULL, 0,
376 GNUNET_HELLO_ADDRESS_INFO_NONE);
379 session->sender = *peer; 377 session->sender = *peer;
380 session->plugin = plugin; 378 session->plugin = plugin;
381 session->distance = distance; 379 session->distance = distance;
@@ -391,14 +389,15 @@ handle_dv_connect (void *cls,
391 GNUNET_i2s (peer), 389 GNUNET_i2s (peer),
392 distance); 390 distance);
393 391
394 /* Notify transport and ats about new connection */
395 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
396 ats[0].value = htonl (distance);
397 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
398 ats[1].value = htonl ((uint32_t) network);
399 session->active = GNUNET_YES; 392 session->active = GNUNET_YES;
400 plugin->env->session_start (plugin->env->cls, session->address, 393 plugin->env->session_start (plugin->env->cls,
401 session, ats, 2); 394 session->address,
395 session,
396 network);
397 plugin->env->update_address_distance (plugin->env->cls,
398 session->address,
399 session->distance);
400
402 notify_session_monitor (session->plugin, 401 notify_session_monitor (session->plugin,
403 session, 402 session,
404 GNUNET_TRANSPORT_SS_UP); 403 GNUNET_TRANSPORT_SS_UP);