ubus: add reload command
[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 union network_endpoint endpoint;
16 };
17
18 struct network_pex {
19 struct uloop_fd fd;
20 struct list_head hosts;
21 struct uloop_timeout request_update_timer;
22 };
23
24 enum pex_event {
25 PEX_EV_HANDSHAKE,
26 PEX_EV_ENDPOINT_CHANGE,
27 PEX_EV_QUERY,
28 PEX_EV_PING,
29 };
30
31 void network_pex_init(struct network *net);
32 int network_pex_open(struct network *net);
33 void network_pex_close(struct network *net);
34 void network_pex_free(struct network *net);
35
36 void network_pex_event(struct network *net, struct network_peer *peer,
37 enum pex_event ev);
38 void network_pex_create_host(struct network *net, union network_endpoint *ep,
39 unsigned int timeout);
40
41 static inline bool network_pex_active(struct network_pex *pex)
42 {
43 return pex->fd.fd >= 0;
44 }
45
46 int global_pex_open(void);
47
48 #endif