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
b5d5f811
Commit
b5d5f811
authored
10 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Add generate-newcomers-auto command
parent
c4cb098a
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/models/key.js
+2
-2
2 additions, 2 deletions
app/models/key.js
app/service/KeychainService.js
+187
-100
187 additions, 100 deletions
app/service/KeychainService.js
bin/ucoind
+5
-0
5 additions, 0 deletions
bin/ucoind
with
194 additions
and
102 deletions
app/models/key.js
+
2
−
2
View file @
b5d5f811
...
...
@@ -119,9 +119,9 @@ KeySchema.statics.getMembers = function(done){
Key
.
find
({
member
:
true
},
done
);
};
KeySchema
.
statics
.
findWhereSignatory
=
function
(
signatory
,
done
){
KeySchema
.
statics
.
find
Members
WhereSignatory
=
function
(
signatory
,
done
){
var
Key
=
this
.
model
(
'
Key
'
);
Key
.
find
({
signatories
:
new
RegExp
(
signatory
.
substring
(
24
)
+
'
$
'
)
},
done
);
Key
.
find
({
member
:
true
,
signatories
:
new
RegExp
(
signatory
.
substring
(
24
)
+
'
$
'
)
},
done
);
};
KeySchema
.
statics
.
addMember
=
function
(
fingerprint
,
done
){
...
...
This diff is collapsed.
Click to expand it.
app/service/KeychainService.js
+
187
−
100
View file @
b5d5f811
...
...
@@ -990,11 +990,78 @@ function KeyService (conn, conf, PublicKeyService) {
};
/**
* Generate the "pulse" keyblock: the #1 keyblock (following the root keyblock) avoiding WoT collapsing
this.generateNewcomers = function (done) {
* Generate a "newcomers" keyblock
*/
this
.
generateNewcomers
=
function
(
done
)
{
var
filteringFunc
=
function
(
preJoinData
,
next
)
{
var
joinData
=
{};
var
newcomers
=
_
(
preJoinData
).
keys
();
var
uids
=
[];
newcomers
.
forEach
(
function
(
newcomer
){
uids
.
push
(
preJoinData
[
newcomer
].
ms
.
userid
);
});
if
(
newcomers
.
length
>
0
)
{
inquirer
.
prompt
([{
type
:
"
checkbox
"
,
name
:
"
uids
"
,
message
:
"
Newcomers to add
"
,
choices
:
uids
,
default
:
uids
[
0
]
}],
function
(
answers
)
{
newcomers
.
forEach
(
function
(
newcomer
){
if
(
~
answers
.
uids
.
indexOf
(
preJoinData
[
newcomer
].
ms
.
userid
))
joinData
[
newcomer
]
=
preJoinData
[
newcomer
];
});
if
(
answers
.
uids
.
length
==
0
)
next
(
'
No newcomer selected
'
);
else
next
(
null
,
joinData
);
});
}
else
{
next
(
'
No newcomer found
'
);
}
};
var
checkingWoTFunc
=
function
(
newcomers
,
checkWoTForNewcomers
,
done
)
{
checkWoTForNewcomers
(
newcomers
,
function
(
err
)
{
// If success, simply add all newcomers. Otherwise, stop everything.
done
(
err
,
newcomers
);
});
};
KeychainService
.
generateNewcomersBlock
(
filteringFunc
,
checkingWoTFunc
,
done
);
}
/**
this.generateNewcomers = function (done) {
* Generate a "newcomers" keyblock
*/
this
.
generateNewcomersAuto
=
function
(
done
)
{
var
filtering
=
function
(
preJoinData
,
next
)
{
// No manual filtering, takes all
next
(
null
,
preJoinData
);
};
var
checking
=
function
(
newcomers
,
checkWoTForNewcomers
,
done
)
{
var
passingNewcomers
=
[];
async
.
forEachSeries
(
newcomers
,
function
(
newcomer
,
callback
){
checkWoTForNewcomers
(
passingNewcomers
.
concat
(
newcomer
),
function
(
err
)
{
// If success, add this newcomer to the valid newcomers. Otherwise, reject him.
if
(
!
err
)
passingNewcomers
.
push
(
newcomer
);
callback
();
});
},
function
(){
done
(
null
,
passingNewcomers
);
});
}
KeychainService
.
generateNewcomersBlock
(
filtering
,
checking
,
done
);
}
/**
* Generate a "newcomers" keyblock
*/
this
.
generateNewcomersBlock
=
function
(
filteringFunc
,
checkingWoTFunc
,
done
)
{
// 1. See available keychanges
var
m
embers
=
[];
var
wotM
embers
=
[];
var
preJoinData
=
{};
var
joinData
=
{};
var
updates
=
{};
...
...
@@ -1049,112 +1116,130 @@ function KeyService (conn, conf, PublicKeyService) {
},
next
);
},
function
(
next
){
var
newcomers
=
_
(
preJoinData
).
keys
();
var
uids
=
[];
newcomers
.
forEach
(
function
(
newcomer
){
uids
.
push
(
preJoinData
[
newcomer
].
ms
.
userid
);
});
if
(
newcomers
.
length
>
0
)
{
inquirer
.
prompt
([{
type
:
"
checkbox
"
,
name
:
"
uids
"
,
message
:
"
Newcomers to add
"
,
choices
:
uids
,
default
:
uids
[
0
]
}],
function
(
answers
)
{
newcomers
.
forEach
(
function
(
newcomer
){
if
(
~
answers
.
uids
.
indexOf
(
preJoinData
[
newcomer
].
ms
.
userid
))
joinData
[
newcomer
]
=
preJoinData
[
newcomer
];
});
if
(
answers
.
uids
.
length
==
0
)
next
(
'
No newcomer selected
'
);
else
next
();
});
}
else
{
next
(
'
No newcomer found
'
);
}
filteringFunc
(
preJoinData
,
next
);
},
function
(
next
)
{
function
(
filteredJoinData
,
next
)
{
joinData
=
filteredJoinData
;
// Cache the members
Key
.
getMembers
(
next
);
},
function
(
membersKeys
,
next
)
{
membersKeys
.
forEach
(
function
(
mKey
)
{
wotMembers
.
push
(
mKey
.
fingerprint
);
});
// Look for signatures from newcomers to the WoT
async
.
forEach
(
_
(
joinData
).
keys
(),
function
(
newcomer
,
searchedSignaturesOfTheWoT
){
async
.
waterfall
([
function
(
next
){
Key
.
findWhereSignatory
(
newcomer
,
next
);
},
function
(
keys
,
next
){
async
.
forEach
(
keys
,
function
(
signedKey
,
extractedSignatures
){
async
.
waterfall
([
function
(
next
){
async
.
parallel
({
trusted
:
function
(
callback
){
TrustedKey
.
getTheOne
(
signedKey
.
fingerprint
,
callback
);
},
pubkey
:
function
(
callback
){
PublicKey
.
getTheOne
(
signedKey
.
fingerprint
,
callback
);
},
},
next
);
},
function
(
res
,
next
){
var
key
=
keyhelper
.
fromArmored
(
res
.
pubkey
.
raw
);
var
certifs
=
key
.
getCertificationsFromSignatory
(
newcomer
);
if
(
certifs
.
length
>
0
)
{
updates
[
res
.
pubkey
.
fingerprint
]
=
certifs
;
certifs
.
forEach
(
function
(){
logger
.
debug
(
'
Found WoT certif %s --> %s
'
,
newcomer
,
res
.
pubkey
.
fingerprint
);
findSignaturesFromNewcomerToWoT
(
newcomer
,
function
(
err
,
signatures
)
{
_
(
signatures
).
keys
().
forEach
(
function
(
signedMember
){
updates
[
signedMember
]
=
(
updates
[
signedMember
]
||
new
openpgp
.
packet
.
List
());
updates
[
signedMember
].
concat
(
signatures
[
signedMember
]);
});
}
next
();
},
],
function
()
{
extractedSignatures
();
searchedSignaturesOfTheWoT
(
err
);
});
},
next
);
},
],
searchedSignaturesOfTheWoT
);
},
next
);
},
function
(
next
)
{
Key
.
getMembers
(
next
);
},
function
(
membersKeys
,
next
)
{
// Checking step
var
newcomers
=
_
(
joinData
).
keys
();
// Checking algo is defined by 'checkingWoTFunc'
checkingWoTFunc
(
newcomers
,
function
(
theNewcomers
,
onceChecked
)
{
var
members
=
wotMembers
.
slice
();
// Concats the joining members
var
members
=
[];
membersKeys
.
forEach
(
function
(
mKey
)
{
members
.
push
(
mKey
.
fingerprint
);
});
_
(
joinData
).
keys
().
forEach
(
function
(
fpr
)
{
theNewcomers
.
forEach
(
function
(
fpr
)
{
members
.
push
(
fpr
);
});
// Check WoT stability
var
membersChanges
=
[];
var
newLinks
=
{};
var
error
;
_
(
joinData
).
keys
().
forEach
(
function
(
fpr
)
{
membersChanges
.
push
(
'
+
'
+
fpr
);
newLinks
[
fpr
]
=
[];
var
certifs
=
joinData
[
fpr
].
key
.
getOtherCertifications
();
// Cache new links from WoT => newcomer
theNewcomers
.
forEach
(
function
(
newcomer
)
{
membersChanges
.
push
(
'
+
'
+
newcomer
);
newLinks
[
newcomer
]
=
[];
var
certifs
=
joinData
[
newcomer
].
key
.
getOtherCertifications
();
certifs
.
forEach
(
function
(
certif
)
{
var
issuer
=
certif
.
issuerKeyId
.
toHex
().
toUpperCase
();
var
matched
=
matchFingerprint
(
issuer
,
members
);
if
(
matched
)
newLinks
[
fp
r
].
push
(
matched
);
newLinks
[
newcome
r
].
push
(
matched
);
else
error
=
'
Unknown key
'
+
issuer
+
'
: not a member nor a newcomer
'
;
});
// Cache new links from newcomer => WoT
var
newcomerKeyID
=
newcomer
.
substring
(
24
);
_
(
updates
).
keys
().
forEach
(
function
(
signedFPR
){
updates
[
signedFPR
].
forEach
(
function
(
certif
){
if
(
certif
.
issuerKeyId
.
toHex
().
toUpperCase
()
==
newcomerKeyID
)
newLinks
[
signedFPR
]
=
(
newLinks
[
signedFPR
]
||
[]);
newLinks
[
signedFPR
].
push
(
newcomer
);
});
next
(
error
,
newLinks
,
membersChanges
);
},
function
(
newLinks
,
membersChanges
,
next
)
{
checkWoTStability
({
number
:
current
.
number
+
1
,
membersChanges
:
membersChanges
},
newLinks
,
next
);
});
});
if
(
error
)
onceChecked
(
error
);
else
checkWoTStability
({
number
:
current
.
number
+
1
,
membersChanges
:
membersChanges
},
newLinks
,
onceChecked
);
},
next
);
},
function
(
next
)
{
function
(
realNewcomers
,
next
)
{
var
finalJoinData
=
{};
var
initialNewcomers
=
_
(
joinData
).
keys
();
var
nonKept
=
_
(
initialNewcomers
).
difference
(
realNewcomers
);
// Only keep membership of selected newcomers
realNewcomers
.
forEach
(
function
(
newcomer
){
finalJoinData
[
newcomer
]
=
joinData
[
newcomer
];
});
// Only keep signatures of selected newcomers
_
(
updates
).
keys
().
forEach
(
function
(
signedFPR
){
var
keptCertifs
=
new
openpgp
.
packet
.
List
();
(
updates
[
signedFPR
]
||
new
openpgp
.
packet
.
List
()).
forEach
(
function
(
certif
){
var
issuerKeyId
=
certif
.
issuerKeyId
.
toHex
().
toUpperCase
();
var
fingerprint
=
matchFingerprint
(
issuerKeyId
,
initialNewcomers
);
if
(
fingerprint
&&
~
realNewcomers
.
indexOf
(
fingerprint
))
{
keptCertifs
.
push
(
certif
);
}
});
updates
[
signedFPR
]
=
keptCertifs
;
});
// Create the block
createNewcomerBlock
(
current
,
m
embers
,
j
oinData
,
updates
,
next
);
createNewcomerBlock
(
current
,
wotM
embers
.
concat
(
realNewcomers
),
finalJ
oinData
,
updates
,
next
);
},
],
done
);
};
function
findSignaturesFromNewcomerToWoT
(
newcomer
,
done
)
{
var
updates
=
{};
async
.
waterfall
([
function
(
next
){
Key
.
findMembersWhereSignatory
(
newcomer
,
next
);
},
function
(
keys
,
next
){
async
.
forEach
(
keys
,
function
(
signedKey
,
extractedSignatures
){
async
.
waterfall
([
function
(
next
){
PublicKey
.
getTheOne
(
signedKey
.
fingerprint
,
next
);
},
function
(
signedPubkey
,
next
){
var
key
=
keyhelper
.
fromArmored
(
signedPubkey
.
raw
);
var
certifs
=
key
.
getCertificationsFromSignatory
(
newcomer
);
if
(
certifs
.
length
>
0
)
{
updates
[
signedPubkey
.
fingerprint
]
=
certifs
;
certifs
.
forEach
(
function
(){
logger
.
debug
(
'
Found WoT certif %s --> %s
'
,
newcomer
,
signedPubkey
.
fingerprint
);
});
}
next
();
},
],
function
()
{
extractedSignatures
();
});
},
function
(
err
)
{
next
(
err
,
updates
);
});
},
],
done
);
}
function
matchFingerprint
(
keyID
,
fingerprints
)
{
var
matched
=
""
;
var
i
=
0
;
...
...
@@ -1199,6 +1284,7 @@ function KeyService (conn, conf, PublicKeyService) {
});
// Keychanges - updates: signatures from newcomers
_
(
updates
).
keys
().
forEach
(
function
(
fpr
){
if
(
updates
[
fpr
].
length
>
0
)
{
block
.
keysChanges
.
push
({
type
:
'
U
'
,
fingerprint
:
fpr
,
...
...
@@ -1206,6 +1292,7 @@ function KeyService (conn, conf, PublicKeyService) {
certpackets
:
base64
.
encode
(
updates
[
fpr
].
write
()),
membership
:
{}
});
}
});
done
(
null
,
block
);
}
...
...
This diff is collapsed.
Click to expand it.
bin/ucoind
+
5
−
0
View file @
b5d5f811
...
...
@@ -303,6 +303,11 @@ program
.
description
(
'
Tries to generate a newcomers (#2+) keyblock, containing only newcomers changes
'
)
.
action
(
service
(
DO_NOT_LISTEN_HTTP
,
ucoin
.
createWOTServer
,
generateAndSend
(
"
generateNewcomers
"
)));
program
.
command
(
'
gen-newcomers-auto [host] [port] [difficulty]
'
)
.
description
(
'
Tries to generate a newcomers (#2+) keyblock, containing only newcomers changes
'
)
.
action
(
service
(
DO_NOT_LISTEN_HTTP
,
ucoin
.
createWOTServer
,
generateAndSend
(
"
generateNewcomersAuto
"
)));
program
.
command
(
'
compute-distances
'
)
.
description
(
'
Recompute distance between each member and the whole WoT and mark outdistanced ones as kicked
'
)
...
...
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