Commit 3e117452 authored by Éloïs's avatar Éloïs
Browse files

proxy attribute re-encapsulation

parent 02883fa2
const SocksProxyAgent = require('socks-proxy-agent');
const constants = require('./constants');
const WS2PConstants = require('../modules/ws2p/lib/constants');
const DEFAULT_PROXY_TIMEOUT:number = 30000
const TOR_PROXY_TIMEOUT:number = 60000
const HTTP_ENDPOINT_ONION_REGEX = new RegExp('(?:https?:\/\/)?(?:www)?(\S*?\.onion)(\/[-\w]*)*')
......@@ -21,25 +18,32 @@ export interface ProxyConf {
}
export class Proxy {
public agent: any
private agent: any
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") {
this.agent = SocksProxyAgent("socks://"+proxy)
this.url = "socks://"+proxy
this.agent = SocksProxyAgent("socks://"+proxy)
this.url = "socks://"+proxy
}
else {
this.url = ""
this.agent = undefined
this.agent = undefined
this.url = ""
}
this.timeout = timeout
}
getAgent() {
return this.agent;
}
getUrl() {
return this.url;
}
getTimeout() {
return this.timeout;
}
static defaultConf():ProxyConf {
return {
proxySocksAddress: undefined,
......
......@@ -279,11 +279,11 @@ export class WS2PConnection {
expectedPub:string = "") {
if (proxy !== undefined) {
options = {
connectionTimeout: proxy.timeout,
requestTimeout: proxy.timeout
connectionTimeout: proxy.getTimeout(),
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 => {
websocket.on('open', () => res())
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment