diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-08-05 09:15:17 -0600 |
---|---|---|
committer | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-08-05 09:15:17 -0600 |
commit | ffd8de94c9b3829116f6604dfae8aa9a24ef2ef3 (patch) | |
tree | c610c50a35925d2456382610fbba875c2e6ae1ea | |
parent | 6464bb4b9759b10aa144af2edf98a898a60256c7 (diff) | |
download | ouroboros-ffd8de94c9b3829116f6604dfae8aa9a24ef2ef3.tar.gz ouroboros-ffd8de94c9b3829116f6604dfae8aa9a24ef2ef3.zip |
irmd: Specify timeout per command
The commands towards the IPCPs have different time requirements, but
the irmd had only a single timeout value to wait for a response. This
commit allows setting different timeouts for the IRMd based on the
command, configurable globally.
-rw-r--r-- | include/ouroboros/config.h.in | 7 | ||||
-rw-r--r-- | src/irmd/ipcp.c | 66 |
2 files changed, 49 insertions, 24 deletions
diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in index 4c255da5..0957ee4d 100644 --- a/include/ouroboros/config.h.in +++ b/include/ouroboros/config.h.in @@ -66,8 +66,11 @@ #define IRMD_REQ_ARR_TIMEOUT 500 #define IRMD_FLOW_TIMEOUT 5000 #define IPCP_ACCEPT_TIMEOUT 100 -#define SOCKET_TIMEOUT 10000 +#define SOCKET_TIMEOUT 1000 +#define BOOTSTRAP_TIMEOUT 5000 +#define ENROLL_TIMEOUT 60000 +#define REG_TIMEOUT 10000 +#define QUERY_TIMEOUT 3000 #define CDAP_REPLY_TIMEOUT 1000 -#define ENROLL_TIMEOUT 2000 #endif /* OUROBOROS_CONFIG */ diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index 28e91b18..bf71bc3d 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -48,13 +48,12 @@ static void close_ptr(void * o) ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) { - int sockfd = 0; - buffer_t buf; - char * sock_path = NULL; - ssize_t count = 0; - ipcp_msg_t * recv_msg = NULL; - struct timeval tv = {(SOCKET_TIMEOUT / 1000), - (SOCKET_TIMEOUT % 1000) * 1000}; + int sockfd = 0; + buffer_t buf; + char * sock_path = NULL; + ssize_t count = 0; + ipcp_msg_t * recv_msg = NULL; + struct timeval tv; if (kill(api, 0) < 0) return NULL; @@ -83,6 +82,29 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, return NULL; } + switch (msg->code) { + case IPCP_MSG_CODE__IPCP_BOOTSTRAP: + tv.tv_sec = BOOTSTRAP_TIMEOUT / 1000; + tv.tv_usec = (BOOTSTRAP_TIMEOUT % 1000) * 1000; + break; + case IPCP_MSG_CODE__IPCP_ENROLL: + tv.tv_sec = ENROLL_TIMEOUT / 1000; + tv.tv_usec = (ENROLL_TIMEOUT % 1000) * 1000; + break; + case IPCP_MSG_CODE__IPCP_REG: + tv.tv_sec = REG_TIMEOUT / 1000; + tv.tv_usec = (REG_TIMEOUT % 1000) * 1000; + break; + case IPCP_MSG_CODE__IPCP_QUERY: + tv.tv_sec = QUERY_TIMEOUT / 1000; + tv.tv_usec = (QUERY_TIMEOUT % 1000) * 1000; + break; + default: + tv.tv_sec = SOCKET_TIMEOUT / 1000; + tv.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; + break; + } + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, sizeof(tv))) log_warn("Failed to set timeout on socket."); @@ -187,9 +209,9 @@ int ipcp_destroy(pid_t api) int ipcp_bootstrap(pid_t api, ipcp_config_msg_t * conf) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; if (conf == NULL) return -EINVAL; @@ -223,7 +245,7 @@ int ipcp_enroll(pid_t api, if (dst == NULL) return -EINVAL; - msg.code = IPCP_MSG_CODE__IPCP_ENROLL; + msg.code = IPCP_MSG_CODE__IPCP_ENROLL; msg.dst_name = (char *) dst; recv_msg = send_recv_ipcp_msg(api, &msg); @@ -259,9 +281,9 @@ int ipcp_reg(pid_t api, const uint8_t * hash, size_t len) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; assert(hash); @@ -289,9 +311,9 @@ int ipcp_unreg(pid_t api, const uint8_t * hash, size_t len) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; msg.code = IPCP_MSG_CODE__IPCP_UNREG; msg.has_hash = true; @@ -317,9 +339,9 @@ int ipcp_query(pid_t api, const uint8_t * hash, size_t len) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; msg.code = IPCP_MSG_CODE__IPCP_QUERY; msg.has_hash = true; @@ -348,9 +370,9 @@ int ipcp_flow_alloc(pid_t api, size_t len, qoscube_t cube) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; assert(dst); @@ -385,9 +407,9 @@ int ipcp_flow_alloc_resp(pid_t api, pid_t n_api, int response) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP; msg.has_port_id = true; @@ -415,9 +437,9 @@ int ipcp_flow_alloc_resp(pid_t api, int ipcp_flow_dealloc(pid_t api, int port_id) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; msg.code = IPCP_MSG_CODE__IPCP_FLOW_DEALLOC; msg.has_port_id = true; |