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
07c76637
Commit
07c76637
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[enh] add options --ws2p-prefered-only and --ws2p-privileged-only
#1181
parent
50d29e79
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/dto/ConfDTO.ts
+4
-0
4 additions, 0 deletions
app/lib/dto/ConfDTO.ts
app/modules/ws2p/index.ts
+7
-1
7 additions, 1 deletion
app/modules/ws2p/index.ts
app/modules/ws2p/lib/WS2PCluster.ts
+8
-4
8 additions, 4 deletions
app/modules/ws2p/lib/WS2PCluster.ts
with
19 additions
and
5 deletions
app/lib/dto/ConfDTO.ts
+
4
−
0
View file @
07c76637
...
...
@@ -73,7 +73,9 @@ export interface WS2PConfDTO {
maxPublic
?:
number
maxPrivate
?:
number
preferedNodes
?:
string
[]
preferedOnly
:
boolean
privilegedNodes
?:
string
[]
privilegedOnly
:
boolean
}
}
...
...
@@ -145,7 +147,9 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
port
?:
number
host
?:
string
preferedNodes
?:
string
[]
preferedOnly
:
boolean
privilegedNodes
?:
string
[]
privilegedOnly
:
boolean
maxPublic
?:
number
maxPrivate
?:
number
}
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/index.ts
+
7
−
1
View file @
07c76637
...
...
@@ -28,8 +28,10 @@ export const WS2PDependency = {
{
value
:
'
--ws2p-nopublic
'
,
desc
:
'
Disable WS2P Public access.
'
},
{
value
:
'
--ws2p-prefered-add <pubkey>
'
,
desc
:
'
Add a prefered node to connect to through private access.
'
},
{
value
:
'
--ws2p-prefered-rm <pubkey>
'
,
desc
:
'
Remove prefered node.
'
},
{
value
:
'
--ws2p-prefered-only <pubkey>
'
,
desc
:
'
Only connect to prefered node.
'
},
{
value
:
'
--ws2p-privileged-add <pubkey>
'
,
desc
:
'
Add a privileged node to for our public access.
'
},
{
value
:
'
--ws2p-privileged-rm <pubkey>
'
,
desc
:
'
Remove a privileged.
'
},
{
value
:
'
--ws2p-privileged-only <pubkey>
'
,
desc
:
'
Accept only connections from a privileged node.
'
},
],
config
:
{
...
...
@@ -39,7 +41,9 @@ export const WS2PDependency = {
conf
.
ws2p
=
conf
.
ws2p
||
{
uuid
:
nuuid
.
v4
().
slice
(
0
,
8
),
privateAccess
:
true
,
publicAccess
:
true
publicAccess
:
true
,
preferedOnly
:
false
,
privilegedOnly
:
false
}
// For config with missing value
...
...
@@ -73,6 +77,7 @@ export const WS2PDependency = {
conf
.
ws2p
.
preferedNodes
.
splice
(
index
,
1
)
}
}
if
(
program
.
ws2pPreferedOnly
!==
undefined
)
conf
.
ws2p
.
preferedOnly
=
true
// Privileged nodes
if
(
program
.
ws2pPrivilegedAdd
!==
undefined
)
{
...
...
@@ -86,6 +91,7 @@ export const WS2PDependency = {
conf
.
ws2p
.
privilegedNodes
.
splice
(
index
,
1
)
}
}
if
(
program
.
ws2pPrivilegedOnly
!==
undefined
)
conf
.
ws2p
.
privilegedOnly
=
true
// Default value
if
(
conf
.
ws2p
.
upnp
===
undefined
||
conf
.
ws2p
.
upnp
===
null
)
{
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/lib/WS2PCluster.ts
+
8
−
4
View file @
07c76637
...
...
@@ -265,7 +265,8 @@ export class WS2PCluster {
await
this
.
ws2pServer
.
close
()
}
this
.
ws2pServer
=
await
WS2PServer
.
bindOn
(
this
.
server
,
host
,
port
,
this
.
fifo
,
(
pubkey
:
string
,
connectedPubkeys
:
string
[])
=>
{
return
this
.
acceptPubkey
(
pubkey
,
connectedPubkeys
,
()
=>
this
.
servedCount
(),
this
.
maxLevel2Peers
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
privilegedNodes
||
[]))
const
privilegedNodes
=
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
privilegedNodes
)
?
this
.
server
.
conf
.
ws2p
.
privilegedNodes
:[]
return
this
.
acceptPubkey
(
pubkey
,
connectedPubkeys
,
()
=>
this
.
servedCount
(),
this
.
maxLevel2Peers
,
privilegedNodes
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
privilegedOnly
||
false
))
},
this
.
messageHandler
)
this
.
host
=
host
this
.
port
=
port
...
...
@@ -295,7 +296,8 @@ export class WS2PCluster {
const
fullEndpointAddress
=
WS2PCluster
.
getFullAddress
(
host
,
port
,
path
)
const
ws2pc
=
await
WS2PClient
.
connectTo
(
this
.
server
,
fullEndpointAddress
,
messageHandler
,
expectedPub
,
(
pub
:
string
)
=>
{
const
connectedPubkeys
=
this
.
getConnectedPubkeys
()
return
this
.
acceptPubkey
(
expectedPub
,
connectedPubkeys
,
()
=>
this
.
clientsCount
(),
this
.
maxLevel1Size
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedNodes
||
[]),
ws2pEndpointUUID
)
const
preferedNodes
=
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedNodes
)
?
this
.
server
.
conf
.
ws2p
.
preferedNodes
:[]
return
this
.
acceptPubkey
(
expectedPub
,
connectedPubkeys
,
()
=>
this
.
clientsCount
(),
this
.
maxLevel1Size
,
preferedNodes
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedOnly
)
||
false
,
ws2pEndpointUUID
)
})
this
.
ws2pClients
[
uuid
]
=
ws2pc
pub
=
ws2pc
.
connection
.
pubkey
...
...
@@ -375,7 +377,8 @@ export class WS2PCluster {
if
(
ws2pEnpoint
)
{
// Check if already connected to the pubkey (in any way: server or client)
const
connectedPubkeys
=
this
.
getConnectedPubkeys
()
const
shouldAccept
=
await
this
.
acceptPubkey
(
peer
.
pubkey
,
connectedPubkeys
,
()
=>
this
.
clientsCount
(),
this
.
maxLevel1Size
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedNodes
||
[]),
ws2pEnpoint
.
uuid
)
const
preferedNodes
=
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedNodes
)
?
this
.
server
.
conf
.
ws2p
.
preferedNodes
:[]
const
shouldAccept
=
await
this
.
acceptPubkey
(
peer
.
pubkey
,
connectedPubkeys
,
()
=>
this
.
clientsCount
(),
this
.
maxLevel1Size
,
preferedNodes
,
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
preferedOnly
)
||
false
,
ws2pEnpoint
.
uuid
)
if
(
shouldAccept
&&
(
!
this
.
server
.
conf
.
ws2p
||
ws2pEnpoint
.
uuid
!==
this
.
server
.
conf
.
ws2p
.
uuid
||
peer
.
pubkey
!==
this
.
server
.
conf
.
pair
.
pub
||
ws2pEnpoint
.
uuid
===
'
11111111
'
))
{
await
this
.
connectToRemoteWS
(
ws2pEnpoint
.
host
,
ws2pEnpoint
.
port
,
ws2pEnpoint
.
path
,
this
.
messageHandler
,
peer
.
pubkey
)
await
this
.
trimClientConnections
()
...
...
@@ -546,6 +549,7 @@ export class WS2PCluster {
getConcurrentConnexionsCount
:()
=>
number
,
maxConcurrentConnexionsSize
:
number
,
priorityKeys
:
string
[],
priorityKeysOnly
:
boolean
,
targetWS2PUID
=
""
)
{
// We do not accept banned keys
...
...
@@ -554,7 +558,7 @@ export class WS2PCluster {
return
false
}
let
accept
=
priorityKeys
.
indexOf
(
pub
)
!==
-
1
if
(
!
accept
&&
connectedPubkeys
.
indexOf
(
pub
)
===
-
1
)
{
if
(
!
accept
&&
!
priorityKeysOnly
&&
connectedPubkeys
.
indexOf
(
pub
)
===
-
1
)
{
// Do we have room?
if
(
this
.
server
.
conf
.
pair
.
pub
===
pub
&&
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
uuid
===
targetWS2PUID
)
{
accept
=
false
...
...
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