Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are websockets blocked? #273

Open
eddyem opened this issue Oct 23, 2020 · 6 comments
Open

Are websockets blocked? #273

eddyem opened this issue Oct 23, 2020 · 6 comments

Comments

@eddyem
Copy link

eddyem commented Oct 23, 2020

I try to work with websockets but found that if one websocket is opened, I can't open another (in another tab, another browser or any other PC).
How can I fix this bug for opening websockets to given port in any quantity?

@davidmoreno
Copy link
Owner

davidmoreno commented Oct 23, 2020 via email

@eddyem
Copy link
Author

eddyem commented Oct 23, 2020

I run it with O_THREADED:

static void *runWS(_U_ void *data){
    ow = onion_new(O_THREADED);
    if(!(onion_flags(ow) & O_SSL_AVAILABLE)){
        ONION_ERROR("SSL support is not available");
        signals(1);
    }
    int error = onion_set_certificate(ow, O_SSL_CERTIFICATE_KEY, G.certfile, G.keyfile);
    if(error){
        ONION_ERROR("Can't set certificate and key files (%s, %s)", G.certfile, G.keyfile);
        signals(1);
    }
    onion_set_port(ow, G.wsport);
    onion_url *url = onion_root_url(ow);
    onion_url_add(url, "", websocket_run);
    DBG("Listen websocket");
    error = onion_listen(ow);
    if(error) ONION_ERROR("Can't create WEBSOCKET server: %s", strerror(errno));
    onion_free(ow);
    return NULL;
}

But when one websocket is opened, no other connections could be done. And this function don't run:

onion_connection_status websocket_run(_U_ void *data, onion_request *req, onion_response *res){
    FNAME();
    onion_websocket *ws = onion_websocket_new(req, res);
    if (!ws){
        red("OCS_PROCESSED");
        DBG("Processed");
        return OCS_PROCESSED;
    }
    DBG("WS ready");
    const char *host = onion_request_get_client_description(req);
    const char *UA = onion_request_get_header(req, "User-Agent");
    green("Got WS connection from %s (UA: %s)\n", host, UA);
    WSdata *wsdata = calloc(1, sizeof(WSdata));
    wsdata->flags = WS_FLAG_NOTAUTHORIZED;
    wsdata->IPhash = MurmurOAAT64(host);
    wsdata->UAhash = MurmurOAAT64(UA);
    onion_websocket_set_userdata(ws, (void*)wsdata, free);
    onion_websocket_set_callback(ws, websocket_cont);
    return OCS_WEBSOCKET;
}

@eddyem
Copy link
Author

eddyem commented Oct 27, 2020

I have tried an websocket example from libonion. And it don't work too! As only I open one connection, I can't open another.
What's the right way to work with websockets in libonion? I need at least 10-20 simultaneous connections.

@davidmoreno
Copy link
Owner

davidmoreno commented Oct 27, 2020 via email

@YggdrasiI
Copy link
Contributor

YggdrasiI commented Nov 10, 2020

websockets.c.txt
Hello eddyem,

I've attached my adaption of the websocket example for multiple clients. It uses
onion threaded
o = onion_new(O_THREADED|O_NO_SIGTERM|O_DETACH_LISTEN);

and then pushs periodical test strings data to clients.

Edit: Upload better version.
websockets.c.txt

@eddyem
Copy link
Author

eddyem commented Nov 10, 2020

I found a problem: websockets didn't work for several clients due to gentoo's ebuild of libonion. When I use onion from git, it works, but with segfaults when client transmit some data.
Also there's a problem with such little active clients (8 by default in libonion). This number should be at least several thousands!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants