aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c121
1 files changed, 71 insertions, 50 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index afe7ac467..c0e605114 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -931,8 +931,9 @@ multicast_pong (void *cls,
931 * @param hdr the PING 931 * @param hdr the PING
932 * @param sender_address the sender address as we got it 932 * @param sender_address the sender address as we got it
933 * @param session session we got the PING from 933 * @param session session we got the PING from
934 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
934 */ 935 */
935void 936int
936GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 937GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
937 const struct GNUNET_MessageHeader *hdr, 938 const struct GNUNET_MessageHeader *hdr,
938 const struct GNUNET_HELLO_Address *sender_address, 939 const struct GNUNET_HELLO_Address *sender_address,
@@ -956,7 +957,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
956 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) 957 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
957 { 958 {
958 GNUNET_break_op (0); 959 GNUNET_break_op (0);
959 return; 960 return GNUNET_SYSERR;
960 } 961 }
961 ping = (const struct TransportPingMessage *) hdr; 962 ping = (const struct TransportPingMessage *) hdr;
962 if (0 != 963 if (0 !=
@@ -967,7 +968,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
967 gettext_noop 968 gettext_noop
968 ("# PING message for different peer received"), 1, 969 ("# PING message for different peer received"), 1,
969 GNUNET_NO); 970 GNUNET_NO);
970 return; 971 return GNUNET_SYSERR;
971 } 972 }
972 GNUNET_STATISTICS_update (GST_stats, 973 GNUNET_STATISTICS_update (GST_stats,
973 gettext_noop ("# PING messages received"), 1, 974 gettext_noop ("# PING messages received"), 1,
@@ -986,7 +987,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
986 if (NULL == addrend) 987 if (NULL == addrend)
987 { 988 {
988 GNUNET_break_op (0); 989 GNUNET_break_op (0);
989 return; 990 return GNUNET_SYSERR;
990 } 991 }
991 addrend++; 992 addrend++;
992 slen = strlen (addr) + 1; 993 slen = strlen (addr) + 1;
@@ -998,38 +999,40 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
998 999
999 if (NULL == address.transport_name) 1000 if (NULL == address.transport_name)
1000 { 1001 {
1001 GNUNET_break (0); 1002 GNUNET_break (0);
1002 } 1003 }
1003 1004
1004 if (0 != strstr (address.transport_name, "_client")) 1005 if (0 != strstr (address.transport_name, "_client"))
1005 { 1006 {
1006 plugin_name = GNUNET_strdup (address.transport_name); 1007 plugin_name = GNUNET_strdup (address.transport_name);
1007 pos = strstr (plugin_name, "_client"); 1008 pos = strstr (plugin_name, "_client");
1008 GNUNET_assert (NULL != pos); 1009 GNUNET_assert (NULL != pos);
1009 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server"); 1010 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1010 } 1011 }
1011 else 1012 else
1012 plugin_name = GNUNET_strdup (address.transport_name); 1013 plugin_name = GNUNET_strdup (address.transport_name);
1013 1014
1014 if (NULL == (papi = GST_plugins_find (plugin_name))) 1015 if (NULL == (papi = GST_plugins_find (plugin_name)))
1015 { 1016 {
1016 /* we don't have the plugin for this address */ 1017 /* we don't have the plugin for this address */
1017 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin `%s' not available, cannot confirm having this address \n", 1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1018 plugin_name); 1019 _("Plugin `%s' not available, cannot confirm having this address\n"),
1020 plugin_name);
1019 GNUNET_free (plugin_name); 1021 GNUNET_free (plugin_name);
1020 return; 1022 return GNUNET_SYSERR;
1021 } 1023 }
1022 GNUNET_free (plugin_name); 1024 GNUNET_free (plugin_name);
1023 if (GNUNET_OK != papi->check_address (papi->cls, addrend, alen)) 1025 if (GNUNET_OK != papi->check_address (papi->cls, addrend, alen))
1024 { 1026 {
1025 GNUNET_STATISTICS_update (GST_stats, 1027 GNUNET_STATISTICS_update (GST_stats,
1026 gettext_noop 1028 gettext_noop
1027 ("# failed address checks during validation"), 1, 1029 ("# failed address checks during validation"), 1,
1028 GNUNET_NO); 1030 GNUNET_NO);
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Address `%s' is not one of my addresses, not confirming PING\n", 1031 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1030 GST_plugins_a2s (&address)); 1032 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1031 return; 1033 GST_plugins_a2s (&address));
1032 } 1034 return GNUNET_SYSERR;
1035 }
1033 else 1036 else
1034 { 1037 {
1035 GNUNET_STATISTICS_update (GST_stats, 1038 GNUNET_STATISTICS_update (GST_stats,
@@ -1046,10 +1049,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1046 if (GNUNET_NO == buggy) 1049 if (GNUNET_NO == buggy)
1047 { 1050 {
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049 "Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n", 1052 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1050 GNUNET_i2s (sender), 1053 GNUNET_i2s (sender),
1051 GST_plugins_a2s (&address)); 1054 GST_plugins_a2s (&address));
1052 return; 1055 return GNUNET_SYSERR;
1053 } 1056 }
1054 else 1057 else
1055 { 1058 {
@@ -1145,8 +1148,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1145 NULL, NULL); 1148 NULL, NULL);
1146 if (-1 != ret) 1149 if (-1 != ret)
1147 GST_neighbours_notify_data_sent (sender, 1150 GST_neighbours_notify_data_sent (sender,
1148 sender_address, session, pong->header.size); 1151 sender_address, session,
1149 1152 pong->header.size);
1150 } 1153 }
1151 } 1154 }
1152 if (ret != -1) 1155 if (ret != -1)
@@ -1160,7 +1163,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1160 ("# PONGs unicast via reliable transport"), 1, 1163 ("# PONGs unicast via reliable transport"), 1,
1161 GNUNET_NO); 1164 GNUNET_NO);
1162 GNUNET_free (pong); 1165 GNUNET_free (pong);
1163 return; 1166 return GNUNET_OK;
1164 } 1167 }
1165 1168
1166 /* no reliable method found, try transmission via all known addresses */ 1169 /* no reliable method found, try transmission via all known addresses */
@@ -1168,13 +1171,15 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1168 gettext_noop 1171 gettext_noop
1169 ("# PONGs multicast to all available addresses"), 1, 1172 ("# PONGs multicast to all available addresses"), 1,
1170 GNUNET_NO); 1173 GNUNET_NO);
1171 GST_validation_get_addresses (sender, &multicast_pong, pong); 1174 GST_validation_get_addresses (sender,
1175 &multicast_pong, pong);
1172 GNUNET_free (pong); 1176 GNUNET_free (pong);
1177 return GNUNET_OK;
1173} 1178}
1174 1179
1175 1180
1176/** 1181/**
1177 * Context for the 'validate_address' function 1182 * Context for the #validate_address_iterator() function
1178 */ 1183 */
1179struct ValidateAddressContext 1184struct ValidateAddressContext
1180{ 1185{
@@ -1187,6 +1192,7 @@ struct ValidateAddressContext
1187 * Public key of the peer whose address is being validated. 1192 * Public key of the peer whose address is being validated.
1188 */ 1193 */
1189 struct GNUNET_CRYPTO_EddsaPublicKey public_key; 1194 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
1195
1190}; 1196};
1191 1197
1192 1198
@@ -1194,7 +1200,7 @@ struct ValidateAddressContext
1194 * Iterator callback to go over all addresses and try to validate them 1200 * Iterator callback to go over all addresses and try to validate them
1195 * (unless blocked or already validated). 1201 * (unless blocked or already validated).
1196 * 1202 *
1197 * @param cls pointer to a 'struct ValidateAddressContext' 1203 * @param cls pointer to a `struct ValidateAddressContext`
1198 * @param address the address 1204 * @param address the address
1199 * @param expiration expiration time 1205 * @param expiration expiration time
1200 * @return #GNUNET_OK (keep the address) 1206 * @return #GNUNET_OK (keep the address)
@@ -1218,7 +1224,7 @@ validate_address_iterator (void *cls,
1218 { 1224 {
1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1220 "Starting validation for fresh address %s\n", 1226 "Starting validation for fresh address %s\n",
1221 GST_plugins_a2s (ve->address)); 1227 GST_plugins_a2s (ve->address));
1222 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 1228 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1223 } 1229 }
1224 return GNUNET_OK; 1230 return GNUNET_OK;
@@ -1252,8 +1258,9 @@ add_valid_peer_address (void *cls, size_t max, void *buf)
1252 * 1258 *
1253 * @param sender peer sending the PONG 1259 * @param sender peer sending the PONG
1254 * @param hdr the PONG 1260 * @param hdr the PONG
1261 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1255 */ 1262 */
1256void 1263int
1257GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, 1264GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1258 const struct GNUNET_MessageHeader *hdr) 1265 const struct GNUNET_MessageHeader *hdr)
1259{ 1266{
@@ -1272,7 +1279,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1272 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) 1279 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1273 { 1280 {
1274 GNUNET_break_op (0); 1281 GNUNET_break_op (0);
1275 return; 1282 return GNUNET_SYSERR;
1276 } 1283 }
1277 GNUNET_STATISTICS_update (GST_stats, 1284 GNUNET_STATISTICS_update (GST_stats,
1278 gettext_noop ("# PONG messages received"), 1, 1285 gettext_noop ("# PONG messages received"), 1,
@@ -1288,7 +1295,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1288 if (NULL == addr) 1295 if (NULL == addr)
1289 { 1296 {
1290 GNUNET_break_op (0); 1297 GNUNET_break_op (0);
1291 return; 1298 return GNUNET_SYSERR;
1292 } 1299 }
1293 addr++; 1300 addr++;
1294 slen = strlen (tname) + 1; 1301 slen = strlen (tname) + 1;
@@ -1304,13 +1311,13 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1304 gettext_noop 1311 gettext_noop
1305 ("# PONGs dropped, no matching pending validation"), 1312 ("# PONGs dropped, no matching pending validation"),
1306 1, GNUNET_NO); 1313 1, GNUNET_NO);
1307 return; 1314 return GNUNET_OK;
1308 } 1315 }
1309 /* now check that PONG is well-formed */ 1316 /* now check that PONG is well-formed */
1310 if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity))) 1317 if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity)))
1311 { 1318 {
1312 GNUNET_break_op (0); 1319 GNUNET_break_op (0);
1313 return; 1320 return GNUNET_SYSERR;
1314 } 1321 }
1315 if (GNUNET_TIME_absolute_get_remaining 1322 if (GNUNET_TIME_absolute_get_remaining
1316 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us == 0) 1323 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us == 0)
@@ -1319,7 +1326,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1319 gettext_noop 1326 gettext_noop
1320 ("# PONGs dropped, signature expired"), 1, 1327 ("# PONGs dropped, signature expired"), 1,
1321 GNUNET_NO); 1328 GNUNET_NO);
1322 return; 1329 return GNUNET_SYSERR;
1323 } 1330 }
1324 1331
1325 sig_res = GNUNET_SYSERR; 1332 sig_res = GNUNET_SYSERR;
@@ -1348,13 +1355,20 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1348 &pong->purpose, &pong->signature, 1355 &pong->purpose, &pong->signature,
1349 &ve->public_key); 1356 &ve->public_key);
1350 if (sig_res == GNUNET_SYSERR) 1357 if (sig_res == GNUNET_SYSERR)
1358 {
1359 GNUNET_break_op (0);
1351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1352 "Failed to verify: invalid signature on address %s:%s from peer `%s'\n", 1361 "Failed to verify: invalid signature on address %s:%s from peer `%s'\n",
1353 tname, GST_plugins_a2s (ve->address),GNUNET_i2s (sender)); 1362 tname,
1363 GST_plugins_a2s (ve->address),
1364 GNUNET_i2s (sender));
1365 }
1354 } 1366 }
1355
1356 if (sig_res == GNUNET_SYSERR) 1367 if (sig_res == GNUNET_SYSERR)
1357 return; 1368 {
1369 GNUNET_break_op (0);
1370 return GNUNET_SYSERR;
1371 }
1358 1372
1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1360 "Address validated for peer `%s' with plugin `%s': `%s'\n", 1374 "Address validated for peer `%s' with plugin `%s': `%s'\n",
@@ -1367,6 +1381,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1367 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); 1381 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1368 { 1382 {
1369 struct GNUNET_ATS_Information ats[2]; 1383 struct GNUNET_ATS_Information ats[2];
1384
1370 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 1385 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
1371 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us); 1386 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
1372 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); 1387 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -1381,7 +1396,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1381 validations_running); 1396 validations_running);
1382 } 1397 }
1383 else 1398 else
1384 GNUNET_break (0); 1399 {
1400 GNUNET_break (0);
1401 }
1385 1402
1386 /* build HELLO to store in PEERINFO */ 1403 /* build HELLO to store in PEERINFO */
1387 ve->copied = GNUNET_NO; 1404 ve->copied = GNUNET_NO;
@@ -1390,6 +1407,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1390 GNUNET_NO); 1407 GNUNET_NO);
1391 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL); 1408 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1392 GNUNET_free (hello); 1409 GNUNET_free (hello);
1410 return GNUNET_OK;
1393} 1411}
1394 1412
1395 1413
@@ -1398,8 +1416,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1398 * validation. 1416 * validation.
1399 * 1417 *
1400 * @param hello the HELLO we received 1418 * @param hello the HELLO we received
1419 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1401 */ 1420 */
1402void 1421int
1403GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) 1422GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1404{ 1423{
1405 const struct GNUNET_HELLO_Message *hm = 1424 const struct GNUNET_HELLO_Message *hm =
@@ -1409,17 +1428,18 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1409 int friend; 1428 int friend;
1410 1429
1411 friend = GNUNET_HELLO_is_friend_only (hm); 1430 friend = GNUNET_HELLO_is_friend_only (hm);
1412 if (((GNUNET_YES != friend) && (GNUNET_NO != friend)) || 1431 if ( ( (GNUNET_YES != friend) &&
1413 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) || 1432 (GNUNET_NO != friend) ) ||
1414 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key))) 1433 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1434 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
1415 { 1435 {
1416 /* malformed HELLO */ 1436 /* malformed HELLO */
1417 GNUNET_break (0); 1437 GNUNET_break_op (0);
1418 return; 1438 return GNUNET_SYSERR;
1419 } 1439 }
1420 if (0 == 1440 if (0 ==
1421 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity))) 1441 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
1422 return; 1442 return GNUNET_OK;
1423 /* Add peer identity without addresses to peerinfo service */ 1443 /* Add peer identity without addresses to peerinfo service */
1424 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL, friend); 1444 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL, friend);
1425 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL); 1445 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
@@ -1433,11 +1453,12 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1433 GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO, 1453 GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO,
1434 &validate_address_iterator, 1454 &validate_address_iterator,
1435 &vac)); 1455 &vac));
1456 return GNUNET_OK;
1436} 1457}
1437 1458
1438 1459
1439/** 1460/**
1440 * Closure for 'iterate_addresses' 1461 * Closure for #iterate_addresses().
1441 */ 1462 */
1442struct IteratorContext 1463struct IteratorContext
1443{ 1464{
@@ -1447,7 +1468,7 @@ struct IteratorContext
1447 GST_ValidationAddressCallback cb; 1468 GST_ValidationAddressCallback cb;
1448 1469
1449 /** 1470 /**
1450 * Closure for 'cb'. 1471 * Closure for @e cb.
1451 */ 1472 */
1452 void *cb_cls; 1473 void *cb_cls;
1453 1474
@@ -1457,9 +1478,9 @@ struct IteratorContext
1457/** 1478/**
1458 * Call the callback in the closure for each validation entry. 1479 * Call the callback in the closure for each validation entry.
1459 * 1480 *
1460 * @param cls the 'struct GST_ValidationIteratorContext' 1481 * @param cls the `struct IteratorContext`
1461 * @param key the peer's identity 1482 * @param key the peer's identity
1462 * @param value the 'struct ValidationEntry' 1483 * @param value the `struct ValidationEntry`
1463 * @return #GNUNET_OK (continue to iterate) 1484 * @return #GNUNET_OK (continue to iterate)
1464 */ 1485 */
1465static int 1486static int