<div dir="ltr"><div>> +               vhd->context = lws_get_context(wsi);</div><div>I just forgot this while copy/pasting :)</div><div><br></div><div>*local_protocol_name was the problem. Thanks!</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 30, 2018 at 3:59 PM Andy Green <<a href="mailto:andy@warmcat.com">andy@warmcat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 30/11/2018 18:31, Vitaly Shevtsov wrote:<br>
> Good day! I use vanila lwsws and try to implement simple plugin. In <br>
> plugin I use lws_client_connect_via_info to connect to another <br>
> WS-server. On the server side I see my connection but I can't see <br>
> LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?<br>
> <br>
> Forgot to mention: If I use this plugin standalone, client connection <br>
> works as expected.<br>
> Thanks!<br>
> <br>
> <br>
> On November 29, 2018 10:22:47 PM GMT+08:00, Vitaly Shevtsov <br>
> <<a href="mailto:shev.vt1984@gmail.com" target="_blank">shev.vt1984@gmail.com</a> <br>
> <<a href="https://e.mail.ru/compose/?mailto=mailto%3ashev.vt1984@gmail.com" rel="noreferrer" target="_blank">https://e.mail.ru/compose/?mailto=mailto%3ashev.vt1984@gmail.com</a>>> wrote:<br>
>  >Good day! I use vanila lwsws and try to implement simple plugin. In<br>
>  >plugin<br>
>  >I use lws_client_connect_via_info to connect to another WS-server. On<br>
>  >the<br>
>  >server side I see my connection but I can't see<br>
>  >LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?<br>
> <br>
> You need "enable-client-ssl": "1" on the config for the vhost you <br>
> created the client on, if the destination is wss.<br>
> <br>
> You also need to list your protocol under "ws-protocols" for the vhost conf.<br>
> <br>
> Notice the client connect info struct allows you to bind the new <br>
> connection to a specific local protocol name.<br>
> <br>
> <a href="https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n108-114" rel="noreferrer" target="_blank">https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n108-114</a><br>
> <br>
> But nost of all you need to enable logging with eg, -d1039 and confirm <br>
> your plugin loaded and the protocol is there.  And look at the logging <br>
> to see what it says about the client connect.<br>
> <br>
> If you want to follow up please use the mailing list.<br>
> <br>
> -Andy<br>
> <br>
>  >Thanks!<br>
> <br>
> <br>
> Thanks for your reply. Unfortunately this didn't help, all you wrote <br>
> have been done before and works well when there is no client connection <br>
> inside the plugin.<br>
<br>
Yeah... well... "why doesn't this work" with no logs or reproducer is a <br>
bit of an optimistic question, isn't it.<br>
<br>
> I found the way to reproduce this issue - I attached modified <br>
> protocol_dumb_increment.c to show what I mean. Thanks!<br>
<br>
That just crashes as it is... it's missing this:<br>
<br>
@@ -56,10 +88,14 @@ callback_dumb_increment(struct lws *wsi, enum <br>
lws_callback_reasons reason,<br>
                         sizeof(struct vhd__dumb_increment));<br>
                 if (!vhd)<br>
                         return -1;<br>
+               vhd->context = lws_get_context(wsi);<br>
                 if ((opt = lws_pvo_search(<br>
                                 (const struct <br>
lws_protocol_vhost_options *)in,<br>
                                 "options")))<br>
                         vhd->options = (unsigned int *)opt->value;<br>
<br>
<br>
Trying it like this he seems happy<br>
<br>
$ libwebsockets-test-server -s -d1031<br>
[2018/11/30 18:53:36:0006] NOTICE: libwebsockets test server - license <br>
LGPL2.1+SLE<br>
[2018/11/30 18:53:36:0006] NOTICE: (C) Copyright 2010-2018 Andy Green <br>
<<a href="mailto:andy@warmcat.com" target="_blank">andy@warmcat.com</a>><br>
Using resource path "/usr/local/share/libwebsockets-test-server"<br>
[2018/11/30 18:53:37:0057] NOTICE: Creating Vhost 'default' port 7681, 5 <br>
protocols, IPv6 off<br>
[2018/11/30 18:53:37:0058] NOTICE:  SSL ciphers: <br>
'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:!SHA1:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES128-SHA256:!AES128-GCM-SH...<br>
[2018/11/30 18:53:37:0058] NOTICE:  Using SSL mode<br>
[2018/11/30 18:53:37:0062] NOTICE:  SSL ECDH curve 'prime256v1'<br>
[2018/11/30 18:53:37:0105] NOTICE: lws_tls_client_create_vhost_context: <br>
doing cert filepath <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem<br>
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem<br>
[2018/11/30 18:53:37:0106] NOTICE: lws_tls_client_create_vhost_context: <br>
doing private key filepath<br>
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert private key <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.key.pem<br>
[2018/11/30 18:53:37:0106] NOTICE: created client ssl context for default<br>
[2018/11/30 18:53:37:0107] USER: connecting to <a href="http://libwebsockets.org:443/%5B2018/11/30" rel="noreferrer" target="_blank">libwebsockets.org:443/<br>
[2018/11/30</a> 18:53:37:0173] NOTICE:    vhost default: cert expiry: 9998d<br>
[2018/11/30 18:53:38:7986] USER: LWS_CALLBACK_CLIENT_ESTABLISHED<br>
[2018/11/30 18:53:38:8392] USER: LWS_CALLBACK_CLIENT_RECEIVE<br>
[2018/11/30 18:53:39:0929] USER: LWS_CALLBACK_CLIENT_RECEIVE<br>
[2018/11/30 18:53:39:1102] USER: LWS_CALLBACK_CLIENT_RECEIVE<br>
[2018/11/30 18:53:39:1602] USER: LWS_CALLBACK_CLIENT_RECEIVE<br>
[2018/11/30 18:53:39:3880] USER: LWS_CALLBACK_CLIENT_RECEIVE<br>
...<br>
<br>
Running him under lwsws also works<br>
<br>
[agreen@learn build]$ sudo /usr/local/bin/lwsws<br>
Root process is 53269<br>
lwsws libwebsockets web server - license CC0 + LGPL2.1<br>
(C) Copyright 2010-2018 Andy Green <<a href="mailto:andy@warmcat.com" target="_blank">andy@warmcat.com</a>><br>
Using config dir: "/etc/lwsws"<br>
   Plugins:<br>
   Scanning /usr/local/share/libwebsockets-test-server/plugins/<br>
    libprotocol_client_loopback_test.so<br>
    libprotocol_deaddrop.so<br>
    libprotocol_dumb_increment.so<br>
    libprotocol_fulltext_demo.so<br>
    libprotocol_generic_sessions.so<br>
    libprotocol_lws_acme_client.so<br>
    libprotocol_lws_messageboard.so<br>
    libprotocol_lws_meta.so<br>
    libprotocol_lws_mirror.so<br>
    libprotocol_lws_raw_test.so<br>
    libprotocol_lws_server_status.so<br>
    libprotocol_lws_ssh_base.so<br>
    libprotocol_lws_sshd_demo.so<br>
    libprotocol_lws_status.so<br>
    libprotocol_lws_table_dirlisting.so<br>
    libprotocol_post_demo.so<br>
  Using foreign event loop...<br>
   adding header content-security-policy=default-src 'none'; img-src <br>
