pex: track indirect hosts (reachable via gateway) as peers without adding them to wg
[project/unetd.git] / host.h
diff --git a/host.h b/host.h
index 2f8f881d7e204fe91baf4640ef2f3193fd1db1b3..56d359c7e0580aa9df5243c6bc7ce29c97487416 100644 (file)
--- a/host.h
+++ b/host.h
@@ -5,6 +5,14 @@
 #ifndef __UNETD_HOST_H
 #define __UNETD_HOST_H
 
+enum peer_endpoint_type {
+       ENDPOINT_TYPE_STATIC,
+       ENDPOINT_TYPE_PEX,
+       ENDPOINT_TYPE_ENDPOINT_NOTIFY,
+       ENDPOINT_TYPE_ENDPOINT_PORT_NOTIFY,
+       __ENDPOINT_TYPE_MAX,
+};
+
 struct network_peer {
        struct vlist_node node;
        uint8_t key[CURVE25519_KEY_SIZE];
@@ -14,26 +22,38 @@ struct network_peer {
        struct blob_attr *subnet;
        int port;
        int pex_port;
+       bool dynamic;
+       bool indirect;
 
        struct {
                int connect_attempt;
                bool connected;
                bool handshake;
                bool has_local_ep_addr;
+               bool pinged;
                union network_addr local_ep_addr;
                union network_endpoint endpoint;
 
-               union network_endpoint next_endpoint;
+               uint8_t next_endpoint_idx;
+               union network_endpoint next_endpoint[__ENDPOINT_TYPE_MAX];
                uint64_t last_ep_update;
 
                uint64_t rx_bytes;
                uint64_t last_handshake;
                uint64_t last_request;
+               uint64_t last_query_sent;
+
                int idle;
                int num_net_queries;
        } state;
 };
 
+struct network_dynamic_peer {
+       struct list_head list;
+
+       struct network_peer peer;
+};
+
 struct network_host {
        struct avl_node node;
 
@@ -66,7 +86,7 @@ static inline const char *network_peer_name(struct network_peer *peer)
 {
        struct network_host *host;
 
-       if (!peer)
+       if (!peer || peer->dynamic)
                return "(none)";
 
        host = container_of(peer, struct network_host, peer);
@@ -99,6 +119,7 @@ network_host_uses_peer_route(struct network_host *host, struct network *net,
 void network_hosts_update_start(struct network *net);
 void network_hosts_update_done(struct network *net);
 void network_hosts_add(struct network *net, struct blob_attr *hosts);
+void network_hosts_reload_dynamic_peers(struct network *net);
 
 void network_hosts_init(struct network *net);
 void network_hosts_free(struct network *net);