I was trying to implement TCP connection and streaming for lightway-laser. I am having the following issue :
lw.out: src/unix/stream.c:1405: uv_write2: Assertion `(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE || stream->type == UV_TTY) && "uv_write (unix) does not yet support other types of streams"' failed.
Current Behavior
Log :
[email protected]:/lw_reference# scripts/run_iperf_client.sh
Resolved to target 172.18.0.3 server 172.18.0.2
Check that we have connectivity to the lightway server
PING 172.18.0.2 (172.18.0.2) 56(84) bytes of data.
64 bytes from 172.18.0.2: icmp_seq=1 ttl=64 time=0.094 ms
--- 172.18.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.094/0.094/0.094/0.000 ms
[11:54:16.833530s] Starting client...
[11:54:16.833599s] Connecting to: 172.18.0.2:19655
[11:54:16.833604s] Username: test
[11:54:16.833608s] Client cert: certs/shared.crt
[11:54:16.833610s] Streaming Mode: true
[11:54:16.833613s] Tun device: helium-test
lw.out: src/unix/stream.c:1405: uv_write2: Assertion `(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE || stream->type == UV_TTY) && "uv_write (unix) does not yet support other types of streams"' failed.
scripts/run_iperf_client.sh: line 15: 37 Aborted (core dumped) build/release/lw.out --client --protocol tcp --username test --password test --server_ip ${SERVER} --server_port 19655 --cert certs/shared.crt --tun helium-test
Setting route to 172.18.0.3 via 10.125.0.2
Error: Nexthop has invalid gateway.
Warnings on compilation :
Release build 'lw.out'
----------------------
Compiling flow.c...
cc1: warning: third_party/zlog/tidy/zlog.c: not a directory
cc1: warning: third_party/argparse/tidy/argparse.c: not a directory
src/udp/flow.c: In function ‘tcp_write_cb’:
src/udp/flow.c:282:41: warning: passing argument 2 of ‘uv_write’ from incompatible pointer type [-Wincompatible-pointer-types]
int res = uv_write((uv_write_t *)req, &state->tcp_socket, &req->buf, 1, on_send);
^~~~~~~~~~~~~~~~~~
In file included from include/lw.h:24,
from src/udp/flow.h:23,
from src/udp/flow.c:20:
third_party/builds/libuv/include/uv.h:510:37: note: expected ‘uv_stream_t *’ {aka ‘struct uv_stream_s *’} but argument is of type ‘uv_tcp_t *’ {aka ‘struct uv_tcp_s *’}
uv_stream_t* handle,
~~~~~~~~~~~~~^~~~~~
src/udp/flow.c:282:75: warning: passing argument 5 of ‘uv_write’ from incompatible pointer type [-Wincompatible-pointer-types]
int res = uv_write((uv_write_t *)req, &state->tcp_socket, &req->buf, 1, on_send);
^~~~~~~
In file included from include/lw.h:24,
from src/udp/flow.h:23,
from src/udp/flow.c:20:
third_party/builds/libuv/include/uv.h:513:36: note: expected ‘uv_write_cb’ {aka ‘void (*)(struct uv_write_s *, int)’} but argument is of type ‘void (*)(uv_udp_send_t *, int)’ {aka ‘void (*)(struct uv_udp_send_s *, int)’}
uv_write_cb cb);
~~~~~~~~~~~~^~
src/udp/flow.c: In function ‘he_session_reject_tcp’:
src/udp/flow.c:359:41: warning: passing argument 2 of ‘uv_write’ from incompatible pointer type [-Wincompatible-pointer-types]
int err = uv_write((uv_write_t *)req, &state->tcp_socket, &req->buf, 1, on_send);
^~~~~~~~~~~~~~~~~~
In file included from include/lw.h:24,
from src/udp/flow.h:23,
from src/udp/flow.c:20:
third_party/builds/libuv/include/uv.h:510:37: note: expected ‘uv_stream_t *’ {aka ‘struct uv_stream_s *’} but argument is of type ‘uv_tcp_t *’ {aka ‘struct uv_tcp_s *’}
uv_stream_t* handle,
~~~~~~~~~~~~~^~~~~~
src/udp/flow.c:359:75: warning: passing argument 5 of ‘uv_write’ from incompatible pointer type [-Wincompatible-pointer-types]
int err = uv_write((uv_write_t *)req, &state->tcp_socket, &req->buf, 1, on_send);
^~~~~~~
In file included from include/lw.h:24,
from src/udp/flow.h:23,
from src/udp/flow.c:20:
third_party/builds/libuv/include/uv.h:513:36: note: expected ‘uv_write_cb’ {aka ‘void (*)(struct uv_write_s *, int)’} but argument is of type ‘void (*)(uv_udp_send_t *, int)’ {aka ‘void (*)(struct uv_udp_send_s *, int)’}
uv_write_cb cb);
~~~~~~~~~~~~^~
Linking lw.out...
I am attaching the parts I added in files I felt revelant to this issue :
udp/client.c :
void configure_tcp_client(lw_config_t *config, lw_state_t *state) {
zlogf_time(ZLOG_INFO_LOG_MSG, "Configuring TCP Client...\n");
int res = uv_udp_init(state->loop, &state->tcp_socket);
LW_CHECK_WITH_MSG(res == 0, "Unable to initialise TCP socket");
res = uv_ip4_addr(config->server_ip, config->server_port, &state->send_addr);
LW_CHECK_WITH_MSG(res == 0, "Invalid IP address or port");
int udp_buffer_size = 15 * MEGABYTE;
uv_send_buffer_size((uv_handle_t *)&state->tcp_socket, &udp_buffer_size);
uv_recv_buffer_size((uv_handle_t *)&state->tcp_socket, &udp_buffer_size);
state->tcp_socket.data = state;
he_ssl_ctx_set_outside_write_cb(state->he_ctx, tcp_write_cb);
return;
}
void start_tcp_client(lw_state_t *state) {
int res = uv_listen(&state->tcp_socket, DEFAULT_BACKLOG, on_new_connection);
LW_CHECK_WITH_MSG(res == 0, "Unable to start recv on udp socket");
return;
}
/udp/flow.c :
/* Callback if a new connection arrives */
void on_new_connection(uv_stream_t *server, int status) {
if(status < 0){
zlogf_time(ZLOG_INFO_LOG_MSG, "New connection error %s\n", uv_strerror(status));
return ;
}
/* Create a new client socket */
uv_tcp_t *client = calloc(1,sizeof(uv_tcp_t));
int res = uv_tcp_init(server->loop,client);
LW_CHECK_WITH_MSG(res == 0, "Unable to initialise Client Socket");
/* Accept the client */
res = uv_accept(server, (uv_stream_t *) client);
LW_CHECK_WITH_MSG(res == 0, "Unable to accept the client");
/* Read from the client socket */
res = uv_read_start((uv_stream_t *) client,alloc_buffer,on_read_stream);
LW_CHECK_WITH_MSG(res == 0, "Unable to read from client socket");
}
he_return_code_t tcp_write_cb(he_conn_t *he_conn, uint8_t *packet, size_t length, void *context) {
// Get our context back
lw_state_t *state = (lw_state_t *)context;
write_req_t *req = (write_req_t *)calloc(1, sizeof(write_req_t));
LW_CHECK_WITH_MSG(req, "Unable to allocate write request!");
uint8_t *output_buffer = calloc(1, LW_MAX_WIRE_MTU);
LW_CHECK_WITH_MSG(output_buffer, "Unable to allocate write buffer");
memcpy(output_buffer, packet, length);
req->buf = uv_buf_init((char *)output_buffer, (unsigned int)length);
int res = uv_write((uv_write_t *)req, &state->tcp_socket, &req->buf, 1, on_send);
if(res) {
zlogf_time(ZLOG_INFO_LOG_MSG, "Error occurred during uv_write: %s (%d)\n", uv_strerror(res),
res);
return HE_ERR_CALLBACK_FAILED;
}
return HE_SUCCESS;
}
Context
I am unable to set up Helium connection when running run_iperf_client.sh
Your Environment
- Version used: lightway-laser latest version
- Operating System and version: Endeavour Os 1.4 - Arch Rolling