summaryrefslogtreecommitdiff
path: root/minecproxy/main.h
blob: f7dd54742e0fd2e119eb11ad2894df68592b944c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef foomainhfoo
#define foomainhfoo

#include <sys/socket.h>
#include <netinet/ip.h>

struct cfg;
struct uring_task;

#include "misc.h"
#include "shared/utils.h"

extern struct cfg *cfg;
extern bool exiting;

void dump_tree();

/* To save typing in all the function definitions below */
typedef void (*utask_cb_t)(struct uring_task *, int res);
typedef int (*rutask_cb_t)(struct uring_task *, int res);

struct uring_task_buf {
	char buf[4096];
	size_t len;
	size_t done;
	struct iovec iov;
	struct msghdr msg;
};

struct uring_task {
	const char *name;
	int refcount; /* signed to catch refcount bugs */
	int fd;
	struct uring_task *parent;
	void (*free)(struct uring_task *);
	bool dead;
	struct uring_task_buf *tbuf;

	/* called once or repeatedly until is_complete_cb is satisfied */
	utask_cb_t cb;

	/* returns: 0 = not complete; < 0 = error; > 0 = complete */
	rutask_cb_t is_complete_cb;

	/* called once tbuf processing is done */
	utask_cb_t final_cb;

	/* used for recvmsg/sendmsg */
	struct saddr saddr;
	void *priv;
};

struct cfg {
	/* Options */
	const char *cfg_path;
	char *cfg_real_path;
	DIR *cfg_dir;
	const char *data_path;
	char *data_real_path;
	DIR *data_dir;
	uid_t uid;
	gid_t gid;
	bool do_igmp;
	char *igmp_iface;
	bool splice_supported;
	uint16_t announce_interval;
	uint16_t proxy_connection_interval;
	uint16_t proxy_connection_attempts;
	bool socket_defer;
	bool socket_freebind;
	bool socket_keepalive;
	bool socket_iptos;
	bool socket_nodelay;

	/* Bookkeeping */
	struct uring_ev *uring;
	struct server_cfg_monitor *server_cfg_monitor;
	struct signal_ev *signal;
	struct announce *announce;
	struct ptimer *ptimer;
	struct igmp *igmp;
	struct idle *idle;
	struct uring_task task;
	struct list_head servers;
};

#endif