@Test public void shouldSendClientVersionOnChannelOpen() throws Exception { PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, null, clientChannelProperties, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(defaultTimeWindow); }
@Override public void connectionOpen() { lock.lock(); try { connectionOpen = true; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); if (channels != null) storedChannel = channels.getUsableChannelForServerID(serverId); step = InitStep.WAITING_FOR_VERSION_NEGOTIATION; Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder() .setMajor(versionSelector.getRequestedMajorVersion()) .setMinor(versionSelector.getRequestedMinorVersion()) .setTimeWindowSecs(timeWindow); if (storedChannel != null) { versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getTxId().getBytes())); log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getTxId()); } else log.info("Begun version handshake creating new channel"); conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder() .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION) .setClientVersion(versionNegotiationBuilder) .build()); } finally { lock.unlock(); } }
PaymentChannelClient implements IPaymentChannelClient { @Override public void connectionOpen() { lock.lock(); try { connectionOpen = true; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); if (channels != null) storedChannel = channels.getUsableChannelForServerID(serverId); step = InitStep.WAITING_FOR_VERSION_NEGOTIATION; Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder() .setMajor(versionSelector.getRequestedMajorVersion()) .setMinor(versionSelector.getRequestedMinorVersion()) .setTimeWindowSecs(timeWindow); if (storedChannel != null) { versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getTxId().getBytes())); log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getTxId()); } else log.info("Begun version handshake creating new channel"); conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder() .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION) .setClientVersion(versionNegotiationBuilder) .build()); } finally { lock.unlock(); } } }
PaymentChannelClient implements IPaymentChannelClient { @Override public void connectionOpen() { lock.lock(); try { connectionOpen = true; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); if (channels != null) storedChannel = channels.getUsableChannelForServerID(serverId); step = InitStep.WAITING_FOR_VERSION_NEGOTIATION; Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder() .setMajor(versionSelector.getRequestedMajorVersion()) .setMinor(versionSelector.getRequestedMinorVersion()) .setTimeWindowSecs(timeWindow); if (storedChannel != null) { versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getTxId().getBytes())); log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getTxId()); } else log.info("Begun version handshake creating new channel"); conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder() .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION) .setClientVersion(versionNegotiationBuilder) .build()); } finally { lock.unlock(); } } PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, @Nullable ClientChannelProperties clientChannelProperties,
                                ClientConnection conn); }
PaymentChannelClient implements IPaymentChannelClient { @Override public void connectionOpen() { lock.lock(); try { connectionOpen = true; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); if (channels != null) storedChannel = channels.getUsableChannelForServerID(serverId); step = InitStep.WAITING_FOR_VERSION_NEGOTIATION; Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder() .setMajor(versionSelector.getRequestedMajorVersion()) .setMinor(versionSelector.getRequestedMinorVersion()) .setTimeWindowSecs(timeWindow); if (storedChannel != null) { versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getTxId().getBytes())); log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getTxId()); } else log.info("Begun version handshake creating new channel"); conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder() .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION) .setClientVersion(versionNegotiationBuilder) .build()); } finally { lock.unlock(); } } PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, @Nullable ClientChannelProperties clientChannelProperties,
                                ClientConnection conn); Coin getMissing(); @Override void receiveMessage(Protos.TwoWayChannelMessage msg); @Override void connectionClosed(); @Override void settle(); @Override void connectionOpen(); PaymentChannelClientState state(); ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size); @Override ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size, @Nullable ByteString info, @Nullable KeyParameter userKey); }
PaymentChannelClient implements IPaymentChannelClient { @Override public void connectionOpen() { lock.lock(); try { connectionOpen = true; StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); if (channels != null) storedChannel = channels.getUsableChannelForServerID(serverId); step = InitStep.WAITING_FOR_VERSION_NEGOTIATION; Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder() .setMajor(versionSelector.getRequestedMajorVersion()) .setMinor(versionSelector.getRequestedMinorVersion()) .setTimeWindowSecs(timeWindow); if (storedChannel != null) { versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getTxId().getBytes())); log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getTxId()); } else log.info("Begun version handshake creating new channel"); conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder() .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION) .setClientVersion(versionNegotiationBuilder) .build()); } finally { lock.unlock(); } } PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, ClientConnection conn);  PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
                                @Nullable KeyParameter userKeySetup, @Nullable ClientChannelProperties clientChannelProperties,
                                ClientConnection conn); Coin getMissing(); @Override void receiveMessage(Protos.TwoWayChannelMessage msg); @Override void connectionClosed(); @Override void settle(); @Override void connectionOpen(); PaymentChannelClientState state(); ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size); @Override ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size, @Nullable ByteString info, @Nullable KeyParameter userKey); static final long DEFAULT_TIME_WINDOW; static DefaultClientChannelProperties defaultChannelProperties; }