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
224b37a3
Commit
224b37a3
authored
Dec 23, 2015
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Fix: make tests pass
parent
a103ba2e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/service/PeeringService.js
+14
-14
14 additions, 14 deletions
app/service/PeeringService.js
test/integration/peerings.js
+55
-100
55 additions, 100 deletions
test/integration/peerings.js
with
69 additions
and
114 deletions
app/service/PeeringService.js
+
14
−
14
View file @
224b37a3
...
@@ -52,7 +52,7 @@ function PeeringService(server, pair, dal) {
...
@@ -52,7 +52,7 @@ function PeeringService(server, pair, dal) {
this
.
submitP
=
function
(
peering
,
eraseIfAlreadyRecorded
,
cautious
){
this
.
submitP
=
function
(
peering
,
eraseIfAlreadyRecorded
,
cautious
){
let
thePeer
=
new
Peer
(
peering
);
let
thePeer
=
new
Peer
(
peering
);
let
sp
=
thePeer
.
block
.
split
(
'
-
'
);
let
sp
=
thePeer
.
block
.
split
(
'
-
'
);
let
blockNumber
=
sp
[
0
];
let
blockNumber
=
parseInt
(
sp
[
0
]
)
;
let
blockHash
=
sp
[
1
];
let
blockHash
=
sp
[
1
];
let
sigTime
=
0
;
let
sigTime
=
0
;
let
block
;
let
block
;
...
@@ -84,7 +84,7 @@ function PeeringService(server, pair, dal) {
...
@@ -84,7 +84,7 @@ function PeeringService(server, pair, dal) {
if
(
found
){
if
(
found
){
// Already existing peer
// Already existing peer
var
sp2
=
found
.
block
.
split
(
'
-
'
);
var
sp2
=
found
.
block
.
split
(
'
-
'
);
var
previousBlockNumber
=
sp2
[
0
];
var
previousBlockNumber
=
parseInt
(
sp2
[
0
]
)
;
if
(
blockNumber
<=
previousBlockNumber
&&
!
eraseIfAlreadyRecorded
){
if
(
blockNumber
<=
previousBlockNumber
&&
!
eraseIfAlreadyRecorded
){
throw
constants
.
ERROR
.
PEER
.
ALREADY_RECORDED
;
throw
constants
.
ERROR
.
PEER
.
ALREADY_RECORDED
;
}
}
...
@@ -373,8 +373,9 @@ function PeeringService(server, pair, dal) {
...
@@ -373,8 +373,9 @@ function PeeringService(server, pair, dal) {
let
peers
=
yield
dal
.
findAllPeersNEWUPBut
([
selfPubkey
]);
let
peers
=
yield
dal
.
findAllPeersNEWUPBut
([
selfPubkey
]);
peers
=
_
.
shuffle
(
peers
);
peers
=
_
.
shuffle
(
peers
);
for
(
let
i
=
0
,
len
=
peers
.
length
;
i
<
len
;
i
++
)
{
for
(
let
i
=
0
,
len
=
peers
.
length
;
i
<
len
;
i
++
)
{
var
p
=
new
Peer
(
peers
[
i
]);
let
p
=
new
Peer
(
peers
[
i
]);
logger
.
info
(
"
Try with %s %s
"
,
p
.
getURL
(),
p
.
pubkey
.
substr
(
0
,
6
));
logger
.
info
(
"
Try with %s %s
"
,
p
.
getURL
(),
p
.
pubkey
.
substr
(
0
,
6
));
try
{
let
node
=
yield
Q
.
nfcall
(
p
.
connect
);
let
node
=
yield
Q
.
nfcall
(
p
.
connect
);
let
okUP
=
yield
processAscendingUntilNoBlock
(
p
,
node
,
current
);
let
okUP
=
yield
processAscendingUntilNoBlock
(
p
,
node
,
current
);
if
(
okUP
)
{
if
(
okUP
)
{
...
@@ -386,7 +387,6 @@ function PeeringService(server, pair, dal) {
...
@@ -386,7 +387,6 @@ function PeeringService(server, pair, dal) {
yield
processLastTen
(
p
,
node
,
nowCurrent
);
yield
processLastTen
(
p
,
node
,
nowCurrent
);
}
}
}
}
try
{
// Try to fork as a final treatment
// Try to fork as a final treatment
let
nowCurrent
=
yield
dal
.
getCurrentBlockOrNull
();
let
nowCurrent
=
yield
dal
.
getCurrentBlockOrNull
();
yield
server
.
BlockchainService
.
tryToFork
(
nowCurrent
);
yield
server
.
BlockchainService
.
tryToFork
(
nowCurrent
);
...
...
This diff is collapsed.
Click to expand it.
test/integration/peerings.js
+
55
−
100
View file @
224b37a3
"
use strict
"
;
"
use strict
"
;
var
co
=
require
(
'
co
'
);
var
Q
=
require
(
'
q
'
);
var
Q
=
require
(
'
q
'
);
var
_
=
require
(
'
underscore
'
);
var
_
=
require
(
'
underscore
'
);
var
should
=
require
(
'
should
'
);
var
should
=
require
(
'
should
'
);
...
@@ -102,105 +103,59 @@ describe("Network", function() {
...
@@ -102,105 +103,59 @@ describe("Network", function() {
},
Q
())
},
Q
())
.
then
(
function
(){
.
then
(
function
(){
return
co
(
function
*
()
{
nodeS1
=
vucoin_p
(
'
127.0.0.1
'
,
s1
.
conf
.
port
);
nodeS1
=
vucoin_p
(
'
127.0.0.1
'
,
s1
.
conf
.
port
);
nodeS2
=
vucoin_p
(
'
127.0.0.1
'
,
s2
.
conf
.
port
);
nodeS2
=
vucoin_p
(
'
127.0.0.1
'
,
s2
.
conf
.
port
);
nodeS3
=
vucoin_p
(
'
127.0.0.1
'
,
s3
.
conf
.
port
);
nodeS3
=
vucoin_p
(
'
127.0.0.1
'
,
s3
.
conf
.
port
);
// Server 1
// Server 1
return
Q
()
yield
cat
.
selfCertPromise
(
now
);
.
then
(
function
()
{
yield
toc
.
selfCertPromise
(
now
);
return
cat
.
selfCertPromise
(
now
);
yield
tic
.
selfCertPromise
(
now
);
})
yield
toc
.
certPromise
(
cat
);
.
then
(
function
()
{
yield
cat
.
certPromise
(
toc
);
return
toc
.
selfCertPromise
(
now
);
yield
cat
.
certPromise
(
tic
);
})
yield
cat
.
joinPromise
();
.
then
(
function
()
{
yield
toc
.
joinPromise
();
return
tic
.
selfCertPromise
(
now
);
yield
tic
.
joinPromise
();
})
yield
commitS1
();
.
then
(
_
.
partial
(
toc
.
certPromise
,
cat
))
.
then
(
_
.
partial
(
cat
.
certPromise
,
toc
))
.
then
(
_
.
partial
(
cat
.
certPromise
,
tic
))
.
then
(
cat
.
joinPromise
)
.
then
(
toc
.
joinPromise
)
.
then
(
tic
.
joinPromise
)
.
then
(
commitS1
);
})
.
then
(
function
(){
return
Q
()
.
then
(
function
(){
// Server 2 syncs block 0
// Server 2 syncs block 0
return
sync
(
0
,
0
,
s1
,
s2
);
yield
sync
(
0
,
0
,
s1
,
s2
);
})
.
then
(
function
(){
// Server 3 syncs block 0
// Server 3 syncs block 0
return
sync
(
0
,
0
,
s1
,
s3
);
yield
sync
(
0
,
0
,
s1
,
s3
);
})
yield
nodeS1
.
getPeer
().
then
((
peer
)
=>
nodeS2
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
()));
.
then
(
function
(){
yield
nodeS2
.
getPeer
().
then
((
peer
)
=>
nodeS1
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
()));
return
nodeS1
.
getPeer
().
then
(
function
(
peer
)
{
yield
nodeS3
.
getPeer
().
then
((
peer
)
=>
nodeS1
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
()));
return
nodeS2
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
());
yield
commitS1
();
});
yield
[
})
.
then
(
function
(){
return
nodeS2
.
getPeer
().
then
(
function
(
peer
)
{
return
nodeS1
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
());
});
})
.
then
(
function
(){
return
nodeS3
.
getPeer
().
then
(
function
(
peer
)
{
return
nodeS1
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
());
});
})
.
then
(
commitS1
)
.
then
(
function
(){
return
Q
.
all
([
until
(
s2
,
'
block
'
,
1
),
until
(
s2
,
'
block
'
,
1
),
until
(
s3
,
'
block
'
,
1
)
until
(
s3
,
'
block
'
,
1
)
]);
];
})
.
then
(
function
(){
// A block was successfully spread accross the network
// A block was successfully spread accross the network
s2
.
bma
.
closeConnections
();
s2
.
bma
.
closeConnections
();
})
yield
commitS1
();
.
then
(
commitS1
)
yield
[
.
then
(
function
(){
return
Q
.
all
([
until
(
s3
,
'
block
'
,
1
)
until
(
s3
,
'
block
'
,
1
)
]);
];
})
.
then
(
function
(){
s2
.
bma
.
reopenConnections
();
s2
.
bma
.
reopenConnections
();
// Server 2 syncs block number 2 (it did not have it)
// Server 2 syncs block number 2 (it did not have it)
return
sync
(
2
,
2
,
s1
,
s2
);
yield
sync
(
2
,
2
,
s1
,
s2
);
})
yield
s2
.
recomputeSelfPeer
();
.
then
(
function
(){
yield
[
return
s2
.
recomputeSelfPeer
();
})
.
then
(
function
(){
return
nodeS2
.
getPeer
().
then
(
function
(
peer
)
{
return
nodeS1
.
postPeer
(
new
Peer
(
peer
).
getRawSigned
());
});
})
.
then
(
function
(){
return
Q
.
all
([
until
(
s2
,
'
block
'
,
2
),
until
(
s2
,
'
block
'
,
2
),
until
(
s3
,
'
block
'
,
2
),
until
(
s3
,
'
block
'
,
2
),
commitS1
()
commitS1
()
.
then
(
commitS1
)
.
then
(
commitS1
)
]);
];
})
yield
commitS3
();
.
then
(
commitS3
)
yield
[
.
then
(
function
(){
return
Q
.
all
([
until
(
s1
,
'
block
'
,
1
),
until
(
s1
,
'
block
'
,
1
),
until
(
s2
,
'
block
'
,
1
)
until
(
s2
,
'
block
'
,
1
)
]);
];
})
yield
commitS2
();
.
then
(
commitS2
)
yield
[
.
then
(
function
(){
return
Q
.
all
([
until
(
s1
,
'
block
'
,
1
),
until
(
s1
,
'
block
'
,
1
),
until
(
s3
,
'
block
'
,
1
)
until
(
s3
,
'
block
'
,
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
sign in
to comment