Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
89a716bf
Commit
89a716bf
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
rewrite proxiesConf type
parent
8198ed46
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1178
Add WS2PTOR features
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/proxy.ts
+24
-80
24 additions, 80 deletions
app/lib/proxy.ts
index.ts
+2
-2
2 additions, 2 deletions
index.ts
server.ts
+2
-2
2 additions, 2 deletions
server.ts
with
28 additions
and
84 deletions
app/lib/proxy.ts
+
24
−
80
View file @
89a716bf
const
SocksProxyAgent
=
require
(
'
socks-proxy-agent
'
);
const
DEFAULT_PROXY_TIMEOUT
:
number
=
30000
const
TOR_PROXY_TIMEOUT
:
number
=
60000
const
HTTP_ENDPOINT_ONION_REGEX
=
new
RegExp
(
'
(?:https?:
\
/
\
/)?(?:www)?(
\
S*?
\
.onion)(
\
/[-
\
w]*)*
'
)
const
WS_ENDPOINT_ONION_REGEX
=
new
RegExp
(
'
(?:wss?:
\
/
\
/)?(?:www)?(
\
S*?
\
.onion)(
\
/[-
\
w]*)*
'
)
const
HOST_ONION_REGEX
=
new
RegExp
(
'
(
\
S*?
\
.onion)$
'
);
const
WS_ENDPOINT_ONION_REGEX
=
new
RegExp
(
'
(?:wss?:
\
/
\
/)?(?:www)?(
\
S*?
\
.onion)(
\
/[-
\
w]*)*
'
);
export
interface
Proxies
{
proxySocks
:
Proxy
|
undefined
,
proxyTor
:
Proxy
|
undefined
}
export
interface
ProxyConf
{
proxySocksAddress
:
string
|
undefined
,
proxyTorAddress
:
string
|
undefined
,
alwaysUseTor
:
boolean
|
undefined
,
proxies
:
Proxies
|
undefined
}
export
class
Proxy
{
private
agent
:
any
private
url
:
string
constructor
(
proxy
:
string
,
type
:
string
=
"
socks
"
,
private
timeout
:
number
=
DEFAULT_PROXY_TIMEOUT
)
{
if
(
type
===
"
socks
"
)
{
this
.
agent
=
SocksProxyAgent
(
"
socks://
"
+
proxy
)
this
.
url
=
"
socks://
"
+
proxy
}
else
{
this
.
agent
=
undefined
this
.
url
=
""
}
}
getAgent
()
{
return
this
.
agent
;
}
getUrl
()
{
return
this
.
url
;
}
export
class
ProxiesConf
{
public
proxySocksAddress
:
string
|
undefined
public
proxyTorAddress
:
string
|
undefined
public
alwaysUseTor
:
boolean
|
undefined
getTimeout
()
{
return
this
.
timeout
;
constructor
()
{
this
.
proxySocksAddress
=
undefined
this
.
proxyTorAddress
=
undefined
this
.
alwaysUseTor
=
undefined
}
static
defaultConf
():
ProxyConf
{
return
{
proxySocksAddress
:
undefined
,
proxyTorAddress
:
undefined
,
alwaysUseTor
:
undefined
,
proxies
:
undefined
}
}
static
canReachTorEndpoint
(
proxyConf
:
ProxyConf
|
undefined
):
boolean
{
return
(
proxyConf
!==
undefined
&&
(
proxyConf
.
alwaysUseTor
===
true
||
(
proxyConf
.
proxies
!==
undefined
&&
proxyConf
.
proxies
.
proxyTor
!==
undefined
)
)
)
}
static
createProxies
(
proxyConf
:
ProxyConf
|
undefined
)
:
Proxies
|
undefined
{
if
(
proxyConf
!==
undefined
)
{
return
{
proxySocks
:
(
proxyConf
.
proxySocksAddress
!==
undefined
)
?
new
Proxy
(
proxyConf
.
proxySocksAddress
,
"
socks
"
):
undefined
,
proxyTor
:
(
proxyConf
.
proxyTorAddress
!==
undefined
)
?
new
Proxy
(
proxyConf
.
proxyTorAddress
,
"
socks
"
,
TOR_PROXY_TIMEOUT
):
undefined
}
}
else
{
return
undefined
}
static
canReachTorEndpoint
(
proxyConf
:
ProxiesConf
|
undefined
):
boolean
{
return
(
proxyConf
!==
undefined
&&
(
proxyConf
.
alwaysUseTor
===
true
||
(
proxyConf
.
proxyTorAddress
!==
undefined
)
)
)
}
static
httpProxy
(
url
:
string
,
proxyConf
:
Prox
y
Conf
|
undefined
)
{
return
Prox
y
.
chooseProxy
(
url
,
proxyConf
,
H
TTP_ENDPOIN
T_ONION_REGEX
)
static
httpProxy
(
url
:
string
,
proxyConf
:
Prox
ies
Conf
|
undefined
)
:
string
|
undefined
{
return
Prox
iesConf
.
chooseProxy
Agent
(
url
,
proxyConf
,
H
OS
T_ONION_REGEX
)
}
static
wsProxy
(
address
:
string
,
proxyConf
:
Prox
y
Conf
|
undefined
,
mySelf
:
boolean
=
false
)
{
return
Prox
y
.
chooseProxy
(
address
,
proxyConf
,
WS_ENDPOINT_ONION_REGEX
,
mySelf
)
static
wsProxy
(
address
:
string
,
proxyConf
:
Prox
ies
Conf
|
undefined
):
string
|
undefined
{
return
Prox
iesConf
.
chooseProxy
Agent
(
address
,
proxyConf
,
WS_ENDPOINT_ONION_REGEX
)
}
private
static
chooseProxy
(
address
:
string
,
proxyConf
:
Prox
y
Conf
|
undefined
,
onionRegex
:
RegExp
,
mySelf
:
boolean
=
false
):
Proxy
|
undefined
{
private
static
chooseProxy
Agent
(
address
:
string
,
proxyConf
:
Prox
ies
Conf
|
undefined
,
onionRegex
:
RegExp
):
string
|
undefined
{
if
(
proxyConf
!==
undefined
)
{
if
(
proxyConf
.
proxies
===
undefined
)
{
proxyConf
.
proxies
=
Proxy
.
createProxies
(
proxyConf
)
}
if
(
proxyConf
.
proxies
!==
undefined
)
{
if
(
proxyConf
.
proxies
.
proxyTor
!==
undefined
&&
proxyConf
.
proxies
.
proxyTor
.
agent
!==
undefined
&&
(
proxyConf
.
alwaysUseTor
||
address
.
match
(
onionRegex
))
&&
!
mySelf
)
if
(
proxyConf
.
proxyTorAddress
!==
undefined
&&
(
proxyConf
.
alwaysUseTor
||
address
.
match
(
onionRegex
)))
{
return
proxyConf
.
proxies
.
proxyTor
}
else
if
(
proxyConf
.
proxies
.
proxySocks
!==
undefined
&&
proxyConf
.
proxies
.
proxySocks
.
agent
!==
undefined
)
{
return
proxyConf
.
proxies
.
proxySocks
return
proxyConf
.
proxyTorAddress
}
else
if
(
proxyConf
.
proxySocksAddress
!==
undefined
)
{
return
proxyConf
.
proxySocksAddress
}
}
return
undefined
...
...
This diff is collapsed.
Click to expand it.
index.ts
+
2
−
2
View file @
89a716bf
...
...
@@ -8,7 +8,7 @@ import {CrawlerDependency} from "./app/modules/crawler/index"
import
{
BmaDependency
}
from
"
./app/modules/bma/index
"
import
{
WS2PDependency
}
from
"
./app/modules/ws2p/index
"
import
{
Constants
}
from
"
./app/modules/prover/lib/constants
"
import
{
Prox
y
}
from
'
./app/lib/proxy
'
;
import
{
Prox
iesConf
}
from
'
./app/lib/proxy
'
;
const
path
=
require
(
'
path
'
);
const
_
=
require
(
'
underscore
'
);
...
...
@@ -469,7 +469,7 @@ function commandLineConf(program:any, conf:any = {}) {
// Declare proxyConf
if
(
cli
.
proxies
.
proxySocks
||
cli
.
proxies
.
proxyTor
||
cli
.
proxies
.
torAlways
||
cli
.
proxies
.
torMixed
||
cli
.
proxies
.
rmProxies
)
{
conf
.
proxyConf
=
Proxy
.
default
Conf
()
conf
.
proxyConf
=
new
Proxies
Conf
()
}
// Update conf
...
...
This diff is collapsed.
Click to expand it.
server.ts
+
2
−
2
View file @
89a716bf
...
...
@@ -24,7 +24,7 @@ import {PeerDTO} from "./app/lib/dto/PeerDTO"
import
{
OtherConstants
}
from
"
./app/lib/other_constants
"
import
{
WS2PCluster
}
from
"
./app/modules/ws2p/lib/WS2PCluster
"
import
{
DBBlock
}
from
"
./app/lib/db/DBBlock
"
import
{
Prox
y
}
from
'
./app/lib/proxy
'
;
import
{
Prox
iesConf
}
from
'
./app/lib/proxy
'
;
export
interface
HookableServer
{
generatorGetJoinData
:
(...
args
:
any
[])
=>
Promise
<
any
>
...
...
@@ -149,7 +149,7 @@ export class Server extends stream.Duplex implements HookableServer {
logger
.
debug
(
'
Loading conf...
'
);
this
.
conf
=
await
this
.
dal
.
loadConf
(
this
.
overrideConf
,
useDefaultConf
)
// Default values
this
.
conf
.
proxyConf
=
this
.
conf
.
proxyConf
===
undefined
?
Proxy
.
default
Conf
()
:
this
.
conf
.
proxyConf
this
.
conf
.
proxyConf
=
this
.
conf
.
proxyConf
===
undefined
?
new
Proxies
Conf
()
:
this
.
conf
.
proxyConf
this
.
conf
.
proxyConf
.
alwaysUseTor
=
this
.
conf
.
proxyConf
.
alwaysUseTor
===
undefined
?
false
:
this
.
conf
.
proxyConf
.
alwaysUseTor
this
.
conf
.
remoteipv6
=
this
.
conf
.
remoteipv6
===
undefined
?
this
.
conf
.
ipv6
:
this
.
conf
.
remoteipv6
this
.
conf
.
remoteport
=
this
.
conf
.
remoteport
===
undefined
?
this
.
conf
.
port
:
this
.
conf
.
remoteport
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment