use of io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder in project teku by ConsenSys.
the class LibP2PParamsFactory method createPeerScoreParams.
public static GossipPeerScoreParams createPeerScoreParams(final GossipPeerScoringConfig config) {
final GossipPeerScoreParamsBuilder builder = GossipPeerScoreParams.builder().topicScoreCap(config.getTopicScoreCap()).appSpecificWeight(config.getAppSpecificWeight()).ipColocationFactorWeight(config.getIpColocationFactorWeight()).ipColocationFactorThreshold(config.getIpColocationFactorThreshold()).behaviourPenaltyWeight(config.getBehaviourPenaltyWeight()).behaviourPenaltyDecay(config.getBehaviourPenaltyDecay()).behaviourPenaltyThreshold(config.getBehaviourPenaltyThreshold()).decayInterval(config.getDecayInterval()).decayToZero(config.getDecayToZero()).retainScore(config.getRetainScore());
// Configure optional params
config.getAppSpecificScorer().ifPresent(scorer -> {
final Function1<? super PeerId, Double> appSpecificScore = peerId -> scorer.scorePeer(new LibP2PNodeId(peerId));
builder.appSpecificScore(appSpecificScore);
});
config.getDirectPeerManager().ifPresent(mgr -> {
final Function1<? super PeerId, Boolean> isDirectPeer = peerId -> mgr.isDirectPeer(new LibP2PNodeId(peerId));
builder.isDirect(isDirectPeer);
});
config.getWhitelistManager().ifPresent(mgr -> {
// Ip whitelisting
final Function1<? super String, Boolean> isIpWhitelisted = mgr::isWhitelisted;
builder.ipWhitelisted(isIpWhitelisted);
});
return builder.build();
}
Aggregations