summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_cadet_service.h55
-rw-r--r--src/include/gnunet_client_lib.h2
-rw-r--r--src/include/gnunet_common.h17
-rw-r--r--src/include/gnunet_constants.h6
-rw-r--r--src/include/gnunet_container_lib.h277
-rw-r--r--src/include/gnunet_core_service.h142
-rw-r--r--src/include/gnunet_crypto_lib.h28
-rw-r--r--src/include/gnunet_mq_lib.h13
-rw-r--r--src/include/gnunet_nat_auto_service.h135
-rw-r--r--src/include/gnunet_nat_lib.h591
-rw-r--r--src/include/gnunet_nat_service.h407
-rw-r--r--src/include/gnunet_peerinfo_service.h2
-rw-r--r--src/include/gnunet_protocols.h66
-rw-r--r--src/include/gnunet_signatures.h5
15 files changed, 694 insertions, 1054 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index f27fd6e36..bf3ffe482 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -78,7 +78,7 @@ gnunetinclude_HEADERS = \
78 gnunet_namecache_service.h \ 78 gnunet_namecache_service.h \
79 gnunet_namestore_plugin.h \ 79 gnunet_namestore_plugin.h \
80 gnunet_namestore_service.h \ 80 gnunet_namestore_service.h \
81 gnunet_nat_lib.h \ 81 gnunet_nat_auto_service.h \
82 gnunet_nat_service.h \ 82 gnunet_nat_service.h \
83 gnunet_nc_lib.h \ 83 gnunet_nc_lib.h \
84 gnunet_network_lib.h \ 84 gnunet_network_lib.h \
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index c32311643..7090d4410 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -67,15 +67,6 @@ struct GNUNET_CADET_Channel;
67 */ 67 */
68struct GNUNET_CADET_Port; 68struct GNUNET_CADET_Port;
69 69
70/**
71 * Hash to be used in Cadet communication. Only 256 bits needed,
72 * instead of the 512 from `struct GNUNET_HashCode`.
73 */
74struct GNUNET_CADET_Hash
75{
76 unsigned char bits[256 / 8];
77};
78
79 70
80/** 71/**
81 * Channel options. Second line indicates filed in the 72 * Channel options. Second line indicates filed in the
@@ -102,9 +93,9 @@ enum GNUNET_CADET_ChannelOption
102 93
103 /** 94 /**
104 * Enable out of order delivery of messages. 95 * Enable out of order delivery of messages.
105 * Yes/No. 96 * Set bit for out-of-order delivery.
106 */ 97 */
107 GNUNET_CADET_OPTION_OOORDER = 0x4, 98 GNUNET_CADET_OPTION_OUT_OF_ORDER = 0x4,
108 99
109 /** 100 /**
110 * Who is the peer at the other end of the channel. 101 * Who is the peer at the other end of the channel.
@@ -255,8 +246,7 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle);
255struct GNUNET_CADET_Port * 246struct GNUNET_CADET_Port *
256GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, 247GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
257 const struct GNUNET_HashCode *port, 248 const struct GNUNET_HashCode *port,
258 GNUNET_CADET_InboundChannelNotificationHandler 249 GNUNET_CADET_InboundChannelNotificationHandler new_channel,
259 new_channel,
260 void *new_channel_cls); 250 void *new_channel_cls);
261 251
262/** 252/**
@@ -332,7 +322,8 @@ union GNUNET_CADET_ChannelInfo
332 */ 322 */
333const union GNUNET_CADET_ChannelInfo * 323const union GNUNET_CADET_ChannelInfo *
334GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, 324GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
335 enum GNUNET_CADET_ChannelOption option, ...); 325 enum GNUNET_CADET_ChannelOption option,
326 ...);
336 327
337 328
338/** 329/**
@@ -421,10 +412,10 @@ typedef void
421(*GNUNET_CADET_ChannelCB) (void *cls, 412(*GNUNET_CADET_ChannelCB) (void *cls,
422 const struct GNUNET_PeerIdentity *root, 413 const struct GNUNET_PeerIdentity *root,
423 const struct GNUNET_PeerIdentity *dest, 414 const struct GNUNET_PeerIdentity *dest,
424 uint32_t port, 415 uint32_t /* UGH */ port,
425 uint32_t root_channel_number, 416 uint32_t /* ugh */ root_channel_number,
426 uint32_t dest_channel_number, 417 uint32_t /* ugh */ dest_channel_number,
427 uint32_t public_channel_number); 418 uint32_t /* ugh */ public_channel_number);
428 419
429/** 420/**
430 * Method called to retrieve information about all peers in CADET, called 421 * Method called to retrieve information about all peers in CADET, called
@@ -491,6 +482,28 @@ typedef void
491 482
492 483
493/** 484/**
485 * Hash uniquely identifying a connection below a tunnel.
486 */
487struct GNUNET_CADET_ConnectionTunnelIdentifier
488{
489 struct GNUNET_ShortHashCode connection_of_tunnel;
490};
491
492
493/**
494 * Number identifying a CADET channel within a tunnel.
495 */
496struct GNUNET_CADET_ChannelTunnelNumber
497{
498 /**
499 * Which number does this channel have that uniquely identfies
500 * it within its tunnel?
501 */
502 uint32_t cn GNUNET_PACKED;
503};
504
505
506/**
494 * Method called to retrieve information about a specific tunnel the cadet peer 507 * Method called to retrieve information about a specific tunnel the cadet peer
495 * has established, o`r is trying to establish. 508 * has established, o`r is trying to establish.
496 * 509 *
@@ -508,8 +521,8 @@ typedef void
508 const struct GNUNET_PeerIdentity *peer, 521 const struct GNUNET_PeerIdentity *peer,
509 unsigned int n_channels, 522 unsigned int n_channels,
510 unsigned int n_connections, 523 unsigned int n_connections,
511 uint32_t *channels, 524 const struct GNUNET_CADET_ChannelTunnelNumber *channels,
512 struct GNUNET_CADET_Hash *connections, 525 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
513 unsigned int estate, 526 unsigned int estate,
514 unsigned int cstate); 527 unsigned int cstate);
515 528
@@ -528,7 +541,7 @@ typedef void
528void 541void
529GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h, 542GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h,
530 struct GNUNET_PeerIdentity *peer, 543 struct GNUNET_PeerIdentity *peer,
531 uint32_t channel_number, 544 uint32_t /* UGH */ channel_number,
532 GNUNET_CADET_ChannelCB callback, 545 GNUNET_CADET_ChannelCB callback,
533 void *callback_cls); 546 void *callback_cls);
534 547
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index f98620dfa..613349fdd 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -57,7 +57,7 @@ extern "C"
57 * @return the message queue, NULL on error 57 * @return the message queue, NULL on error
58 */ 58 */
59struct GNUNET_MQ_Handle * 59struct GNUNET_MQ_Handle *
60GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg, 60GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
61 const char *service_name, 61 const char *service_name,
62 const struct GNUNET_MQ_MessageHandler *handlers, 62 const struct GNUNET_MQ_MessageHandler *handlers,
63 GNUNET_MQ_ErrorHandler error_handler, 63 GNUNET_MQ_ErrorHandler error_handler,
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 897502155..9ad604711 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -66,7 +66,7 @@ extern "C"
66/** 66/**
67 * Version of the API (for entire gnunetutil.so library). 67 * Version of the API (for entire gnunetutil.so library).
68 */ 68 */
69#define GNUNET_UTIL_VERSION 0x000A0101 69#define GNUNET_UTIL_VERSION 0x000A0102
70 70
71 71
72/** 72/**
@@ -558,6 +558,19 @@ GNUNET_logger_remove (GNUNET_Logger logger,
558 558
559/** 559/**
560 * @ingroup logging 560 * @ingroup logging
561 * Convert a short hash value to a string (for printing debug messages).
562 * This is one of the very few calls in the entire API that is
563 * NOT reentrant!
564 *
565 * @param shc the hash code
566 * @return string
567 */
568const char *
569GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
570
571
572/**
573 * @ingroup logging
561 * Convert a hash value to a string (for printing debug messages). 574 * Convert a hash value to a string (for printing debug messages).
562 * This is one of the very few calls in the entire API that is 575 * This is one of the very few calls in the entire API that is
563 * NOT reentrant! 576 * NOT reentrant!
@@ -655,7 +668,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
655/** 668/**
656 * @ingroup logging 669 * @ingroup logging
657 * Use this for fatal errors that cannot be handled 670 * Use this for fatal errors that cannot be handled
658 * 671 *
659 * @param cond Condition to evaluate 672 * @param cond Condition to evaluate
660 * @param comp Component string to use for logging 673 * @param comp Component string to use for logging
661 */ 674 */
diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h
index ef9b27318..1d0232cea 100644
--- a/src/include/gnunet_constants.h
+++ b/src/include/gnunet_constants.h
@@ -127,9 +127,9 @@ extern "C"
127 127
128/** 128/**
129 * Size of the CADET message overhead: 129 * Size of the CADET message overhead:
130 * = sizeof (struct GNUNET_CADET_Encrypted) 130 * = sizeof (struct GNUNET_CADET_TunnelEncryptedMessage)
131 * + sizeof (struct GNUNET_CADET_Data) 131 * + sizeof (struct GNUNET_CADET_ChannelAppDataMessage)
132 * + sizeof (struct GNUNET_CADET_ACK)) 132 * + sizeof (struct GNUNET_CADET_ConnectionEncryptedAckMessage))
133 * 133 *
134 * Checked for correcteness in gnunet-service-cadet_tunnel.c: GCT_init(). 134 * Checked for correcteness in gnunet-service-cadet_tunnel.c: GCT_init().
135 */ 135 */
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 03c47c201..f3aaa943b 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -1285,6 +1285,275 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee
1285 void *it_cls); 1285 void *it_cls);
1286 1286
1287 1287
1288/* ***************** Version of Multihashmap for short hashes ****************** */
1289
1290/**
1291 * @ingroup hashmap
1292 * Iterator over hash map entries.
1293 *
1294 * @param cls closure
1295 * @param key current public key
1296 * @param value value in the hash map
1297 * @return #GNUNET_YES if we should continue to
1298 * iterate,
1299 * #GNUNET_NO if not.
1300 */
1301typedef int
1302(*GNUNET_CONTAINER_ShortmapIterator) (void *cls,
1303 const struct GNUNET_ShortHashCode *key,
1304 void *value);
1305
1306
1307/**
1308 * Hash map from peer identities to values.
1309 */
1310struct GNUNET_CONTAINER_MultiShortmap;
1311
1312
1313/**
1314 * @ingroup hashmap
1315 * Create a multi peer map (hash map for public keys of peers).
1316 *
1317 * @param len initial size (map will grow as needed)
1318 * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
1319 * #GNUNET_YES means that on 'put', the 'key' does not have
1320 * to be copied as the destination of the pointer is
1321 * guaranteed to be life as long as the value is stored in
1322 * the hashmap. This can significantly reduce memory
1323 * consumption, but of course is also a recipie for
1324 * heap corruption if the assumption is not true. Only
1325 * use this if (1) memory use is important in this case and
1326 * (2) you have triple-checked that the invariant holds
1327 * @return NULL on error
1328 */
1329struct GNUNET_CONTAINER_MultiShortmap *
1330GNUNET_CONTAINER_multishortmap_create (unsigned int len,
1331 int do_not_copy_keys);
1332
1333
1334/**
1335 * @ingroup hashmap
1336 * Destroy a hash map. Will not free any values
1337 * stored in the hash map!
1338 *
1339 * @param map the map
1340 */
1341void
1342GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map);
1343
1344
1345/**
1346 * @ingroup hashmap
1347 * Given a key find a value in the map matching the key.
1348 *
1349 * @param map the map
1350 * @param key what to look for
1351 * @return NULL if no value was found; note that
1352 * this is indistinguishable from values that just
1353 * happen to be NULL; use "contains" to test for
1354 * key-value pairs with value NULL
1355 */
1356void *
1357GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map,
1358 const struct GNUNET_ShortHashCode *key);
1359
1360
1361/**
1362 * @ingroup hashmap
1363 * Remove the given key-value pair from the map. Note that if the
1364 * key-value pair is in the map multiple times, only one of the pairs
1365 * will be removed.
1366 *
1367 * @param map the map
1368 * @param key key of the key-value pair
1369 * @param value value of the key-value pair
1370 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1371 * is not in the map
1372 */
1373int
1374GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map,
1375 const struct GNUNET_ShortHashCode * key,
1376 const void *value);
1377
1378/**
1379 * @ingroup hashmap
1380 * Remove all entries for the given key from the map.
1381 * Note that the values would not be "freed".
1382 *
1383 * @param map the map
1384 * @param key identifies values to be removed
1385 * @return number of values removed
1386 */
1387int
1388GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map,
1389 const struct GNUNET_ShortHashCode *key);
1390
1391
1392/**
1393 * @ingroup hashmap
1394 * Check if the map contains any value under the given
1395 * key (including values that are NULL).
1396 *
1397 * @param map the map
1398 * @param key the key to test if a value exists for it
1399 * @return #GNUNET_YES if such a value exists,
1400 * #GNUNET_NO if not
1401 */
1402int
1403GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map,
1404 const struct GNUNET_ShortHashCode *key);
1405
1406
1407/**
1408 * @ingroup hashmap
1409 * Check if the map contains the given value under the given
1410 * key.
1411 *
1412 * @param map the map
1413 * @param key the key to test if a value exists for it
1414 * @param value value to test for
1415 * @return #GNUNET_YES if such a value exists,
1416 * #GNUNET_NO if not
1417 */
1418int
1419GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map,
1420 const struct GNUNET_ShortHashCode * key,
1421 const void *value);
1422
1423
1424/**
1425 * @ingroup hashmap
1426 * Store a key-value pair in the map.
1427 *
1428 * @param map the map
1429 * @param key key to use
1430 * @param value value to use
1431 * @param opt options for put
1432 * @return #GNUNET_OK on success,
1433 * #GNUNET_NO if a value was replaced (with REPLACE)
1434 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1435 * value already exists
1436 */
1437int
1438GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
1439 const struct GNUNET_ShortHashCode *key,
1440 void *value,
1441 enum GNUNET_CONTAINER_MultiHashMapOption opt);
1442
1443
1444/**
1445 * @ingroup hashmap
1446 * Get the number of key-value pairs in the map.
1447 *
1448 * @param map the map
1449 * @return the number of key value pairs
1450 */
1451unsigned int
1452GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map);
1453
1454
1455/**
1456 * @ingroup hashmap
1457 * Iterate over all entries in the map.
1458 *
1459 * @param map the map
1460 * @param it function to call on each entry
1461 * @param it_cls extra argument to @a it
1462 * @return the number of key value pairs processed,
1463 * #GNUNET_SYSERR if it aborted iteration
1464 */
1465int
1466GNUNET_CONTAINER_multishortmap_iterate (const struct GNUNET_CONTAINER_MultiShortmap *map,
1467 GNUNET_CONTAINER_ShortmapIterator it,
1468 void *it_cls);
1469
1470
1471struct GNUNET_CONTAINER_MultiShortmapIterator;
1472
1473
1474/**
1475 * @ingroup hashmap
1476 * Create an iterator for a multihashmap.
1477 * The iterator can be used to retrieve all the elements in the multihashmap
1478 * one by one, without having to handle all elements at once (in contrast to
1479 * #GNUNET_CONTAINER_multishortmap_iterate). Note that the iterator can not be
1480 * used anymore if elements have been removed from @a map after the creation of
1481 * the iterator, or 'map' has been destroyed. Adding elements to @a map may
1482 * result in skipped or repeated elements.
1483 *
1484 * @param map the map to create an iterator for
1485 * @return an iterator over the given multihashmap @a map
1486 */
1487struct GNUNET_CONTAINER_MultiShortmapIterator *
1488GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map);
1489
1490
1491/**
1492 * @ingroup hashmap
1493 * Retrieve the next element from the hash map at the iterator's
1494 * position. If there are no elements left, #GNUNET_NO is returned,
1495 * and @a key and @a value are not modified. This operation is only
1496 * allowed if no elements have been removed from the multihashmap
1497 * since the creation of @a iter, and the map has not been destroyed.
1498 * Adding elements may result in repeating or skipping elements.
1499 *
1500 * @param iter the iterator to get the next element from
1501 * @param key pointer to store the key in, can be NULL
1502 * @param value pointer to store the value in, can be NULL
1503 * @return #GNUNET_YES we returned an element,
1504 * #GNUNET_NO if we are out of elements
1505 */
1506int
1507GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
1508 struct GNUNET_ShortHashCode *key,
1509 const void **value);
1510
1511
1512/**
1513 * @ingroup hashmap
1514 * Destroy a multishortmap iterator.
1515 *
1516 * @param iter the iterator to destroy
1517 */
1518void
1519GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter);
1520
1521
1522/**
1523 * @ingroup hashmap
1524 * Iterate over all entries in the map that match a particular key.
1525 *
1526 * @param map the map
1527 * @param key public key that the entries must correspond to
1528 * @param it function to call on each entry
1529 * @param it_cls extra argument to @a it
1530 * @return the number of key value pairs processed,
1531 * #GNUNET_SYSERR if it aborted iteration
1532 */
1533int
1534GNUNET_CONTAINER_multishortmap_get_multiple (const struct GNUNET_CONTAINER_MultiShortmap *map,
1535 const struct GNUNET_ShortHashCode *key,
1536 GNUNET_CONTAINER_ShortmapIterator it,
1537 void *it_cls);
1538
1539
1540/**
1541 * @ingroup hashmap
1542 * Call @a it on a random value from the map, or not at all
1543 * if the map is empty. Note that this function has linear
1544 * complexity (in the size of the map).
1545 *
1546 * @param map the map
1547 * @param it function to call on a random entry
1548 * @param it_cls extra argument to @a it
1549 * @return the number of key value pairs processed, zero or one.
1550 */
1551unsigned int
1552GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map,
1553 GNUNET_CONTAINER_ShortmapIterator it,
1554 void *it_cls);
1555
1556
1288/* Version of multihashmap with 32 bit keys */ 1557/* Version of multihashmap with 32 bit keys */
1289 1558
1290/** 1559/**
@@ -1915,8 +2184,8 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
1915 * @return cost of the node 2184 * @return cost of the node
1916 */ 2185 */
1917GNUNET_CONTAINER_HeapCostType 2186GNUNET_CONTAINER_HeapCostType
1918GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode 2187GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node);
1919 *node); 2188
1920 2189
1921/** 2190/**
1922 * @ingroup heap 2191 * @ingroup heap
@@ -2006,13 +2275,11 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
2006 * @ingroup heap 2275 * @ingroup heap
2007 * Updates the cost of any node in the tree 2276 * Updates the cost of any node in the tree
2008 * 2277 *
2009 * @param heap heap to modify
2010 * @param node node for which the cost is to be changed 2278 * @param node node for which the cost is to be changed
2011 * @param new_cost new cost for the node 2279 * @param new_cost new cost for the node
2012 */ 2280 */
2013void 2281void
2014GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, 2282GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
2015 struct GNUNET_CONTAINER_HeapNode *node,
2016 GNUNET_CONTAINER_HeapCostType new_cost); 2283 GNUNET_CONTAINER_HeapCostType new_cost);
2017 2284
2018 2285
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 6ec486b26..8136770b7 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -91,30 +91,8 @@ struct GNUNET_CORE_Handle;
91 * @param cls closure 91 * @param cls closure
92 * @param peer peer identity this notification is about 92 * @param peer peer identity this notification is about
93 */ 93 */
94typedef void
95(*GNUNET_CORE_ConnectEventHandler) (void *cls,
96 const struct GNUNET_PeerIdentity *peer);
97
98
99/**
100 * Method called whenever a peer disconnects.
101 *
102 * @param cls closure
103 * @param peer peer identity this notification is about
104 */
105typedef void
106(*GNUNET_CORE_DisconnectEventHandler) (void *cls,
107 const struct GNUNET_PeerIdentity *peer);
108
109
110/**
111 * Method called whenever a given peer connects.
112 *
113 * @param cls closure
114 * @param peer peer identity this notification is about
115 */
116typedef void * 94typedef void *
117(*GNUNET_CORE_ConnecTEventHandler) (void *cls, 95(*GNUNET_CORE_ConnectEventHandler) (void *cls,
118 const struct GNUNET_PeerIdentity *peer, 96 const struct GNUNET_PeerIdentity *peer,
119 struct GNUNET_MQ_Handle *mq); 97 struct GNUNET_MQ_Handle *mq);
120 98
@@ -126,55 +104,12 @@ typedef void *
126 * @param peer peer identity this notification is about 104 * @param peer peer identity this notification is about
127 */ 105 */
128typedef void 106typedef void
129(*GNUNET_CORE_DisconnecTEventHandler) (void *cls, 107(*GNUNET_CORE_DisconnectEventHandler) (void *cls,
130 const struct GNUNET_PeerIdentity *peer, 108 const struct GNUNET_PeerIdentity *peer,
131 void *peer_cls); 109 void *peer_cls);
132 110
133 111
134/** 112/**
135 * Functions with this signature are called whenever a message is
136 * received or transmitted.
137 *
138 * @param cls closure (set from #GNUNET_CORE_connect)
139 * @param peer the other peer involved (sender or receiver, NULL
140 * for loopback messages where we are both sender and receiver)
141 * @param message the actual message
142 * @return #GNUNET_OK to keep the connection open,
143 * #GNUNET_SYSERR to close connection to the peer (signal serious error)
144 */
145typedef int
146(*GNUNET_CORE_MessageCallback) (void *cls,
147 const struct GNUNET_PeerIdentity *other,
148 const struct GNUNET_MessageHeader *message);
149
150
151/**
152 * Message handler. Each struct specifies how to handle on particular
153 * type of message received.
154 */
155struct GNUNET_CORE_MessageHandler
156{
157 /**
158 * Function to call for messages of @e type.
159 */
160 GNUNET_CORE_MessageCallback callback;
161
162 /**
163 * Type of the message this handler covers.
164 */
165 uint16_t type;
166
167 /**
168 * Expected size of messages of this type. Use 0 for variable-size.
169 * If non-zero, messages of the given type will be discarded if they
170 * do not have the right size.
171 */
172 uint16_t expected_size;
173
174};
175
176
177/**
178 * Function called after #GNUNET_CORE_connect has succeeded (or failed 113 * Function called after #GNUNET_CORE_connect has succeeded (or failed
179 * for good). Note that the private key of the peer is intentionally 114 * for good). Note that the private key of the peer is intentionally
180 * not exposed here; if you need it, your process should try to read 115 * not exposed here; if you need it, your process should try to read
@@ -208,26 +143,6 @@ typedef void
208 * connected to the core service 143 * connected to the core service
209 * @param connects function to call on peer connect, can be NULL 144 * @param connects function to call on peer connect, can be NULL
210 * @param disconnects function to call on peer disconnect / timeout, can be NULL 145 * @param disconnects function to call on peer disconnect / timeout, can be NULL
211 * @param inbound_notify function to call for all inbound messages, can be NULL
212 * note that the core is allowed to drop notifications about inbound
213 * messages if the client does not process them fast enough (for this
214 * notification type, a bounded queue is used)
215 * @param inbound_hdr_only set to #GNUNET_YES if @a inbound_notify will only read the
216 * `struct GNUNET_MessageHeader` and hence we do not need to give it the full message;
217 * can be used to improve efficiency, ignored if inbound_notify is NULL
218 * note that the core is allowed to drop notifications about inbound
219 * messages if the client does not process them fast enough (for this
220 * notification type, a bounded queue is used)
221 * @param outbound_notify function to call for all outbound messages, can be NULL;
222 * note that the core is allowed to drop notifications about outbound
223 * messages if the client does not process them fast enough (for this
224 * notification type, a bounded queue is used)
225 * @param outbound_hdr_only set to #GNUNET_YES if @a outbound_notify will only read the
226 * `struct GNUNET_MessageHeader` and hence we do not need to give it the full message
227 * can be used to improve efficiency, ignored if outbound_notify is NULL
228 * note that the core is allowed to drop notifications about outbound
229 * messages if the client does not process them fast enough (for this
230 * notification type, a bounded queue is used)
231 * @param handlers callbacks for messages we care about, NULL-terminated 146 * @param handlers callbacks for messages we care about, NULL-terminated
232 * note that the core is allowed to drop notifications about inbound 147 * note that the core is allowed to drop notifications about inbound
233 * messages if the client does not process them fast enough (for this 148 * messages if the client does not process them fast enough (for this
@@ -241,53 +156,6 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
241 GNUNET_CORE_StartupCallback init, 156 GNUNET_CORE_StartupCallback init,
242 GNUNET_CORE_ConnectEventHandler connects, 157 GNUNET_CORE_ConnectEventHandler connects,
243 GNUNET_CORE_DisconnectEventHandler disconnects, 158 GNUNET_CORE_DisconnectEventHandler disconnects,
244 GNUNET_CORE_MessageCallback inbound_notify,
245 int inbound_hdr_only,
246 GNUNET_CORE_MessageCallback outbound_notify,
247 int outbound_hdr_only,
248 const struct GNUNET_CORE_MessageHandler *handlers);
249
250/**
251 * Disconnect from the core service. This function can only
252 * be called *after* all pending #GNUNET_CORE_notify_transmit_ready
253 * requests have been explicitly cancelled.
254 *
255 * @param handle connection to core to disconnect
256 */
257void
258GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
259
260
261/**
262 * Connect to the core service. Note that the connection may complete
263 * (or fail) asynchronously. This function primarily causes the given
264 * callback notification functions to be invoked whenever the
265 * specified event happens. The maximum number of queued
266 * notifications (queue length) is per client; the queue is shared
267 * across all types of notifications. So a slow client that registers
268 * for @a outbound_notify also risks missing @a inbound_notify messages.
269 * Certain events (such as connect/disconnect notifications) are not
270 * subject to queue size limitations.
271 *
272 * @param cfg configuration to use
273 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
274 * @param init callback to call once we have successfully
275 * connected to the core service
276 * @param connects function to call on peer connect, can be NULL
277 * @param disconnects function to call on peer disconnect / timeout, can be NULL
278 * @param handlers callbacks for messages we care about, NULL-terminated
279 * note that the core is allowed to drop notifications about inbound
280 * messages if the client does not process them fast enough (for this
281 * notification type, a bounded queue is used)
282 * @return handle to the core service (only useful for disconnect until @a init is called),
283 * NULL on error (in this case, init is never called)
284 */
285struct GNUNET_CORE_Handle *
286GNUNET_CORE_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
287 void *cls,
288 GNUNET_CORE_StartupCallback init,
289 GNUNET_CORE_ConnecTEventHandler connects,
290 GNUNET_CORE_DisconnecTEventHandler disconnects,
291 const struct GNUNET_MQ_MessageHandler *handlers); 159 const struct GNUNET_MQ_MessageHandler *handlers);
292 160
293 161
@@ -297,7 +165,7 @@ GNUNET_CORE_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
297 * @param handle connection to core to disconnect 165 * @param handle connection to core to disconnect
298 */ 166 */
299void 167void
300GNUNET_CORE_disconnecT (struct GNUNET_CORE_Handle *handle); 168GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
301 169
302 170
303/** 171/**
@@ -305,7 +173,7 @@ GNUNET_CORE_disconnecT (struct GNUNET_CORE_Handle *handle);
305 * so that it is transmitted with the given @a priority and 173 * so that it is transmitted with the given @a priority and
306 * the given @a cork value. 174 * the given @a cork value.
307 * 175 *
308 * @param cork desired corking 176 * @param cork desired corking
309 * @param priority desired message priority 177 * @param priority desired message priority
310 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options() 178 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
311 * @return `extra` argument to give to #GNUNET_MQ_set_options() 179 * @return `extra` argument to give to #GNUNET_MQ_set_options()
@@ -320,7 +188,7 @@ GNUNET_CORE_get_mq_options (int cork,
320 * Obtain the message queue for a connected peer. 188 * Obtain the message queue for a connected peer.
321 * 189 *
322 * @param h the core handle 190 * @param h the core handle
323 * @param pid the identity of the peer 191 * @param pid the identity of the peer
324 * @return NULL if @a pid is not connected 192 * @return NULL if @a pid is not connected
325 */ 193 */
326struct GNUNET_MQ_Handle * 194struct GNUNET_MQ_Handle *
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 8002b7710..43fd32a58 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -52,9 +52,24 @@ extern "C"
52#endif 52#endif
53 53
54/** 54/**
55 * @brief A 512-bit hashcode 55 * @brief A 512-bit hashcode. These are the default length for GNUnet, using SHA-512.
56 */ 56 */
57struct GNUNET_HashCode; 57struct GNUNET_HashCode
58{
59 uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */
60};
61
62
63
64/**
65 * @brief A 256-bit hashcode. Used under special conditions, like when space
66 * is critical and security is not impacted by it.
67 */
68struct GNUNET_ShortHashCode
69{
70 uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */
71};
72
58 73
59/** 74/**
60 * The identity of the host (wraps the signing key of the peer). 75 * The identity of the host (wraps the signing key of the peer).
@@ -66,15 +81,6 @@ struct GNUNET_PeerIdentity;
66 81
67 82
68/** 83/**
69 * @brief A 512-bit hashcode
70 */
71struct GNUNET_HashCode
72{
73 uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */
74};
75
76
77/**
78 * Maximum length of an ECC signature. 84 * Maximum length of an ECC signature.
79 * Note: round up to multiple of 8 minus 2 for alignment. 85 * Note: round up to multiple of 8 minus 2 for alignment.
80 */ 86 */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index d1a045b8b..108ba5d54 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -255,15 +255,6 @@ typedef void
255 255
256 256
257/** 257/**
258 * Callback used for notifications
259 *
260 * @param cls closure
261 */
262typedef void
263(*GNUNET_MQ_NotifyCallback) (void *cls);
264
265
266/**
267 * Generic error handler, called with the appropriate 258 * Generic error handler, called with the appropriate
268 * error code and the same closure specified at the creation of 259 * error code and the same closure specified at the creation of
269 * the message queue. 260 * the message queue.
@@ -402,7 +393,7 @@ struct GNUNET_MQ_MessageHandler
402 * @param ctx context for the callbacks 393 * @param ctx context for the callbacks
403 */ 394 */
404#define GNUNET_MQ_hd_var_size(name,code,str,ctx) \ 395#define GNUNET_MQ_hd_var_size(name,code,str,ctx) \
405 ({ \ 396 __extension__ ({ \
406 int (*_mv)(void *cls, const str *msg) = &check_##name; \ 397 int (*_mv)(void *cls, const str *msg) = &check_##name; \
407 void (*_cb)(void *cls, const str *msg) = &handle_##name; \ 398 void (*_cb)(void *cls, const str *msg) = &handle_##name; \
408 ((struct GNUNET_MQ_MessageHandler) \ 399 ((struct GNUNET_MQ_MessageHandler) \
@@ -634,7 +625,7 @@ GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
634 */ 625 */
635void 626void
636GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev, 627GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
637 GNUNET_MQ_NotifyCallback cb, 628 GNUNET_SCHEDULER_TaskCallback cb,
638 void *cb_cls); 629 void *cb_cls);
639 630
640 631
diff --git a/src/include/gnunet_nat_auto_service.h b/src/include/gnunet_nat_auto_service.h
new file mode 100644
index 000000000..a369c49e0
--- /dev/null
+++ b/src/include/gnunet_nat_auto_service.h
@@ -0,0 +1,135 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007-2017 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @author Christian Grothoff
23 * @author Milan Bouchet-Valat
24 *
25 * @file
26 * Service for testing and autoconfiguration of
27 * NAT traversal functionality
28 *
29 * @defgroup nat NAT testing library
30 *
31 * @{
32 */
33
34#ifndef GNUNET_NAT_AUTO_SERVICE_H
35#define GNUNET_NAT_AUTO_SERVICE_H
36
37#include "gnunet_util_lib.h"
38#include "gnunet_nat_service.h"
39
40
41/**
42 * Handle to a NAT test.
43 */
44struct GNUNET_NAT_AUTO_Test;
45
46
47/**
48 * Start testing if NAT traversal works using the given configuration.
49 * The transport adapters should be down while using this function.
50 *
51 * @param cfg configuration for the NAT traversal
52 * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
53 * @param section_name configuration section to use for configuration
54 * @param report function to call with the result of the test
55 * @param report_cls closure for @a report
56 * @return handle to cancel NAT test
57 */
58struct GNUNET_NAT_AUTO_Test *
59GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
60 uint8_t proto,
61 const char *section_name,
62 GNUNET_NAT_TestCallback report,
63 void *report_cls);
64
65
66/**
67 * Stop an active NAT test.
68 *
69 * @param tst test to stop.
70 */
71void
72GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst);
73
74
75/**
76 * Handle to auto-configuration in progress.
77 */
78struct GNUNET_NAT_AUTO_AutoHandle;
79
80
81/**
82 * Converts `enum GNUNET_NAT_StatusCode` to string
83 *
84 * @param err error code to resolve to a string
85 * @return point to a static string containing the error code
86 */
87const char *
88GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err);
89
90
91/**
92 * Function called with the result from the autoconfiguration.
93 *
94 * @param cls closure
95 * @param diff minimal suggested changes to the original configuration
96 * to make it work (as best as we can)
97 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
98 * @param type what the situation of the NAT
99 */
100typedef void
101(*GNUNET_NAT_AUTO_AutoResultCallback)(void *cls,
102 const struct GNUNET_CONFIGURATION_Handle *diff,
103 enum GNUNET_NAT_StatusCode result,
104 enum GNUNET_NAT_Type type);
105
106
107/**
108 * Start auto-configuration routine. The transport adapters should
109 * be stopped while this function is called.
110 *
111 * @param cfg initial configuration
112 * @param cb function to call with autoconfiguration result
113 * @param cb_cls closure for @a cb
114 * @return handle to cancel operation
115 */
116struct GNUNET_NAT_AUTO_AutoHandle *
117GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
118 GNUNET_NAT_AUTO_AutoResultCallback cb,
119 void *cb_cls);
120
121
122/**
123 * Abort autoconfiguration.
124 *
125 * @param ah handle for operation to abort
126 */
127void
128GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah);
129
130
131#endif
132
133/** @} */ /* end of group */
134
135/* end of gnunet_nat_auto_service.h */
diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h
deleted file mode 100644
index 853a86c2d..000000000
--- a/src/include/gnunet_nat_lib.h
+++ /dev/null
@@ -1,591 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007-2014 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @author Christian Grothoff
23 * @author Milan Bouchet-Valat
24 *
25 * @file
26 * Library handling UPnP and NAT-PMP port forwarding
27 * and external IP address retrieval
28 *
29 * @defgroup nat NAT library
30 * Library handling UPnP and NAT-PMP port forwarding
31 * and external IP address retrieval
32 *
33 * @{
34 */
35
36#ifndef GNUNET_NAT_LIB_H
37#define GNUNET_NAT_LIB_H
38
39#include "gnunet_util_lib.h"
40
41
42/**
43 * Signature of the callback passed to #GNUNET_NAT_register() for
44 * a function to call whenever our set of 'valid' addresses changes.
45 *
46 * @param cls closure
47 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
48 * the previous (now invalid) one
49 * @param addr either the previous or the new public IP address
50 * @param addrlen actual length of the @a addr
51 */
52typedef void
53(*GNUNET_NAT_AddressCallback) (void *cls,
54 int add_remove,
55 const struct sockaddr *addr,
56 socklen_t addrlen);
57
58
59/**
60 * Signature of the callback passed to #GNUNET_NAT_register().
61 * for a function to call whenever someone asks us to do connection
62 * reversal.
63 *
64 * @param cls closure
65 * @param addr public IP address of the other peer
66 * @param addrlen actual lenght of the @a addr
67 */
68typedef void
69(*GNUNET_NAT_ReversalCallback) (void *cls,
70 const struct sockaddr *addr,
71 socklen_t addrlen);
72
73
74/**
75 * Handle for active NAT registrations.
76 */
77struct GNUNET_NAT_Handle;
78
79
80
81/**
82 * What the situation of the NAT connectivity
83 */
84enum GNUNET_NAT_Type
85{
86 /**
87 * We have a direct connection
88 */
89 GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK,
90
91 /**
92 * We are under a NAT but cannot traverse it
93 */
94 GNUNET_NAT_TYPE_UNREACHABLE_NAT,
95
96 /**
97 * We can traverse using STUN
98 */
99 GNUNET_NAT_TYPE_STUN_PUNCHED_NAT,
100
101 /**
102 * WE can traverse using UPNP
103 */
104 GNUNET_NAT_TYPE_UPNP_NAT
105
106};
107
108/**
109 * Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
110 */
111enum GNUNET_NAT_StatusCode
112{
113 /**
114 * Just the default
115 */
116 GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK,
117
118 /**
119 * IPC Failure
120 */
121 GNUNET_NAT_ERROR_IPC_FAILURE,
122
123 /**
124 * Failure in network subsystem, check permissions
125 */
126 GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR,
127
128 /**
129 * test timed out
130 */
131 GNUNET_NAT_ERROR_TIMEOUT,
132
133 /**
134 * detected that we are offline
135 */
136 GNUNET_NAT_ERROR_NOT_ONLINE,
137
138 /**
139 * `upnpc` command not found
140 */
141 GNUNET_NAT_ERROR_UPNPC_NOT_FOUND,
142
143 /**
144 * Failed to run `upnpc` command
145 */
146 GNUNET_NAT_ERROR_UPNPC_FAILED,
147
148 /**
149 * `upnpc' command took too long, process killed
150 */
151 GNUNET_NAT_ERROR_UPNPC_TIMEOUT,
152
153 /**
154 * `upnpc' command failed to establish port mapping
155 */
156 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED,
157
158 /**
159 * `external-ip' command not found
160 */
161 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND,
162
163 /**
164 * Failed to run `external-ip` command
165 */
166 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED,
167
168 /**
169 * `external-ip' command output invalid
170 */
171 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID,
172
173 /**
174 * "no valid address was returned by `external-ip'"
175 */
176 GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID,
177
178 /**
179 * Could not determine interface with internal/local network address
180 */
181 GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO,
182
183 /**
184 * No working gnunet-helper-nat-server found
185 */
186 GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND,
187
188 /**
189 * NAT test could not be initialized
190 */
191 GNUNET_NAT_ERROR_NAT_TEST_START_FAILED,
192
193 /**
194 * NAT test timeout
195 */
196 GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT,
197
198 /**
199 * NAT test failed to initiate
200 */
201 GNUNET_NAT_ERROR_NAT_REGISTER_FAILED,
202
203 /**
204 *
205 */
206 GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND,
207
208 /**
209 *
210 */
211 GNUNET_NAT_ERROR_
212};
213
214
215/**
216 * Converts `enum GNUNET_NAT_StatusCode` to string
217 *
218 * @param err error code to resolve to a string
219 * @return point to a static string containing the error code
220 */
221const char *
222GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err);
223
224
225/**
226 * Attempt to enable port redirection and detect public IP address
227 * contacting UPnP or NAT-PMP routers on the local network. Use addr
228 * to specify to which of the local host's addresses should the
229 * external port be mapped. The port is taken from the corresponding
230 * sockaddr_in[6] field. The NAT module should call the given
231 * callback for any 'plausible' external address.
232 *
233 * @param cfg configuration to use
234 * @param is_tcp #GNUNET_YES for TCP, #GNUNET_NO for UDP
235 * @param adv_port advertised port (port we are either bound to or that our OS
236 * locally performs redirection from to our bound port).
237 * @param num_addrs number of addresses in @a addrs
238 * @param addrs list of local addresses packets should be redirected to
239 * @param addrlens actual lengths of the addresses in @a addrs
240 * @param address_callback function to call everytime the public IP address changes
241 * @param reversal_callback function to call if someone wants connection reversal from us,
242 * NULL if connection reversal is not supported
243 * @param callback_cls closure for callbacks
244 * @return NULL on error, otherwise handle that can be used to unregister
245 */
246struct GNUNET_NAT_Handle *
247GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
248 int is_tcp,
249 uint16_t adv_port,
250 unsigned int num_addrs,
251 const struct sockaddr **addrs,
252 const socklen_t *addrlens,
253 GNUNET_NAT_AddressCallback address_callback,
254 GNUNET_NAT_ReversalCallback reversal_callback,
255 void *callback_cls,
256 struct GNUNET_NETWORK_Handle* sock);
257
258
259/**
260 * Test if the given address is (currently) a plausible IP address for
261 * this peer.
262 *
263 * @param h the handle returned by register
264 * @param addr IP address to test (IPv4 or IPv6)
265 * @param addrlen number of bytes in @a addr
266 * @return #GNUNET_YES if the address is plausible,
267 * #GNUNET_NO if the address is not plausible,
268 * #GNUNET_SYSERR if the address is malformed
269 */
270int
271GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
272 const void *addr,
273 socklen_t addrlen);
274
275
276/**
277 * We learned about a peer (possibly behind NAT) so run the
278 * gnunet-nat-client to send dummy ICMP responses to cause
279 * that peer to connect to us (connection reversal).
280 *
281 * @param h handle (used for configuration)
282 * @param sa the address of the peer (IPv4-only)
283 * @return #GNUNET_SYSERR on error, #GNUNET_NO if nat client is disabled,
284 * #GNUNET_OK otherwise
285 */
286int
287GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
288 const struct sockaddr_in *sa);
289
290
291/**
292 * Stop port redirection and public IP address detection for the given
293 * handle. This frees the handle, after having sent the needed
294 * commands to close open ports.
295 *
296 * @param h the handle to stop
297 */
298void
299GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h);
300
301
302/**
303 * Handle to a NAT test.
304 */
305struct GNUNET_NAT_Test;
306
307
308/**
309 * Function called to report success or failure for
310 * NAT configuration test.
311 *
312 * @param cls closure
313 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
314 */
315typedef void (*GNUNET_NAT_TestCallback) (void *cls,
316 enum GNUNET_NAT_StatusCode result);
317
318
319/**
320 * Start testing if NAT traversal works using the
321 * given configuration (IPv4-only).
322 *
323 * @param cfg configuration for the NAT traversal
324 * @param is_tcp #GNUNET_YES to test TCP, #GNUNET_NO to test UDP
325 * @param bnd_port port to bind to, 0 for connection reversal
326 * @param adv_port externally advertised port to use
327 * @param timeout delay after which the test should be aborted
328 * @param report function to call with the result of the test;
329 * you still must call #GNUNET_NAT_test_stop().
330 * @param report_cls closure for @a report
331 * @return handle to cancel NAT test
332 */
333struct GNUNET_NAT_Test *
334GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
335 int is_tcp,
336 uint16_t bnd_port,
337 uint16_t adv_port,
338 struct GNUNET_TIME_Relative timeout,
339 GNUNET_NAT_TestCallback report,
340 void *report_cls);
341
342
343/**
344 * Stop an active NAT test.
345 *
346 * @param tst test to stop.
347 */
348void
349GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst);
350
351
352/**
353 * Signature of a callback that is given an IP address.
354 *
355 * @param cls closure
356 * @param addr the address, NULL on errors
357 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
358 */
359typedef void
360(*GNUNET_NAT_IPCallback) (void *cls,
361 const struct in_addr *addr,
362 enum GNUNET_NAT_StatusCode result);
363
364
365/**
366 * Opaque handle to cancel #GNUNET_NAT_mini_get_external_ipv4() operation.
367 */
368struct GNUNET_NAT_ExternalHandle;
369
370
371/**
372 * Try to get the external IPv4 address of this peer.
373 *
374 * @param timeout when to fail
375 * @param cb function to call with result
376 * @param cb_cls closure for @a cb
377 * @return handle for cancellation (can only be used until @a cb is called), NULL on error
378 */
379struct GNUNET_NAT_ExternalHandle *
380GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
381 GNUNET_NAT_IPCallback cb,
382 void *cb_cls);
383
384
385/**
386 * Cancel operation.
387 *
388 * @param eh operation to cancel
389 */
390void
391GNUNET_NAT_mini_get_external_ipv4_cancel (struct GNUNET_NAT_ExternalHandle *eh);
392
393
394/**
395 * Handle to a mapping created with upnpc.
396 */
397struct GNUNET_NAT_MiniHandle;
398
399
400/**
401 * Signature of the callback passed to #GNUNET_NAT_register() for
402 * a function to call whenever our set of 'valid' addresses changes.
403 *
404 * @param cls closure
405 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
406 * the previous (now invalid) one, #GNUNET_SYSERR indicates an error
407 * @param addr either the previous or the new public IP address
408 * @param addrlen actual length of the @a addr
409 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
410 */
411typedef void
412(*GNUNET_NAT_MiniAddressCallback) (void *cls,
413 int add_remove,
414 const struct sockaddr *addr,
415 socklen_t addrlen,
416 enum GNUNET_NAT_StatusCode result);
417
418
419/**
420 * Start mapping the given port using (mini)upnpc. This function
421 * should typically not be used directly (it is used within the
422 * general-purpose #GNUNET_NAT_register() code). However, it can be
423 * used if specifically UPnP-based NAT traversal is to be used or
424 * tested.
425 *
426 * @param port port to map
427 * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
428 * @param ac function to call with mapping result
429 * @param ac_cls closure for @a ac
430 * @return NULL on error
431 */
432struct GNUNET_NAT_MiniHandle *
433GNUNET_NAT_mini_map_start (uint16_t port,
434 int is_tcp,
435 GNUNET_NAT_MiniAddressCallback ac,
436 void *ac_cls);
437
438
439/**
440 * Remove a mapping created with (mini)upnpc. Calling
441 * this function will give 'upnpc' 1s to remove the mapping,
442 * so while this function is non-blocking, a task will be
443 * left with the scheduler for up to 1s past this call.
444 *
445 * @param mini the handle
446 */
447void
448GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini);
449
450
451/**
452 * Handle to auto-configuration in progress.
453 */
454struct GNUNET_NAT_AutoHandle;
455
456
457/**
458 * Function called with the result from the autoconfiguration.
459 *
460 * @param cls closure
461 * @param diff minimal suggested changes to the original configuration
462 * to make it work (as best as we can)
463 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
464 * @param type what the situation of the NAT
465 */
466typedef void
467(*GNUNET_NAT_AutoResultCallback)(void *cls,
468 const struct GNUNET_CONFIGURATION_Handle *diff,
469 enum GNUNET_NAT_StatusCode result,
470 enum GNUNET_NAT_Type type);
471
472
473/**
474 * Start auto-configuration routine. The resolver service should
475 * be available when this function is called.
476 *
477 * @param cfg initial configuration
478 * @param cb function to call with autoconfiguration result
479 * @param cb_cls closure for @a cb
480 * @return handle to cancel operation
481 */
482struct GNUNET_NAT_AutoHandle *
483GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
484 GNUNET_NAT_AutoResultCallback cb,
485 void *cb_cls);
486
487
488/**
489 * Abort autoconfiguration.
490 *
491 * @param ah handle for operation to abort
492 */
493void
494GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah);
495
496/**
497 * Handle for active STUN Requests.
498 */
499struct GNUNET_NAT_STUN_Handle;
500
501
502/**
503 * Function called with the result if an error happened during STUN request.
504 *
505 * @param cls closure
506 * @param result the specific error code
507 */
508typedef void
509(*GNUNET_NAT_STUN_ErrorCallback)(void *cls,
510 enum GNUNET_NAT_StatusCode error);
511
512
513/**
514 * Handle to a request given to the resolver. Can be used to cancel
515 * the request prior to the timeout or successful execution. Also
516 * used to track our internal state for the request.
517 */
518struct GNUNET_NAT_STUN_Handle;
519
520
521/**
522 * Make generic STUN request. Sends a generic stun request to the
523 * server specified using the specified socket. The caller must
524 * wait for a reply on the @a sock and call
525 * #GNUNET_NAT_stun_handle_packet() if a reply is received.
526 *
527 * @param server the address of the stun server
528 * @param port port of the stun server
529 * @param sock the socket used to send the request
530 * @param cb callback in case of error (or completion)
531 * @param cb_cls closure for @a cb
532 * @return NULL on error
533 */
534struct GNUNET_NAT_STUN_Handle *
535GNUNET_NAT_stun_make_request (const char *server,
536 uint16_t port,
537 struct GNUNET_NETWORK_Handle *sock,
538 GNUNET_NAT_STUN_ErrorCallback cb,
539 void *cb_cls);
540
541
542/**
543 * Cancel active STUN request. Frees associated resources
544 * and ensures that the callback is no longer invoked.
545 *
546 * @param rh request to cancel
547 */
548void
549GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh);
550
551
552/**
553 * Handle an incoming STUN message. Do some basic sanity checks on
554 * packet size and content, try to extract a bit of information, and
555 * possibly reply. At the moment this only processes BIND requests,
556 * and returns the externally visible address of the request. If a
557 * callback is specified, invoke it with the attribute.
558 *
559 * @param data the packet
560 * @param len the length of the packet
561 * @param arg sockaddr_in where we will set our discovered packet
562 * @return #GNUNET_OK on OK,
563 * #GNUNET_NO if the packet is not a stun packet
564 */
565int
566GNUNET_NAT_stun_handle_packet (const void *data,
567 size_t len,
568 struct sockaddr_in *arg);
569
570
571/**
572 * CHECK if is a valid STUN packet sending to #GNUNET_NAT_stun_handle_packet().
573 * It also check if it can handle the packet based on the NAT handler.
574 * You don't need to call anything else to check if the packet is valid,
575 *
576 * @param cls the NAT handle
577 * @param data packet
578 * @param len length of @a data
579 * @return #GNUNET_NO if it can't decode, #GNUNET_YES if is a packet
580 */
581int
582GNUNET_NAT_is_valid_stun_packet (void *cls,
583 const void *data,
584 size_t len);
585
586
587#endif
588
589/** @} */ /* end of group */
590
591/* end of gnunet_nat_lib.h */
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index 1620c9433..e75845207 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2007-2016 GNUnet e.V. 3 Copyright (C) 2007-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -123,6 +123,12 @@ enum GNUNET_NAT_AddressClass
123 GNUNET_NAT_AC_EXTERN = 128, 123 GNUNET_NAT_AC_EXTERN = 128,
124 124
125 /** 125 /**
126 * Addresses that were manually configured by the user.
127 * Used as a bit in combination with #GNUNET_NAT_AC_GLOBAL.
128 */
129 GNUNET_NAT_AC_MANUAL = 256,
130
131 /**
126 * Bitmask for "any" address. 132 * Bitmask for "any" address.
127 */ 133 */
128 GNUNET_NAT_AC_ANY = 65535 134 GNUNET_NAT_AC_ANY = 65535
@@ -131,6 +137,144 @@ enum GNUNET_NAT_AddressClass
131 137
132 138
133/** 139/**
140 * Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
141 */
142enum GNUNET_NAT_StatusCode
143{
144 /**
145 * Just the default
146 */
147 GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK,
148
149 /**
150 * IPC Failure
151 */
152 GNUNET_NAT_ERROR_IPC_FAILURE,
153
154 /**
155 * Failure in network subsystem, check permissions
156 */
157 GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR,
158
159 /**
160 * test timed out
161 */
162 GNUNET_NAT_ERROR_TIMEOUT,
163
164 /**
165 * detected that we are offline
166 */
167 GNUNET_NAT_ERROR_NOT_ONLINE,
168
169 /**
170 * `upnpc` command not found
171 */
172 GNUNET_NAT_ERROR_UPNPC_NOT_FOUND,
173
174 /**
175 * Failed to run `upnpc` command
176 */
177 GNUNET_NAT_ERROR_UPNPC_FAILED,
178
179 /**
180 * `upnpc' command took too long, process killed
181 */
182 GNUNET_NAT_ERROR_UPNPC_TIMEOUT,
183
184 /**
185 * `upnpc' command failed to establish port mapping
186 */
187 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED,
188
189 /**
190 * `external-ip' command not found
191 */
192 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND,
193
194 /**
195 * Failed to run `external-ip` command
196 */
197 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED,
198
199 /**
200 * `external-ip' command output invalid
201 */
202 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID,
203
204 /**
205 * "no valid address was returned by `external-ip'"
206 */
207 GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID,
208
209 /**
210 * Could not determine interface with internal/local network address
211 */
212 GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO,
213
214 /**
215 * No working gnunet-helper-nat-server found
216 */
217 GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND,
218
219 /**
220 * NAT test could not be initialized
221 */
222 GNUNET_NAT_ERROR_NAT_TEST_START_FAILED,
223
224 /**
225 * NAT test timeout
226 */
227 GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT,
228
229 /**
230 * NAT test failed to initiate
231 */
232 GNUNET_NAT_ERROR_NAT_REGISTER_FAILED,
233
234 /**
235 *
236 */
237 GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
238
239};
240
241
242
243/**
244 * What the situation of the NAT connectivity
245 */
246enum GNUNET_NAT_Type
247{
248 /**
249 * We have a direct connection
250 */
251 GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK,
252
253 /**
254 * We are under a NAT but cannot traverse it
255 */
256 GNUNET_NAT_TYPE_UNREACHABLE_NAT,
257
258 /**
259 * We can traverse using STUN
260 */
261 GNUNET_NAT_TYPE_STUN_PUNCHED_NAT,
262
263 /**
264 * We can traverse using UPNP
265 */
266 GNUNET_NAT_TYPE_UPNP_NAT,
267
268 /**
269 * We know nothing about the NAT.
270 */
271 GNUNET_NAT_TYPE_UNKNOWN
272
273};
274
275
276
277/**
134 * Signature of the callback passed to #GNUNET_NAT_register() for 278 * Signature of the callback passed to #GNUNET_NAT_register() for
135 * a function to call whenever our set of 'valid' addresses changes. 279 * a function to call whenever our set of 'valid' addresses changes.
136 * 280 *
@@ -179,8 +323,8 @@ struct GNUNET_NAT_Handle;
179 * address_callback for any 'plausible' external address. 323 * address_callback for any 'plausible' external address.
180 * 324 *
181 * @param cfg configuration to use 325 * @param cfg configuration to use
326 * @param config_section name of the configuration section for options
182 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP 327 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
183 * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
184 * @param num_addrs number of addresses in @a addrs 328 * @param num_addrs number of addresses in @a addrs
185 * @param addrs list of local addresses packets should be redirected to 329 * @param addrs list of local addresses packets should be redirected to
186 * @param addrlens actual lengths of the addresses in @a addrs 330 * @param addrlens actual lengths of the addresses in @a addrs
@@ -192,8 +336,8 @@ struct GNUNET_NAT_Handle;
192 */ 336 */
193struct GNUNET_NAT_Handle * 337struct GNUNET_NAT_Handle *
194GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, 338GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
339 const char *config_section,
195 uint8_t proto, 340 uint8_t proto,
196 const char *hole_external,
197 unsigned int num_addrs, 341 unsigned int num_addrs,
198 const struct sockaddr **addrs, 342 const struct sockaddr **addrs,
199 const socklen_t *addrlens, 343 const socklen_t *addrlens,
@@ -251,127 +395,6 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh);
251 395
252 396
253/** 397/**
254 * Handle to a NAT test.
255 */
256struct GNUNET_NAT_Test;
257
258
259/**
260 * Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
261 */
262enum GNUNET_NAT_StatusCode
263{
264 /**
265 * Just the default
266 */
267 GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK,
268
269 /**
270 * IPC Failure
271 */
272 GNUNET_NAT_ERROR_IPC_FAILURE,
273
274 /**
275 * Failure in network subsystem, check permissions
276 */
277 GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR,
278
279 /**
280 * test timed out
281 */
282 GNUNET_NAT_ERROR_TIMEOUT,
283
284 /**
285 * detected that we are offline
286 */
287 GNUNET_NAT_ERROR_NOT_ONLINE,
288
289 /**
290 * `upnpc` command not found
291 */
292 GNUNET_NAT_ERROR_UPNPC_NOT_FOUND,
293
294 /**
295 * Failed to run `upnpc` command
296 */
297 GNUNET_NAT_ERROR_UPNPC_FAILED,
298
299 /**
300 * `upnpc' command took too long, process killed
301 */
302 GNUNET_NAT_ERROR_UPNPC_TIMEOUT,
303
304 /**
305 * `upnpc' command failed to establish port mapping
306 */
307 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED,
308
309 /**
310 * `external-ip' command not found
311 */
312 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND,
313
314 /**
315 * Failed to run `external-ip` command
316 */
317 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED,
318
319 /**
320 * `external-ip' command output invalid
321 */
322 GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID,
323
324 /**
325 * "no valid address was returned by `external-ip'"
326 */
327 GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID,
328
329 /**
330 * Could not determine interface with internal/local network address
331 */
332 GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO,
333
334 /**
335 * No working gnunet-helper-nat-server found
336 */
337 GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND,
338
339 /**
340 * NAT test could not be initialized
341 */
342 GNUNET_NAT_ERROR_NAT_TEST_START_FAILED,
343
344 /**
345 * NAT test timeout
346 */
347 GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT,
348
349 /**
350 * NAT test failed to initiate
351 */
352 GNUNET_NAT_ERROR_NAT_REGISTER_FAILED,
353
354 /**
355 *
356 */
357 GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
358
359};
360
361
362/**
363 * Function called to report success or failure for
364 * NAT configuration test.
365 *
366 * @param cls closure
367 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
368 */
369typedef void
370(*GNUNET_NAT_TestCallback) (void *cls,
371 enum GNUNET_NAT_StatusCode result);
372
373
374/**
375 * Handle an incoming STUN message. This function is useful as 398 * Handle an incoming STUN message. This function is useful as
376 * some GNUnet service may be listening on a UDP port and might 399 * some GNUnet service may be listening on a UDP port and might
377 * thus receive STUN messages while trying to receive other data. 400 * thus receive STUN messages while trying to receive other data.
@@ -411,6 +434,18 @@ struct GNUNET_NAT_STUN_Handle;
411 434
412 435
413/** 436/**
437 * Function called to report success or failure for
438 * NAT configuration test.
439 *
440 * @param cls closure
441 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
442 */
443typedef void
444(*GNUNET_NAT_TestCallback) (void *cls,
445 enum GNUNET_NAT_StatusCode result);
446
447
448/**
414 * Make Generic STUN request. Sends a generic stun request to the 449 * Make Generic STUN request. Sends a generic stun request to the
415 * server specified using the specified socket. If we do this, 450 * server specified using the specified socket. If we do this,
416 * we need to watch for possible responses and call 451 * we need to watch for possible responses and call
@@ -442,130 +477,6 @@ void
442GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh); 477GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh);
443 478
444 479
445/**
446 * Start testing if NAT traversal works using the given configuration
447 * (IPv4-only). The transport adapters should be down while using
448 * this function.
449 *
450 * @param cfg configuration for the NAT traversal
451 * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
452 * @param bind_ip IPv4 address to bind to
453 * @param bnd_port port to bind to, 0 to test connection reversal
454 * @param extern_ip IPv4 address to externally advertise
455 * @param extern_port externally advertised port to use
456 * @param report function to call with the result of the test
457 * @param report_cls closure for @a report
458 * @return handle to cancel NAT test
459 */
460struct GNUNET_NAT_Test *
461GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
462 uint8_t proto,
463 struct in_addr bind_ip,
464 uint16_t bnd_port,
465 struct in_addr extern_ip,
466 uint16_t extern_port,
467 GNUNET_NAT_TestCallback report,
468 void *report_cls);
469
470
471/**
472 * Stop an active NAT test.
473 *
474 * @param tst test to stop.
475 */
476void
477GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst);
478
479
480/**
481 * Handle to auto-configuration in progress.
482 */
483struct GNUNET_NAT_AutoHandle;
484
485
486/**
487 * What the situation of the NAT connectivity
488 */
489enum GNUNET_NAT_Type
490{
491 /**
492 * We have a direct connection
493 */
494 GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK,
495
496 /**
497 * We are under a NAT but cannot traverse it
498 */
499 GNUNET_NAT_TYPE_UNREACHABLE_NAT,
500
501 /**
502 * We can traverse using STUN
503 */
504 GNUNET_NAT_TYPE_STUN_PUNCHED_NAT,
505
506 /**
507 * We can traverse using UPNP
508 */
509 GNUNET_NAT_TYPE_UPNP_NAT,
510
511 /**
512 * We know nothing about the NAT.
513 */
514 GNUNET_NAT_TYPE_UNKNOWN
515
516};
517
518
519/**
520 * Converts `enum GNUNET_NAT_StatusCode` to string
521 *
522 * @param err error code to resolve to a string
523 * @return point to a static string containing the error code
524 */
525const char *
526GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err);
527
528
529/**
530 * Function called with the result from the autoconfiguration.
531 *
532 * @param cls closure
533 * @param diff minimal suggested changes to the original configuration
534 * to make it work (as best as we can)
535 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
536 * @param type what the situation of the NAT
537 */
538typedef void
539(*GNUNET_NAT_AutoResultCallback)(void *cls,
540 const struct GNUNET_CONFIGURATION_Handle *diff,
541 enum GNUNET_NAT_StatusCode result,
542 enum GNUNET_NAT_Type type);
543
544
545/**
546 * Start auto-configuration routine. The transport adapters should
547 * be stopped while this function is called.
548 *
549 * @param cfg initial configuration
550 * @param cb function to call with autoconfiguration result
551 * @param cb_cls closure for @a cb
552 * @return handle to cancel operation
553 */
554struct GNUNET_NAT_AutoHandle *
555GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
556 GNUNET_NAT_AutoResultCallback cb,
557 void *cb_cls);
558
559
560/**
561 * Abort autoconfiguration.
562 *
563 * @param ah handle for operation to abort
564 */
565void
566GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah);
567
568
569#endif 480#endif
570 481
571/** @} */ /* end of group */ 482/** @} */ /* end of group */
diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h
index 44df483a0..b5c2153ac 100644
--- a/src/include/gnunet_peerinfo_service.h
+++ b/src/include/gnunet_peerinfo_service.h
@@ -101,7 +101,7 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
101struct GNUNET_MQ_Envelope * 101struct GNUNET_MQ_Envelope *
102GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, 102GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
103 const struct GNUNET_HELLO_Message *hello, 103 const struct GNUNET_HELLO_Message *hello,
104 GNUNET_MQ_NotifyCallback cont, 104 GNUNET_SCHEDULER_TaskCallback cont,
105 void *cont_cls); 105 void *cont_cls);
106 106
107 107
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index cf26f1727..e31b1f33c 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2645,7 +2645,7 @@ extern "C"
2645/** 2645/**
2646 * Send origin an ACK that the connection is complete 2646 * Send origin an ACK that the connection is complete
2647 */ 2647 */
2648#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK 1001 2648#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK 1001
2649 2649
2650/** 2650/**
2651 * Notify that a connection is no longer valid 2651 * Notify that a connection is no longer valid
@@ -2660,49 +2660,53 @@ extern "C"
2660/** 2660/**
2661 * At some point, the route will spontaneously change TODO 2661 * At some point, the route will spontaneously change TODO
2662 */ 2662 */
2663#define GNUNET_MESSAGE_TYPE_CADET_PATH_CHANGED 1004 2663#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_PATH_CHANGED_UNIMPLEMENTED 1004
2664 2664
2665/** 2665/**
2666 * Hop-by-hop, connection dependent ACK. 2666 * Hop-by-hop, connection dependent ACK.
2667 */ 2667 */
2668#define GNUNET_MESSAGE_TYPE_CADET_ACK 1005 2668#define GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK 1005
2669 2669
2670/** 2670/**
2671 * Poll for a hop-by-hop ACK. 2671 * Axolotl key exchange.
2672 */ 2672 */
2673#define GNUNET_MESSAGE_TYPE_CADET_POLL 1006 2673#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX 1007
2674 2674
2675/** 2675/**
2676 * Key exchange encapsulation. 2676 * Axolotl encrypted data.
2677 */ 2677 */
2678#define GNUNET_MESSAGE_TYPE_CADET_KX 1007 2678#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED 1008
2679 2679
2680/** 2680/**
2681 * Axolotl encrypted data. 2681 * We do not bother with ACKs for
2682 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED messages, but we instead
2683 * poll for one if we got nothing for a while and start to be worried.
2682 */ 2684 */
2683#define GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED 1008 2685#define GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL 1006
2686
2687
2684 2688
2685/********************************** Channel *********************************/ 2689/********************************** Channel *********************************/
2686 2690
2687/** 2691/**
2688 * Payload data (inside an encrypted tunnel). 2692 * Payload data (inside an encrypted tunnel).
2689 */ 2693 */
2690#define GNUNET_MESSAGE_TYPE_CADET_DATA 1010 2694#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA 1010
2691 2695
2692/** 2696/**
2693 * Confirm payload data end-to-end. 2697 * Confirm payload data end-to-end.
2694 */ 2698 */
2695#define GNUNET_MESSAGE_TYPE_CADET_DATA_ACK 1011 2699#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK 1011
2696 2700
2697/** 2701/**
2698 * Announce connection is still alive (direction sensitive). 2702 * Announce connection is still alive (direction sensitive).
2699 */ 2703 */
2700#define GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE 1012 2704#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE 1012
2701 2705
2702/** 2706/**
2703 * Ask the cadet service to create a new channel. 2707 * Ask the cadet service to create a new channel.
2704 */ 2708 */
2705#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE 1013 2709#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN 1013
2706 2710
2707/** 2711/**
2708 * Ask the cadet service to destroy a channel. 2712 * Ask the cadet service to destroy a channel.
@@ -2712,12 +2716,12 @@ extern "C"
2712/** 2716/**
2713 * Confirm the creation of a channel 2717 * Confirm the creation of a channel
2714 */ 2718 */
2715#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK 1015 2719#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK 1015
2716 2720
2717/** 2721/**
2718 * Reject the creation of a channel 2722 * Reject the creation of a channel
2719 */ 2723 */
2720#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK 1016 2724#define GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED 1016
2721 2725
2722/*********************************** Local **********************************/ 2726/*********************************** Local **********************************/
2723 2727
@@ -2789,6 +2793,11 @@ extern "C"
2789 */ 2793 */
2790#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1038 2794#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1038
2791 2795
2796/**
2797 * End of local information about all peers known to the service.
2798 */
2799#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER_END 1039
2800
2792/******************************** Application *******************************/ 2801/******************************** Application *******************************/
2793 2802
2794/** 2803/**
@@ -2833,7 +2842,7 @@ extern "C"
2833/** 2842/**
2834 * Message to ask NAT service to request autoconfiguration. 2843 * Message to ask NAT service to request autoconfiguration.
2835 */ 2844 */
2836#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG 1067 2845#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067
2837 2846
2838/** 2847/**
2839 * Message from NAT service with the autoconfiguration result. 2848 * Message from NAT service with the autoconfiguration result.
@@ -2841,8 +2850,31 @@ extern "C"
2841#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT 1068 2850#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT 1068
2842 2851
2843 2852
2853/* 1080-1109 reserved for TMCG (Heiko Stamer, see gnunet-developers, January 2017) */
2854
2855
2856/******************************************************************************/
2857/*********************************** AUCTION ********************************/
2858/******************************************************************************/
2859
2860/**
2861 * Client wants to create a new auction.
2862 */
2863#define GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE 1110
2864
2865/**
2866 * Client wants to join an existing auction.
2867 */
2868#define GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_JOIN 1111
2869
2870/**
2871 * Service reports the auction outcome to the client.
2872 */
2873#define GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_OUTCOME 1112
2874
2875
2844/** 2876/**
2845 * Next available: 1080 2877 * Next available: 1130
2846 */ 2878 */
2847 2879
2848 2880
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 353287cbf..03bc4575e 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -151,11 +151,6 @@ extern "C"
151#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20 151#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20
152 152
153/** 153/**
154 * Key exchange in CADET
155 */
156#define GNUNET_SIGNATURE_PURPOSE_CADET_KX 21
157
158/**
159 * Signature for the first round of distributed key generation. 154 * Signature for the first round of distributed key generation.
160 */ 155 */
161#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 22 156#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 22