From b280d826343788e9f8a9e50ef06f73333cc7ca62 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Mon, 30 Oct 2017 20:43:23 +0100 Subject: [PATCH] [ifx] getWS2P : return WS2P endpoint if there not WS2PTOR --- app/lib/dto/PeerDTO.ts | 13 ++++++++++++- app/modules/ws2p/index.ts | 2 +- app/modules/ws2p/lib/WS2PCluster.ts | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index d0e661bb8..2bb2e91cd 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -98,7 +98,18 @@ export class PeerDTO implements Cloneable { let api:{ uuid:string, host:string, port:number, path:string }|null = null const endpointRegexp = (tor) ? CommonConstants.WS2PTOR_REGEXP:CommonConstants.WS2P_REGEXP for (const ep of this.endpoints) { - const matches:any = !api && ep.match(endpointRegexp) + if (tor) { + const matches:any = ep.match(CommonConstants.WS2PTOR_REGEXP) + if (matches) { + return { + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] + } + } + } + const matches:any = !api && ep.match(CommonConstants.WS2P_REGEXP) if (matches) { api = { uuid: matches[1], diff --git a/app/modules/ws2p/index.ts b/app/modules/ws2p/index.ts index 6a3dd8fbc..a225e63ec 100644 --- a/app/modules/ws2p/index.ts +++ b/app/modules/ws2p/index.ts @@ -141,7 +141,7 @@ export const WS2PDependency = { const peers = await server.dal.getWS2Peers() for (const p of peers) { for (const ep of p.endpoints) { - if (ep.match(/^WS2P /)) { + if (ep.match(/^WS2P/)) { console.log(p.pubkey, ep) } } diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index d1aa4ece5..93e8119d8 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -369,7 +369,7 @@ export class WS2PCluster { let i = 0 while (i < peers.length && this.clientsCount() < this.maxLevel1Size) { const p = peers[i] - const api = p.getWS2P(imCanReachTorEndpoint !== undefined) + const api = p.getWS2P(imCanReachTorEndpoint) if (api) { try { await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) -- GitLab