d5d08878791591019ba67357e23de86cf53639dd
[project/unetd.git] / pex.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
4 */
5 #ifndef __UNETD_PEX_H
6 #define __UNETD_PEX_H
7
8 #include <libubox/uloop.h>
9
10 struct network;
11
12 struct network_pex_host {
13 struct list_head list;
14 uint64_t timeout;
15 uint64_t last_active;
16 union network_endpoint endpoint;
17 };
18
19 struct network_pex {
20 struct uloop_fd fd;
21 struct list_head hosts;
22 struct uloop_timeout request_update_timer;
23 };
24
25 enum pex_event {
26 PEX_EV_HANDSHAKE,
27 PEX_EV_ENDPOINT_CHANGE,
28 PEX_EV_QUERY,
29 PEX_EV_PING,
30 };
31
32 void network_pex_init(struct network *net);
33 int network_pex_open(struct network *net);
34 void network_pex_close(struct network *net);
35 void network_pex_free(struct network *net);
36
37 void network_pex_event(struct network *net, struct network_peer *peer,
38 enum pex_event ev);
39 void network_pex_create_host(struct network *net, union network_endpoint *ep,
40 unsigned int timeout);
41
42 static inline bool network_pex_active(struct network_pex *pex)
43 {
44 return pex->fd.fd >= 0;
45 }
46
47 int global_pex_open(const char *unix_path);
48
49 #endif