'self' data: <a href="https://travis-ci.org" rel="noreferrer" target="_blank">https://travis-ci.org</a> <a href="https://api.travis-ci.org" rel="noreferrer" target="_blank">https://api.travis-ci.org</a> <br>
<a href="https://ci.appveyor.com" rel="noreferrer" target="_blank">https://ci.appveyor.com</a> <a href="https://scan.coverity.com" rel="noreferrer" target="_blank">https://scan.coverity.com</a>; script-src 'self'; <br>
font-src 'self'; style-src 'self'; connect-src 'self...<br>
   adding header x-content-type-options=nosniff<br>
   adding header x-xss-protection=1; mode=block<br>
   adding header x-frame-options=deny<br>
   adding header referrer-policy=no-referrer<br>
   + extra-mimetypes .ttf -> application/x-font-truetype<br>
   + extra-mimetypes .otf -> application/font-sfnt<br>
   + extra-mimetypes .zip -> application/zip<br>
   + extra-mimetypes .webm -> video/webm<br>
   + extra-mimetypes .romfs -> application/octet-stream<br>
   + extra-mimetypes .pdf -> application/pdf<br>
   + extra-mimetypes .odt -> application/vnd.oasis.opendocument.text<br>
Creating Vhost 'localhost' port 7681, 8 protocols, IPv6 off<br>
  SSL ciphers: <br>
'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:!SHA1:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES128-SHA256:!AES128-GCM-SH...<br>
  Using SSL mode<br>
  SSL ECDH curve 'prime256v1'<br>
lws_tls_client_create_vhost_context: doing cert filepath <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem<br>
Loaded client cert <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem<br>
lws_tls_client_create_vhost_context: doing private key filepath<br>
Loaded client cert private key <br>
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.key.pem<br>
created client ssl context for localhost<br>
Creating Vhost 'sshd' port 2222, 3 protocols, IPv6 off<br>
  Using non-SSL mode<br>
connecting to <a href="http://libwebsockets.org:443/" rel="noreferrer" target="_blank">libwebsockets.org:443/</a><br>
   deaddrop: vh localhost, upload dir /var/cache/deaddrop-uploads, max <br>
size 10000000<br>
Set privs to user 'apache'<br>
    vhost localhost: cert expiry: 9998d<br>
    vhost sshd: no cert<br>
LWS_CALLBACK_CLIENT_ESTABLISHED<br>
LWS_CALLBACK_CLIENT_RECEIVE<br>
LWS_CALLBACK_CLIENT_RECEIVE<br>
LWS_CALLBACK_CLIENT_RECEIVE<br>
LWS_CALLBACK_CLIENT_RECEIVE<br>
...<br>
<br>
Assuming something different happens your end, please paste the logs.<br>
<br>
If it's surprising to you that your reproducer was broken, then take a <br>
moment to confirm that the plugin you think lwsws is pulling in, is <br>
actually created from the sources you think it should use to create that.<br>
<br>
-Andy<br>
<br>
> _______________________________________________<br>
> Libwebsockets mailing list<br>
> <a href="mailto:Libwebsockets@ml.libwebsockets.org" target="_blank">Libwebsockets@ml.libwebsockets.org</a><br>
> <a href="https://libwebsockets.org/mailman/listinfo/libwebsockets" rel="noreferrer" target="_blank">https://libwebsockets.org/mailman/listinfo/libwebsockets</a><br>
> <br>
</blockquote></div>