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
1bf4910e
Commit
1bf4910e
authored
7 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#1084
WS2P: move the wrong endpoint detection in modules definition
parent
6f4fc6ad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/modules/bma/index.ts
+22
-0
22 additions, 0 deletions
app/modules/bma/index.ts
app/modules/ws2p/index.ts
+8
-0
8 additions, 0 deletions
app/modules/ws2p/index.ts
app/service/PeeringService.ts
+7
-23
7 additions, 23 deletions
app/service/PeeringService.ts
server.ts
+14
-0
14 additions, 0 deletions
server.ts
with
51 additions
and
23 deletions
app/modules/bma/index.ts
+
22
−
0
View file @
1bf4910e
...
@@ -6,9 +6,11 @@ import {BmaApi, Network} from "./lib/network"
...
@@ -6,9 +6,11 @@ import {BmaApi, Network} from "./lib/network"
import
{
UpnpApi
}
from
"
./lib/upnp
"
import
{
UpnpApi
}
from
"
./lib/upnp
"
import
{
BMAConstants
}
from
"
./lib/constants
"
import
{
BMAConstants
}
from
"
./lib/constants
"
import
{
BMALimitation
}
from
"
./lib/limiter
"
import
{
BMALimitation
}
from
"
./lib/limiter
"
import
{
PeerDTO
}
from
"
../../lib/dto/PeerDTO
"
const
Q
=
require
(
'
q
'
);
const
Q
=
require
(
'
q
'
);
const
os
=
require
(
'
os
'
);
const
os
=
require
(
'
os
'
);
const
rp
=
require
(
'
request-promise
'
);
const
async
=
require
(
'
async
'
);
const
async
=
require
(
'
async
'
);
const
_
=
require
(
'
underscore
'
);
const
_
=
require
(
'
underscore
'
);
const
upnp
=
require
(
'
./lib/upnp
'
).
Upnp
const
upnp
=
require
(
'
./lib/upnp
'
).
Upnp
...
@@ -139,6 +141,7 @@ export const BmaDependency = {
...
@@ -139,6 +141,7 @@ export const BmaDependency = {
service
:
{
service
:
{
input
:
(
server
:
Server
,
conf
:
NetworkConfDTO
,
logger
:
any
)
=>
{
input
:
(
server
:
Server
,
conf
:
NetworkConfDTO
,
logger
:
any
)
=>
{
server
.
addEndpointsDefinitions
(()
=>
Promise
.
resolve
(
getEndpoint
(
conf
)))
server
.
addEndpointsDefinitions
(()
=>
Promise
.
resolve
(
getEndpoint
(
conf
)))
server
.
addWrongEndpointFilter
((
endpoints
:
string
[])
=>
getWrongEndpoints
(
endpoints
,
server
.
conf
.
pair
.
pub
))
return
new
BMAPI
(
server
,
conf
,
logger
)
return
new
BMAPI
(
server
,
conf
,
logger
)
}
}
},
},
...
@@ -151,6 +154,25 @@ export const BmaDependency = {
...
@@ -151,6 +154,25 @@ export const BmaDependency = {
}
}
}
}
async
function
getWrongEndpoints
(
endpoints
:
string
[],
selfPubkey
:
string
)
{
const
wrongs
:
string
[]
=
[]
await
Promise
.
all
(
endpoints
.
map
(
async
(
theEndpoint
:
string
)
=>
{
let
remote
=
PeerDTO
.
endpoint2host
(
theEndpoint
)
try
{
// We test only BMA APIs, because other may exist and we cannot judge against them
if
(
theEndpoint
.
startsWith
(
'
BASIC_MERKLED_API
'
))
{
let
answer
=
await
rp
(
'
http://
'
+
remote
+
'
/network/peering
'
,
{
json
:
true
});
if
(
!
answer
||
answer
.
pubkey
!=
selfPubkey
)
{
throw
Error
(
"
Not same pubkey as local instance
"
);
}
}
}
catch
(
e
)
{
wrongs
.
push
(
theEndpoint
)
}
}))
return
wrongs
}
export
class
BMAPI
extends
stream
.
Transform
{
export
class
BMAPI
extends
stream
.
Transform
{
// Public http interface
// Public http interface
...
...
This diff is collapsed.
Click to expand it.
app/modules/ws2p/index.ts
+
8
−
0
View file @
1bf4910e
...
@@ -48,12 +48,20 @@ export const WS2PDependency = {
...
@@ -48,12 +48,20 @@ export const WS2PDependency = {
input
:
(
server
:
Server
,
conf
:
WS2PConfDTO
,
logger
:
any
)
=>
{
input
:
(
server
:
Server
,
conf
:
WS2PConfDTO
,
logger
:
any
)
=>
{
const
api
=
new
WS2PAPI
(
server
,
conf
,
logger
)
const
api
=
new
WS2PAPI
(
server
,
conf
,
logger
)
server
.
addEndpointsDefinitions
(()
=>
api
.
getEndpoint
())
server
.
addEndpointsDefinitions
(()
=>
api
.
getEndpoint
())
server
.
addWrongEndpointFilter
((
endpoints
:
string
[])
=>
getWrongEndpoints
(
endpoints
,
conf
))
return
api
return
api
}
}
}
}
}
}
}
}
async
function
getWrongEndpoints
(
endpoints
:
string
[],
ws2pConf
:
WS2PConfDTO
)
{
return
endpoints
.
filter
(
ep
=>
{
const
match
=
ep
.
match
(
CommonConstants
.
WS2P_REGEXP
)
return
ws2pConf
.
ws2p
&&
match
&&
match
[
1
]
===
ws2pConf
.
ws2p
.
uuid
})
}
export
class
WS2PAPI
extends
stream
.
Transform
{
export
class
WS2PAPI
extends
stream
.
Transform
{
// Public http interface
// Public http interface
...
...
This diff is collapsed.
Click to expand it.
app/service/PeeringService.ts
+
7
−
23
View file @
1bf4910e
...
@@ -9,11 +9,11 @@ import {dos2unix} from "../lib/common-libs/dos2unix"
...
@@ -9,11 +9,11 @@ import {dos2unix} from "../lib/common-libs/dos2unix"
import
{
rawer
}
from
"
../lib/common-libs/index
"
import
{
rawer
}
from
"
../lib/common-libs/index
"
import
{
Server
}
from
"
../../server
"
import
{
Server
}
from
"
../../server
"
import
{
GlobalFifoPromise
}
from
"
./GlobalFifoPromise
"
import
{
GlobalFifoPromise
}
from
"
./GlobalFifoPromise
"
import
{
server
}
from
"
../../test/integration/tools/toolbox
"
const
util
=
require
(
'
util
'
);
const
util
=
require
(
'
util
'
);
const
_
=
require
(
'
underscore
'
);
const
_
=
require
(
'
underscore
'
);
const
events
=
require
(
'
events
'
);
const
events
=
require
(
'
events
'
);
const
rp
=
require
(
'
request-promise
'
);
const
logger
=
require
(
'
../lib/logger
'
).
NewLogger
(
'
peering
'
);
const
logger
=
require
(
'
../lib/logger
'
).
NewLogger
(
'
peering
'
);
const
constants
=
require
(
'
../lib/constants
'
);
const
constants
=
require
(
'
../lib/constants
'
);
...
@@ -199,28 +199,12 @@ export class PeeringService {
...
@@ -199,28 +199,12 @@ export class PeeringService {
const
localEndpoints
=
await
this
.
server
.
getEndpoints
()
const
localEndpoints
=
await
this
.
server
.
getEndpoints
()
const
otherPotentialEndpoints
=
this
.
getOtherEndpoints
(
p1
.
endpoints
,
localEndpoints
)
const
otherPotentialEndpoints
=
this
.
getOtherEndpoints
(
p1
.
endpoints
,
localEndpoints
)
logger
.
info
(
'
Sibling endpoints:
'
,
otherPotentialEndpoints
);
logger
.
info
(
'
Sibling endpoints:
'
,
otherPotentialEndpoints
);
let
reals
=
await
Promise
.
all
(
otherPotentialEndpoints
.
map
(
async
(
theEndpoint
:
string
)
=>
{
const
wrongEndpoints
=
await
this
.
server
.
getWrongEndpoints
(
otherPotentialEndpoints
)
let
real
=
true
;
for
(
const
wrong
of
wrongEndpoints
)
{
let
remote
=
PeerDTO
.
endpoint2host
(
theEndpoint
)
logger
.
warn
(
'
Wrong endpoint
\'
%s
\'
'
,
wrong
)
try
{
}
// We test only BMA APIs, because other may exist and we cannot judge against them yet
const
toRemoveByConf
=
(
this
.
conf
.
rmEndpoints
||
[])
if
(
theEndpoint
.
startsWith
(
'
BASIC_MERKLED_API
'
))
{
let
toConserve
=
otherPotentialEndpoints
.
filter
(
ep
=>
wrongEndpoints
.
indexOf
(
ep
)
===
-
1
&&
toRemoveByConf
.
indexOf
(
ep
)
===
-
1
)
let
answer
=
await
rp
(
'
http://
'
+
remote
+
'
/network/peering
'
,
{
json
:
true
});
if
(
!
answer
||
answer
.
pubkey
!=
this
.
selfPubkey
)
{
throw
Error
(
"
Not same pubkey as local instance
"
);
}
}
// We also remove endpoints this are *asked* to be removed in the conf file
if
((
this
.
conf
.
rmEndpoints
||
[]).
indexOf
(
theEndpoint
)
!==
-
1
)
{
real
=
false
;
}
}
catch
(
e
)
{
logger
.
warn
(
'
Wrong endpoint
\'
%s
\'
:
\'
%s
\'
'
,
theEndpoint
,
e
.
message
||
e
);
real
=
false
;
}
return
real
;
}))
let
toConserve
=
otherPotentialEndpoints
.
filter
((
ep
,
i
)
=>
reals
[
i
]);
if
(
!
currency
)
{
if
(
!
currency
)
{
logger
.
error
(
'
It seems there is an issue with your configuration.
'
);
logger
.
error
(
'
It seems there is an issue with your configuration.
'
);
logger
.
error
(
'
Please restart your node with:
'
);
logger
.
error
(
'
Please restart your node with:
'
);
...
...
This diff is collapsed.
Click to expand it.
server.ts
+
14
−
0
View file @
1bf4910e
...
@@ -47,6 +47,7 @@ export class Server extends stream.Duplex implements HookableServer {
...
@@ -47,6 +47,7 @@ export class Server extends stream.Duplex implements HookableServer {
private
paramsP
:
Promise
<
any
>|
null
private
paramsP
:
Promise
<
any
>|
null
private
endpointsDefinitions
:(()
=>
Promise
<
string
>
)[]
=
[]
private
endpointsDefinitions
:(()
=>
Promise
<
string
>
)[]
=
[]
private
wrongEndpointsFilters
:((
endpoints
:
string
[])
=>
Promise
<
string
[]
>
)[]
=
[]
conf
:
ConfDTO
conf
:
ConfDTO
dal
:
FileDAL
dal
:
FileDAL
...
@@ -569,11 +570,24 @@ export class Server extends stream.Duplex implements HookableServer {
...
@@ -569,11 +570,24 @@ export class Server extends stream.Duplex implements HookableServer {
this
.
endpointsDefinitions
.
push
(
definition
)
this
.
endpointsDefinitions
.
push
(
definition
)
}
}
addWrongEndpointFilter
(
filter
:(
endpoints
:
string
[])
=>
Promise
<
string
[]
>
)
{
this
.
wrongEndpointsFilters
.
push
(
filter
)
}
async
getEndpoints
()
{
async
getEndpoints
()
{
const
endpoints
=
await
Promise
.
all
(
this
.
endpointsDefinitions
.
map
(
d
=>
d
()))
const
endpoints
=
await
Promise
.
all
(
this
.
endpointsDefinitions
.
map
(
d
=>
d
()))
return
endpoints
.
filter
(
ep
=>
!!
ep
)
return
endpoints
.
filter
(
ep
=>
!!
ep
)
}
}
async
getWrongEndpoints
(
endpoints
:
string
[])
{
let
wrongs
:
string
[]
=
[]
for
(
const
filter
of
this
.
wrongEndpointsFilters
)
{
const
newWrongs
=
await
filter
(
endpoints
)
wrongs
=
wrongs
.
concat
(
newWrongs
)
}
return
wrongs
}
/*****************
/*****************
* MODULES PLUGS
* MODULES PLUGS
****************/
****************/
...
...
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