Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
boxfort
clang-tools
criterion
gdb
jq
libffi
libgit2
Expand Down
8 changes: 2 additions & 6 deletions include/villas/nodes/webrtc/signaling_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class SignalingClient {

Logger logger;

int protocolCallback(struct lws *wsi, enum lws_callback_reasons reason,
void *in, size_t len);

static void connectStatic(struct lws_sorted_usec_list *sul);

int writable();
Expand All @@ -85,9 +82,8 @@ class SignalingClient {
const std::string &peer, Web *w);
~SignalingClient();

static int protocolCallbackStatic(struct lws *wsi,
enum lws_callback_reasons reason,
void *user, void *in, size_t len);
static int protocolCallback(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len);

void connect();
void disconnect();
Expand Down
59 changes: 32 additions & 27 deletions lib/nodes/webrtc/signaling_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,58 +99,63 @@ void SignalingClient::connectStatic(struct lws_sorted_usec_list *sul) {
}
}

int SignalingClient::protocolCallbackStatic(struct lws *wsi,
enum lws_callback_reasons reason,
void *user, void *in, size_t len) {
auto *c = reinterpret_cast<SignalingClient *>(user);

return c->protocolCallback(wsi, reason, in, len);
}

int SignalingClient::protocolCallback(struct lws *wsi,
enum lws_callback_reasons reason,
void *in, size_t len) {
void *user, void *in, size_t len) {
Comment thread
pjungkamp marked this conversation as resolved.
auto *c = reinterpret_cast<SignalingClient *>(user);
Comment thread
pjungkamp marked this conversation as resolved.

int ret;

switch (reason) {
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
cbError(in ? (char *)in : "unknown error");
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: {
assert(c);
c->cbError(in ? (char *)in : "unknown error");
goto do_retry;
}

case LWS_CALLBACK_CLIENT_RECEIVE: {
assert(c);
auto &buffer = c->buffer;

case LWS_CALLBACK_CLIENT_RECEIVE:
if (lws_is_first_fragment(wsi))
buffer.clear();

buffer.append((char *)in, len);

if (lws_is_final_fragment(wsi)) {
logger->trace("Signaling message received: {:.{}}", buffer.data(),
buffer.size());
c->logger->trace("Signaling message received: {:.{}}", buffer.data(),
buffer.size());

auto *json = buffer.decode();
if (json == nullptr) {
logger->error("Failed to decode JSON");
c->logger->error("Failed to decode JSON");
goto do_retry;
}

cbMessage(SignalingMessage::fromJson(json));
c->cbMessage(SignalingMessage::fromJson(json));

json_decref(json);
}

break;
}

case LWS_CALLBACK_CLIENT_ESTABLISHED:
retry_count = 0;
cbConnected();
case LWS_CALLBACK_CLIENT_ESTABLISHED: {
assert(c);
c->retry_count = 0;
c->cbConnected();
break;
}

case LWS_CALLBACK_CLIENT_CLOSED:
cbDisconnected();
case LWS_CALLBACK_CLIENT_CLOSED: {
assert(c);
c->cbDisconnected();
goto do_retry;
}

case LWS_CALLBACK_CLIENT_WRITEABLE: {
ret = writable();
assert(c);
ret = c->writable();
if (ret)
goto do_retry;

Expand All @@ -161,10 +166,10 @@ int SignalingClient::protocolCallback(struct lws *wsi,
break;
}

return lws_callback_http_dummy(wsi, reason, this, in, len);
return lws_callback_http_dummy(wsi, reason, user, in, len);

do_retry:
logger->info("Attempting to reconnect...");
c->logger->info("Attempting to reconnect...");

/* Retry the connection to keep it nailed up
*
Expand All @@ -175,9 +180,9 @@ int SignalingClient::protocolCallback(struct lws *wsi,
* elements in the backoff table, it will never give up and keep
* retrying at the last backoff delay plus the random jitter amount.
*/
if (lws_retry_sul_schedule_retry_wsi(wsi, &sul_helper.sul, connectStatic,
&retry_count))
logger->error("Signaling connection attempts exhausted");
if (lws_retry_sul_schedule_retry_wsi(wsi, &c->sul_helper.sul, connectStatic,
&c->retry_count))
c->logger->error("Signaling connection attempts exhausted");

return -1;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ lws_protocols protocols[] = {
#endif // WITH_NODE_WEBSOCKET
#ifdef WITH_NODE_WEBRTC
{.name = "webrtc-signaling",
.callback = webrtc::SignalingClient::protocolCallbackStatic,
.per_session_data_size = sizeof(webrtc::SignalingClient),
Comment thread
pjungkamp marked this conversation as resolved.
.callback = webrtc::SignalingClient::protocolCallback,
.rx_buffer_size = 0},
#endif
{
Expand Down