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
414c5ece
Commit
414c5ece
authored
7 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#1135
Never allow to loose all the WS2P connections
parent
68087678
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/modules/ws2p/lib/WS2PCluster.ts
+89
-65
89 additions, 65 deletions
app/modules/ws2p/lib/WS2PCluster.ts
app/modules/ws2p/lib/constants.ts
+1
-0
1 addition, 0 deletions
app/modules/ws2p/lib/constants.ts
test/integration/ws2p_heads.ts
+5
-3
5 additions, 3 deletions
test/integration/ws2p_heads.ts
with
95 additions
and
68 deletions
app/modules/ws2p/lib/WS2PCluster.ts
+
89
−
65
View file @
414c5ece
...
@@ -100,6 +100,7 @@ export class WS2PCluster {
...
@@ -100,6 +100,7 @@ export class WS2PCluster {
async
headsReceived
(
heads
:[{
message
:
string
,
sig
:
string
}])
{
async
headsReceived
(
heads
:[{
message
:
string
,
sig
:
string
}])
{
const
added
:{
message
:
string
,
sig
:
string
}[]
=
[]
const
added
:{
message
:
string
,
sig
:
string
}[]
=
[]
await
Promise
.
all
(
heads
.
map
(
async
(
h
:{
message
:
string
,
sig
:
string
})
=>
{
await
Promise
.
all
(
heads
.
map
(
async
(
h
:{
message
:
string
,
sig
:
string
})
=>
{
try
{
const
message
=
h
.
message
const
message
=
h
.
message
const
sig
=
h
.
sig
const
sig
=
h
.
sig
if
(
!
message
)
{
if
(
!
message
)
{
...
@@ -178,6 +179,9 @@ export class WS2PCluster {
...
@@ -178,6 +179,9 @@ export class WS2PCluster {
throw
"
HEAD_MESSAGE_WRONGLY_SIGNED
"
throw
"
HEAD_MESSAGE_WRONGLY_SIGNED
"
}
}
}
}
}
catch
(
e
)
{
this
.
server
.
logger
.
trace
(
e
)
}
}))
}))
this
.
server
.
push
({
this
.
server
.
push
({
ws2p
:
'
heads
'
,
ws2p
:
'
heads
'
,
...
@@ -339,6 +343,10 @@ export class WS2PCluster {
...
@@ -339,6 +343,10 @@ export class WS2PCluster {
// Trim the eventual extra connections
// Trim the eventual extra connections
setTimeout
(()
=>
this
.
trimClientConnections
(),
WS2PConstants
.
CONNEXION_TIMEOUT
)
setTimeout
(()
=>
this
.
trimClientConnections
(),
WS2PConstants
.
CONNEXION_TIMEOUT
)
}
}
}
listenServerFlow
()
{
let
connectingToNodesByFlow
=
false
// Also listen for network updates, and connect to new nodes
// Also listen for network updates, and connect to new nodes
this
.
server
.
pipe
(
es
.
mapSync
((
data
:
any
)
=>
{
this
.
server
.
pipe
(
es
.
mapSync
((
data
:
any
)
=>
{
...
@@ -375,6 +383,21 @@ export class WS2PCluster {
...
@@ -375,6 +383,21 @@ export class WS2PCluster {
this
.
server
.
logger
.
warn
(
e
)
this
.
server
.
logger
.
warn
(
e
)
}
}
}
}
// WS2P disconnection
else
if
(
data
.
ws2p
===
'
disconnected
'
)
{
const
nbConnections
=
this
.
getAllConnections
().
length
if
(
nbConnections
<
WS2PConstants
.
CONNECTIONS_LOW_LEVEL
&&
!
connectingToNodesByFlow
)
{
try
{
connectingToNodesByFlow
=
true
await
this
.
connectToWS2Peers
()
}
catch
(
e
)
{
throw
e
}
finally
{
connectingToNodesByFlow
=
false
}
}
}
})()
})()
return
data
return
data
...
@@ -594,6 +617,7 @@ export class WS2PCluster {
...
@@ -594,6 +617,7 @@ export class WS2PCluster {
// Pull blocks right on start
// Pull blocks right on start
const
init
=
async
()
=>
{
const
init
=
async
()
=>
{
try
{
try
{
await
this
.
listenServerFlow
()
await
this
.
connectToWS2Peers
()
await
this
.
connectToWS2Peers
()
await
this
.
pullBlocks
()
await
this
.
pullBlocks
()
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/lib/constants.ts
+
1
−
0
View file @
414c5ece
...
@@ -15,6 +15,7 @@ export const WS2PConstants = {
...
@@ -15,6 +15,7 @@ export const WS2PConstants = {
MAX_LEVEL_1_PEERS
:
10
,
MAX_LEVEL_1_PEERS
:
10
,
MAX_LEVEL_2_PEERS
:
10
,
MAX_LEVEL_2_PEERS
:
10
,
CONNECTIONS_LOW_LEVEL
:
3
,
BAN_DURATION_IN_SECONDS
:
120
,
BAN_DURATION_IN_SECONDS
:
120
,
ERROR_RECALL_DURATION_IN_SECONDS
:
60
,
ERROR_RECALL_DURATION_IN_SECONDS
:
60
,
...
...
This diff is collapsed.
Click to expand it.
test/integration/ws2p_heads.ts
+
5
−
3
View file @
414c5ece
...
@@ -82,10 +82,12 @@ describe("WS2P heads propagation", function() {
...
@@ -82,10 +82,12 @@ describe("WS2P heads propagation", function() {
})
})
})
})
it
(
'
should be able to
connect to s3 if the we increase size limit
'
,
async
()
=>
{
it
(
'
should be able to
receive HEADs
'
,
async
()
=>
{
b3
=
s1
.
commit
({
time
:
now
})
b3
=
s1
.
commit
({
time
:
now
})
await
s2
.
waitToHaveBlock
(
3
)
await
Promise
.
all
([
await
s2
.
waitForHeads
(
1
)
s2
.
waitToHaveBlock
(
3
),
s2
.
waitForHeads
(
1
)
])
await
s1
.
expect
(
'
/network/ws2p/info
'
,
(
res
:
any
)
=>
{
await
s1
.
expect
(
'
/network/ws2p/info
'
,
(
res
:
any
)
=>
{
assert
.
equal
(
res
.
peers
.
level1
,
0
)
assert
.
equal
(
res
.
peers
.
level1
,
0
)
assert
.
equal
(
res
.
peers
.
level2
,
1
)
assert
.
equal
(
res
.
peers
.
level2
,
1
)
...
...
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