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
cf7d2068
Unverified
Commit
cf7d2068
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[fix] async isMember
parent
f0e29f79
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!1222
Add startup scripts
,
!1220
Stable/ws2p v1.1 trymerge
,
!1208
Stable/ws2p v1.1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/dal/fileDAL.ts
+3
-3
3 additions, 3 deletions
app/lib/dal/fileDAL.ts
app/modules/ws2p/lib/WS2PCluster.ts
+13
-10
13 additions, 10 deletions
app/modules/ws2p/lib/WS2PCluster.ts
app/modules/ws2p/lib/WS2PServer.ts
+2
-2
2 additions, 2 deletions
app/modules/ws2p/lib/WS2PServer.ts
with
18 additions
and
15 deletions
app/lib/dal/fileDAL.ts
+
3
−
3
View file @
cf7d2068
...
...
@@ -503,13 +503,13 @@ export class FileDAL {
return
this
.
sindexDAL
.
getSource
(
identifier
,
pos
)
}
async
isMember
(
pubkey
:
string
)
{
async
isMember
(
pubkey
:
string
)
:
Promise
<
boolean
>
{
try
{
const
idty
=
await
this
.
iindexDAL
.
getFromPubkey
(
pubkey
);
if
(
!
idty
)
{
if
(
idty
===
null
)
{
return
false
}
return
idty
.
member
;
return
true
;
}
catch
(
err
)
{
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/lib/WS2PCluster.ts
+
13
−
10
View file @
cf7d2068
...
...
@@ -106,7 +106,7 @@ export class WS2PCluster {
if
(
!
this
.
headsCache
[
myFullId
])
{
const
current
=
await
this
.
server
.
dal
.
getCurrentBlockOrNull
()
if
(
current
)
{
const
myHead
=
this
.
sayHeadChangedTo
(
current
.
number
,
current
.
hash
)
const
myHead
=
await
this
.
sayHeadChangedTo
(
current
.
number
,
current
.
hash
)
const
blockstamp
=
[
current
.
number
,
current
.
hash
].
join
(
'
-
'
)
this
.
headsCache
[
myFullId
]
=
{
blockstamp
,
message
:
myHead
.
message
,
sig
:
myHead
.
sig
,
messageV2
:
myHead
.
messageV2
,
sigV2
:
myHead
.
sigV2
,
step
:
myHead
.
step
}
...
...
@@ -496,7 +496,7 @@ export class WS2PCluster {
// HEAD changed
else
if
(
data
.
bcEvent
===
OtherConstants
.
BC_EVENT
.
HEAD_CHANGED
||
data
.
bcEvent
===
OtherConstants
.
BC_EVENT
.
SWITCHED
)
{
// Propagate this change to the network
const
myHead
=
this
.
sayHeadChangedTo
(
data
.
block
.
number
,
data
.
block
.
hash
)
const
myHead
=
await
this
.
sayHeadChangedTo
(
data
.
block
.
number
,
data
.
block
.
hash
)
try
{
await
this
.
broadcastHead
(
myHead
)
}
catch
(
e
)
{
...
...
@@ -535,14 +535,14 @@ export class WS2PCluster {
return
heads
}
private
sayHeadChangedTo
(
number
:
number
,
hash
:
string
)
{
private
async
sayHeadChangedTo
(
number
:
number
,
hash
:
string
)
{
const
api
=
this
.
getApi
()
const
key
=
new
Key
(
this
.
server
.
conf
.
pair
.
pub
,
this
.
server
.
conf
.
pair
.
sec
)
const
software
=
'
duniter
'
const
softVersion
=
Package
.
getInstance
().
version
const
ws2pId
=
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
uuid
)
||
'
00000000
'
const
prefix
=
this
.
server
.
conf
.
prefix
||
ProverConstants
.
DEFAULT_PEER_ID
const
{
freeMemberRoom
,
freeMirorRoom
}
=
this
.
countFreeRooms
()
const
{
freeMemberRoom
,
freeMirorRoom
}
=
await
this
.
countFreeRooms
()
const
message
=
`
${
api
}
:HEAD:1:
${
key
.
publicKey
}
:
${
number
}
-
${
hash
}
:
${
ws2pId
}
:
${
software
}
:
${
softVersion
}
:
${
prefix
}
`
const
sig
=
key
.
signSync
(
message
)
const
messageV2
=
`
${
api
}
:HEAD:2:
${
key
.
publicKey
}
:
${
number
}
-
${
hash
}
:
${
ws2pId
}
:
${
software
}
:
${
softVersion
}
:
${
prefix
}
:
${
freeMemberRoom
}
:
${
freeMirorRoom
}
`
...
...
@@ -604,7 +604,7 @@ export class WS2PCluster {
return
api
}
private
countFreeRooms
()
{
private
async
countFreeRooms
()
{
if
(
!
this
.
ws2pServer
)
{
return
{
freeMemberRoom
:
0
,
...
...
@@ -616,7 +616,8 @@ export class WS2PCluster {
let
freeMemberRoom
=
freeMirorRoom
const
privilegedNodes
=
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
privilegedNodes
)
?
this
.
server
.
conf
.
ws2p
.
privilegedNodes
:[]
for
(
const
c
of
this
.
ws2pServer
.
getConnexions
())
{
if
(
this
.
keyPriorityLevel
(
c
.
pubkey
,
privilegedNodes
)
<
WS2PConstants
.
CONNECTIONS_PRIORITY
.
MEMBER_KEY_LEVEL
)
{
const
connexionPriority
=
await
this
.
keyPriorityLevel
(
c
.
pubkey
,
privilegedNodes
)
if
(
connexionPriority
<
WS2PConstants
.
CONNECTIONS_PRIORITY
.
MEMBER_KEY_LEVEL
)
{
freeMemberRoom
++
}
}
...
...
@@ -673,8 +674,9 @@ export class WS2PCluster {
}
}
keyPriorityLevel
(
pubkey
:
string
,
preferedOrPrivilegedKeys
:
string
[])
{
let
priorityLevel
=
(
this
.
server
.
dal
.
isMember
(
pubkey
))
?
WS2PConstants
.
CONNECTIONS_PRIORITY
.
MEMBER_KEY_LEVEL
:
0
async
keyPriorityLevel
(
pubkey
:
string
,
preferedOrPrivilegedKeys
:
string
[])
{
const
isMember
=
await
this
.
server
.
dal
.
isMember
(
pubkey
)
let
priorityLevel
=
(
isMember
)
?
WS2PConstants
.
CONNECTIONS_PRIORITY
.
MEMBER_KEY_LEVEL
:
0
priorityLevel
+=
(
preferedOrPrivilegedKeys
.
indexOf
(
pubkey
)
!==
-
1
)
?
WS2PConstants
.
CONNECTIONS_PRIORITY
.
PREFERED_PRIVILEGED_KEY_LEVEL
:
0
priorityLevel
+=
(
this
.
server
.
conf
.
pair
.
pub
===
pubkey
)
?
WS2PConstants
.
CONNECTIONS_PRIORITY
.
SELF_KEY_LEVEL
:
0
return
priorityLevel
...
...
@@ -834,12 +836,13 @@ export class WS2PCluster {
else
{
let
minPriorityLevel
=
WS2PConstants
.
CONNECTIONS_PRIORITY
.
MAX_PRIORITY_LEVEL
for
(
const
connectedPubkey
of
connectedPubkeys
)
{
le
t
connectedPubkeyPriorityLevel
=
this
.
keyPriorityLevel
(
connectedPubkey
,
priorityKeys
)
cons
t
connectedPubkeyPriorityLevel
=
await
this
.
keyPriorityLevel
(
connectedPubkey
,
priorityKeys
)
if
(
connectedPubkeyPriorityLevel
<
minPriorityLevel
)
{
minPriorityLevel
=
connectedPubkeyPriorityLevel
}
}
if
(
this
.
keyPriorityLevel
(
pub
,
priorityKeys
)
>
minPriorityLevel
)
{
const
pubkeyPriorityLevel
=
await
this
.
keyPriorityLevel
(
pub
,
priorityKeys
)
if
(
pubkeyPriorityLevel
>
minPriorityLevel
)
{
return
true
}
}
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/lib/WS2PServer.ts
+
2
−
2
View file @
cf7d2068
...
...
@@ -23,7 +23,7 @@ export class WS2PServer extends events.EventEmitter {
private
port
:
number
,
private
fifo
:
GlobalFifoPromise
,
private
shouldAcceptConnection
:(
pubkey
:
string
,
connectedPubkeys
:
string
[])
=>
Promise
<
boolean
>
,
public
keyPriorityLevel
:(
pubkey
:
string
,
privilegedKeys
:
string
[])
=>
number
)
{
public
keyPriorityLevel
:(
pubkey
:
string
,
privilegedKeys
:
string
[])
=>
Promise
<
number
>
)
{
super
()
// Conf: max public connections
if
(
this
.
server
.
conf
.
ws2p
&&
this
.
server
.
conf
.
ws2p
.
maxPublic
!==
undefined
)
{
...
...
@@ -212,7 +212,7 @@ export class WS2PServer extends events.EventEmitter {
}))
}
static
async
bindOn
(
server
:
Server
,
host
:
string
,
port
:
number
,
fifo
:
GlobalFifoPromise
,
shouldAcceptConnection
:(
pubkey
:
string
,
connectedPubkeys
:
string
[])
=>
Promise
<
boolean
>
,
keyPriorityLevel
:(
pubkey
:
string
,
privilegedKeys
:
string
[])
=>
number
,
messageHandler
:
WS2PMessageHandler
)
{
static
async
bindOn
(
server
:
Server
,
host
:
string
,
port
:
number
,
fifo
:
GlobalFifoPromise
,
shouldAcceptConnection
:(
pubkey
:
string
,
connectedPubkeys
:
string
[])
=>
Promise
<
boolean
>
,
keyPriorityLevel
:(
pubkey
:
string
,
privilegedKeys
:
string
[])
=>
Promise
<
number
>
,
messageHandler
:
WS2PMessageHandler
)
{
const
ws2ps
=
new
WS2PServer
(
server
,
host
,
port
,
fifo
,
shouldAcceptConnection
,
keyPriorityLevel
)
await
ws2ps
.
listenToWebSocketConnections
(
messageHandler
)
server
.
logger
.
info
(
'
WS2P server %s listening on %s:%s
'
,
server
.
conf
.
pair
.
pub
,
host
,
port
)
...
...
This diff is collapsed.
Click to expand it.
Moul
@moul
mentioned in commit
f9778328
·
6 years ago
mentioned in commit
f9778328
mentioned in commit f9778328c483f7a5a0b565f0f9d539fb175bec55
Toggle commit list
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