Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter4j
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
java
duniter4j
Commits
c49b8394
Commit
c49b8394
authored
6 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[enh] Add conversion method
parent
e5bbb622
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#4643
passed
6 years ago
Stage: github-sync
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peers.java
+27
-27
27 additions, 27 deletions
.../main/java/org/duniter/core/client/model/local/Peers.java
with
27 additions
and
27 deletions
duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peers.java
+
27
−
27
View file @
c49b8394
...
@@ -24,6 +24,7 @@ package org.duniter.core.client.model.local;
...
@@ -24,6 +24,7 @@ package org.duniter.core.client.model.local;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.google.common.collect.ArrayListMultimap
;
import
com.google.common.collect.ArrayListMultimap
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
org.duniter.core.client.model.bma.*
;
import
org.duniter.core.client.model.bma.*
;
...
@@ -84,11 +85,32 @@ public final class Peers {
...
@@ -84,11 +85,32 @@ public final class Peers {
return
peer
.
getStats
()
!=
null
&&
peer
.
getStats
().
isReacheable
();
return
peer
.
getStats
()
!=
null
&&
peer
.
getStats
().
isReacheable
();
}
}
public
static
NetworkPeers
.
Peer
toBmaPeer
(
Peer
endpointAsPeer
)
{
NetworkPeers
.
Peer
result
=
new
NetworkPeers
.
Peer
();
try
{
// Fill BMA peer, using the raw document
NetworkPeerings
.
parse
(
endpointAsPeer
.
getPeering
().
getRaw
(),
result
);
// Override the status, last_try and first_down, using stats
Peer
.
PeerStatus
status
=
getStatus
(
endpointAsPeer
).
orElse
(
Peer
.
PeerStatus
.
DOWN
);
result
.
setStatus
(
status
.
name
());
if
(
status
==
Peer
.
PeerStatus
.
UP
)
{
result
.
setLastTry
(
getLastUpTime
(
endpointAsPeer
).
get
());
}
else
{
result
.
setFirstDown
(
getFirstDownTime
(
endpointAsPeer
).
get
());
}
return
result
;
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to parse peering raw document found in: "
+
e
.
getMessage
());
// Continue to next endpoint
}
return
null
;
}
public
static
List
<
NetworkPeers
.
Peer
>
toBmaPeers
(
List
<
Peer
>
endpointAsPeers
)
{
public
static
List
<
NetworkPeers
.
Peer
>
toBmaPeers
(
List
<
Peer
>
endpointAsPeers
)
{
if
(
CollectionUtils
.
isEmpty
(
endpointAsPeers
))
return
null
;
if
(
CollectionUtils
.
isEmpty
(
endpointAsPeers
))
return
null
;
Joiner
keyJoiner
=
Joiner
.
on
(
':'
);
// Group by peering document
// Group by peering document
Multimap
<
String
,
Peer
>
groupByPeering
=
ArrayListMultimap
.
create
();
Multimap
<
String
,
Peer
>
groupByPeering
=
ArrayListMultimap
.
create
();
endpointAsPeers
.
stream
()
endpointAsPeers
.
stream
()
...
@@ -118,31 +140,9 @@ public final class Peers {
...
@@ -118,31 +140,9 @@ public final class Peers {
processedPubkeys
.
add
(
pubkey
);
processedPubkeys
.
add
(
pubkey
);
// Get the first endpoint found for this pubkey
// Get the first endpoint found for this pubkey
for
(
Peer
peer:
groupByPeering
.
get
(
peeringKey
))
{
return
groupByPeering
.
get
(
peeringKey
).
stream
().
map
(
Peers:
:
toBmaPeer
)
NetworkPeers
.
Peer
result
=
new
NetworkPeers
.
Peer
();
.
filter
(
Objects:
:
nonNull
)
.
findFirst
().
orElse
(
null
);
try
{
// Fill BMA peer, using the raw document
NetworkPeerings
.
parse
(
peer
.
getPeering
().
getRaw
(),
result
);
// Override the status, last_try and first_down, using stats
Peer
.
PeerStatus
status
=
getStatus
(
peer
).
orElse
(
Peer
.
PeerStatus
.
DOWN
);
result
.
setStatus
(
status
.
name
());
if
(
status
==
Peer
.
PeerStatus
.
UP
)
{
result
.
setLastTry
(
getLastUpTime
(
peer
).
get
());
}
else
{
result
.
setFirstDown
(
getFirstDownTime
(
peer
).
get
());
}
return
result
;
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to parse peering raw document found in: "
+
e
.
getMessage
());
// Continue to next endpoint
}
}
return
null
;
})
})
// Remove skipped items
// Remove skipped items
.
filter
(
Objects:
:
nonNull
)
.
filter
(
Objects:
:
nonNull
)
...
...
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