From 823190475b3850864214f2e2cc9ef84ed299ba51 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sun, 12 Jan 2014 18:23:29 +0100 Subject: [PATCH] print textual name of messages exchanged. --- src/common.c | 36 ++++++++++++++++++++++++++++++++++++ src/common.h | 2 ++ src/main-misc.c | 3 ++- src/main.h | 2 +- src/worker-auth.c | 2 -- src/worker-resume.c | 4 ---- src/worker.h | 2 +- 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/common.c b/src/common.c index 596797a1..4364b6a9 100644 --- a/src/common.c +++ b/src/common.c @@ -24,6 +24,42 @@ #include #include "common.h" +const char* cmd_request_to_str(unsigned _cmd) +{ +cmd_request_t cmd = _cmd; + + switch(cmd) { + case AUTH_INIT: + return "auth init"; + case AUTH_REP: + return "auth reply"; + case AUTH_REQ: + return "auth request"; + case AUTH_COOKIE_REQ: + return "auth cookie request"; + case AUTH_MSG: + return "auth msg"; + case RESUME_STORE_REQ: + return "resume data store request"; + case RESUME_DELETE_REQ: + return "resume data delete request"; + case RESUME_FETCH_REQ: + return "resume data fetch request"; + case RESUME_FETCH_REP: + return "resume data fetch reply"; + case CMD_UDP_FD: + return "udp fd"; + case CMD_TUN_MTU: + return "tun mtu change"; + case CMD_TERMINATE: + return "terminate"; + case CMD_SESSION_INFO: + return "session info"; + default: + return "unknown"; + } +} + ssize_t force_write(int sockfd, const void *buf, size_t len) { int left = len; diff --git a/src/common.h b/src/common.h index 0d2df13a..a810cb98 100644 --- a/src/common.h +++ b/src/common.h @@ -50,5 +50,7 @@ int recv_msg(int fd, uint8_t cmd, int recv_socket_msg(int fd, uint8_t cmd, int *socketfd, void** msg, unpack_func); +const char* cmd_request_to_str(unsigned cmd); + #endif diff --git a/src/main-misc.c b/src/main-misc.c index 0173c56a..f01bac64 100644 --- a/src/main-misc.c +++ b/src/main-misc.c @@ -384,7 +384,8 @@ int handle_commands(main_server_st *s, struct proc_st* proc) return ERR_BAD_COMMAND; } - mslog(s, proc, LOG_DEBUG, "main received message %u of %u bytes\n", (unsigned)cmd, (unsigned)length); + mslog(s, proc, LOG_DEBUG, "main received message '%s' of %u bytes\n", + cmd_request_to_str(cmd), (unsigned)length); raw = malloc(length); if (raw == NULL) { diff --git a/src/main.h b/src/main.h index 28658497..49357748 100644 --- a/src/main.h +++ b/src/main.h @@ -259,7 +259,7 @@ inline static int send_msg_to_worker(main_server_st* s, struct proc_st* proc, uint8_t cmd, const void* msg, pack_size_func get_size, pack_func pack) { - mslog(s, proc, LOG_DEBUG, "sending message %u to worker", (unsigned)cmd); + mslog(s, proc, LOG_DEBUG, "sending message '%s' to worker", cmd_request_to_str(cmd)); return send_msg(proc->fd, cmd, msg, get_size, pack); } diff --git a/src/worker-auth.c b/src/worker-auth.c index 6f9acb76..674b3425 100644 --- a/src/worker-auth.c +++ b/src/worker-auth.c @@ -405,8 +405,6 @@ int auth_cookie(worker_st * ws, void *cookie, size_t cookie_size) msg.cookie.data = cookie; msg.cookie.len = cookie_size; - oclog(ws, LOG_DEBUG, "sending cookie authentication request"); - ret = send_msg_to_main(ws, AUTH_COOKIE_REQ, &msg, (pack_size_func) auth_cookie_request_msg__get_packed_size, diff --git a/src/worker-resume.c b/src/worker-resume.c index a6854536..963e8cf9 100644 --- a/src/worker-resume.c +++ b/src/worker-resume.c @@ -93,8 +93,6 @@ SessionResumeFetchMsg msg = SESSION_RESUME_FETCH_MSG__INIT; msg.session_id.len = key.size; msg.session_id.data = key.data; - oclog(ws, LOG_DEBUG, "sending resumption request (fetch)"); - ret = send_msg_to_main(ws, RESUME_FETCH_REQ, &msg, (pack_size_func)session_resume_fetch_msg__get_packed_size, (pack_func)session_resume_fetch_msg__pack); @@ -158,8 +156,6 @@ SessionResumeFetchMsg msg = SESSION_RESUME_FETCH_MSG__INIT; msg.session_id.len = key.size; msg.session_id.data = key.data; - oclog(ws, LOG_DEBUG, "sending resumption request (delete)"); - ret = send_msg_to_main(ws, RESUME_DELETE_REQ, &msg, (pack_size_func)session_resume_fetch_msg__get_packed_size, (pack_func)session_resume_fetch_msg__pack); diff --git a/src/worker.h b/src/worker.h index b1d6654f..16edc61f 100644 --- a/src/worker.h +++ b/src/worker.h @@ -194,7 +194,7 @@ inline static int send_msg_to_main(worker_st *ws, uint8_t cmd, const void* msg, pack_size_func get_size, pack_func pack) { - oclog(ws, LOG_DEBUG, "sending message %u to main", (unsigned)cmd); + oclog(ws, LOG_DEBUG, "sending message '%s' to main", cmd_request_to_str(cmd)); return send_msg(ws->cmd_fd, cmd, msg, get_size, pack); }