Error in starting lightway-laser cli
sheharyaar opened this issue · 5 comments
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 :
root@88a0bda6b34a:/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
I tried adding this line in configure_tcp_client
:
state->tcp_socket.type = UV_TCP;
But doing that created different errors.
Could you open a pull request so that I can see and try to build your code please?
Based on the log messages, it sounds like some of the data structures or set up that was copied from the UDP version isn't adapted to the TCP version. For example in the code you provide you have this:
int res = uv_udp_init(state->loop, &state->tcp_socket);
LW_CHECK_WITH_MSG(res == 0, "Unable to initialise TCP socket");
There's also lots of things in there that have names with udp
in them or reference udp
in their log messages. If you're going to try to do a "lift and shift" approach to get tcp
support working, you'd be best off to go through all the files and update / remove anything that is UDP centric. This will make debugging and sanity checking much easier.
Looking forward to seeing your PR!
Thanks for the insight!
Hi, I have created a PR. Kindly look into it.
Thanks :)
I'm going to close this issue for now as the related PR has also been closed. We are still keen to get TCP support in Lightway Laser and will revisit it later this year if no one completes an implementation first. Feel free to open another PR if you've been able to resolve the tun
issue. Once we've got a better test harness that we can share, I'll also open another issue and tag you.
In either case, thanks for the time and effort you've already put in!