From d3352b997ca59a336a40fe6660c6e5b7079864aa Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sun, 28 Jun 2020 14:58:32 +0200 Subject: Run clang-format on source tree (excl igmp.c) --- minecproxy/server-proxy.c | 185 +++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 93 deletions(-) (limited to 'minecproxy/server-proxy.c') diff --git a/minecproxy/server-proxy.c b/minecproxy/server-proxy.c index 087773d..b80a220 100644 --- a/minecproxy/server-proxy.c +++ b/minecproxy/server-proxy.c @@ -13,8 +13,7 @@ #include "server.h" #include "server-proxy.h" -static void -format_bytes(char *buf, size_t len, uint64_t val) +static void format_bytes(char *buf, size_t len, uint64_t val) { uint64_t tmp; const char *suffix = "B"; @@ -24,11 +23,11 @@ format_bytes(char *buf, size_t len, uint64_t val) tmp = val * 10; if (val > 1152921504606846976ULL) { tmp = val / 115292150460684697ULL; - suffix= "EiB"; + suffix = "EiB"; } else if (val > 1125899906842624ULL) { tmp /= 1125899906842624ULL; suffix = "PiB"; - } else if (val > 1099511627776ULL) { + } else if (val > 1099511627776ULL) { tmp /= 1099511627776ULL; suffix = "TiB"; } else if (val > 1073741824ULL) { @@ -45,8 +44,7 @@ format_bytes(char *buf, size_t len, uint64_t val) snprintf(buf, len, "%lu.%lu %s", tmp / 10, tmp % 10, suffix); } -static void -format_time(char *buf, size_t len, time_t diff) +static void format_time(char *buf, size_t len, time_t diff) { unsigned hh, mm, ss; @@ -61,62 +59,60 @@ format_time(char *buf, size_t len, time_t diff) snprintf(buf, len, "%02u:%02u:%02u", hh, mm, ss); } -static void -proxy_free(struct uring_task *task) +static void proxy_free(struct uring_task *task) { - struct server_proxy *proxy = container_of(task, struct server_proxy, task); + struct server_proxy *proxy = + container_of(task, struct server_proxy, task); char cts[100]; char stc[100]; char duration[100]; assert_return(task); - debug(DBG_PROXY, "server: %s, src: %s, dst: %s", - proxy->server->name, + debug(DBG_PROXY, "server: %s, src: %s, dst: %s", proxy->server->name, proxy->client_conn.remote.addrstr, proxy->server_conn.remote.addrstr); if (proxy->begin > 0) { - format_time(duration, sizeof(duration), time(NULL) - proxy->begin); + format_time(duration, sizeof(duration), + time(NULL) - proxy->begin); format_bytes(cts, sizeof(cts), proxy->client_bytes); format_bytes(stc, sizeof(stc), proxy->server_bytes); info("%s: proxy connection %s -> %s closed " "(CtS: %s, StC: %s), duration %s", - proxy->server->name, - proxy->client_conn.remote.addrstr, - proxy->server_conn.remote.addrstr, - cts, stc, duration); + proxy->server->name, proxy->client_conn.remote.addrstr, + proxy->server_conn.remote.addrstr, cts, stc, duration); } list_del(&proxy->list); xfree(proxy); } -static void -proxy_client_free(struct uring_task *task) +static void proxy_client_free(struct uring_task *task) { - struct server_proxy *proxy = container_of(task, struct server_proxy, clienttask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, clienttask); assert_return(task); debug(DBG_PROXY, "%s: client connection closed", proxy->server->name); } -static void -proxy_server_free(struct uring_task *task) +static void proxy_server_free(struct uring_task *task) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); debug(DBG_PROXY, "%s: server connection closed", proxy->server->name); } -void -proxy_delete(struct server_proxy *proxy) +void proxy_delete(struct server_proxy *proxy) { - debug(DBG_PROXY, "%s: shutting down proxy %p", proxy->server->name, proxy); + debug(DBG_PROXY, "%s: shutting down proxy %p", proxy->server->name, + proxy); assert_return(proxy); @@ -141,10 +137,10 @@ proxy_delete(struct server_proxy *proxy) */ static void proxy_client_read(struct uring_task *task, int res); -static void -proxy_client_written(struct uring_task *task, int res) +static void proxy_client_written(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, clienttask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, clienttask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -160,10 +156,10 @@ proxy_client_written(struct uring_task *task, int res) uring_tbuf_read(task, proxy_client_read); } -static void -proxy_client_read(struct uring_task *task, int res) +static void proxy_client_read(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, clienttask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, clienttask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -180,10 +176,10 @@ proxy_client_read(struct uring_task *task, int res) static void proxy_server_read(struct uring_task *task, int res); -static void -proxy_server_written(struct uring_task *task, int res) +static void proxy_server_written(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -199,10 +195,10 @@ proxy_server_written(struct uring_task *task, int res) uring_tbuf_read(&proxy->servertask, proxy_server_read); } -static void -proxy_server_read(struct uring_task *task, int res) +static void proxy_server_read(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -222,10 +218,10 @@ proxy_server_read(struct uring_task *task, int res) */ static void proxy_client_spliced_in(struct uring_task *task, int res); -static void -proxy_client_spliced_out(struct uring_task *task, int res) +static void proxy_client_spliced_out(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -236,13 +232,14 @@ proxy_client_spliced_out(struct uring_task *task, int res) return; } - uring_splice(task, proxy->cfd, proxy->cpipe[PIPE_WR], proxy_client_spliced_in); + uring_splice(task, proxy->cfd, proxy->cpipe[PIPE_WR], + proxy_client_spliced_in); } -static void -proxy_client_spliced_in(struct uring_task *task, int res) +static void proxy_client_spliced_in(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -253,15 +250,16 @@ proxy_client_spliced_in(struct uring_task *task, int res) return; } - uring_splice(task, proxy->cpipe[PIPE_RD], proxy->sfd, proxy_client_spliced_out); + uring_splice(task, proxy->cpipe[PIPE_RD], proxy->sfd, + proxy_client_spliced_out); } static void proxy_server_spliced_in(struct uring_task *task, int res); -static void -proxy_server_spliced_out(struct uring_task *task, int res) +static void proxy_server_spliced_out(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -272,13 +270,14 @@ proxy_server_spliced_out(struct uring_task *task, int res) return; } - uring_splice(task, proxy->sfd, proxy->spipe[PIPE_WR], proxy_server_spliced_in); + uring_splice(task, proxy->sfd, proxy->spipe[PIPE_WR], + proxy_server_spliced_in); } -static void -proxy_server_spliced_in(struct uring_task *task, int res) +static void proxy_server_spliced_in(struct uring_task *task, int res) { - struct server_proxy *proxy = container_of(task, struct server_proxy, servertask); + struct server_proxy *proxy = + container_of(task, struct server_proxy, servertask); assert_return(task); assert_task_alive(DBG_PROXY, task); @@ -289,13 +288,14 @@ proxy_server_spliced_in(struct uring_task *task, int res) return; } - uring_splice(task, proxy->spipe[PIPE_RD], proxy->cfd, proxy_server_spliced_out); + uring_splice(task, proxy->spipe[PIPE_RD], proxy->cfd, + proxy_server_spliced_out); } -static void -proxy_connected_cb(struct connection *conn, bool connected) +static void proxy_connected_cb(struct connection *conn, bool connected) { - struct server_proxy *proxy = container_of(conn, struct server_proxy, server_conn); + struct server_proxy *proxy = + container_of(conn, struct server_proxy, server_conn); assert_return(conn); assert_task_alive(DBG_PROXY, &proxy->clienttask); @@ -313,16 +313,17 @@ proxy_connected_cb(struct connection *conn, bool connected) ptimer_del_task(&proxy->ptask); proxy->sfd = proxy->servertask.fd; - verbose("%s: proxy connection %s -> %s opened", - proxy->server->name, + verbose("%s: proxy connection %s -> %s opened", proxy->server->name, proxy->client_conn.remote.addrstr, proxy->server_conn.remote.addrstr); proxy->begin = time(NULL); if (cfg->splice_supported) { debug(DBG_PROXY, "handling proxy connection with splice"); - uring_splice(&proxy->clienttask, proxy->cfd, proxy->cpipe[PIPE_WR], proxy_client_spliced_in); - uring_splice(&proxy->servertask, proxy->sfd, proxy->spipe[PIPE_WR], proxy_server_spliced_in); + uring_splice(&proxy->clienttask, proxy->cfd, + proxy->cpipe[PIPE_WR], proxy_client_spliced_in); + uring_splice(&proxy->servertask, proxy->sfd, + proxy->spipe[PIPE_WR], proxy_server_spliced_in); } else { debug(DBG_PROXY, "handling proxy connection with read-write"); uring_tbuf_read(&proxy->clienttask, proxy_client_read); @@ -330,8 +331,7 @@ proxy_connected_cb(struct connection *conn, bool connected) } } -void -proxy_refdump(struct server_proxy *proxy) +void proxy_refdump(struct server_proxy *proxy) { assert_return(proxy); @@ -340,10 +340,10 @@ proxy_refdump(struct server_proxy *proxy) uring_task_refdump(&proxy->servertask); } -static void -proxy_connect_timer_cb(struct ptimer_task *ptask) +static void proxy_connect_timer_cb(struct ptimer_task *ptask) { - struct server_proxy *proxy = container_of(ptask, struct server_proxy, ptask); + struct server_proxy *proxy = + container_of(ptask, struct server_proxy, ptask); assert_return(ptask); @@ -355,8 +355,8 @@ proxy_connect_timer_cb(struct ptimer_task *ptask) &proxy->server_conn, proxy_connected_cb); } -struct server_proxy * -proxy_new(struct server *server, struct saddr *client, int fd) +struct server_proxy *proxy_new(struct server *server, struct saddr *client, + int fd) { struct server_proxy *proxy; @@ -412,8 +412,8 @@ proxy_new(struct server *server, struct saddr *client, int fd) } proxy->connecting = true; - connect_any(&proxy->servertask, &server->remotes, - &proxy->server_conn, proxy_connected_cb); + connect_any(&proxy->servertask, &server->remotes, &proxy->server_conn, + proxy_connected_cb); return proxy; @@ -426,10 +426,10 @@ out: return NULL; } -static void -local_accept(struct uring_task *task, int res) +static void local_accept(struct uring_task *task, int res) { - struct server_local *local = container_of(task, struct server_local, task); + struct server_local *local = + container_of(task, struct server_local, task); struct server *server = container_of(task->parent, struct server, task); struct server_proxy *proxy; @@ -445,8 +445,8 @@ local_accept(struct uring_task *task, int res) saddr_set_addrstr(&local->client); - verbose("%s: incoming proxy connection: %s -> %s", - server->name, local->client.addrstr, local->local.addrstr); + verbose("%s: incoming proxy connection: %s -> %s", server->name, + local->client.addrstr, local->local.addrstr); if (list_empty(&server->remotes)) { /* This shouldn't be possible, checked before opening local */ @@ -463,8 +463,7 @@ out: uring_accept(&local->task, &local->client, local_accept); } -bool -local_open(struct server_local *local) +bool local_open(struct server_local *local) { int sfd; int option; @@ -472,14 +471,15 @@ local_open(struct server_local *local) assert_return(local && local->server, false); - sfd = socket(local->local.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0); + sfd = socket(local->local.st.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0); if (sfd < 0) { error("socket: %m"); goto error; } option = true; - if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) < 0) { + if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) < + 0) { error("setsockopt: %m"); goto error; } @@ -487,7 +487,8 @@ local_open(struct server_local *local) /* The MC protocol expects the client to send data first */ if (cfg->socket_defer) { option = true; - if (setsockopt(sfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &option, sizeof(option)) < 0) + if (setsockopt(sfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &option, + sizeof(option)) < 0) error("setsockopt: %m"); } @@ -497,14 +498,16 @@ local_open(struct server_local *local) */ if (cfg->socket_freebind) { option = true; - if (setsockopt(sfd, IPPROTO_IP, IP_FREEBIND, &option, sizeof(option)) < 0) + if (setsockopt(sfd, IPPROTO_IP, IP_FREEBIND, &option, + sizeof(option)) < 0) error("setsockopt: %m"); } - socket_set_low_latency(sfd, cfg->socket_keepalive, - cfg->socket_iptos, cfg->socket_nodelay); + socket_set_low_latency(sfd, cfg->socket_keepalive, cfg->socket_iptos, + cfg->socket_nodelay); - r = bind(sfd, (struct sockaddr *)&local->local.storage, local->local.addrlen); + r = bind(sfd, (struct sockaddr *)&local->local.st, + local->local.addrlen); if (r < 0) { error("bind: %m"); goto error; @@ -526,18 +529,17 @@ error: return false; } -void -local_refdump(struct server_local *local) +void local_refdump(struct server_local *local) { assert_return(local); uring_task_refdump(&local->task); } -static void -local_free(struct uring_task *task) +static void local_free(struct uring_task *task) { - struct server_local *local = container_of(task, struct server_local, task); + struct server_local *local = + container_of(task, struct server_local, task); assert_return(task); @@ -546,16 +548,14 @@ local_free(struct uring_task *task) xfree(local); } -void -local_delete(struct server_local *local) +void local_delete(struct server_local *local) { assert_return(local); uring_task_destroy(&local->task); } -struct server_local * -local_new(struct server *server, struct saddr *saddr) +struct server_local *local_new(struct server *server, struct saddr *saddr) { struct server_local *local; @@ -574,4 +574,3 @@ local_new(struct server *server, struct saddr *saddr) xfree(saddr); return local; } - -- cgit v1.2.3