peers / peerjs-server

Server for PeerJS
https://peerjs.com
MIT License
4.38k stars 1.09k forks source link

No error when client tries to establish a data connection with a non-existing ID #127

Closed bilo1967 closed 5 years ago

bilo1967 commented 5 years ago

See details about my setup below. This is the issue;

The same code works fine if I connect to the public server.

Any clue?

My setup:

I've set up a plain-vanilla PeerJS server on my CentOS6 distro. I've made no changes to the server code and I start it with:

/opt/peerjs-server/bin/peerjs  \
    --port 9000 \
    --sslkey /etc/letsencrypt/live/my.own.domain/privkey.pem  \
    --sslcert /etc/letsencrypt/live/my.own.domain  \
    --path '/'

In /opt/peerjs-server/config/index.js I have:

module.exports = {
  port: 9000,
  expire_timeout: 5000,
  path: '/',
  concurrent_limit: 5000,
  allow_discovery: false,
  proxied: false,
  cleanup_out_msgs: 1000,
  ssl: {
    key: '/etc/letsencrypt/live/my.own.domain/privkey.pem',
    cert: '/etc/letsencrypt/live/my.own.domain/cert.pem'
  }
};

P.S. Where do I find the server log file and how do I set the server log level?

kidandcat commented 5 years ago

Hi, it looks latest PeerServer version is not stable yet. @afrokick was developing it. Meanwhile you should be ok with the version of the public server which I've published in the branch: v0.2.9 test it and write if it works in your case.

PD: I wouldn't recommend to let PeerServer (or any NodeJS service) to manage SSL. Public PeerServer SSL is managed by a bastion Caddyserver.

bilo1967 commented 5 years ago

Hi, it looks latest PeerServer version is not stable yet. @afrokick was developing it. Meanwhile you should be ok with the version of the public server which I've published in the branch: v0.2.9 test it and write if it works in your case.

Seems like it's working fine, thank you!

PD: I wouldn't recommend to let PeerServer (or any NodeJS service) to manage SSL. Public PeerServer SSL is managed by a bastion Caddyserver.

Ok. Is there any guide to configure Caddy to proxy the PeerServer? Silly question. I found it googling a while. It seems that dowloading caddy with http.cors plugin and the following config file does the job:

my.domain.tld:9443 {

  proxy / http://localhost:9000 {
    websocket
  }

  cors / {
    origin            *
    methods           POST,PUT,GET
    allowed_headers   Content-Length,range
    exposed_headers   Content-Length,range
  }

  tls /etc/letsencrypt/live/my.domain.tld/cert.pem /etc/letsencrypt/live/my.domain.tld/privkey.pem
}
kidandcat commented 5 years ago

As easy as:

Caddyfile:

0.peerjs.com {
  proxy / http://localhost:9000 {
    websocket
  }
  tls your@email.com
}

Then execute caddy where you have your config.

d07RiV commented 5 years ago

I don't think it's related to clients trying to connect to non existing peers.

Looking at the code in question, I'm not sure what it was even supposed to be doing:

TypeError: Cannot destructure property `realm` of 'undefined' or 'null'.
    at module.exports (/home/___/peerjs-server/src/messageHandler/index.js:24:18)
    at pruneOutstanding (/home/___/peerjs-server/src/services/messagesExpire/index.js:23:11)
    at Timeout.setTimeout [as _onTimeout] (/home/___/peerjs-server/src/services/messagesExpire/index.js:45:7)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

messageHandler line 24:

module.exports = ({ realm }) => {

messagesExpire around line 23:

    if (!seen[message.src]) {
      messageHandler(null, {
        type: MessageType.EXPIRE,
        src: message.dst,
        dst: message.src
      });
      seen[message.src] = true;
    }

It straight up calls a single argument function with two arguments, first of them being null. I see no way for this code to not crash under any condition. Seems that someone made a PR for this already, though I'm not sure if that is enough since the second argument is never read, either.

afrokick commented 5 years ago

@bilo1967 we fixed some bugs, could you please try to check the latest version from master branch?

bilo1967 commented 5 years ago

@bilo1967 we fixed some bugs, could you please try to check the latest version from master branch?

Did just a quick test and it seems to work fine. I'll keep this version of the server and let you know if there are problems.

afrokick commented 5 years ago

Ok, please reopen an issue if it still exists