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
c4cb098a
Commit
c4cb098a
authored
10 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
gen-newcomers command now asks which newcomers to integrate
parent
174068a2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/service/KeychainService.js
+72
-3
72 additions, 3 deletions
app/service/KeychainService.js
with
72 additions
and
3 deletions
app/service/KeychainService.js
+
72
−
3
View file @
c4cb098a
...
...
@@ -10,6 +10,7 @@ var parsers = require('../lib/streams/parsers/doc');
var
keyhelper
=
require
(
'
../lib/keyhelper
'
);
var
logger
=
require
(
'
../lib/logger
'
)(
'
membership
'
);
var
moment
=
require
(
'
moment
'
);
var
inquirer
=
require
(
'
inquirer
'
);
module
.
exports
.
get
=
function
(
conn
,
conf
,
PublicKeyService
)
{
return
new
KeyService
(
conn
,
conf
,
PublicKeyService
);
...
...
@@ -994,6 +995,7 @@ function KeyService (conn, conf, PublicKeyService) {
this
.
generateNewcomers
=
function
(
done
)
{
// 1. See available keychanges
var
members
=
[];
var
preJoinData
=
{};
var
joinData
=
{};
var
updates
=
{};
var
current
;
...
...
@@ -1001,7 +1003,12 @@ function KeyService (conn, conf, PublicKeyService) {
function
(
next
)
{
KeyBlock
.
current
(
function
(
err
,
currentBlock
)
{
current
=
currentBlock
;
next
(
err
&&
'
No root block: cannot generate pulse block
'
);
if
(
!
current
)
next
(
'
No root block: cannot generate newcomer block
'
);
else
if
(
current
.
number
==
0
)
next
(
'
No pulse block: cannot generate newcomer block
'
);
else
next
();
});
},
function
(
next
){
...
...
@@ -1009,7 +1016,7 @@ function KeyService (conn, conf, PublicKeyService) {
},
function
(
mss
,
next
){
async
.
forEach
(
mss
,
function
(
ms
,
callback
){
var
join
=
{
pubkey
:
null
,
ms
:
ms
};
var
join
=
{
pubkey
:
null
,
ms
:
ms
,
key
:
null
};
async
.
waterfall
([
function
(
next
){
async
.
parallel
({
...
...
@@ -1029,17 +1036,45 @@ function KeyService (conn, conf, PublicKeyService) {
return
;
}
var
key
=
keyhelper
.
fromArmored
(
pubk
.
raw
);
join
.
key
=
key
;
// Just require a good udid2
if
(
!
key
.
hasValidUdid2
())
{
next
(
'
User
'
+
uid
+
'
does not have a valid udid2 userId
'
);
return
;
}
j
oinData
[
join
.
pubkey
.
fingerprint
]
=
join
;
preJ
oinData
[
join
.
pubkey
.
fingerprint
]
=
join
;
next
();
},
],
callback
);
},
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
'
);
}
},
function
(
next
)
{
// Look for signatures from newcomers to the WoT
async
.
forEach
(
_
(
joinData
).
keys
(),
function
(
newcomer
,
searchedSignaturesOfTheWoT
){
...
...
@@ -1091,12 +1126,46 @@ function KeyService (conn, conf, PublicKeyService) {
_
(
joinData
).
keys
().
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
();
certifs
.
forEach
(
function
(
certif
)
{
var
issuer
=
certif
.
issuerKeyId
.
toHex
().
toUpperCase
();
var
matched
=
matchFingerprint
(
issuer
,
members
);
if
(
matched
)
newLinks
[
fpr
].
push
(
matched
);
else
error
=
'
Unknown key
'
+
issuer
+
'
: not a member nor a newcomer
'
;
});
});
next
(
error
,
newLinks
,
membersChanges
);
},
function
(
newLinks
,
membersChanges
,
next
)
{
checkWoTStability
({
number
:
current
.
number
+
1
,
membersChanges
:
membersChanges
},
newLinks
,
next
);
},
function
(
next
)
{
// Create the block
createNewcomerBlock
(
current
,
members
,
joinData
,
updates
,
next
);
},
],
done
);
};
function
matchFingerprint
(
keyID
,
fingerprints
)
{
var
matched
=
""
;
var
i
=
0
;
while
(
!
matched
&&
i
<
fingerprints
.
length
)
{
if
(
fingerprints
[
i
].
match
(
new
RegExp
(
keyID
+
'
$
'
)))
matched
=
fingerprints
[
i
];
i
++
;
}
return
matched
;
}
function
createNewcomerBlock
(
current
,
members
,
joinData
,
updates
,
done
)
{
var
block
=
new
KeyBlock
();
block
.
version
=
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