[Libwebsockets] lwsws

Andy Green andy at warmcat.com
Fri Nov 30 11:59:14 CET 2018

On 30/11/2018 18:31, Vitaly Shevtsov wrote:
> Good day! I use vanila lwsws and try to implement simple plugin. In 
> plugin I use lws_client_connect_via_info to connect to another 
> WS-server. On the server side I see my connection but I can't see 
> LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?
> Forgot to mention: If I use this plugin standalone, client connection 
> works as expected.
> Thanks!
> On November 29, 2018 10:22:47 PM GMT+08:00, Vitaly Shevtsov 
> <shev.vt1984 at gmail.com 
> <https://e.mail.ru/compose/?mailto=mailto%3ashev.vt1984@gmail.com>> wrote:
>  >Good day! I use vanila lwsws and try to implement simple plugin. In
>  >plugin
>  >I use lws_client_connect_via_info to connect to another WS-server. On
>  >the
>  >server side I see my connection but I can't see
>  >LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?
> You need "enable-client-ssl": "1" on the config for the vhost you 
> created the client on, if the destination is wss.
> You also need to list your protocol under "ws-protocols" for the vhost conf.
> Notice the client connect info struct allows you to bind the new 
> connection to a specific local protocol name.
> https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n108-114
> But nost of all you need to enable logging with eg, -d1039 and confirm 
> your plugin loaded and the protocol is there.  And look at the logging 
> to see what it says about the client connect.
> If you want to follow up please use the mailing list.
> -Andy
>  >Thanks!
> Thanks for your reply. Unfortunately this didn't help, all you wrote 
> have been done before and works well when there is no client connection 
> inside the plugin.

Yeah... well... "why doesn't this work" with no logs or reproducer is a 
bit of an optimistic question, isn't it.

> I found the way to reproduce this issue - I attached modified 
> protocol_dumb_increment.c to show what I mean. Thanks!

That just crashes as it is... it's missing this:

@@ -56,10 +88,14 @@ callback_dumb_increment(struct lws *wsi, enum 
lws_callback_reasons reason,
                         sizeof(struct vhd__dumb_increment));
                 if (!vhd)
                         return -1;
+               vhd->context = lws_get_context(wsi);
                 if ((opt = lws_pvo_search(
                                 (const struct 
lws_protocol_vhost_options *)in,
                         vhd->options = (unsigned int *)opt->value;

Trying it like this he seems happy

$ libwebsockets-test-server -s -d1031
[2018/11/30 18:53:36:0006] NOTICE: libwebsockets test server - license 
[2018/11/30 18:53:36:0006] NOTICE: (C) Copyright 2010-2018 Andy Green 
<andy at warmcat.com>
Using resource path "/usr/local/share/libwebsockets-test-server"
[2018/11/30 18:53:37:0057] NOTICE: Creating Vhost 'default' port 7681, 5 
protocols, IPv6 off
[2018/11/30 18:53:37:0058] NOTICE:  SSL ciphers: 
[2018/11/30 18:53:37:0058] NOTICE:  Using SSL mode
[2018/11/30 18:53:37:0062] NOTICE:  SSL ECDH curve 'prime256v1'
[2018/11/30 18:53:37:0105] NOTICE: lws_tls_client_create_vhost_context: 
doing cert filepath 
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert 
[2018/11/30 18:53:37:0106] NOTICE: lws_tls_client_create_vhost_context: 
doing private key filepath
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert private key 
[2018/11/30 18:53:37:0106] NOTICE: created client ssl context for default
[2018/11/30 18:53:37:0107] USER: connecting to libwebsockets.org:443/
[2018/11/30 18:53:37:0173] NOTICE:    vhost default: cert expiry: 9998d
[2018/11/30 18:53:38:7986] USER: LWS_CALLBACK_CLIENT_ESTABLISHED
[2018/11/30 18:53:38:8392] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:0929] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:1102] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:1602] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:3880] USER: LWS_CALLBACK_CLIENT_RECEIVE

Running him under lwsws also works

[agreen at learn build]$ sudo /usr/local/bin/lwsws
Root process is 53269
lwsws libwebsockets web server - license CC0 + LGPL2.1
(C) Copyright 2010-2018 Andy Green <andy at warmcat.com>
Using config dir: "/etc/lwsws"
   Scanning /usr/local/share/libwebsockets-test-server/plugins/
  Using foreign event loop...
   adding header content-security-policy=default-src 'none'; img-src 
'self' data: https://travis-ci.org https://api.travis-ci.org 
https://ci.appveyor.com https://scan.coverity.com; script-src 'self'; 
font-src 'self'; style-src 'self'; connect-src 'self...
   adding header x-content-type-options=nosniff
   adding header x-xss-protection=1; mode=block
   adding header x-frame-options=deny
   adding header referrer-policy=no-referrer
   + extra-mimetypes .ttf -> application/x-font-truetype
   + extra-mimetypes .otf -> application/font-sfnt
   + extra-mimetypes .zip -> application/zip
   + extra-mimetypes .webm -> video/webm
   + extra-mimetypes .romfs -> application/octet-stream
   + extra-mimetypes .pdf -> application/pdf
   + extra-mimetypes .odt -> application/vnd.oasis.opendocument.text
Creating Vhost 'localhost' port 7681, 8 protocols, IPv6 off
  SSL ciphers: 
  Using SSL mode
  SSL ECDH curve 'prime256v1'
lws_tls_client_create_vhost_context: doing cert filepath 
Loaded client cert 
lws_tls_client_create_vhost_context: doing private key filepath
Loaded client cert private key 
created client ssl context for localhost
Creating Vhost 'sshd' port 2222, 3 protocols, IPv6 off
  Using non-SSL mode
connecting to libwebsockets.org:443/
   deaddrop: vh localhost, upload dir /var/cache/deaddrop-uploads, max 
size 10000000
Set privs to user 'apache'
    vhost localhost: cert expiry: 9998d
    vhost sshd: no cert

Assuming something different happens your end, please paste the logs.

If it's surprising to you that your reproducer was broken, then take a 
moment to confirm that the plugin you think lwsws is pulling in, is 
actually created from the sources you think it should use to create that.


> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list