diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_nat_lib.h | 5 | ||||
-rw-r--r-- | src/include/gnunet_peerstore_service.h | 4 | ||||
-rw-r--r-- | src/nat/nat.c | 225 | ||||
-rw-r--r-- | src/nat/nat.h | 4 | ||||
-rw-r--r-- | src/peerinfo-tool/gnunet-peerinfo.c | 15 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 16 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_hello.c | 65 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 10 |
8 files changed, 211 insertions, 133 deletions
diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h index 88f8f6d65..101517e8b 100644 --- a/src/include/gnunet_nat_lib.h +++ b/src/include/gnunet_nat_lib.h | |||
@@ -80,14 +80,17 @@ enum GNUNET_NAT_Type | |||
80 | * We have a direct connection | 80 | * We have a direct connection |
81 | */ | 81 | */ |
82 | GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, | 82 | GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, |
83 | |||
83 | /** | 84 | /** |
84 | * We are under a NAT but cannot traverse it | 85 | * We are under a NAT but cannot traverse it |
85 | */ | 86 | */ |
86 | GNUNET_NAT_TYPE_UNREACHABLE_NAT, | 87 | GNUNET_NAT_TYPE_UNREACHABLE_NAT, |
88 | |||
87 | /** | 89 | /** |
88 | * We can traverse using STUN | 90 | * We can traverse using STUN |
89 | */ | 91 | */ |
90 | GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, | 92 | GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, |
93 | |||
91 | /** | 94 | /** |
92 | * WE can traverse using UPNP | 95 | * WE can traverse using UPNP |
93 | */ | 96 | */ |
@@ -195,8 +198,6 @@ enum GNUNET_NAT_StatusCode | |||
195 | */ | 198 | */ |
196 | GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND, | 199 | GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND, |
197 | 200 | ||
198 | |||
199 | |||
200 | /** | 201 | /** |
201 | * | 202 | * |
202 | */ | 203 | */ |
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h index b32b29a78..556260928 100644 --- a/src/include/gnunet_peerstore_service.h +++ b/src/include/gnunet_peerstore_service.h | |||
@@ -116,7 +116,9 @@ struct GNUNET_PEERSTORE_Record | |||
116 | * @param success #GNUNET_OK or #GNUNET_SYSERR | 116 | * @param success #GNUNET_OK or #GNUNET_SYSERR |
117 | */ | 117 | */ |
118 | typedef void | 118 | typedef void |
119 | (*GNUNET_PEERSTORE_Continuation)(void *cls, int success); | 119 | (*GNUNET_PEERSTORE_Continuation)(void *cls, |
120 | int success); | ||
121 | |||
120 | 122 | ||
121 | /** | 123 | /** |
122 | * Function called by PEERSTORE for each matching record. | 124 | * Function called by PEERSTORE for each matching record. |
diff --git a/src/nat/nat.c b/src/nat/nat.c index e51c001f2..709a13f03 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -454,18 +454,15 @@ static void | |||
454 | start_gnunet_nat_server (struct GNUNET_NAT_Handle *h); | 454 | start_gnunet_nat_server (struct GNUNET_NAT_Handle *h); |
455 | 455 | ||
456 | 456 | ||
457 | |||
458 | |||
459 | /** | 457 | /** |
460 | * Call task to process STUN | 458 | * Call task to process STUN |
461 | * | 459 | * |
462 | * @param cls handle to NAT | 460 | * @param cls handle to NAT |
463 | * @param tc TaskContext | 461 | * @param tc TaskContext |
464 | */ | 462 | */ |
465 | |||
466 | static void | 463 | static void |
467 | process_stun (void *cls, | 464 | process_stun (void *cls, |
468 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 465 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
469 | 466 | ||
470 | 467 | ||
471 | /** | 468 | /** |
@@ -488,10 +485,14 @@ remove_from_address_list_by_source (struct GNUNET_NAT_Handle *h, | |||
488 | next = pos->next; | 485 | next = pos->next; |
489 | if (pos->source != src) | 486 | if (pos->source != src) |
490 | continue; | 487 | continue; |
491 | GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); | 488 | GNUNET_CONTAINER_DLL_remove (h->lal_head, |
489 | h->lal_tail, | ||
490 | pos); | ||
492 | if (NULL != h->address_callback) | 491 | if (NULL != h->address_callback) |
493 | h->address_callback (h->callback_cls, GNUNET_NO, | 492 | h->address_callback (h->callback_cls, |
494 | (const struct sockaddr *) &pos[1], pos->addrlen); | 493 | GNUNET_NO, |
494 | (const struct sockaddr *) &pos[1], | ||
495 | pos->addrlen); | ||
495 | GNUNET_free (pos); | 496 | GNUNET_free (pos); |
496 | } | 497 | } |
497 | } | 498 | } |
@@ -509,7 +510,8 @@ remove_from_address_list_by_source (struct GNUNET_NAT_Handle *h, | |||
509 | static void | 510 | static void |
510 | add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | 511 | add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, |
511 | enum LocalAddressSource src, | 512 | enum LocalAddressSource src, |
512 | const struct sockaddr *arg, socklen_t arg_size) | 513 | const struct sockaddr *arg, |
514 | socklen_t arg_size) | ||
513 | { | 515 | { |
514 | struct LocalAddressList *lal; | 516 | struct LocalAddressList *lal; |
515 | 517 | ||
@@ -517,13 +519,18 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | |||
517 | memcpy (&lal[1], arg, arg_size); | 519 | memcpy (&lal[1], arg, arg_size); |
518 | lal->addrlen = arg_size; | 520 | lal->addrlen = arg_size; |
519 | lal->source = src; | 521 | lal->source = src; |
520 | GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal); | 522 | GNUNET_CONTAINER_DLL_insert (h->lal_head, |
523 | h->lal_tail, | ||
524 | lal); | ||
521 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 525 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
522 | "Adding address `%s' from source %d\n", | 526 | "Adding address `%s' from source %d\n", |
523 | GNUNET_a2s (arg, arg_size), | 527 | GNUNET_a2s (arg, arg_size), |
524 | src); | 528 | src); |
525 | if (NULL != h->address_callback) | 529 | if (NULL != h->address_callback) |
526 | h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size); | 530 | h->address_callback (h->callback_cls, |
531 | GNUNET_YES, | ||
532 | arg, | ||
533 | arg_size); | ||
527 | } | 534 | } |
528 | 535 | ||
529 | 536 | ||
@@ -1110,15 +1117,13 @@ list_interfaces (void *cls, | |||
1110 | * @param result , the status | 1117 | * @param result , the status |
1111 | */ | 1118 | */ |
1112 | static void | 1119 | static void |
1113 | stun_request_callback(void *cls, | 1120 | stun_request_callback (void *cls, |
1114 | enum GNUNET_NAT_StatusCode result) | 1121 | enum GNUNET_NAT_StatusCode result) |
1115 | { | 1122 | { |
1116 | |||
1117 | struct GNUNET_NAT_Handle *h = cls; | 1123 | struct GNUNET_NAT_Handle *h = cls; |
1118 | 1124 | ||
1119 | if(NULL == cls) | 1125 | if (NULL == h) |
1120 | return; | 1126 | return; |
1121 | |||
1122 | h->waiting_stun = GNUNET_NO; | 1127 | h->waiting_stun = GNUNET_NO; |
1123 | 1128 | ||
1124 | if(result != GNUNET_OK) | 1129 | if(result != GNUNET_OK) |
@@ -1126,58 +1131,64 @@ stun_request_callback(void *cls, | |||
1126 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1131 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1127 | "Error processing a STUN request"); | 1132 | "Error processing a STUN request"); |
1128 | } | 1133 | } |
1134 | } | ||
1129 | 1135 | ||
1130 | }; | ||
1131 | 1136 | ||
1132 | /** | 1137 | /** |
1133 | * CHECK if is a valid STUN packet sending to GNUNET_NAT_stun_handle_packet. | 1138 | * CHECK if is a valid STUN packet sending to GNUNET_NAT_stun_handle_packet(). |
1134 | * It also check if it can handle the packet based on the NAT handler. | 1139 | * It also check if it can handle the packet based on the NAT handler. |
1135 | * You don't need to call anything else to check if the packet is valid, | 1140 | * You don't need to call anything else to check if the packet is valid, |
1136 | * | 1141 | * |
1137 | * @param cls the NAT handle | 1142 | * @param cls the NAT handle |
1138 | * @param data, packet | 1143 | * @param data packet |
1139 | * @param len, packet length | 1144 | * @param len packet length |
1140 | * | ||
1141 | * @return #GNUNET_NO if it can't decode, #GNUNET_YES if is a packet | 1145 | * @return #GNUNET_NO if it can't decode, #GNUNET_YES if is a packet |
1142 | */ | 1146 | */ |
1143 | int | 1147 | int |
1144 | GNUNET_NAT_is_valid_stun_packet(void *cls, const void *data, size_t len) | 1148 | GNUNET_NAT_is_valid_stun_packet (void *cls, |
1149 | const void *data, | ||
1150 | size_t len) | ||
1145 | { | 1151 | { |
1146 | struct GNUNET_NAT_Handle *h = cls; | 1152 | struct GNUNET_NAT_Handle *h = cls; |
1147 | struct sockaddr_in answer; | 1153 | struct sockaddr_in answer; |
1148 | 1154 | ||
1149 | /* We are not expecting a STUN message*/ | 1155 | /* We are not expecting a STUN message */ |
1150 | if(!h->waiting_stun) | 1156 | if (! h->waiting_stun) |
1151 | return GNUNET_NO; | 1157 | return GNUNET_NO; |
1152 | 1158 | ||
1153 | /*We dont have STUN installed*/ | 1159 | /* We dont have STUN installed */ |
1154 | if(!h->use_stun) | 1160 | if (! h->use_stun) |
1155 | return GNUNET_NO; | 1161 | return GNUNET_NO; |
1156 | 1162 | ||
1157 | /* Empty the answer structure */ | 1163 | /* Empty the answer structure */ |
1158 | memset(&answer, 0, sizeof(struct sockaddr_in)); | 1164 | memset (&answer, |
1165 | 0, | ||
1166 | sizeof(struct sockaddr_in)); | ||
1159 | 1167 | ||
1160 | /*Lets handle the packet*/ | 1168 | /*Lets handle the packet*/ |
1161 | int valid = GNUNET_NAT_stun_handle_packet(data,len, &answer); | 1169 | int valid = GNUNET_NAT_stun_handle_packet (data, |
1162 | if(valid) | 1170 | len, |
1163 | { | 1171 | &answer); |
1164 | LOG (GNUNET_ERROR_TYPE_INFO, | 1172 | if (! valid) |
1165 | "Stun server returned IP %s , with port %d \n", inet_ntoa(answer.sin_addr), ntohs(answer.sin_port)); | ||
1166 | /* ADD IP AS VALID*/ | ||
1167 | add_to_address_list (h, LAL_EXTERNAL_IP, (const struct sockaddr *) &answer, | ||
1168 | sizeof (struct sockaddr_in)); | ||
1169 | h->waiting_stun = GNUNET_NO; | ||
1170 | return GNUNET_YES; | ||
1171 | } | ||
1172 | else | ||
1173 | { | ||
1174 | return GNUNET_NO; | 1173 | return GNUNET_NO; |
1175 | } | ||
1176 | |||
1177 | |||
1178 | 1174 | ||
1175 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1176 | "Stun server returned %s:%d\n", | ||
1177 | inet_ntoa (answer.sin_addr), | ||
1178 | ntohs (answer.sin_port)); | ||
1179 | /* Remove old IPs from previous STUN calls */ | ||
1180 | remove_from_address_list_by_source (h, | ||
1181 | LAL_EXTERNAL_STUN_IP); | ||
1182 | /* Add new IP from STUN packet */ | ||
1183 | add_to_address_list (h, | ||
1184 | LAL_EXTERNAL_STUN_IP, | ||
1185 | (const struct sockaddr *) &answer, | ||
1186 | sizeof (struct sockaddr_in)); | ||
1187 | h->waiting_stun = GNUNET_NO; | ||
1188 | return GNUNET_YES; | ||
1179 | } | 1189 | } |
1180 | 1190 | ||
1191 | |||
1181 | /** | 1192 | /** |
1182 | * Task to do a STUN request | 1193 | * Task to do a STUN request |
1183 | * | 1194 | * |
@@ -1186,36 +1197,39 @@ GNUNET_NAT_is_valid_stun_packet(void *cls, const void *data, size_t len) | |||
1186 | */ | 1197 | */ |
1187 | static void | 1198 | static void |
1188 | process_stun (void *cls, | 1199 | process_stun (void *cls, |
1189 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1200 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1190 | { | 1201 | { |
1191 | struct GNUNET_NAT_Handle *h = cls; | 1202 | struct GNUNET_NAT_Handle *h = cls; |
1192 | |||
1193 | h->stun_task = NULL; | ||
1194 | |||
1195 | |||
1196 | |||
1197 | struct StunServerList* elem = h->actual_stun_server; | 1203 | struct StunServerList* elem = h->actual_stun_server; |
1198 | 1204 | ||
1205 | h->stun_task = NULL; | ||
1199 | /* Make the request */ | 1206 | /* Make the request */ |
1200 | LOG (GNUNET_ERROR_TYPE_INFO, | 1207 | LOG (GNUNET_ERROR_TYPE_INFO, |
1201 | "I will request the stun server %s:%i !\n", elem->address, elem->port); | 1208 | "I will request the stun server %s:%i\n", |
1202 | 1209 | elem->address, | |
1203 | if(GNUNET_OK == GNUNET_NAT_stun_make_request(elem->address, elem->port, h->socket, &stun_request_callback, NULL)) | 1210 | elem->port); |
1211 | if (GNUNET_OK == | ||
1212 | GNUNET_NAT_stun_make_request (elem->address, | ||
1213 | elem->port, | ||
1214 | h->socket, | ||
1215 | &stun_request_callback, | ||
1216 | NULL)) | ||
1204 | { | 1217 | { |
1205 | h->waiting_stun = GNUNET_YES; | 1218 | h->waiting_stun = GNUNET_YES; |
1206 | } | 1219 | } |
1207 | else | 1220 | else |
1208 | { | 1221 | { |
1209 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1222 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1210 | "STUN request failed %s:%i !\n", elem->address, elem->port); | 1223 | "STUN request to %s:%i failed\n", |
1224 | elem->address, | ||
1225 | elem->port); | ||
1211 | } | 1226 | } |
1212 | |||
1213 | h->stun_task = | 1227 | h->stun_task = |
1214 | GNUNET_SCHEDULER_add_delayed (h->stun_frequency, | 1228 | GNUNET_SCHEDULER_add_delayed (h->stun_frequency, |
1215 | &process_stun, h); | 1229 | &process_stun, h); |
1216 | 1230 | ||
1217 | /* Set actual Server*/ | 1231 | /* Set actual Server*/ |
1218 | if(elem->next) | 1232 | if (NULL != elem->next) |
1219 | { | 1233 | { |
1220 | h->actual_stun_server = elem->next; | 1234 | h->actual_stun_server = elem->next; |
1221 | } | 1235 | } |
@@ -1223,11 +1237,9 @@ process_stun (void *cls, | |||
1223 | { | 1237 | { |
1224 | h->actual_stun_server = h->stun_servers_head; | 1238 | h->actual_stun_server = h->stun_servers_head; |
1225 | } | 1239 | } |
1226 | |||
1227 | } | 1240 | } |
1228 | 1241 | ||
1229 | 1242 | ||
1230 | |||
1231 | /** | 1243 | /** |
1232 | * Task to do a lookup on our hostname for IP addresses. | 1244 | * Task to do a lookup on our hostname for IP addresses. |
1233 | * | 1245 | * |
@@ -1303,15 +1315,16 @@ upnp_add (void *cls, | |||
1303 | /* Error while running upnp client */ | 1315 | /* Error while running upnp client */ |
1304 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1316 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1305 | _("Error while running upnp client:\n")); | 1317 | _("Error while running upnp client:\n")); |
1306 | |||
1307 | //FIXME: convert error code to string | 1318 | //FIXME: convert error code to string |
1308 | |||
1309 | return; | 1319 | return; |
1310 | } | 1320 | } |
1311 | 1321 | ||
1312 | if (GNUNET_YES == add_remove) | 1322 | if (GNUNET_YES == add_remove) |
1313 | { | 1323 | { |
1314 | add_to_address_list (h, LAL_UPNP, addr, addrlen); | 1324 | add_to_address_list (h, |
1325 | LAL_UPNP, | ||
1326 | addr, | ||
1327 | addrlen); | ||
1315 | return; | 1328 | return; |
1316 | } | 1329 | } |
1317 | else if (GNUNET_NO == add_remove) | 1330 | else if (GNUNET_NO == add_remove) |
@@ -1324,10 +1337,14 @@ upnp_add (void *cls, | |||
1324 | if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) || | 1337 | if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) || |
1325 | (0 != memcmp (&pos[1], addr, addrlen))) | 1338 | (0 != memcmp (&pos[1], addr, addrlen))) |
1326 | continue; | 1339 | continue; |
1327 | GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); | 1340 | GNUNET_CONTAINER_DLL_remove (h->lal_head, |
1341 | h->lal_tail, | ||
1342 | pos); | ||
1328 | if (NULL != h->address_callback) | 1343 | if (NULL != h->address_callback) |
1329 | h->address_callback (h->callback_cls, GNUNET_NO, | 1344 | h->address_callback (h->callback_cls, |
1330 | (const struct sockaddr *) &pos[1], pos->addrlen); | 1345 | GNUNET_NO, |
1346 | (const struct sockaddr *) &pos[1], | ||
1347 | pos->addrlen); | ||
1331 | GNUNET_free (pos); | 1348 | GNUNET_free (pos); |
1332 | return; /* only remove once */ | 1349 | return; /* only remove once */ |
1333 | } | 1350 | } |
@@ -1377,7 +1394,9 @@ add_minis (struct GNUNET_NAT_Handle *h, | |||
1377 | return; | 1394 | return; |
1378 | } | 1395 | } |
1379 | 1396 | ||
1380 | GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml); | 1397 | GNUNET_CONTAINER_DLL_insert (h->mini_head, |
1398 | h->mini_tail, | ||
1399 | ml); | ||
1381 | } | 1400 | } |
1382 | 1401 | ||
1383 | 1402 | ||
@@ -1470,7 +1489,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1470 | GNUNET_NAT_AddressCallback address_callback, | 1489 | GNUNET_NAT_AddressCallback address_callback, |
1471 | GNUNET_NAT_ReversalCallback reversal_callback, | 1490 | GNUNET_NAT_ReversalCallback reversal_callback, |
1472 | void *callback_cls, | 1491 | void *callback_cls, |
1473 | struct GNUNET_NETWORK_Handle* sock ) | 1492 | struct GNUNET_NETWORK_Handle *sock) |
1474 | { | 1493 | { |
1475 | struct GNUNET_NAT_Handle *h; | 1494 | struct GNUNET_NAT_Handle *h; |
1476 | struct in_addr in_addr; | 1495 | struct in_addr in_addr; |
@@ -1489,7 +1508,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1489 | h->callback_cls = callback_cls; | 1508 | h->callback_cls = callback_cls; |
1490 | h->num_local_addrs = num_addrs; | 1509 | h->num_local_addrs = num_addrs; |
1491 | h->adv_port = adv_port; | 1510 | h->adv_port = adv_port; |
1492 | if (num_addrs != 0) | 1511 | if (0 != num_addrs) |
1493 | { | 1512 | { |
1494 | h->local_addrs = GNUNET_malloc (num_addrs * sizeof (struct sockaddr *)); | 1513 | h->local_addrs = GNUNET_malloc (num_addrs * sizeof (struct sockaddr *)); |
1495 | h->local_addrlens = GNUNET_malloc (num_addrs * sizeof (socklen_t)); | 1514 | h->local_addrlens = GNUNET_malloc (num_addrs * sizeof (socklen_t)); |
@@ -1574,11 +1593,14 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1574 | 1593 | ||
1575 | /* STUN */ | 1594 | /* STUN */ |
1576 | h->use_stun = | 1595 | h->use_stun = |
1577 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", | 1596 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1578 | "USE_STUN"); | 1597 | "nat", |
1598 | "USE_STUN"); | ||
1579 | 1599 | ||
1580 | if (GNUNET_OK != | 1600 | if (GNUNET_OK != |
1581 | GNUNET_CONFIGURATION_get_value_time (cfg, "nat", "STUN_FREQUENCY", | 1601 | GNUNET_CONFIGURATION_get_value_time (cfg, |
1602 | "nat", | ||
1603 | "STUN_FREQUENCY", | ||
1582 | &h->stun_frequency)) | 1604 | &h->stun_frequency)) |
1583 | h->stun_frequency = STUN_FREQUENCY; | 1605 | h->stun_frequency = STUN_FREQUENCY; |
1584 | 1606 | ||
@@ -1599,25 +1621,28 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1599 | "No external IP address given to add to our list of addresses\n"); | 1621 | "No external IP address given to add to our list of addresses\n"); |
1600 | } | 1622 | } |
1601 | 1623 | ||
1602 | /* ENABLE STUN ONLY ON UDP*/ | 1624 | /* ENABLE STUN ONLY ON UDP */ |
1603 | if(!is_tcp && (NULL != sock) && h->use_stun ) | 1625 | if( (! is_tcp) && |
1626 | (NULL != sock) && | ||
1627 | h->use_stun) | ||
1604 | { | 1628 | { |
1605 | h->socket = sock; | ||
1606 | h->actual_stun_server = NULL; | ||
1607 | |||
1608 | /* Lets process the servers*/ | ||
1609 | char *stun_servers; | 1629 | char *stun_servers; |
1610 | |||
1611 | size_t urls; | 1630 | size_t urls; |
1612 | int pos; | 1631 | int pos; |
1613 | size_t pos_port; | 1632 | size_t pos_port; |
1614 | 1633 | ||
1634 | h->socket = sock; | ||
1635 | h->actual_stun_server = NULL; | ||
1636 | /* Lets process the servers*/ | ||
1615 | if (GNUNET_OK != | 1637 | if (GNUNET_OK != |
1616 | GNUNET_CONFIGURATION_get_value_string (cfg, "nat", "STUN_SERVERS", | 1638 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1639 | "nat", | ||
1640 | "STUN_SERVERS", | ||
1617 | &stun_servers)) | 1641 | &stun_servers)) |
1618 | { | 1642 | { |
1619 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 1643 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1620 | "nat", "STUN_SERVERS"); | 1644 | "nat", |
1645 | "STUN_SERVERS"); | ||
1621 | } | 1646 | } |
1622 | 1647 | ||
1623 | urls = 0; | 1648 | urls = 0; |
@@ -1649,10 +1674,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1649 | 1674 | ||
1650 | struct StunServerList* ml = GNUNET_new (struct StunServerList); | 1675 | struct StunServerList* ml = GNUNET_new (struct StunServerList); |
1651 | 1676 | ||
1652 | ml->next = NULL; | 1677 | ml->port = atoi (&stun_servers[pos_port]); |
1653 | ml->prev = NULL; | ||
1654 | |||
1655 | ml->port = atoi(&stun_servers[pos_port]); | ||
1656 | stun_servers[pos_port-1] = '\0'; | 1678 | stun_servers[pos_port-1] = '\0'; |
1657 | 1679 | ||
1658 | /* Remove trailing space */ | 1680 | /* Remove trailing space */ |
@@ -1662,11 +1684,15 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1662 | ml->address = GNUNET_strdup (&stun_servers[pos]); | 1684 | ml->address = GNUNET_strdup (&stun_servers[pos]); |
1663 | 1685 | ||
1664 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1686 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1665 | "Found STUN server %s port %i !!!\n", ml->address, ml->port); | 1687 | "Found STUN server %s:%i\n", |
1688 | ml->address, | ||
1689 | ml->port); | ||
1666 | 1690 | ||
1667 | GNUNET_CONTAINER_DLL_insert (h->stun_servers_head, h->stun_servers_tail, ml); | 1691 | GNUNET_CONTAINER_DLL_insert (h->stun_servers_head, |
1692 | h->stun_servers_tail, | ||
1693 | ml); | ||
1668 | /* Make sure that we STOP if is the last one*/ | 1694 | /* Make sure that we STOP if is the last one*/ |
1669 | if(0== pos) | 1695 | if (0 == pos) |
1670 | break; | 1696 | break; |
1671 | } | 1697 | } |
1672 | 1698 | ||
@@ -1684,17 +1710,21 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1684 | h->actual_stun_server = h->stun_servers_head; | 1710 | h->actual_stun_server = h->stun_servers_head; |
1685 | } | 1711 | } |
1686 | 1712 | ||
1687 | h->stun_task = GNUNET_SCHEDULER_add_now(&process_stun, | 1713 | h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun, |
1688 | h); | 1714 | h); |
1689 | } | 1715 | } |
1690 | 1716 | ||
1691 | 1717 | ||
1692 | /* Test for SUID binaries */ | 1718 | /* Test for SUID binaries */ |
1693 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); | 1719 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); |
1694 | if ((h->behind_nat == GNUNET_YES) && (GNUNET_YES == h->enable_nat_server) && | 1720 | if ( (GNUNET_YES == h->behind_nat) && |
1695 | (GNUNET_YES != | 1721 | (GNUNET_YES == h->enable_nat_server) && |
1696 | GNUNET_OS_check_helper_binary (binary, GNUNET_YES, "-d 127.0.0.1" ))) // use localhost as source for that one udp-port, ok for testing | 1722 | (GNUNET_YES != |
1723 | GNUNET_OS_check_helper_binary (binary, | ||
1724 | GNUNET_YES, | ||
1725 | "-d 127.0.0.1" ))) | ||
1697 | { | 1726 | { |
1727 | // use localhost as source for that one udp-port, ok for testing | ||
1698 | h->enable_nat_server = GNUNET_NO; | 1728 | h->enable_nat_server = GNUNET_NO; |
1699 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1729 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1700 | _("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), | 1730 | _("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), |
@@ -1708,8 +1738,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1708 | { | 1738 | { |
1709 | h->enable_nat_client = GNUNET_NO; | 1739 | h->enable_nat_client = GNUNET_NO; |
1710 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1740 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1711 | _ | 1741 | _("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), |
1712 | ("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), | ||
1713 | "gnunet-helper-nat-client"); | 1742 | "gnunet-helper-nat-client"); |
1714 | } | 1743 | } |
1715 | GNUNET_free (binary); | 1744 | GNUNET_free (binary); |
@@ -1809,10 +1838,14 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) | |||
1809 | } | 1838 | } |
1810 | while (NULL != (lal = h->lal_head)) | 1839 | while (NULL != (lal = h->lal_head)) |
1811 | { | 1840 | { |
1812 | GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, lal); | 1841 | GNUNET_CONTAINER_DLL_remove (h->lal_head, |
1842 | h->lal_tail, | ||
1843 | lal); | ||
1813 | if (NULL != h->address_callback) | 1844 | if (NULL != h->address_callback) |
1814 | h->address_callback (h->callback_cls, GNUNET_NO, | 1845 | h->address_callback (h->callback_cls, |
1815 | (const struct sockaddr *) &lal[1], lal->addrlen); | 1846 | GNUNET_NO, |
1847 | (const struct sockaddr *) &lal[1], | ||
1848 | lal->addrlen); | ||
1816 | GNUNET_free (lal); | 1849 | GNUNET_free (lal); |
1817 | } | 1850 | } |
1818 | for (i = 0; i < h->num_local_addrs; i++) | 1851 | for (i = 0; i < h->num_local_addrs; i++) |
diff --git a/src/nat/nat.h b/src/nat/nat.h index 28eadba7a..44cd81d42 100644 --- a/src/nat/nat.h +++ b/src/nat/nat.h | |||
@@ -37,7 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | struct GNUNET_NAT_TestMessage | 37 | struct GNUNET_NAT_TestMessage |
38 | { | 38 | { |
39 | /** | 39 | /** |
40 | * Header with type "GNUNET_MESSAGE_TYPE_NAT_TEST" | 40 | * Header with type #GNUNET_MESSAGE_TYPE_NAT_TEST |
41 | */ | 41 | */ |
42 | struct GNUNET_MessageHeader header; | 42 | struct GNUNET_MessageHeader header; |
43 | 43 | ||
@@ -57,7 +57,7 @@ struct GNUNET_NAT_TestMessage | |||
57 | uint16_t data; | 57 | uint16_t data; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * GNUNET_YES for TCP, GNUNET_NO for UDP. | 60 | * #GNUNET_YES for TCP, #GNUNET_NO for UDP. |
61 | */ | 61 | */ |
62 | int32_t is_tcp; | 62 | int32_t is_tcp; |
63 | 63 | ||
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 75969d140..53c2293d8 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -291,15 +291,19 @@ process_resolved_address (void *cls, | |||
291 | 291 | ||
292 | if (NULL != address) | 292 | if (NULL != address) |
293 | { | 293 | { |
294 | if (NULL == ar->result) | 294 | if (0 != strlen (address)) |
295 | { | ||
296 | if (NULL != ar->result) | ||
297 | GNUNET_free (ar->result); | ||
295 | ar->result = GNUNET_strdup (address); | 298 | ar->result = GNUNET_strdup (address); |
299 | } | ||
296 | return; | 300 | return; |
297 | } | 301 | } |
298 | ar->atsc = NULL; | 302 | ar->atsc = NULL; |
299 | if (GNUNET_SYSERR == res) | 303 | if (GNUNET_SYSERR == res) |
300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
301 | _("Failure: Cannot convert address to string for peer `%s'\n"), | 305 | _("Failure: Cannot convert address to string for peer `%s'\n"), |
302 | GNUNET_i2s (&ar->pc->peer)); | 306 | GNUNET_i2s (&ar->pc->peer)); |
303 | pc->num_addresses++; | 307 | pc->num_addresses++; |
304 | if (pc->num_addresses == pc->address_list_size) | 308 | if (pc->num_addresses == pc->address_list_size) |
305 | dump_pc (pc); | 309 | dump_pc (pc); |
@@ -346,6 +350,11 @@ print_address (void *cls, | |||
346 | ar = &pc->address_list[--pc->off]; | 350 | ar = &pc->address_list[--pc->off]; |
347 | ar->pc = pc; | 351 | ar->pc = pc; |
348 | ar->expiration = expiration; | 352 | ar->expiration = expiration; |
353 | GNUNET_asprintf (&ar->result, | ||
354 | "%s:%u:%u", | ||
355 | address->transport_name, | ||
356 | address->address_length, | ||
357 | address->local_info); | ||
349 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, | 358 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, |
350 | address, | 359 | address, |
351 | no_resolve, | 360 | no_resolve, |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index f545b29f9..9cf4bdcac 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -515,23 +515,31 @@ plugin_env_address_change_notification (void *cls, | |||
515 | if (GNUNET_YES == add_remove) | 515 | if (GNUNET_YES == add_remove) |
516 | { | 516 | { |
517 | addresses ++; | 517 | addresses ++; |
518 | GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO); | 518 | GNUNET_STATISTICS_update (cfg, |
519 | "# transport addresses", | ||
520 | 1, | ||
521 | GNUNET_NO); | ||
519 | } | 522 | } |
520 | else if (GNUNET_NO == add_remove) | 523 | else if (GNUNET_NO == add_remove) |
521 | { | 524 | { |
522 | if (0 == addresses) | 525 | if (0 == addresses) |
526 | { | ||
523 | GNUNET_break (0); | 527 | GNUNET_break (0); |
528 | } | ||
524 | else | 529 | else |
525 | { | 530 | { |
526 | addresses --; | 531 | addresses --; |
527 | GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO); | 532 | GNUNET_STATISTICS_update (cfg, |
533 | "# transport addresses", | ||
534 | -1, | ||
535 | GNUNET_NO); | ||
528 | } | 536 | } |
529 | } | 537 | } |
530 | |||
531 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 538 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
532 | "Transport now has %u addresses to communicate\n", | 539 | "Transport now has %u addresses to communicate\n", |
533 | addresses); | 540 | addresses); |
534 | GST_hello_modify_addresses (add_remove, address); | 541 | GST_hello_modify_addresses (add_remove, |
542 | address); | ||
535 | } | 543 | } |
536 | 544 | ||
537 | 545 | ||
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index 4607902a2..f1a16f112 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c | |||
@@ -76,6 +76,13 @@ struct OwnAddressList | |||
76 | */ | 76 | */ |
77 | struct GNUNET_CRYPTO_EddsaSignature pong_signature; | 77 | struct GNUNET_CRYPTO_EddsaSignature pong_signature; |
78 | 78 | ||
79 | /** | ||
80 | * How often has this address been added/removed? Used as | ||
81 | * some plugins may learn the same external address from | ||
82 | * multiple origins. | ||
83 | */ | ||
84 | unsigned int rc; | ||
85 | |||
79 | }; | 86 | }; |
80 | 87 | ||
81 | 88 | ||
@@ -133,7 +140,7 @@ struct GeneratorContext | |||
133 | 140 | ||
134 | 141 | ||
135 | /** | 142 | /** |
136 | * Add an address from the 'OwnAddressList' to the buffer. | 143 | * Add an address from the `struct OwnAddressList` to the buffer. |
137 | * | 144 | * |
138 | * @param cls the `struct GeneratorContext` | 145 | * @param cls the `struct GeneratorContext` |
139 | * @param max maximum number of bytes left | 146 | * @param max maximum number of bytes left |
@@ -151,8 +158,10 @@ address_generator (void *cls, | |||
151 | 158 | ||
152 | if (NULL == gc->addr_pos) | 159 | if (NULL == gc->addr_pos) |
153 | return GNUNET_SYSERR; /* Done */ | 160 | return GNUNET_SYSERR; /* Done */ |
154 | ret = GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf, | 161 | ret = GNUNET_HELLO_add_address (gc->addr_pos->address, |
155 | max); | 162 | gc->expiration, |
163 | buf, | ||
164 | max); | ||
156 | gc->addr_pos = gc->addr_pos->next; | 165 | gc->addr_pos = gc->addr_pos->next; |
157 | return ret; | 166 | return ret; |
158 | } | 167 | } |
@@ -267,7 +276,7 @@ GST_hello_stop () | |||
267 | const struct GNUNET_MessageHeader * | 276 | const struct GNUNET_MessageHeader * |
268 | GST_hello_get () | 277 | GST_hello_get () |
269 | { | 278 | { |
270 | return (struct GNUNET_MessageHeader *) our_hello; | 279 | return (const struct GNUNET_MessageHeader *) our_hello; |
271 | } | 280 | } |
272 | 281 | ||
273 | 282 | ||
@@ -284,28 +293,44 @@ GST_hello_modify_addresses (int addremove, | |||
284 | struct OwnAddressList *al; | 293 | struct OwnAddressList *al; |
285 | 294 | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
287 | (addremove == | 296 | (GNUNET_YES == addremove) |
288 | GNUNET_YES) ? "Adding `%s' to the set of our addresses\n" : | 297 | ? "Adding `%s' to the set of our addresses\n" |
289 | "Removing `%s' from the set of our addresses\n", | 298 | : "Removing `%s' from the set of our addresses\n", |
290 | GST_plugins_a2s (address)); | 299 | GST_plugins_a2s (address)); |
291 | GNUNET_assert (address != NULL); | 300 | GNUNET_assert (NULL != address); |
301 | for (al = oal_head; al != NULL; al = al->next) | ||
302 | if (0 == GNUNET_HELLO_address_cmp (address, al->address)) | ||
303 | break; | ||
292 | if (GNUNET_NO == addremove) | 304 | if (GNUNET_NO == addremove) |
293 | { | 305 | { |
294 | for (al = oal_head; al != NULL; al = al->next) | 306 | if (NULL == al) |
295 | if (0 == GNUNET_HELLO_address_cmp (address, al->address)) | 307 | { |
296 | { | 308 | /* address to be removed not found!? */ |
297 | GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); | 309 | GNUNET_break (0); |
298 | GNUNET_HELLO_address_free (al->address); | 310 | return; |
299 | GNUNET_free (al); | 311 | } |
300 | refresh_hello (); | 312 | al->rc--; |
301 | return; | 313 | if (0 != al->rc) |
302 | } | 314 | return; /* RC not yet zero */ |
303 | /* address to be removed not found!? */ | 315 | GNUNET_CONTAINER_DLL_remove (oal_head, |
304 | GNUNET_break (0); | 316 | oal_tail, |
317 | al); | ||
318 | GNUNET_HELLO_address_free (al->address); | ||
319 | GNUNET_free (al); | ||
320 | refresh_hello (); | ||
321 | return; | ||
322 | } | ||
323 | if (NULL != al) | ||
324 | { | ||
325 | /* address added twice or more */ | ||
326 | al->rc++; | ||
305 | return; | 327 | return; |
306 | } | 328 | } |
307 | al = GNUNET_new (struct OwnAddressList); | 329 | al = GNUNET_new (struct OwnAddressList); |
308 | GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); | 330 | al->rc = 1; |
331 | GNUNET_CONTAINER_DLL_insert (oal_head, | ||
332 | oal_tail, | ||
333 | al); | ||
309 | al->address = GNUNET_HELLO_address_copy (address); | 334 | al->address = GNUNET_HELLO_address_copy (address); |
310 | refresh_hello (); | 335 | refresh_hello (); |
311 | } | 336 | } |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 5836f28bc..c7ee5b6e5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -2855,11 +2855,11 @@ udp_select_read (struct Plugin *plugin, | |||
2855 | return; | 2855 | return; |
2856 | } | 2856 | } |
2857 | 2857 | ||
2858 | 2858 | /* Check if this is a STUN packet */ | |
2859 | /* PROCESS STUN PACKET */ | 2859 | if (GNUNET_NAT_is_valid_stun_packet (plugin->nat, |
2860 | if(GNUNET_NAT_is_valid_stun_packet(plugin->nat,(uint8_t *)buf, size )) | 2860 | (uint8_t *)buf, |
2861 | return; | 2861 | size)) |
2862 | 2862 | return; /* was STUN, do not process further */ | |
2863 | 2863 | ||
2864 | if (size < sizeof(struct GNUNET_MessageHeader)) | 2864 | if (size < sizeof(struct GNUNET_MessageHeader)) |
2865 | { | 2865 | { |