From 8c33efe2fe7f7e2a706be0feccbc633e51e273e4 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sat, 4 Nov 2017 01:45:27 +0100 Subject: [PATCH] [enh] prepare api type in head mesage --- app/modules/ws2p/lib/WS2PCluster.ts | 5 +++-- app/modules/ws2p/lib/constants.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 875c552dd..701973334 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -291,7 +291,7 @@ export class WS2PCluster { async connectToRemoteWS(host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise<WS2PConnection> { const uuid = nuuid.v4() - let pub = "--------" + let pub = expectedPub.slice(0, 8) const api:string = (host.match(WS2PConstants.HOST_ONION_REGEX) !== null) ? 'WS2PTOR':'WS2P' try { const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) @@ -463,13 +463,14 @@ export class WS2PCluster { } private sayHeadChangedTo(number:number, hash:string) { + const api = (this.server.conf.ws2p && this.server.conf.ws2p.remotehost && this.server.conf.ws2p.remotehost.match(WS2PConstants.HOST_ONION_REGEX)) ? 'WS2P':'WS2P' const key = new Key(this.server.conf.pair.pub, this.server.conf.pair.sec) const pub = key.publicKey const software = 'duniter' const softVersion = Package.getInstance().version const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' const prefix = this.server.conf.prefix || Constants.DEFAULT_PEER_ID - const message = `WS2P:HEAD:1:${pub}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` + const message = `${api}:HEAD:1:${pub}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` const sig = key.signSync(message) return { sig, message, pub } } diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index ca457f1a9..8338f8dbf 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -30,7 +30,7 @@ export const WS2PConstants = { + CommonConstants.FORMATS.BLOCKSTAMP + '$'), - HEAD_V1_REGEXP: new RegExp('^WS2P:HEAD:1:' + HEAD_V1_REGEXP: new RegExp('^WS2P(?:TOR)?:HEAD:1:' + '(' + CommonConstants.FORMATS.PUBKEY + '):' + '(' + CommonConstants.FORMATS.BLOCKSTAMP + '):' + '(' + CommonConstants.FORMATS.WS2PID + '):' -- GitLab