aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-07 22:06:02 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-07 22:06:02 +0000
commitf8c0f7d5c566bbddc2909eceeb63e6ecee591d70 (patch)
treecb03a293b5a5372f18bb114b01d02fd48d76865d
parent174ab5aba2bdfde8a4614bf0069a33a7bbe57ce7 (diff)
downloadgnunet-f8c0f7d5c566bbddc2909eceeb63e6ecee591d70.tar.gz
gnunet-f8c0f7d5c566bbddc2909eceeb63e6ecee591d70.zip
more code to get latency in ATSI working; not complete, also now generating a warning -- for a real problem that still needs to be fixed
-rw-r--r--src/transport/gnunet-service-transport.c8
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c68
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h12
-rw-r--r--src/transport/gnunet-service-transport_validation.c66
-rw-r--r--src/transport/gnunet-service-transport_validation.h16
5 files changed, 132 insertions, 38 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 30bcad806..11a8e23ae 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -135,7 +135,7 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
135 size_t msg_size = ntohs (message->size); 135 size_t msg_size = ntohs (message->size);
136 size_t size = 136 size_t size =
137 sizeof (struct InboundMessage) + msg_size + 137 sizeof (struct InboundMessage) + msg_size +
138 sizeof (struct GNUNET_ATS_Information) * ats_count; 138 sizeof (struct GNUNET_ATS_Information) * (ats_count + 1);
139 char buf[size]; 139 char buf[size];
140 struct GNUNET_ATS_Information *ap; 140 struct GNUNET_ATS_Information *ap;
141 141
@@ -162,11 +162,13 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
162 im = (struct InboundMessage *) buf; 162 im = (struct InboundMessage *) buf;
163 im->header.size = htons (size); 163 im->header.size = htons (size);
164 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 164 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
165 im->ats_count = htonl (ats_count); 165 im->ats_count = htonl (ats_count + 1);
166 im->peer = *peer; 166 im->peer = *peer;
167 ap = (struct GNUNET_ATS_Information *) &im[1]; 167 ap = (struct GNUNET_ATS_Information *) &im[1];
168 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 168 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
169 memcpy (&ap[ats_count], message, ntohs (message->size)); 169 ap[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
170 ap[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value);
171 memcpy (&ap[ats_count + 1], message, ntohs (message->size));
170 172
171 GST_clients_broadcast (&im->header, GNUNET_YES); 173 GST_clients_broadcast (&im->header, GNUNET_YES);
172 174
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 32ac7c05d..e7d458e7f 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -870,6 +870,12 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
870 if (is_disconnecting (n)) 870 if (is_disconnecting (n))
871 return; 871 return;
872 change_state (n, S_DISCONNECT); 872 change_state (n, S_DISCONNECT);
873 GST_validation_set_address_use (&n->id,
874 n->plugin_name,
875 n->session,
876 n->addr,
877 n->addrlen,
878 GNUNET_NO);
873 879
874 if (n->plugin_name != NULL) 880 if (n->plugin_name != NULL)
875 { 881 {
@@ -1301,7 +1307,13 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1301 return GNUNET_NO; 1307 return GNUNET_NO;
1302 } 1308 }
1303 } 1309 }
1304 1310 if (n->state == S_CONNECTED)
1311 GST_validation_set_address_use (&n->id,
1312 n->plugin_name,
1313 n->session,
1314 n->addr,
1315 n->addrlen,
1316 GNUNET_NO);
1305 GNUNET_free_non_null (n->addr); 1317 GNUNET_free_non_null (n->addr);
1306 n->addr = GNUNET_malloc (address_len); 1318 n->addr = GNUNET_malloc (address_len);
1307 memcpy (n->addr, address, address_len); 1319 memcpy (n->addr, address, address_len);
@@ -1315,6 +1327,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1315 n->timeout_task = 1327 n->timeout_task =
1316 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1328 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1317 &neighbour_timeout_task, n); 1329 &neighbour_timeout_task, n);
1330 if (n->state == S_CONNECTED)
1331 GST_validation_set_address_use (&n->id,
1332 n->plugin_name,
1333 n->session,
1334 n->addr,
1335 n->addrlen,
1336 GNUNET_YES);
1337
1318 1338
1319 if (n->state == S_DISCONNECT) 1339 if (n->state == S_DISCONNECT)
1320 { 1340 {
@@ -1400,6 +1420,29 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1400 1420
1401 1421
1402/** 1422/**
1423 * Obtain current latency information for the given neighbour.
1424 *
1425 * @param peer
1426 * @return observed latency of the address, FOREVER if the address was
1427 * never successfully validated
1428 */
1429struct GNUNET_TIME_Relative
1430GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer)
1431{
1432 struct NeighbourMapEntry *n;
1433
1434 n = lookup_neighbour (peer);
1435 if (NULL == n)
1436 return GNUNET_TIME_UNIT_FOREVER_REL;
1437 return GST_validation_get_address_latency (peer,
1438 n->plugin_name,
1439 n->session,
1440 n->addr,
1441 n->addrlen);
1442}
1443
1444
1445/**
1403 * Create an entry in the neighbour map for the given peer 1446 * Create an entry in the neighbour map for the given peer
1404 * 1447 *
1405 * @param peer peer to create an entry for 1448 * @param peer peer to create an entry for
@@ -2042,7 +2085,15 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2042 2085
2043 was_connected = is_connected (n); 2086 was_connected = is_connected (n);
2044 if (!is_connected (n)) 2087 if (!is_connected (n))
2088 {
2045 change_state (n, S_CONNECTED); 2089 change_state (n, S_CONNECTED);
2090 GST_validation_set_address_use (&n->id,
2091 n->plugin_name,
2092 n->session,
2093 n->addr,
2094 n->addrlen,
2095 GNUNET_YES);
2096 }
2046 2097
2047 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, 2098 GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr,
2048 n->addrlen, n->addr, GNUNET_YES); 2099 n->addrlen, n->addr, GNUNET_YES);
@@ -2174,6 +2225,12 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2174 2225
2175 if (!was_connected) 2226 if (!was_connected)
2176 { 2227 {
2228 GST_validation_set_address_use (&n->id,
2229 n->plugin_name,
2230 n->session,
2231 n->addr,
2232 n->addrlen,
2233 GNUNET_YES);
2177 neighbours_connected++; 2234 neighbours_connected++;
2178 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2235 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2179 GNUNET_NO); 2236 GNUNET_NO);
@@ -2333,19 +2390,20 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2333 /* do blacklist check */ 2390 /* do blacklist check */
2334 bcc = 2391 bcc =
2335 GNUNET_malloc (sizeof (struct BlackListCheckContext) + 2392 GNUNET_malloc (sizeof (struct BlackListCheckContext) +
2336 sizeof (struct GNUNET_ATS_Information) * ats_count + 2393 sizeof (struct GNUNET_ATS_Information) * (ats_count + 1) +
2337 sender_address_len + strlen (plugin_name) + 1); 2394 sender_address_len + strlen (plugin_name) + 1);
2338 2395
2339 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2396 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2340 2397
2341 bcc->ats_count = ats_count; 2398 bcc->ats_count = ats_count + 1;
2342 bcc->sender_address_len = sender_address_len; 2399 bcc->sender_address_len = sender_address_len;
2343 bcc->session = session; 2400 bcc->session = session;
2344 2401
2345 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; 2402 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
2346 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); 2403 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2347 2404 bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
2348 bcc->sender_address = (char *) &bcc->ats[ats_count]; 2405 bcc->ats[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value);
2406 bcc->sender_address = (char *) &bcc->ats[ats_count + 1];
2349 memcpy (bcc->sender_address, sender_address, sender_address_len); 2407 memcpy (bcc->sender_address, sender_address, sender_address_len);
2350 2408
2351 bcc->plugin_name = &bcc->sender_address[sender_address_len]; 2409 bcc->plugin_name = &bcc->sender_address[sender_address_len];
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 3aafc3d55..48e54e656 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -265,6 +265,18 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
265 const struct GNUNET_ATS_Information *ats, 265 const struct GNUNET_ATS_Information *ats,
266 uint32_t ats_count); 266 uint32_t ats_count);
267 267
268
269/**
270 * Obtain current latency information for the given neighbour.
271 *
272 * @param peer
273 * @return observed latency of the address, FOREVER if the address was
274 * never successfully validated
275 */
276struct GNUNET_TIME_Relative
277GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
278
279
268/** 280/**
269 * We received a disconnect message from the given peer, 281 * We received a disconnect message from the given peer,
270 * validate and process. 282 * validate and process.
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index ce2ef76a7..afc35a3a6 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -529,13 +529,6 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
529 529
530 ve->revalidation_task = GNUNET_SCHEDULER_NO_TASK; 530 ve->revalidation_task = GNUNET_SCHEDULER_NO_TASK;
531 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); 531 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
532 if (delay.rel_value > 0)
533 {
534 /* should wait a bit longer */
535 ve->revalidation_task =
536 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
537 return;
538 }
539 /* How long until we can possibly permit the next PING? */ 532 /* How long until we can possibly permit the next PING? */
540 canonical_delay = 533 canonical_delay =
541 (ve->in_use == GNUNET_YES) 534 (ve->in_use == GNUNET_YES)
@@ -543,6 +536,19 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
543 : ( (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0) 536 : ( (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0)
544 ? VALIDATED_PING_FREQUENCY 537 ? VALIDATED_PING_FREQUENCY
545 : UNVALIDATED_PING_KEEPALIVE); 538 : UNVALIDATED_PING_KEEPALIVE);
539 if (delay.rel_value > canonical_delay.rel_value * 2)
540 {
541 /* situation changed, recalculate delay */
542 delay = canonical_delay;
543 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
544 }
545 if (delay.rel_value > 0)
546 {
547 /* should wait a bit longer */
548 ve->revalidation_task =
549 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
550 return;
551 }
546 ve->revalidation_block = 552 ve->revalidation_block =
547 GNUNET_TIME_relative_to_absolute (canonical_delay); 553 GNUNET_TIME_relative_to_absolute (canonical_delay);
548 554
@@ -1180,10 +1186,9 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1180 * Based on this, the validation module will measure latency for the 1186 * Based on this, the validation module will measure latency for the
1181 * address more or less often. 1187 * address more or less often.
1182 * 1188 *
1183 * @param sender peer sending the PING 1189 * @param sender peer
1184 * @param hdr the PING 1190 * @param plugin_name name of plugin
1185 * @param plugin_name name of plugin that received the PING 1191 * @param session session
1186 * @param session session we got the PING from
1187 * @param sender_address address of the sender as known to the plugin, NULL 1192 * @param sender_address address of the sender as known to the plugin, NULL
1188 * if we did not initiate the connection 1193 * if we did not initiate the connection
1189 * @param sender_address_len number of bytes in sender_address 1194 * @param sender_address_len number of bytes in sender_address
@@ -1192,13 +1197,32 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1192 */ 1197 */
1193void 1198void
1194GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, 1199GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
1195 const struct GNUNET_MessageHeader *hdr,
1196 const char *plugin_name, struct Session *session, 1200 const char *plugin_name, struct Session *session,
1197 const void *sender_address, 1201 const void *sender_address,
1198 size_t sender_address_len, 1202 size_t sender_address_len,
1199 int in_use) 1203 int in_use)
1200{ 1204{
1201 // FIXME: lookup address, update flag, re-schedule validation task 1205 struct ValidationEntry *ve;
1206
1207 ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len);
1208 if (NULL == ve)
1209 {
1210 /* FIXME: this can happen for inbound connections (sender_address_len == 0);
1211 in that case, we should hack up some more code here to measure
1212 latency for inbound connections! Also, in this case we'll need the session...
1213 */
1214 GNUNET_break (0);
1215 return;
1216 }
1217 GNUNET_break (ve->in_use != in_use); /* should be different... */
1218 ve->in_use = in_use;
1219 if (in_use == GNUNET_YES)
1220 {
1221 /* from now on, higher frequeny, so reschedule now */
1222 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1223 ve->revalidation_task =
1224 GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1225 }
1202} 1226}
1203 1227
1204 1228
@@ -1206,10 +1230,9 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
1206 * Query validation about the latest observed latency on a given 1230 * Query validation about the latest observed latency on a given
1207 * address. 1231 * address.
1208 * 1232 *
1209 * @param sender peer sending the PING 1233 * @param sender peer
1210 * @param hdr the PING 1234 * @param plugin_name name of plugin
1211 * @param plugin_name name of plugin that received the PING 1235 * @param session session
1212 * @param session session we got the PING from
1213 * @param sender_address address of the sender as known to the plugin, NULL 1236 * @param sender_address address of the sender as known to the plugin, NULL
1214 * if we did not initiate the connection 1237 * if we did not initiate the connection
1215 * @param sender_address_len number of bytes in sender_address 1238 * @param sender_address_len number of bytes in sender_address
@@ -1218,13 +1241,16 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
1218 */ 1241 */
1219struct GNUNET_TIME_Relative 1242struct GNUNET_TIME_Relative
1220GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, 1243GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
1221 const struct GNUNET_MessageHeader *hdr,
1222 const char *plugin_name, struct Session *session, 1244 const char *plugin_name, struct Session *session,
1223 const void *sender_address, 1245 const void *sender_address,
1224 size_t sender_address_len) 1246 size_t sender_address_len)
1225{ 1247{
1226 // FIXME: lookup address, return latency field... 1248 struct ValidationEntry *ve;
1227 return GNUNET_TIME_UNIT_ZERO; 1249
1250 ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len);
1251 if (NULL == ve)
1252 return GNUNET_TIME_UNIT_FOREVER_REL;
1253 return ve->latency;
1228} 1254}
1229 1255
1230 1256
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index 0e3c5e96d..2d93e508e 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -50,10 +50,9 @@ GST_validation_stop (void);
50 * Based on this, the validation module will measure latency for the 50 * Based on this, the validation module will measure latency for the
51 * address more or less often. 51 * address more or less often.
52 * 52 *
53 * @param sender peer sending the PING 53 * @param sender peer
54 * @param hdr the PING 54 * @param plugin_name name of plugin
55 * @param plugin_name name of plugin that received the PING 55 * @param session session
56 * @param session session we got the PING from
57 * @param sender_address address of the sender as known to the plugin, NULL 56 * @param sender_address address of the sender as known to the plugin, NULL
58 * if we did not initiate the connection 57 * if we did not initiate the connection
59 * @param sender_address_len number of bytes in sender_address 58 * @param sender_address_len number of bytes in sender_address
@@ -62,7 +61,6 @@ GST_validation_stop (void);
62 */ 61 */
63void 62void
64GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, 63GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
65 const struct GNUNET_MessageHeader *hdr,
66 const char *plugin_name, struct Session *session, 64 const char *plugin_name, struct Session *session,
67 const void *sender_address, 65 const void *sender_address,
68 size_t sender_address_len, 66 size_t sender_address_len,
@@ -73,10 +71,9 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
73 * Query validation about the latest observed latency on a given 71 * Query validation about the latest observed latency on a given
74 * address. 72 * address.
75 * 73 *
76 * @param sender peer sending the PING 74 * @param sender peer
77 * @param hdr the PING 75 * @param plugin_name name of plugin
78 * @param plugin_name name of plugin that received the PING 76 * @param session session
79 * @param session session we got the PING from
80 * @param sender_address address of the sender as known to the plugin, NULL 77 * @param sender_address address of the sender as known to the plugin, NULL
81 * if we did not initiate the connection 78 * if we did not initiate the connection
82 * @param sender_address_len number of bytes in sender_address 79 * @param sender_address_len number of bytes in sender_address
@@ -85,7 +82,6 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender,
85 */ 82 */
86struct GNUNET_TIME_Relative 83struct GNUNET_TIME_Relative
87GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, 84GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
88 const struct GNUNET_MessageHeader *hdr,
89 const char *plugin_name, struct Session *session, 85 const char *plugin_name, struct Session *session,
90 const void *sender_address, 86 const void *sender_address,
91 size_t sender_address_len); 87 size_t sender_address_len);