Skip to content

Commit

Permalink
moving into platform folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Feb 14, 2025
1 parent 8c31f12 commit 33179d8
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/posix/federated/receiver.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/platform/posix/tcp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"

#include <pthread.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/posix/federated/sender.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/platform/posix/tcp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"

#include <errno.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/riot/coap_federated/receiver/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"

#define REMOTE_PROTOCOL_FAMILY AF_INET6
Expand Down
2 changes: 1 addition & 1 deletion examples/riot/coap_federated/sender/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"

#define REMOTE_PROTOCOL_FAMILY AF_INET6

Expand Down
2 changes: 1 addition & 1 deletion examples/zephyr/basic_federated/common/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "reactor-uc/logging.h"
#include "reactor-uc/platform/posix/tcp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/serialization.h"
#include <zephyr/net/net_ip.h>
Expand Down
4 changes: 2 additions & 2 deletions examples/zephyr/basic_federated/federated_sender/src/sender.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/platform/posix/tcp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/serialization.h"
#include <zephyr/net/net_ip.h>
Expand Down Expand Up @@ -169,4 +169,4 @@ int main() {
setup_led();
action_ptr = &main_reactor.sender->act;
lf_start();
}
}
3 changes: 1 addition & 2 deletions src/encryption_layer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "reactor-uc/encryption_layer.h"

#include "./encryption_layers/no_encryption/no_encryption.c"
#include "./platform/posix//no_encryption.c"
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//
// Created by tanneberger on 2/5/25.
//

#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/logging.h"
#include "reactor-uc/serialization.h"

Expand Down Expand Up @@ -65,4 +61,4 @@ void NoEncryptionLayer_ctor(NoEncryptionLayer *self, NetworkChannel *network_cha
self->super.send_message = NoEncryptionLayer_send_message;
self->super.register_receive_callback = NoEncryptionLayer_register_callback;
network_channel->register_receive_callback(network_channel, &self->super, _NoEncryptionLayer_receive_callback);
}
}
14 changes: 6 additions & 8 deletions src/platform/posix/tcp_ip_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) {
}

// bind the socket to that address
int ret = bind(self->fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
const int ret = bind(self->fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (ret < 0) {
TCP_IP_CHANNEL_ERR("Could not bind to %s:%d errno=%d", self->host, self->port, errno);
throw("Bind failed");
Expand All @@ -164,15 +164,14 @@ static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) {
static lf_ret_t _TcpIpChannel_try_connect_server(NetworkChannel *untyped_self) {
TcpIpChannel *self = (TcpIpChannel *)untyped_self;

int new_socket;
struct sockaddr_in address;
socklen_t addrlen = sizeof(address);

new_socket = accept(self->fd, (struct sockaddr *)&address, &addrlen);
int new_socket = accept(self->fd, (struct sockaddr *)&address, &addrlen);
if (new_socket >= 0) {
self->client = new_socket;
FD_SET(new_socket, &self->set);
TCP_IP_CHANNEL_INFO("Connceted to client with address %s", inet_ntoa(address.sin_addr));
TCP_IP_CHANNEL_INFO("Connected to client with address %s", inet_ntoa(address.sin_addr));
_TcpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTED);
return LF_OK;
} else {
Expand All @@ -185,7 +184,6 @@ static lf_ret_t _TcpIpChannel_try_connect_server(NetworkChannel *untyped_self) {
} else {
TCP_IP_CHANNEL_ERR("Accept failed. errno=%d", errno);
throw("Accept failed");
return LF_ERR;
}
}
}
Expand Down Expand Up @@ -228,8 +226,6 @@ static lf_ret_t _TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) {
TCP_IP_CHANNEL_ERR("try_connect_client called in invalid state %d", _TcpIpChannel_get_state(self));
return LF_ERR;
}

return LF_ERR; // Should never reach here
}

