diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index f2533f0cf3b5d81240ff9b2cd22376127ee048aa..361eb49c9d0922b3e4fffb6b4e0c4bc9e25ce7ed 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -67,6 +67,7 @@ export interface WS2PConfDTO { upnp?: boolean remotehost?: string|null remoteport?: number|null + remotepath?: string port?: number host?: string maxPublic?:number @@ -140,6 +141,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, upnp?: boolean remotehost?: string|null remoteport?: number|null + remotepath?: string port?: number host?: string preferedNodes?: string[] diff --git a/app/modules/ws2p/index.ts b/app/modules/ws2p/index.ts index 2f1c745bf1be492aefa22f0e1d37357639eefaa8..433d62c694bd2a99fc0eaffc7ddda00796df4901 100644 --- a/app/modules/ws2p/index.ts +++ b/app/modules/ws2p/index.ts @@ -19,6 +19,7 @@ export const WS2PDependency = { { value: '--ws2p-port <port>', desc: 'Host to listen to.', parser: (val:string) => parseInt(val) }, { value: '--ws2p-remote-host <address>', desc: 'Availabily host.' }, { value: '--ws2p-remote-port <port>', desc: 'Availabily port.', parser: (val:string) => parseInt(val) }, + { value: '--ws2p-remote-path <path>', desc: 'Availabily web path.' }, { value: '--ws2p-max-private <count>', desc: 'Maximum private connections count.', parser: (val:string) => parseInt(val) }, { value: '--ws2p-max-public <count>', desc: 'Maximum public connections count.', parser: (val:string) => parseInt(val) }, { value: '--ws2p-private', desc: 'Enable WS2P Private access.' }, @@ -50,6 +51,7 @@ export const WS2PDependency = { if (program.ws2pPort !== undefined) conf.ws2p.port = parseInt(program.ws2pPort) if (program.ws2pRemotePort !== undefined) conf.ws2p.remoteport = program.ws2pRemotePort if (program.ws2pRemoteHost !== undefined) conf.ws2p.remotehost = program.ws2pRemoteHost + if (program.ws2pRemotePath !== undefined) conf.ws2p.remotepath = program.ws2pRemotePath if (program.ws2pUpnp !== undefined) conf.ws2p.upnp = true if (program.ws2pNoupnp !== undefined) conf.ws2p.upnp = false if (program.ws2pMaxPrivate !== undefined) conf.ws2p.maxPrivate = program.ws2pMaxPrivate @@ -245,11 +247,15 @@ export class WS2PAPI extends stream.Transform { && this.server.conf.ws2p.uuid && this.server.conf.ws2p.remotehost && this.server.conf.ws2p.remoteport) { - return ['WS2P', + let ep = ['WS2P', this.server.conf.ws2p.uuid, this.server.conf.ws2p.remotehost, this.server.conf.ws2p.remoteport ].join(' ') + if (this.server.conf.ws2p.remotepath) { + ep += ` ${this.server.conf.ws2p.remotepath}` + } + return ep } else { return '' diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 7b65e44af8a48fa371171a6cb2dcdfafdbebae00..a860036fd6d388157ebdeff39505e7558e9fea29 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -26,10 +26,13 @@ export interface WS2PHead { export class WS2PCluster { - static getFullAddress(host: string, port: number, path: string): string { + static getFullAddress(host: string, port: number, path: string|null|undefined = null): string { if (host.match(CommonConstants.IPV6_REGEXP)) { host = "[" + host + "]" } + // Make the path be a string + path = path || '' + // Choose the web protocol depending on the port const protocol = port == 443 ? "wss://": "ws://" return [protocol, host, ':', port, path].join('') } diff --git a/test/fast/modules/ws2p/host.ts b/test/fast/modules/ws2p/host.ts index 4fcdae782ca34a28fd5891e0e6d1926e60ab3bd7..34073f4bdb2969fbf175f66221c1717c9c9abcd9 100644 --- a/test/fast/modules/ws2p/host.ts +++ b/test/fast/modules/ws2p/host.ts @@ -4,8 +4,10 @@ import { WS2PCluster } from '../../../../app/modules/ws2p/lib/WS2PCluster'; describe('WS2P IP functions', () => { it('should format correctly DNS endpoints', () => { - assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, ''), 'ws://my.host.com:80') - assert.equal(WS2PCluster.getFullAddress('my.host.com', 443, ''), 'wss://my.host.com:443') + assert.equal(WS2PCluster.getFullAddress('my.host.com', 80), 'ws://my.host.com:80') + assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, null), 'ws://my.host.com:80') + assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, undefined), 'ws://my.host.com:80') + assert.equal(WS2PCluster.getFullAddress('my.host.com', 443, null), 'wss://my.host.com:443') assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, '/'), 'ws://my.host.com:80/') assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, '/path'), 'ws://my.host.com:80/path') assert.equal(WS2PCluster.getFullAddress('my.host.com', 80, '/super/long/path'), 'ws://my.host.com:80/super/long/path')