@Test public void sendPacketWithInvalidCondition() { final InterledgerPreparePacket preparePacket = InterledgerPreparePacket.builder() .amount(UnsignedLong.valueOf(10L)) .executionCondition(InterledgerCondition.of(new byte[32])) .destination(OPERATOR_ADDRESS) .expiresAt(DateUtils.now()) .build(); link.sendPacket(preparePacket).handle(fulfillPacket -> { logger.error("InterledgerFulfillPacket: {}", fulfillPacket); fail("Expected a Reject!"); }, rejectPacket -> { assertThat(rejectPacket.getCode()).isEqualTo(InterledgerErrorCode.F00_BAD_REQUEST); assertThat(rejectPacket.getTriggeredBy().isPresent()).isEqualTo(true); assertThat(rejectPacket.getTriggeredBy()).isEqualTo(EXPECTED_REJECT_PACKET.getTriggeredBy()); } ); }
@Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } }
PingLoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } } }
PingLoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } } PingLoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings
  ); }
PingLoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } } PingLoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings
  ); @Override void registerLinkHandler(LinkHandler ilpDataHandler); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); @Override String toString(); }
PingLoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } } PingLoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings
  ); @Override void registerLinkHandler(LinkHandler ilpDataHandler); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); @Override String toString(); static final String LINK_TYPE_STRING; static final LinkType LINK_TYPE; static final InterledgerFulfillment PING_PROTOCOL_FULFILLMENT; static final InterledgerCondition PING_PROTOCOL_CONDITION; }