static lf_ret_t TcpIpChannel_open_connection(NetworkChannel *untyped_self) {
Expand Down Expand Up @@ -275,7 +271,7 @@ static lf_ret_t TcpIpChannel_send_blocking(NetworkChannel *untyped_self, const c
switch (errno) {
case ETIMEDOUT:
case ENOTCONN:
ssize_t bytes_written_err = write(self->send_failed_event_fds[1], "X", 1);
const ssize_t bytes_written_err = write(self->send_failed_event_fds[1], "X", 1);
if (bytes_written_err == -1) {
TCP_IP_CHANNEL_ERR("Failed informing worker thread, that send_blocking failed, errno=%d", errno);
}
Expand Down Expand Up @@ -326,6 +322,7 @@ static lf_ret_t _TcpIpChannel_receive(NetworkChannel *untyped_self) {
case EAGAIN:
/* The socket has no new data to receive */
return LF_EMPTY;
default:;
}
}

Expand Down Expand Up @@ -355,6 +352,7 @@ static lf_ret_t _TcpIpChannel_receive(NetworkChannel *untyped_self) {
case EAGAIN:
/* The socket has no new data to receive */
return LF_EMPTY;
default:;
}
} else if (bytes_read == 0) {
// This means the connection was closed.
Expand Down
4 changes: 2 additions & 2 deletions src/platform/riot/coap_udp_ip_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static NetworkChannelState _CoapUdpIpChannel_get_state(CoapUdpIpChannel *self) {
static CoapUdpIpChannel *_CoapUdpIpChannel_get_coap_channel_by_remote(const sock_udp_ep_t *remote) {
CoapUdpIpChannel *channel;
for (size_t i = 0; i < _lf_environment->net_bundles_size; i++) {
if (_lf_environment->net_bundles[i]->net_channel->type == NETWORK_CHANNEL_TYPE_COAP_UDP_IP) {
channel = (CoapUdpIpChannel *)_lf_environment->net_bundles[i]->net_channel;
if (_lf_environment->net_bundles[i]->encryption_layer->network_channel->type == NETWORK_CHANNEL_TYPE_COAP_UDP_IP) {
channel = (CoapUdpIpChannel *)_lf_environment->net_bundles[i]->encryption_layer->network_channel;

if (sock_udp_ep_equal(&channel->remote, remote)) {
return channel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"

#define REMOTE_PROTOCOL_FAMILY AF_INET6
Expand Down Expand Up @@ -62,6 +63,7 @@ LF_DEFINE_FEDERATED_INPUT_CONNECTION_CTOR(Receiver, in, lf_msg_t, 5, MSEC(100),
typedef struct {
FederatedConnectionBundle super;
CoapUdpIpChannel channel;
NoEncryptionLayer encryption_layer;
LF_FEDERATED_INPUT_CONNECTION_INSTANCE(Receiver, in);
LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(1, 0)
} LF_FEDERATED_CONNECTION_BUNDLE_TYPE(Receiver, Sender);
Expand Down
2 changes: 2 additions & 0 deletions test/platform/riot/coap_channel_federated_test/sender/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
#include "reactor-uc/platform/posix/no_encryption.h"

#define REMOTE_PROTOCOL_FAMILY AF_INET6

Expand Down Expand Up @@ -62,6 +63,7 @@ LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_CTOR(Sender, out, lf_msg_t)
typedef struct {
FederatedConnectionBundle super;
CoapUdpIpChannel channel;
NoEncryptionLayer encryption_layer;
LF_FEDERATED_OUTPUT_CONNECTION_INSTANCE(Sender, out);
LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(0, 1);
} LF_FEDERATED_CONNECTION_BUNDLE_TYPE(Sender, Receiver);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tcp_channel_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reactor-uc/platform/posix/tcp_ip_channel.h"
#include "reactor-uc/encryption_layers/no_encryption/no_encryption.h"
#include "reactor-uc/platform/posix/no_encryption.h"
#include "reactor-uc/reactor-uc.h"
#include "unity.h"
#include "test_util.h"
Expand Down

0 comments on commit 33179d8

Please sign in to comment.