Skip to content
Snippets Groups Projects
Commit 8c33efe2 authored by Éloïs's avatar Éloïs
Browse files

[enh] prepare api type in head mesage

parent 5e4997b5
No related branches found
No related tags found
1 merge request!1178Add WS2PTOR features
...@@ -291,7 +291,7 @@ export class WS2PCluster { ...@@ -291,7 +291,7 @@ export class WS2PCluster {
async connectToRemoteWS(host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise<WS2PConnection> { async connectToRemoteWS(host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise<WS2PConnection> {
const uuid = nuuid.v4() const uuid = nuuid.v4()
let pub = "--------" let pub = expectedPub.slice(0, 8)
const api:string = (host.match(WS2PConstants.HOST_ONION_REGEX) !== null) ? 'WS2PTOR':'WS2P' const api:string = (host.match(WS2PConstants.HOST_ONION_REGEX) !== null) ? 'WS2PTOR':'WS2P'
try { try {
const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path)
...@@ -463,13 +463,14 @@ export class WS2PCluster { ...@@ -463,13 +463,14 @@ export class WS2PCluster {
} }
private sayHeadChangedTo(number:number, hash:string) { 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 key = new Key(this.server.conf.pair.pub, this.server.conf.pair.sec)
const pub = key.publicKey const pub = key.publicKey
const software = 'duniter' const software = 'duniter'
const softVersion = Package.getInstance().version const softVersion = Package.getInstance().version
const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000'
const prefix = this.server.conf.prefix || Constants.DEFAULT_PEER_ID 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) const sig = key.signSync(message)
return { sig, message, pub } return { sig, message, pub }
} }
......
...@@ -30,7 +30,7 @@ export const WS2PConstants = { ...@@ -30,7 +30,7 @@ export const WS2PConstants = {
+ CommonConstants.FORMATS.BLOCKSTAMP + 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.PUBKEY + '):'
+ '(' + CommonConstants.FORMATS.BLOCKSTAMP + '):' + '(' + CommonConstants.FORMATS.BLOCKSTAMP + '):'
+ '(' + CommonConstants.FORMATS.WS2PID + '):' + '(' + CommonConstants.FORMATS.WS2PID + '):'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment