Search in sources :

Example 1 with Session

use of io.libp2p.core.security.SecureChannel.Session in project teku by ConsenSys.

the class PeerManagerTest method shouldReportSuccessfulConnectionsToReputationManager.

@Test
public void shouldReportSuccessfulConnectionsToReputationManager() {
    final Connection connection = mock(Connection.class);
    final Session secureSession = new Session(PeerId.random(), PeerId.random(), EcdsaKt.generateEcdsaKeyPair().component2());
    when(connection.secureSession()).thenReturn(secureSession);
    when(connection.closeFuture()).thenReturn(new SafeFuture<>());
    final Multiaddr multiaddr = Multiaddr.fromString("/ip4/127.0.0.1/tcp/9000");
    final MultiaddrPeerAddress peerAddress = new MultiaddrPeerAddress(new MockNodeId(1), multiaddr);
    final SafeFuture<Connection> connectionFuture = new SafeFuture<>();
    when(network.connect(multiaddr)).thenReturn(connectionFuture);
    final SafeFuture<Peer> result = peerManager.connect(peerAddress, network);
    peerManager.handleConnection(connection);
    connectionFuture.complete(connection);
    assertThat(result).isCompleted();
    verify(reputationManager).reportInitiatedConnectionSuccessful(peerAddress);
    verify(reputationManager, never()).reportInitiatedConnectionFailed(peerAddress);
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) Connection(io.libp2p.core.Connection) Multiaddr(io.libp2p.core.multiformats.Multiaddr) Session(io.libp2p.core.security.SecureChannel.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (io.libp2p.core.Connection)1 Multiaddr (io.libp2p.core.multiformats.Multiaddr)1 Session (io.libp2p.core.security.SecureChannel.Session)1 Test (org.junit.jupiter.api.Test)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)1 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)1