summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAnton <anton@picapica.im>2026-11-22 18:43:34 +0400
committerAnton <anton@picapica.im>2026-11-22 18:43:34 +0400
commit05b82a33c145f768de9b3b3abca18630a798aabb (patch)
treedf4e709e70f8c67d691ad0264a2191f30cfb3715 /tests
parentee5e6b4dac1d2cf0c2c5a29fe69efd7adf8d4bf6 (diff)
downloadpica-pica-05b82a33c145f768de9b3b3abca18630a798aabb.tar.gz
pica-pica-05b82a33c145f768de9b3b3abca18630a798aabb.zip
rework network settings, add multiple addresses, UDP hole punching
Diffstat (limited to 'tests')
-rw-r--r--tests/test_client.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/test_client.c b/tests/test_client.c
index 0bf7fbc..320e0bb 100644
--- a/tests/test_client.c
+++ b/tests/test_client.c
@@ -239,6 +239,11 @@ void udp_address_cb(struct PICA_c2n *c2n, int status, int type, void *addr_bin,
printf("udp_address_cb: failed, status %i\n", status);
}
+void direct_c2c_established_cb(const unsigned char *peer_id, const char *ciphersuitename)
+{
+ printf("direct c2c connection established, %s\n", ciphersuitename);
+}
+
struct PICA_client_callbacks cbs =
{
newmsg_cb,
@@ -261,6 +266,7 @@ struct PICA_client_callbacks cbs =
c2n_closed_cb,
listener_error,
multilogin_cb,
+ .direct_c2c_established_cb = direct_c2c_established_cb,
.tcp_address_cb = tcp_address_cb,
.udp_address_cb = udp_address_cb
};
@@ -364,7 +370,7 @@ int main(int argc, char** argv)
if (argc < 4 || !nodeaddr || !nodeport || !certfile)
{
puts("usage: test_client -a node address -p node port -c cert_filename [-i peer id]\n\
- -d local address for direct incoming c2c connections\n\
+ -d local address for direct incoming c2c connections, \"auto\" for automatic configuration\n\
-e external port for incoming direct connections\n\
-l internal port to listen for incoming direct connections\n\
-t enable connect-only mode for direct c2c connections\n\
@@ -405,7 +411,33 @@ cert_filename should point to file that contains client certificate, private key
printf("new listener on %s port %i external announced port %i\n", localdirectaddr, intp, extp);
- ret = PICA_new_listener(acc, localdirectaddr, extp, intp, &l);
+ ret = PICA_new_listener(acc, intp, &l);
+
+ /* "auto" leaves the announced addresses to the listener */
+ if (ret == PICA_OK && strcmp(localdirectaddr, "auto") != 0)
+ {
+ /* a comma separated list, announced in its order */
+ const char *addrs[PICA_DIRECTC2C_MAX_ADDRS];
+ int ports[PICA_DIRECTC2C_MAX_ADDRS];
+ char *list = strdup(localdirectaddr), *a;
+ int n = 0;
+
+ for (a = strtok(list, ","); a && n < PICA_DIRECTC2C_MAX_ADDRS; a = strtok(NULL, ","))
+ {
+ addrs[n] = a;
+ ports[n] = extp;
+ n++;
+ }
+
+ ret = PICA_listener_set_addrlist(l, addrs, ports, n);
+ free(list);
+
+ if (ret != PICA_OK)
+ {
+ fprintf(stderr, "failed to set the listener's address, error code: %i\n", ret);
+ PICA_close_listener(l);
+ }
+ }
if (ret != PICA_OK)
{