Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
e18788fa
Commit
e18788fa
authored
Jan 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: lints
parent
f080fa3f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
node.go
op-node/p2p/node.go
+0
-1
peer_scorer.go
op-node/p2p/peer_scorer.go
+18
-11
No files found.
op-node/p2p/node.go
View file @
e18788fa
...
@@ -32,7 +32,6 @@ type NodeP2P struct {
...
@@ -32,7 +32,6 @@ type NodeP2P struct {
dv5Udp
*
discover
.
UDPv5
// p2p discovery service
dv5Udp
*
discover
.
UDPv5
// p2p discovery service
gs
*
pubsub
.
PubSub
// p2p gossip router
gs
*
pubsub
.
PubSub
// p2p gossip router
gsOut
GossipOut
// p2p gossip application interface for publishing
gsOut
GossipOut
// p2p gossip application interface for publishing
scorer
Scorer
// p2p peer scorer
}
}
// NewNodeP2P creates a new p2p node, and returns a reference to it. If the p2p is disabled, it returns nil.
// NewNodeP2P creates a new p2p node, and returns a reference to it. If the p2p is disabled, it returns nil.
...
...
op-node/p2p/peer_scorer.go
View file @
e18788fa
...
@@ -36,18 +36,34 @@ func NewScorer(connGater ConnectionGater, peerStore peerstore.Peerstore, metrice
...
@@ -36,18 +36,34 @@ func NewScorer(connGater ConnectionGater, peerStore peerstore.Peerstore, metrice
// It is passed into the pubsub library as a [pubsub.ExtendedPeerScoreInspectFn] in the [pubsub.WithPeerScoreInspect] option.
// It is passed into the pubsub library as a [pubsub.ExtendedPeerScoreInspectFn] in the [pubsub.WithPeerScoreInspect] option.
// The returned [pubsub.ExtendedPeerScoreInspectFn] is called with a mapping of peer IDs to peer score snapshots.
// The returned [pubsub.ExtendedPeerScoreInspectFn] is called with a mapping of peer IDs to peer score snapshots.
func
(
s
*
scorer
)
SnapshotHook
()
pubsub
.
ExtendedPeerScoreInspectFn
{
func
(
s
*
scorer
)
SnapshotHook
()
pubsub
.
ExtendedPeerScoreInspectFn
{
// peer := s.peerStore.Get(peer.ID)
// loop through each peer ID, get the score
// if the score < the configured threshold, ban the peer
// factor in the number of connections/disconnections into the score
// e.g., score = score - (s.peerConnections[peerID] * ConnectionFactor)
// s.connGater.BanAddr(peerID)
return
func
(
m
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
)
{
return
func
(
m
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
)
{
for
id
,
snap
:=
range
m
{
for
id
,
snap
:=
range
m
{
// Record peer score in the metricer
// Record peer score in the metricer
s
.
metricer
.
RecordPeerScoring
(
id
,
snap
.
Score
)
s
.
metricer
.
RecordPeerScoring
(
id
,
snap
.
Score
)
// TODO: encorporate the number of peer connections/disconnections into the score
// TODO: or should we just affect the score in the OnConnect/OnDisconnect methods?
// TODO: if we don't have to do this calculation here, we can push score updates to the metricer
// TODO: which would leave the scoring to the pubsub lib
// peer, err := s.peerStore.Get(id)
// if err != nil {
// }
// Check if the peer score is below the threshold
// Check if the peer score is below the threshold
// If so, we need to block the peer
// If so, we need to block the peer
if
snap
.
Score
<
PeerScoreThreshold
{
if
snap
.
Score
<
PeerScoreThreshold
{
s
.
connGater
.
BlockPeer
(
id
)
_
=
s
.
connGater
.
BlockPeer
(
id
)
}
}
// Unblock peers whose score has recovered to an acceptable level
// Unblock peers whose score has recovered to an acceptable level
if
(
snap
.
Score
>
PeerScoreThreshold
)
&&
contains
(
s
.
connGater
.
ListBlockedPeers
(),
id
)
{
if
(
snap
.
Score
>
PeerScoreThreshold
)
&&
contains
(
s
.
connGater
.
ListBlockedPeers
(),
id
)
{
s
.
connGater
.
UnblockPeer
(
id
)
_
=
s
.
connGater
.
UnblockPeer
(
id
)
}
}
}
}
}
}
...
@@ -76,12 +92,3 @@ func (s *scorer) OnConnect() {
...
@@ -76,12 +92,3 @@ func (s *scorer) OnConnect() {
func
(
s
*
scorer
)
OnDisconnect
()
{
func
(
s
*
scorer
)
OnDisconnect
()
{
// record a disconnection
// record a disconnection
}
}
func
(
s
*
scorer
)
inspectPeers
(
peersMap
map
[
peer
.
ID
]
*
pubsub
.
PeerScoreSnapshot
)
{
// peer := s.peerStore.Get(peer.ID)
// loop through each peer ID, get the score
// if the score < the configured threshold, ban the peer
// factor in the number of connections/disconnections into the score
// e.g., score = score - (s.peerConnections[peerID] * ConnectionFactor)
// s.connGater.BanAddr(peerID)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment