use of tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId 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();
}
use of tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId in project teku by ConsenSys.
the class RpcHandler method initChannel.
@NotNull
@Override
public SafeFuture<Controller<TOutgoingHandler>> initChannel(final P2PChannel channel, final String selectedProtocol) {
final Connection connection = ((io.libp2p.core.Stream) channel).getConnection();
final NodeId nodeId = new LibP2PNodeId(connection.secureSession().getRemoteId());
final Controller<TOutgoingHandler> controller = new Controller<>(nodeId, channel);
if (!channel.isInitiator()) {
controller.setIncomingRequestHandler(rpcMethod.createIncomingRequestHandler(selectedProtocol));
}
channel.pushHandler(controller);
return controller.activeFuture;
}
use of tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId in project teku by ConsenSys.
the class LibP2PGossipNetwork method getSubscribersByTopic.
@Override
public Map<String, Collection<NodeId>> getSubscribersByTopic() {
Map<PeerId, Set<Topic>> peerTopics = gossip.getPeerTopics().join();
final Map<String, Collection<NodeId>> result = new HashMap<>();
for (Map.Entry<PeerId, Set<Topic>> peerTopic : peerTopics.entrySet()) {
final LibP2PNodeId nodeId = new LibP2PNodeId(peerTopic.getKey());
peerTopic.getValue().forEach(topic -> result.computeIfAbsent(topic.getTopic(), __ -> new HashSet<>()).add(nodeId));
}
return result;
}
use of tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId in project teku by ConsenSys.
the class NodeIdTest method shouldBeEqualToNodeIdsOfDifferentTypes.
@Test
public void shouldBeEqualToNodeIdsOfDifferentTypes() {
final PeerId peerId = PeerId.fromHex(ID);
final NodeId libP2PNodeId = new LibP2PNodeId(peerId);
final MockNodeId mockNodeId = new MockNodeId(Bytes.fromHexString(ID));
assertThat(mockNodeId).isEqualTo(libP2PNodeId);
assertThat(libP2PNodeId).isEqualTo(mockNodeId);
assertThat(mockNodeId.hashCode()).isEqualTo(libP2PNodeId.hashCode());
}
use of tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId in project teku by ConsenSys.
the class NodeIdTest method shouldBeDifferentWhenBytesAreDifferent.
@Test
public void shouldBeDifferentWhenBytesAreDifferent() {
final LibP2PNodeId libP2PNodeId = new LibP2PNodeId(PeerId.fromHex(ID));
final MockNodeId mockNodeId = new MockNodeId(1);
assertThat(mockNodeId).isNotEqualTo(libP2PNodeId);
assertThat(libP2PNodeId).isNotEqualTo(mockNodeId);
assertThat(mockNodeId.hashCode()).isNotEqualTo(libP2PNodeId.hashCode());
}
Aggregations