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
117fd621
Commit
117fd621
authored
Jan 19, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: peer scoring config
parent
f22dac93
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
4 deletions
+56
-4
cmd.go
op-node/cmd/p2p/cmd.go
+1
-3
server.go
op-node/node/server.go
+1
-1
gossip.go
op-node/p2p/gossip.go
+3
-0
peer_score.go
op-node/p2p/peer_score.go
+51
-0
No files found.
op-node/cmd/p2p/cmd.go
View file @
117fd621
package
p2p
import
(
"bufio"
"crypto/rand"
"encoding/hex"
"fmt"
...
...
@@ -52,8 +51,7 @@ func Pub2PeerID(r io.Reader) (string, error) {
}
func
readHexData
(
r
io
.
Reader
)
([]
byte
,
error
)
{
reader
:=
bufio
.
NewReader
(
os
.
Stdin
)
data
,
err
:=
reader
.
ReadString
(
'\n'
)
data
,
err
:=
io
.
ReadAll
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
op-node/node/server.go
View file @
117fd621
...
...
@@ -74,7 +74,7 @@ func (s *rpcServer) Start() error {
// The CORS and VHosts arguments below must be set in order for
// other services to connect to the opnode. VHosts in particular
// defaults to localhost, which will prevent containers from
// calling into the opnode with an "invalid host" error.
// calling into the opnode with
out
an "invalid host" error.
nodeHandler
:=
node
.
NewHTTPHandlerStack
(
srv
,
[]
string
{
"*"
},
[]
string
{
"*"
},
nil
)
mux
:=
http
.
NewServeMux
()
...
...
op-node/p2p/gossip.go
View file @
117fd621
...
...
@@ -151,6 +151,8 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, gossi
return
nil
,
err
}
params
:=
BuildGlobalGossipParams
(
cfg
)
peerScoreParams
:=
NewPeerScoreParams
()
peerScoreThresholds
:=
NewPeerScoreThresholds
()
gossipOpts
:=
[]
pubsub
.
Option
{
pubsub
.
WithMaxMessageSize
(
maxGossipSize
),
pubsub
.
WithMessageIdFn
(
BuildMsgIdFn
(
cfg
)),
...
...
@@ -165,6 +167,7 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, gossi
pubsub
.
WithBlacklist
(
denyList
),
pubsub
.
WithGossipSubParams
(
params
),
pubsub
.
WithEventTracer
(
&
gossipTracer
{
m
:
m
}),
pubsub
.
WithPeerScore
(
&
peerScoreParams
,
&
peerScoreThresholds
),
pubsub
.
WithPeerScoreInspect
(
BuildPeerScoreInspector
(
m
),
peerScoreInspectFrequency
),
}
gossipOpts
=
append
(
gossipOpts
,
gossipConf
.
ConfigureGossip
(
&
params
)
...
)
...
...
op-node/p2p/peer_score.go
0 → 100644
View file @
117fd621
package
p2p
import
(
"math"
"time"
pubsub
"github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
)
// AppScoring scores peers based on application-specific metrics.
func
AppScoring
(
p
peer
.
ID
)
float64
{
return
0
}
// NewPeerScoreParams returns a default [pubsub.PeerScoreParams].
// See [PeerScoreParams] for detailed documentation.
//
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
func
NewPeerScoreParams
()
pubsub
.
PeerScoreParams
{
return
pubsub
.
PeerScoreParams
{
SkipAtomicValidation
:
false
,
Topics
:
make
(
map
[
string
]
*
pubsub
.
TopicScoreParams
),
TopicScoreCap
:
100
,
// Aggregate topic score cap (0 for no cap).
AppSpecificScore
:
AppScoring
,
AppSpecificWeight
:
1
,
IPColocationFactorWeight
:
-
1
,
IPColocationFactorThreshold
:
1
,
BehaviourPenaltyWeight
:
-
1
,
BehaviourPenaltyDecay
:
0.999
,
DecayInterval
:
24
*
time
.
Hour
,
DecayToZero
:
0.01
,
RetainScore
:
math
.
MaxInt64
,
SeenMsgTTL
:
0
,
// Defaults to global TimeCacheDuration when 0
}
}
// NewPeerScoreThresholds returns a default [pubsub.PeerScoreThresholds].
// See [PeerScoreThresholds] for detailed documentation.
//
// [PeerScoreThresholds]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreThresholds
func
NewPeerScoreThresholds
()
pubsub
.
PeerScoreThresholds
{
return
pubsub
.
PeerScoreThresholds
{
SkipAtomicValidation
:
false
,
GossipThreshold
:
-
10
,
PublishThreshold
:
-
40
,
GraylistThreshold
:
-
40
,
AcceptPXThreshold
:
20
,
OpportunisticGraftThreshold
:
0.05
,
}
}
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