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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
005a8c2d
Commit
005a8c2d
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[enh] add Proxy type
parent
a94d5e41
No related branches found
No related tags found
1 merge request
!1178
Add WS2PTOR features
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/proxy.ts
+80
-0
80 additions, 0 deletions
app/lib/proxy.ts
with
80 additions
and
0 deletions
app/lib/proxy.ts
0 → 100644
+
80
−
0
View file @
005a8c2d
const
SocksProxyAgent
=
require
(
'
socks-proxy-agent
'
);
const
constants
=
require
(
'
./constants
'
);
const
WS2PConstants
=
require
(
'
../modules/ws2p/lib/constants
'
);
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
constructor
(
proxy
:
string
,
type
:
string
=
"
socks
"
)
{
if
(
type
===
"
socks
"
)
{
this
.
agent
=
SocksProxyAgent
(
"
socks://
"
+
proxy
)
}
else
{
this
.
agent
=
undefined
}
}
getAgent
()
{
return
this
.
agent
;
}
static
defaultConf
():
ProxyConf
{
return
{
proxySocksAddress
:
undefined
,
proxyTorAddress
:
undefined
,
alwaysUseTor
:
undefined
,
proxies
:
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
"
):
undefined
}
}
else
{
return
undefined
}
}
static
httpProxy
(
url
:
string
,
proxyConf
:
ProxyConf
|
undefined
)
{
return
Proxy
.
chooseProxy
(
url
,
proxyConf
,
constants
.
ONION_ENDPOINT_REGEX
)
}
static
wsProxy
(
address
:
string
,
proxyConf
:
ProxyConf
|
undefined
)
{
return
Proxy
.
chooseProxy
(
address
,
proxyConf
,
WS2PConstants
.
ONION_ENDPOINT_REGEX
)
}
private
static
chooseProxy
(
address
:
string
,
proxyConf
:
ProxyConf
|
undefined
,
onionRegex
:
RegExp
):
Proxy
|
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
.
getAgent
()
!==
undefined
&&
(
proxyConf
.
alwaysUseTor
||
address
.
match
(
onionRegex
)))
{
return
proxyConf
.
proxies
.
proxyTor
}
else
if
(
proxyConf
.
proxies
.
proxySocks
!==
undefined
&&
proxyConf
.
proxies
.
proxySocks
.
getAgent
()
!==
undefined
)
{
return
proxyConf
.
proxies
.
proxyTor
}
}
}
return
undefined
}
}
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