diff options
author | Dimitri Staessens <[email protected]> | 2024-02-25 12:00:11 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2024-02-26 09:00:09 +0100 |
commit | bb617311f4fc4ece5bf963d3f445e73e09a9cdaa (patch) | |
tree | 636e524150e4993544c41c5933bd077d19785ac1 /src/lib/cep.c | |
parent | 7c523eb8167116176eb43d2f9380e0179a6275b0 (diff) | |
download | ouroboros-bb617311f4fc4ece5bf963d3f445e73e09a9cdaa.tar.gz ouroboros-bb617311f4fc4ece5bf963d3f445e73e09a9cdaa.zip |
lib: Rename CACEP to CEP and set conngmr timeout0.21.2
The Common Application Connection Establishment Protocol (CACEP) is a
RINA construct associated with the Common Distributed Application
Protocol (CDAP). We dropped CDAP as O7s sees connection establishment
as common to all applications (though it can be a nop). The wiki
already refers to this as (O7s) Connection Establishment Protocol
(CEP).
The connection manager will now timeout waiting for CEP messages to
avoid hanging forever, configurable at build time via
CONNMGR_RCV_TIMEOUT.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib/cep.c')
-rw-r--r-- | src/lib/cep.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/lib/cep.c b/src/lib/cep.c new file mode 100644 index 00000000..ba238023 --- /dev/null +++ b/src/lib/cep.c @@ -0,0 +1,120 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * The Ouroboros Connection Establishment Protocol + * + * Dimitri Staessens <[email protected]> + * Sander Vrijders <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#define _POSIX_C_SOURCE 199309L + +#include <ouroboros/cep.h> +#include <ouroboros/dev.h> +#include <ouroboros/errno.h> + +#include <stdlib.h> +#include <string.h> + +#include "cep.pb-c.h" +typedef CepMsg cep_msg_t; + +#define BUF_SIZE 128 + +static int read_msg(int fd, + struct conn_info * info) +{ + uint8_t buf[BUF_SIZE]; + cep_msg_t * msg; + ssize_t len; + + len = flow_read(fd, buf, BUF_SIZE); + if (len < 0) + return (int) len; + + msg = cep_msg__unpack(NULL, len, buf); + if (msg == NULL) + return -1; + + if (strlen(msg->comp_name) > OCEP_BUF_STRLEN) { + cep_msg__free_unpacked(msg, NULL); + return -1; + } + + strcpy(info->comp_name, msg->comp_name); + strcpy(info->protocol, msg->protocol); + + info->pref_version = msg->pref_version; + info->pref_syntax = msg->pref_syntax; + info->addr = msg->address; + + cep_msg__free_unpacked(msg, NULL); + + return 0; +} + +static int send_msg(int fd, + const struct conn_info * info) +{ + cep_msg_t msg = CEP_MSG__INIT; + uint8_t * data = NULL; + size_t len = 0; + + msg.comp_name = (char *) info->comp_name; + msg.protocol = (char *) info->protocol; + msg.address = info->addr; + msg.pref_version = info->pref_version; + msg.pref_syntax = info->pref_syntax; + if (msg.pref_syntax < 0) + return -1; + + len = cep_msg__get_packed_size(&msg); + if (len == 0) + return -1; + + data = malloc(len); + if (data == NULL) + return -ENOMEM; + + cep_msg__pack(&msg, data); + + if (flow_write(fd, data, len) < 0) { + free(data); + return -1; + } + + free(data); + + return 0; +} + +int cep_snd(int fd, + const struct conn_info * in) +{ + if (in == NULL) + return -EINVAL; + + return send_msg(fd, in); +} + +int cep_rcv(int fd, + struct conn_info * out) +{ + if (out == NULL) + return -EINVAL; + + return read_msg(fd, out); +} |