fix: update compliance tests for latest interface-transport

License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Jacob Heun 2019-09-06 11:17:59 +02:00
parent 0d1c454ce0
commit d65f3ce228
No known key found for this signature in database
GPG Key ID: CA5A94C15809879F
5 changed files with 17 additions and 8 deletions

View File

@ -47,7 +47,7 @@
"debug": "^4.1.1",
"err-code": "^1.1.2",
"interface-connection": "~0.3.3",
"interface-transport": "~0.5.2",
"interface-transport": "~0.6.0",
"ip-address": "^6.1.0",
"it-pipe": "^1.0.1",
"lodash.includes": "^4.3.0",

View File

@ -8,6 +8,7 @@ const isFunction = require('lodash.isfunction')
const errcode = require('err-code')
const debug = require('debug')
const log = debug('libp2p:tcp:dial')
const assert = require('assert')
const Libp2pSocket = require('./socket')
const createListener = require('./listener')
@ -16,12 +17,17 @@ const { AbortError } = require('interface-transport')
function noop () {}
class TCP {
constructor(options) {
assert(options.upgrader, 'An Upgrader must be provided')
this.upgrader = options.upgrader
}
async dial (ma, options) {
const cOpts = ma.toOptions()
log('Dialing %s:%s', cOpts.host, cOpts.port)
const rawSocket = await this._connect(cOpts, options)
return new Libp2pSocket(rawSocket, ma, options)
return this.upgrader.upgradeOutbound(new Libp2pSocket(rawSocket, ma, options))
}
_connect (cOpts, options = {}) {
@ -80,7 +86,7 @@ class TCP {
}
handler = handler || noop
return createListener(handler)
return createListener(handler, this.upgrader)
}
filter (multiaddrs) {

View File

@ -13,7 +13,7 @@ const Libp2pSocket = require('./socket')
const getMultiaddr = require('./get-multiaddr')
const c = require('./constants')
module.exports = (handler) => {
module.exports = (handler, upgrader) => {
const listener = new EventEmitter()
const server = net.createServer((socket) => {
@ -37,8 +37,9 @@ module.exports = (handler) => {
const s = new Libp2pSocket(socket, addr)
trackSocket(server, socket)
handler && handler(s)
listener.emit('connection', s)
const conn = upgrader.upgradeInbound(s)
handler && handler(conn)
listener.emit('connection', conn)
})
server.on('listening', () => listener.emit('listening'))

View File

@ -10,6 +10,8 @@ class Libp2pSocket {
constructor (rawSocket, ma, opts = {}) {
this._rawSocket = rawSocket
this._ma = ma
this.remoteAddr = ma
this.conn = rawSocket
this.sink = this._sink(opts)
this.source = opts.signal ? abortable(rawSocket, opts.signal) : rawSocket

View File

@ -9,8 +9,8 @@ const TCP = require('../src')
describe('interface-transport compliance', () => {
tests({
setup () {
const tcp = new TCP()
setup (options) {
const tcp = new TCP(options)
const addrs = [
multiaddr('/ip4/127.0.0.1/tcp/9091'),
multiaddr('/ip4/127.0.0.1/tcp/9092'),