@Test public void shouldRespondWithErrorIfStatusUnavailable() { when(statusMessageFactory.createStatusMessage()).thenReturn(Optional.empty()); handler.onIncomingMessage(peer, REMOTE_STATUS, callback); verify(peer).updateStatus(PEER_STATUS); verify(callback).completeWithErrorResponse(NODE_NOT_READY); }
@Override public void onIncomingMessage( final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) { LOG.trace("Peer {} sent status {}", peer.getId(), message); if (!peer.wantToMakeRequest()) { return; } final PeerStatus status = PeerStatus.fromStatusMessage(message); peer.updateStatus(status); final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage(); if (localStatus.isPresent()) { callback.respondAndCompleteSuccessfully(localStatus.get()); } else { LOG.warn( "Node is not ready to receive p2p traffic. Responding to incoming status message with an error."); callback.completeWithErrorResponse(NODE_NOT_READY); } }
StatusMessageHandler extends PeerRequiredLocalMessageHandler<StatusMessage, StatusMessage> { @Override public void onIncomingMessage( final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) { LOG.trace("Peer {} sent status {}", peer.getId(), message); if (!peer.wantToMakeRequest()) { return; } final PeerStatus status = PeerStatus.fromStatusMessage(message); peer.updateStatus(status); final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage(); if (localStatus.isPresent()) { callback.respondAndCompleteSuccessfully(localStatus.get()); } else { LOG.warn( "Node is not ready to receive p2p traffic. Responding to incoming status message with an error."); callback.completeWithErrorResponse(NODE_NOT_READY); } } }
StatusMessageHandler extends PeerRequiredLocalMessageHandler<StatusMessage, StatusMessage> { @Override public void onIncomingMessage( final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) { LOG.trace("Peer {} sent status {}", peer.getId(), message); if (!peer.wantToMakeRequest()) { return; } final PeerStatus status = PeerStatus.fromStatusMessage(message); peer.updateStatus(status); final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage(); if (localStatus.isPresent()) { callback.respondAndCompleteSuccessfully(localStatus.get()); } else { LOG.warn( "Node is not ready to receive p2p traffic. Responding to incoming status message with an error."); callback.completeWithErrorResponse(NODE_NOT_READY); } } StatusMessageHandler(final StatusMessageFactory statusMessageFactory); }
StatusMessageHandler extends PeerRequiredLocalMessageHandler<StatusMessage, StatusMessage> { @Override public void onIncomingMessage( final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) { LOG.trace("Peer {} sent status {}", peer.getId(), message); if (!peer.wantToMakeRequest()) { return; } final PeerStatus status = PeerStatus.fromStatusMessage(message); peer.updateStatus(status); final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage(); if (localStatus.isPresent()) { callback.respondAndCompleteSuccessfully(localStatus.get()); } else { LOG.warn( "Node is not ready to receive p2p traffic. Responding to incoming status message with an error."); callback.completeWithErrorResponse(NODE_NOT_READY); } } StatusMessageHandler(final StatusMessageFactory statusMessageFactory); @Override void onIncomingMessage(
      final Eth2Peer peer,
      final StatusMessage message,
      final ResponseCallback<StatusMessage> callback); }
StatusMessageHandler extends PeerRequiredLocalMessageHandler<StatusMessage, StatusMessage> { @Override public void onIncomingMessage( final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) { LOG.trace("Peer {} sent status {}", peer.getId(), message); if (!peer.wantToMakeRequest()) { return; } final PeerStatus status = PeerStatus.fromStatusMessage(message); peer.updateStatus(status); final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage(); if (localStatus.isPresent()) { callback.respondAndCompleteSuccessfully(localStatus.get()); } else { LOG.warn( "Node is not ready to receive p2p traffic. Responding to incoming status message with an error."); callback.completeWithErrorResponse(NODE_NOT_READY); } } StatusMessageHandler(final StatusMessageFactory statusMessageFactory); @Override void onIncomingMessage(
      final Eth2Peer peer,
      final StatusMessage message,
      final ResponseCallback<StatusMessage> callback);  }