Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 0db9c53c authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1129 Allow additional `path` parameter for WS2P

parent da024d07
......@@ -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[]
......
......@@ -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 ''
......
......@@ -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('')
}
......
......@@ -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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment