aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/core/connection.c')
-rw-r--r--hicn-light/src/hicn/core/connection.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c
index 582e2f56f..fcca364e9 100644
--- a/hicn-light/src/hicn/core/connection.c
+++ b/hicn-light/src/hicn/core/connection.c
@@ -233,7 +233,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
assert(connection);
/* Interface name can be NULL eg always for TCP connnections */
assert(pair);
- assert(address_pair_valid(pair));
+ // assert(address_pair_is_valid(pair)); TODO: local addr in the pair is not initialized for now
*connection = (connection_t) {
.id = connection_id,
@@ -259,13 +259,13 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
.wldr_autostart = true,
};
- connection->data = malloc(connection_vft[connection->type]->data_size);
+ connection->data = malloc(connection_vft[get_protocol(connection->type)]->data_size);
if (!connection->data)
goto ERR_DATA;
- assert(connection_has_valid_type(connection));
+ assert(connection_has_valid_id(connection));
- rc = connection_vft[connection->type]->initialize(connection);
+ rc = connection_vft[get_protocol(connection->type)]->initialize(connection);
if (rc < 0) {
goto ERR_VFT;
}
@@ -273,7 +273,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
// XXX uncertain as fd is created by the listener !!
// XXX check whether it is registered !
#if 0
- connection->fd = connection_vft[connection->type]->get_socket(connection, address, NULL, interface_name);
+ connection->fd = connection_vft[get_protocol(connection->type)]->get_socket(connection, address, NULL, interface_name);
if (connection->fd < 0) {
ERROR("Error creating connection fd: (%d) %s", errno, strerror(errno));
goto ERR_FD;
@@ -282,17 +282,19 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
// XXX data should be pre-allocated here
if (loop_register_fd(MAIN_LOOP, connection->fd, connection,
- connection_vft[connection->type]->read_callback, NULL) < 0)
+ connection_vft[get_protocol(connection->type)]->read_callback, NULL) < 0)
goto ERR_REGISTER_FD;
#endif
- // XXX TODO
- //char *str = pair_ToString(udp->pair);
+ char addr_str[INET6_ADDRSTRLEN];
+ if (local)
+ address_to_string(&(pair->local), addr_str);
+ else
+ address_to_string(&(pair->remote), addr_str);
DEBUG("%s connection %p created for address %s (local=%s)",
- face_type_str(connection->type), connection, "N/A",
+ face_type_str(connection->type), connection, addr_str,
connection_is_local(connection) ? "true" : "false");
- //free(str);
- //
+
return 0;
#if 0
@@ -320,7 +322,7 @@ connection_finalize(connection_t * connection)
if (connection->wldr)
wldr_free(connection->wldr);
- connection_vft[connection->type]->finalize(connection);
+ connection_vft[get_protocol(connection->type)]->finalize(connection);
free(connection->interface_name);
free(connection);
@@ -338,7 +340,7 @@ command_type_t
_isACommand(PARCEventBuffer *input)
{
size_t bytesAvailable = parcEventBuffer_GetLength(input);
- parcAssertTrue(bytesAvailable >= sizeof(header_control_message),
+ parcAssertTrue(bytesAvailable >= sizeof(cmd_header_t),
"Called with too short an input: %zu", bytesAvailable);
uint8_t *msg = parcEventBuffer_Pullup(input, bytesAvailable);
@@ -367,7 +369,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz
/* Too small a packet is not useful to decide between a control message and
* an hICN packet, the size of a control message is enough to test for both
* pakcet types */
- if (size < sizeof(header_control_message))
+ if (size < sizeof(cmd_header_t))
return 0;
/* We expect complete packets most of the time, so don't bother with state */
@@ -376,7 +378,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz
command_type_t command_type = command_type_from_uchar(msg[1]);
if (!command_type_is_valid(command_type))
break;
- expected = sizeof(header_control_message) +
+ expected = sizeof(cmd_header_t) +
command_get_payload_len(command_type);
if (size < expected)
return 0;
@@ -399,9 +401,9 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz
msgbuf_t msgbuf;
MessagePacketType packet_type;
if (messageHandler_IsInterest(message->messageHead)) {
- packet_type = MESSAGE_TYPE_INTEREST;
+ packet_type = MSGBUF_TYPE_INTEREST;
} else if (messageHandler_IsData(message->messageHead)) {
- packet_type = MESSAGE_TYPE_DATA;
+ packet_type = MSGBUF_TYPE_DATA;
} else {
ERROR("Dropped packet that is not interest nor data");
return -1;
@@ -423,7 +425,7 @@ connection_read_message(connection_t * connection, msgbuf_t * msgbuf)
assert(face_type_is_valid(connection->type));
assert(msgbuf);
- return connection_vft[connection->type]->read_message(connection, msgbuf);
+ return connection_vft[get_protocol(connection->type)]->read_message(connection, msgbuf);
}
uint8_t *
@@ -432,7 +434,7 @@ connection_read_packet(connection_t * connection)
assert(connection);
assert(face_type_is_valid(connection->type));
- return connection_vft[connection->type]->read_packet(connection);
+ return connection_vft[get_protocol(connection->type)]->read_packet(connection);
}
#endif
@@ -444,7 +446,7 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet,
assert(face_type_is_valid(connection->type));
assert(packet);
- return connection_vft[connection->type]->send_packet(connection, packet, size);
+ return connection_vft[get_protocol(connection->type)]->send_packet(connection, packet, size);
}
// ALL DEPRECATED CODE HERE TO BE UPDATED
@@ -453,22 +455,31 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet,
bool
_connection_send(const connection_t * connection, msgbuf_t * msgbuf, bool queue)
{
- return connection_vft[connection->type]->send(connection, msgbuf, queue);
+ return connection_vft[get_protocol(connection->type)]->send(connection, msgbuf, queue);
}
bool
-connection_send(const connection_t * connection, msgbuf_t * msgbuf, bool queue)
+connection_flush(const connection_t * connection)
{
- assert(connection);
+ // XXX Replace this with a proper flush function to avoid implementing the
+ // same thing everywhere
+ return _connection_send(connection, NULL, false);
+}
- /* NULL message means flush */
- if (!msgbuf)
- return _connection_send(connection, NULL, false);
+bool
+connection_send(const connection_t * connection, off_t msgbuf_id, bool queue)
+{
+ assert(connection);
+ assert(msgbuf_id_is_valid(msgbuf_id)); // XXX we now have a flush() function
if (!connection_is_up(connection))
return false;
- if (msgbuf_get_type(msgbuf) == MESSAGE_TYPE_DATA) {
+ const forwarder_t * forwarder = connection_get_forwarder(connection);
+ const msgbuf_pool_t * msgbuf_pool = forwarder_get_msgbuf_pool(forwarder);
+ msgbuf_t * msgbuf = msgbuf_pool_at(msgbuf_pool, msgbuf_id);
+
+ if (msgbuf_get_type(msgbuf) == MSGBUF_TYPE_DATA) {
uint8_t conn_id = (uint8_t)connection_get_id(connection);
msgbuf_update_pathlabel(msgbuf, conn_id);
}
@@ -504,7 +515,7 @@ connection_resend(const connection_t * connection, msgbuf_t * msgbuf, bool
if (!connection_is_up(connection))
return ret;
- if (msgbuf_get_type(msgbuf) == MESSAGE_TYPE_DATA) {
+ if (msgbuf_get_type(msgbuf) == MSGBUF_TYPE_DATA) {
uint8_t conn_id = (uint8_t)connection_get_id(connection);
uint32_t old_path_label = msgbuf_get_pathlabel(msgbuf);
msgbuf_update_pathlabel(msgbuf, conn_id);
@@ -551,7 +562,7 @@ connection_wldr_allow_autostart(connection_t * connection, bool value)
}
bool
-connection_wldr_autostart_is_allowed(connection_t * connection)
+connection_wldr_autostart_is_allowed(const connection_t * connection)
{
return connection->wldr_autostart;
}
@@ -579,7 +590,7 @@ connection_has_wldr(const connection_t * connection)
}
void
-connection_wldr_detect_losses(const connection_t * connection, msgbuf_t * msgbuf)
+connection_wldr_detect_losses(const connection_t * connection, const msgbuf_t * msgbuf)
{
if (!connection->wldr)
return;
@@ -587,7 +598,7 @@ connection_wldr_detect_losses(const connection_t * connection, msgbuf_t * msgbuf
}
void
-connection_wldr_handle_notification(const connection_t * connection, msgbuf_t * msgbuf)
+connection_wldr_handle_notification(const connection_t * connection, const msgbuf_t * msgbuf)
{
if (!connection->wldr)
return;