Search in sources :

Example 1 with LibP2PNodeId

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();
}
Also used : GossipPeerScoreParams(io.libp2p.pubsub.gossip.GossipPeerScoreParams) GossipScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipScoringConfig) GossipPeerScoreParamsBuilder(io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder) GossipConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig) GossipParams(io.libp2p.pubsub.gossip.GossipParams) GossipScoreParams(io.libp2p.pubsub.gossip.GossipScoreParams) Function1(kotlin.jvm.functions.Function1) Collectors(java.util.stream.Collectors) GossipPeerScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig) PeerId(io.libp2p.core.PeerId) GossipTopicScoreParams(io.libp2p.pubsub.gossip.GossipTopicScoreParams) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) Map(java.util.Map) GossipTopicsScoreParams(io.libp2p.pubsub.gossip.GossipTopicsScoreParams) GossipTopicScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipTopicScoringConfig) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) GossipPeerScoreParamsBuilder(io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder)

Example 2 with LibP2PNodeId

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;
}
Also used : Connection(io.libp2p.core.Connection) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) RpcStream(tech.pegasys.teku.networking.p2p.rpc.RpcStream) Stream(io.libp2p.core.Stream) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) Controller(tech.pegasys.teku.networking.p2p.libp2p.rpc.RpcHandler.Controller) RpcStreamController(tech.pegasys.teku.networking.p2p.rpc.RpcStreamController) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LibP2PNodeId

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Collection(java.util.Collection) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) HashMap(java.util.HashMap) Map(java.util.Map) PeerId(io.libp2p.core.PeerId)

Example 4 with LibP2PNodeId

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());
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) PeerId(io.libp2p.core.PeerId) Test(org.junit.jupiter.api.Test)

Example 5 with LibP2PNodeId

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());
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) Test(org.junit.jupiter.api.Test)

Aggregations

LibP2PNodeId (tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId)5 PeerId (io.libp2p.core.PeerId)3 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)2 Connection (io.libp2p.core.Connection)1 Stream (io.libp2p.core.Stream)1 GossipParams (io.libp2p.pubsub.gossip.GossipParams)1 GossipPeerScoreParams (io.libp2p.pubsub.gossip.GossipPeerScoreParams)1 GossipScoreParams (io.libp2p.pubsub.gossip.GossipScoreParams)1 GossipTopicScoreParams (io.libp2p.pubsub.gossip.GossipTopicScoreParams)1 GossipTopicsScoreParams (io.libp2p.pubsub.gossip.GossipTopicsScoreParams)1 GossipPeerScoreParamsBuilder (io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Function1 (kotlin.jvm.functions.Function1)1 NotNull (org.jetbrains.annotations.NotNull)1