Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multiserver

Package Overview
Dependencies
Maintainers
5
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiserver - npm Package Compare versions

Comparing version 3.7.1 to 3.7.2

4

package.json
{
"name": "multiserver",
"description": "write a server which works over many protocols at once, or connect to the same",
"version": "3.7.1",
"version": "3.7.2",
"homepage": "https://github.com/ssb-js/multiserver",

@@ -15,3 +15,3 @@ "repository": {

"pull-stream": "^3.6.1",
"pull-ws": "^3.3.0",
"pull-websocket": "^3.4.0",
"secret-handshake": "^1.1.16",

@@ -18,0 +18,0 @@ "separator-escape": "0.0.1",

@@ -1,2 +0,2 @@

var WS = require('pull-ws')
var WS = require('pull-websocket')
var URL = require('url')

@@ -7,4 +7,4 @@ var pull = require('pull-stream/pull')

var http = require('http')
var https = require('https')
var fs = require('fs')
var https = require('https')
var fs = require('fs')
var debug = require('debug')('multiserver:ws')

@@ -55,5 +55,3 @@

server: function (onConnect, startedCb) {
if (WS.createServer == null) {
return null
}
if (WS.createServer == null) return null

@@ -73,5 +71,6 @@ // Maybe weird: this sets a random port each time that `server()` is run

var server = opts.server ||
(opts.key && opts.cert ? https.createServer({ key: opts.key, cert: opts.cert }, opts.handler) : http.createServer(opts.handler))
(opts.key && opts.cert ? https.createServer({ key: opts.key, cert: opts.cert }, opts.handler) : http.createServer(opts.handler))
WS.createServer(Object.assign({}, opts, {server: server}), function (stream) {
const serverOpts = Object.assign({}, opts, {server: server})
let wsServer = WS.createServer(serverOpts, function (stream) {
stream.address = safe_origin(

@@ -96,3 +95,4 @@ stream.headers.origin,

debug('Closing server on %s:%d', opts.host, opts.port)
server.close(function(err) {
wsServer.close((err) => {
debug('after WS close', err)
if (err) console.error(err)

@@ -124,3 +124,3 @@ else debug('No longer listening on %s:%d', opts.host, opts.port)

return function () {
stream.close(cb)
stream.close()
}

@@ -165,5 +165,1 @@ },

}

@@ -359,31 +359,44 @@ var tape = require('tape')

tape('id of stream from server', function (t) {
check = function (id, cb) {
cb(null, true)
}
var close = combined.server(function (stream) {
var addr = combined.parse(stream.address)
t.ok(addr)
//console.log('address as seen on server', addr)
t.equal(addr[0].name, 'net')
t.deepEqual(addr[1], combined.parse(combined.stringify())[1])
function testServerId(combined, name, port) {
tape('id of stream from server', function (t) {
check = function (id, cb) {
cb(null, true)
}
var close = combined.server(function (stream) {
console.log('raw address on server:', stream.address)
var addr = combined.parse(stream.address)
t.ok(addr)
console.log('address as seen on server', addr)
t.equal((addr[0].name || addr[0].protocol).replace(':', ''), name)
t.deepEqual(addr[1], combined.parse(combined.stringify())[1])
pull(stream.source, stream.sink) //echo
}, function (err) {
if(err) throw err
}, function () {
pull(stream.source, stream.sink) //echo
}, function (err) {
if(err) throw err
}, function () {
combined.client(combined.stringify(), function (err, stream) {
if(err) throw err
var addr = combined.parse(stream.address)
t.equal(addr[0].name, 'net')
t.equal(addr[0].port, 4848)
t.deepEqual(addr[1], combined.parse(combined.stringify())[1])
stream.source(true, function () {
close(t.end)
combined.client(combined.stringify(), function (err, stream) {
if(err) throw err
var addr = combined.parse(stream.address)
t.equal((addr[0].name || addr[0].protocol).replace(':', ''), name)
if (addr[0].protocol === 'ws:')
t.equal(+addr[0].port, 4849)
else
t.equal(+addr[0].port, 4848)
t.deepEqual(addr[1], combined.parse(combined.stringify())[1])
stream.source(true, function () {
close(t.end)
})
})
})
})
})
}
testServerId(combined, 'net')
testServerId(combined_ws, 'ws')
function testAbort (name, combined) {

@@ -393,19 +406,19 @@ tape(name+', aborted', function (t) {

throw new Error('should never happen')
}, null, () => {
var abort = combined.client(combined.stringify(), function (err, stream) {
t.ok(err, 'the error is expected')
})
// NOTE: without the timeout, we try to close the server
// before it actually started listening, which fails and then
// the server keeps runnung, causing the next test to fail with EADDRINUSE
//
// This is messy, combined.server should be a proper async call
setTimeout( function() {
//console.log('Calling close')
close(t.end)
}, 500)
})
var abort = combined.client(combined.stringify(), function (err, stream) {
t.ok(err)
console.error("CLIENT ABORTED", err)
// NOTE: without the timeout, we try to close the server
// before it actually started listening, which fails and then
// the server keeps runnung, causing the next test to fail with EADDRINUSE
//
// This is messy, combined.server should be a proper async call
setTimeout( function() {
console.log('Calling close')
close(t.end)
}, 500)
})
abort()
})
abort()
})

@@ -417,26 +430,35 @@ }

tape('error should have client address on it', function (t) {
// return t.end()
check = function (id, cb) {
throw new Error('should never happen')
}
var close = combined.server(function (stream) {
throw new Error('should never happen')
}, function (err) {
t.ok(/^net:/.test(err.address))
t.ok(/~shs:/.test(err.address))
//the shs address won't actually parse, because it doesn't have the key in it
//because the key is not known in a wrong number.
}, function () {
//very unlikely this is the address, which will give a wrong number at the server.
var addr = combined.stringify().replace(/shs:......../, 'shs:XXXXXXXX')
combined.client(addr, function (err, stream) {
//client should see client auth rejected
t.ok(err)
//console.log('Calling close')
close(t.end)
function testErrorAddress(combined, type) {
tape('error should have client address on it:' + type, function (t) {
check = function (id, cb) {
throw new Error('should never happen')
}
var close = combined.server(function (stream) {
throw new Error('should never happen')
}, function (err) {
var addr = err.address
t.ok(err.address.indexOf(type) == 0) //net or ws
t.ok(/\~shs\:/.test(err.address))
//the shs address won't actually parse, because it doesn't have the key in it
//because the key is not known in a wrong number.
}, function () {
//very unlikely this is the address, which will give a wrong number at the server.
var addr = combined.stringify().replace(/shs:......../, 'shs:XXXXXXXX')
combined.client(addr, function (err, stream) {
//client should see client auth rejected
t.ok(err)
close(() => {
if (type === 'ws') // we need to wait for the kill
setTimeout(t.end, 1100)
else
t.end()
})
})
})
})
})
}
testErrorAddress(combined, 'net')
testErrorAddress(combined_ws, 'ws')
tape('multiple public different hosts', function(t) {

@@ -599,2 +621,2 @@ var net1 = Net({ host: '127.0.0.1', port: 4854, scope: 'public'})

t.end()
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc