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

proxy attribute re-encapsulation

parent 02883fa2
No related branches found
No related tags found
1 merge request!1178Add WS2PTOR features
const SocksProxyAgent = require('socks-proxy-agent'); const SocksProxyAgent = require('socks-proxy-agent');
const constants = require('./constants');
const WS2PConstants = require('../modules/ws2p/lib/constants');
const DEFAULT_PROXY_TIMEOUT:number = 30000 const DEFAULT_PROXY_TIMEOUT:number = 30000
const TOR_PROXY_TIMEOUT:number = 60000 const TOR_PROXY_TIMEOUT:number = 60000
const HTTP_ENDPOINT_ONION_REGEX = new RegExp('(?:https?:\/\/)?(?:www)?(\S*?\.onion)(\/[-\w]*)*') const HTTP_ENDPOINT_ONION_REGEX = new RegExp('(?:https?:\/\/)?(?:www)?(\S*?\.onion)(\/[-\w]*)*')
...@@ -21,25 +18,32 @@ export interface ProxyConf { ...@@ -21,25 +18,32 @@ export interface ProxyConf {
} }
export class Proxy { export class Proxy {
public agent: any private agent: any
private url:string private url:string
constructor(proxy:string, type:string = "socks", public timeout:number = DEFAULT_PROXY_TIMEOUT) { constructor(proxy:string, type:string = "socks", private timeout:number = DEFAULT_PROXY_TIMEOUT) {
if (type === "socks") { if (type === "socks") {
this.agent = SocksProxyAgent("socks://"+proxy) this.agent = SocksProxyAgent("socks://"+proxy)
this.url = "socks://"+proxy this.url = "socks://"+proxy
} }
else { else {
this.url = ""
this.agent = undefined this.agent = undefined
this.url = ""
} }
this.timeout = timeout }
getAgent() {
return this.agent;
} }
getUrl() { getUrl() {
return this.url; return this.url;
} }
getTimeout() {
return this.timeout;
}
static defaultConf():ProxyConf { static defaultConf():ProxyConf {
return { return {
proxySocksAddress: undefined, proxySocksAddress: undefined,
......
...@@ -279,11 +279,11 @@ export class WS2PConnection { ...@@ -279,11 +279,11 @@ export class WS2PConnection {
expectedPub:string = "") { expectedPub:string = "") {
if (proxy !== undefined) { if (proxy !== undefined) {
options = { options = {
connectionTimeout: proxy.timeout, connectionTimeout: proxy.getTimeout(),
requestTimeout: proxy.timeout requestTimeout: proxy.getTimeout()
} }
} }
const websocket = (proxy !== undefined) ? new ws(address, { agent: proxy.agent }):new ws(address) const websocket = (proxy !== undefined) ? new ws(address, { agent: proxy.getAgent() }):new ws(address)
const onWsOpened:Promise<void> = new Promise(res => { const onWsOpened:Promise<void> = new Promise(res => {
websocket.on('open', () => res()) websocket.on('open', () => res())
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment