Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 50a2e2e

Browse files
authored
feat: add support for WSS (fixes #32)
Add support for WSS
2 parents 78cdf22 + 331c67e commit 50a2e2e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ A libp2p-websocket-star address, using the signalling server we provide, looks l
6464
Note: The address above indicates WebSockets Secure, which can be accessed from both http and https.
6565

6666

67+
### Using WSS
68+
69+
To be able to interact with a rendezvous server from an HTTPS site, you will need to use websocket secure. To host a secure websocket server, you must provide a keypair to the server.
70+
71+
#### Using key and certificate
72+
73+
```bash
74+
> rendezvous --key="path/to/key.key" --cert="path/to/cert.cert"
75+
```
76+
77+
#### Using PFX with passphrase
78+
79+
```bash
80+
> rendezvous --pfx="path/to/pair.pfx" --passphrase="passphrase"
81+
```
82+
83+
6784
### This module uses `pull-streams`
6885

6986
We expose a streaming interface based on `pull-streams`, rather then on the Node.js core streams implementation (aka Node.js streams). `pull-streams` offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this [issue](https://github.com/ipfs/js-ipfs/issues/362).

src/bin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ let server
1212
signalling.start({
1313
port: argv.port || argv.p || process.env.PORT || 9090,
1414
host: argv.host || argv.h || process.env.HOST || '0.0.0.0',
15+
key: argv.key || process.env.KEY,
16+
cert: argv.cert || process.env.CERT,
17+
pfx: argv.pfx || process.env.PFX,
18+
passphrase: argv.passphrase || process.env.PFX_PASSPHRASE,
1519
cryptoChallenge: !(argv.disableCryptoChallenge || process.env.DISABLE_CRYPTO_CHALLENGE),
1620
strictMultiaddr: !(argv.disableStrictMultiaddr || process.env.DISABLE_STRICT_MULTIADDR),
1721
metrics: !(argv.disableMetrics || process.env.DISABLE_METRICS)

src/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path')
55
const epimetheus = require('epimetheus')
66
const merge = require('merge-recursive').recursive
77
const defaultConfig = require('./config')
8+
const { readFileSync } = require('fs')
89

910
exports = module.exports
1011

@@ -22,7 +23,21 @@ exports.start = (options, callback) => {
2223

2324
const http = new Hapi.Server(config.hapi.options)
2425

25-
http.connection({ port, host })
26+
let tls
27+
if (options.key && options.cert) {
28+
tls = {
29+
key: readFileSync(options.key),
30+
cert: readFileSync(options.cert),
31+
passphrase: options.passphrase
32+
}
33+
} else if (options.pfx && options.passphrase) {
34+
tls = {
35+
pfx: readFileSync(options.pfx),
36+
passphrase: options.passphrase
37+
}
38+
}
39+
40+
http.connection({ port, host, tls })
2641

2742
http.register({ register: require('inert') }, (err) => {
2843
if (err) {

0 commit comments

Comments
 (0)