diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index 28bbae7e199532db2ad0c4e0255e6e78ffcc4acc..b3c263e79f97baf0e92e977fde7c8855fc219eaf 100644 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -27,6 +27,7 @@ const UNLOCK = "(SIG\\(" + INTEGER + "\\)|XHX\\(" + XUNLOCK + "\\))" const CONDITIONS = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9]{64}\\)|CLTV\\(" + CLTV_INTEGER + "\\)|CSV\\(" + CSV_INTEGER + "\\))))*" const BMA_REGEXP = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ +const WS2P_REGEXP = /^WS2P ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)$/ const MAXIMUM_LEN_OF_COMPACT_TX = 100 const MAXIMUM_LEN_OF_OUTPUT = 2000 @@ -76,6 +77,7 @@ export const CommonConstants = { SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS: 3, BMA_REGEXP, + WS2P_REGEXP, PUBLIC_KEY: exact(PUBKEY), INTEGER: /^\d+$/, BASE58: exact(BASE58), diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 50fca302bf241de6011dca8f2117759a467ce8aa..0876235809cf4a7f5d84e528076c5c5138612067 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -141,6 +141,10 @@ export class FileDAL { } } + async getWS2Peers() { + return this.peerDAL.getPeersWithEndpointsLike('WS2P ') + } + async getBlock(number:number) { const block = await this.blockDAL.getBlock(number) return block || null; diff --git a/app/lib/dal/sqliteDAL/PeerDAL.ts b/app/lib/dal/sqliteDAL/PeerDAL.ts index 4603303423f492508b3b8b152f63a3113ae742fd..d38558fe68304cffb14d000371e70d4de94a077d 100644 --- a/app/lib/dal/sqliteDAL/PeerDAL.ts +++ b/app/lib/dal/sqliteDAL/PeerDAL.ts @@ -93,6 +93,10 @@ export class PeerDAL extends AbstractSQLite<DBPeer> { return this.sqlFindOne({ pubkey: pubkey }) } + getPeersWithEndpointsLike(str:string) { + return this.query('SELECT * FROM peer WHERE endpoints LIKE ?', ['%' + str + '%']) + } + savePeer(peer:DBPeer) { return this.saveEntity(peer) } diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index f8db265cb6db2e1f1c4385e7d6e9add1318b11b8..acaf52cdebddbde008216cc876f2c85195bcf89a 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -60,6 +60,7 @@ export interface NetworkConfDTO { export interface WS2PConfDTO { ws2p?: { + uuid: string upnp?: boolean remotehost?: string|null remoteport?: number|null @@ -68,7 +69,7 @@ export interface WS2PConfDTO { } } -export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, BranchingDTO { +export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, BranchingDTO, WS2PConfDTO { constructor( public loglevel: string, @@ -124,6 +125,14 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, public upnp: boolean, public homename: string, public memory: boolean, + public ws2p?: { + uuid: string + upnp?: boolean + remotehost?: string|null + remoteport?: number|null + port?: number + host?: string + } ) {} static mock() { diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index d6df0f8b02873fabcdec2b2bbbaade2d848bc75d..c19b4aed341130cad24f8625be74cd461848d119 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -3,6 +3,12 @@ import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {Cloneable} from "./Cloneable" +export interface WS2PEndpoint { + uuid:string + host:string + port:number +} + export class PeerDTO implements Cloneable { clone(): any { @@ -86,7 +92,22 @@ export class PeerDTO implements Cloneable { } }); return bma || {}; - }; + } + + getWS2P() { + let api:any = null; + this.endpoints.forEach((ep) => { + const matches = !api && ep.match(CommonConstants.WS2P_REGEXP) + if (matches) { + api = { + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0 + } + } + }) + return api || {} + } getDns() { const bma = this.getBMA();