Skip to content
Snippets Groups Projects
Commit 7625c2a1 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] #1084 WS2P: add WS2P handling in PeerDTO + database search

parent 3eed409d
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ const UNLOCK = "(SIG\\(" + INTEGER + "\\)|XHX\\(" + XUNLOCK + "\\))" ...@@ -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 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 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_COMPACT_TX = 100
const MAXIMUM_LEN_OF_OUTPUT = 2000 const MAXIMUM_LEN_OF_OUTPUT = 2000
...@@ -76,6 +77,7 @@ export const CommonConstants = { ...@@ -76,6 +77,7 @@ export const CommonConstants = {
SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS: 3, SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS: 3,
BMA_REGEXP, BMA_REGEXP,
WS2P_REGEXP,
PUBLIC_KEY: exact(PUBKEY), PUBLIC_KEY: exact(PUBKEY),
INTEGER: /^\d+$/, INTEGER: /^\d+$/,
BASE58: exact(BASE58), BASE58: exact(BASE58),
......
...@@ -141,6 +141,10 @@ export class FileDAL { ...@@ -141,6 +141,10 @@ export class FileDAL {
} }
} }
async getWS2Peers() {
return this.peerDAL.getPeersWithEndpointsLike('WS2P ')
}
async getBlock(number:number) { async getBlock(number:number) {
const block = await this.blockDAL.getBlock(number) const block = await this.blockDAL.getBlock(number)
return block || null; return block || null;
......
...@@ -93,6 +93,10 @@ export class PeerDAL extends AbstractSQLite<DBPeer> { ...@@ -93,6 +93,10 @@ export class PeerDAL extends AbstractSQLite<DBPeer> {
return this.sqlFindOne({ pubkey: pubkey }) return this.sqlFindOne({ pubkey: pubkey })
} }
getPeersWithEndpointsLike(str:string) {
return this.query('SELECT * FROM peer WHERE endpoints LIKE ?', ['%' + str + '%'])
}
savePeer(peer:DBPeer) { savePeer(peer:DBPeer) {
return this.saveEntity(peer) return this.saveEntity(peer)
} }
......
...@@ -60,6 +60,7 @@ export interface NetworkConfDTO { ...@@ -60,6 +60,7 @@ export interface NetworkConfDTO {
export interface WS2PConfDTO { export interface WS2PConfDTO {
ws2p?: { ws2p?: {
uuid: string
upnp?: boolean upnp?: boolean
remotehost?: string|null remotehost?: string|null
remoteport?: number|null remoteport?: number|null
...@@ -68,7 +69,7 @@ export interface WS2PConfDTO { ...@@ -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( constructor(
public loglevel: string, public loglevel: string,
...@@ -124,6 +125,14 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, ...@@ -124,6 +125,14 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
public upnp: boolean, public upnp: boolean,
public homename: string, public homename: string,
public memory: boolean, public memory: boolean,
public ws2p?: {
uuid: string
upnp?: boolean
remotehost?: string|null
remoteport?: number|null
port?: number
host?: string
}
) {} ) {}
static mock() { static mock() {
......
...@@ -3,6 +3,12 @@ import {hashf} from "../common" ...@@ -3,6 +3,12 @@ import {hashf} from "../common"
import {CommonConstants} from "../common-libs/constants" import {CommonConstants} from "../common-libs/constants"
import {Cloneable} from "./Cloneable" import {Cloneable} from "./Cloneable"
export interface WS2PEndpoint {
uuid:string
host:string
port:number
}
export class PeerDTO implements Cloneable { export class PeerDTO implements Cloneable {
clone(): any { clone(): any {
...@@ -86,7 +92,22 @@ export class PeerDTO implements Cloneable { ...@@ -86,7 +92,22 @@ export class PeerDTO implements Cloneable {
} }
}); });
return bma || {}; 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() { getDns() {
const bma = this.getBMA(); const bma = this.getBMA();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment