host: deal with host/peer null pointers in debug messages
[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 union network_endpoint endpoint;
15 };
16
17 struct network_pex {
18 struct uloop_fd fd;
19 struct list_head hosts;
20 struct uloop_timeout request_update_timer;
21 };
22
23 enum pex_event {
24 PEX_EV_HANDSHAKE,
25 PEX_EV_ENDPOINT_CHANGE,
26 PEX_EV_QUERY,
27 PEX_EV_PING,
28 };
29
30 void network_pex_init(struct network *net);
31 int network_pex_open(struct network *net);
32 void network_pex_close(struct network *net);
33
34 void network_pex_event(struct network *net, struct network_peer *peer,
35 enum pex_event ev);
36
37 static inline bool network_pex_active(struct network_pex *pex)
38 {
39 return pex->fd.fd >= 0;
40 }
41
42 int global_pex_open(void);
43
44 #endif