diff options
author | marshall <stmr@umich.edu> | 2023-08-03 15:26:31 -0400 |
---|---|---|
committer | marshall <stmr@umich.edu> | 2023-08-03 15:26:31 -0400 |
commit | e91dbda4f99e42dcd74fb8f0eba836a2f039f99c (patch) | |
tree | 5c72fb9cbf2acd61f5958ce68c789a52642e347b | |
parent | ad6099e12f1075879c5eed61c37f30061395d4a7 (diff) | |
download | gnunet-e91dbda4f99e42dcd74fb8f0eba836a2f039f99c.tar.gz gnunet-e91dbda4f99e42dcd74fb8f0eba836a2f039f99c.zip |
quic communicator: add nat handler
-rw-r--r-- | src/transport/gnunet-communicator-quic.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c index 0d47f1469..700fd0ca4 100644 --- a/src/transport/gnunet-communicator-quic.c +++ b/src/transport/gnunet-communicator-quic.c | |||
@@ -64,6 +64,11 @@ struct GNUNET_PeerIdentity my_identity; | |||
64 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | 64 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Connection to NAT service. | ||
68 | */ | ||
69 | static struct GNUNET_NAT_Handle *nat; | ||
70 | |||
71 | /** | ||
67 | * Information we track per peer we have recently been in contact with. | 72 | * Information we track per peer we have recently been in contact with. |
68 | * | 73 | * |
69 | * (Since quiche handles crypto, handshakes, etc. we don't differentiate | 74 | * (Since quiche handles crypto, handshakes, etc. we don't differentiate |
@@ -1062,6 +1067,67 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const | |||
1062 | } | 1067 | } |
1063 | 1068 | ||
1064 | 1069 | ||
1070 | static void | ||
1071 | try_connection_reversal (void *cls, | ||
1072 | const struct sockaddr *addr, | ||
1073 | socklen_t addrlen) | ||
1074 | { | ||
1075 | /* FIXME: support reversal: #5529 */ | ||
1076 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1077 | "No connection reversal implemented!"); | ||
1078 | } | ||
1079 | |||
1080 | |||
1081 | /** | ||
1082 | * Signature of the callback passed to #GNUNET_NAT_register() for | ||
1083 | * a function to call whenever our set of 'valid' addresses changes. | ||
1084 | * | ||
1085 | * @param cls closure | ||
1086 | * @param app_ctx[in,out] location where the app can store stuff | ||
1087 | * on add and retrieve it on remove | ||
1088 | * @param add_remove #GNUNET_YES to add a new public IP address, | ||
1089 | * #GNUNET_NO to remove a previous (now invalid) one | ||
1090 | * @param ac address class the address belongs to | ||
1091 | * @param addr either the previous or the new public IP address | ||
1092 | * @param addrlen actual length of the @a addr | ||
1093 | */ | ||
1094 | static void | ||
1095 | nat_address_cb (void *cls, | ||
1096 | void **app_ctx, | ||
1097 | int add_remove, | ||
1098 | enum GNUNET_NAT_AddressClass ac, | ||
1099 | const struct sockaddr *addr, | ||
1100 | socklen_t addrlen) | ||
1101 | { | ||
1102 | char *my_addr; | ||
1103 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; | ||
1104 | |||
1105 | if (GNUNET_YES == add_remove) | ||
1106 | { | ||
1107 | enum GNUNET_NetworkType nt; | ||
1108 | |||
1109 | GNUNET_asprintf (&my_addr, | ||
1110 | "%s-%s", | ||
1111 | COMMUNICATOR_ADDRESS_PREFIX, | ||
1112 | GNUNET_a2s (addr, addrlen)); | ||
1113 | nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); | ||
1114 | ai = | ||
1115 | GNUNET_TRANSPORT_communicator_address_add (ch, | ||
1116 | my_addr, | ||
1117 | nt, | ||
1118 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1119 | GNUNET_free (my_addr); | ||
1120 | *app_ctx = ai; | ||
1121 | } | ||
1122 | else | ||
1123 | { | ||
1124 | ai = *app_ctx; | ||
1125 | GNUNET_TRANSPORT_communicator_address_remove (ai); | ||
1126 | *app_ctx = NULL; | ||
1127 | } | ||
1128 | } | ||
1129 | |||
1130 | |||
1065 | /** | 1131 | /** |
1066 | * Shutdown the QUIC communicator. | 1132 | * Shutdown the QUIC communicator. |
1067 | * | 1133 | * |
@@ -1527,6 +1593,15 @@ run (void *cls, | |||
1527 | NULL, | 1593 | NULL, |
1528 | ¬ify_cb, | 1594 | ¬ify_cb, |
1529 | NULL); | 1595 | NULL); |
1596 | nat = GNUNET_NAT_register (cfg, | ||
1597 | COMMUNICATOR_CONFIG_SECTION, | ||
1598 | IPPROTO_UDP, | ||
1599 | 1 /* one address */, | ||
1600 | (const struct sockaddr **) &in, | ||
1601 | &in_len, | ||
1602 | &nat_address_cb, | ||
1603 | try_connection_reversal, | ||
1604 | NULL /* closure */); | ||
1530 | if (NULL == ch) | 1605 | if (NULL == ch) |
1531 | { | 1606 | { |
1532 | GNUNET_break (0); | 1607 | GNUNET_break (0); |