/** * <p>Closes the given channel using {@link ServerConnectionEventHandler#closeChannel()} and * {@link PaymentChannelV1ServerState#close()} to notify any connected client of channel closure and to complete and * broadcast the latest payment transaction.</p> * * <p>Removes the given channel from this set of {@link StoredServerChannel}s and notifies the wallet of a change to * this wallet extension.</p> */ public void closeChannel(StoredServerChannel channel) { lock.lock(); try { if (mapChannels.remove(channel.contract.getHash()) == null) return; } finally { lock.unlock(); } synchronized (channel) { channel.closeConnectedHandler(); try { TransactionBroadcaster broadcaster = getBroadcaster(); channel.getOrCreateState(wallet, broadcaster).close(); } catch (InsufficientMoneyException e) { log.error("Exception when closing channel", e); } catch (VerificationException e) { log.error("Exception when closing channel", e); } channel.state = null; } updatedChannel(channel); }
StoredServerChannel storedServerChannel = channels.getChannel(state.getContract().getHash()); if (storedServerChannel != null) { storedServerChannel.clearConnectedHandler();
protected synchronized void updateChannelInWallet() { if (storedServerChannel != null) { storedServerChannel.updateValueToMe(bestValueToMe, bestValueSignature); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID); channels.updatedChannel(storedServerChannel); } }
StoredServerChannel storedServerChannel = channels.getChannel(contractHash); if (storedServerChannel != null) { final PaymentChannelServer existingHandler = storedServerChannel.setConnectedHandler(this, false); if (existingHandler != this) { log.warn(" ... and that channel is already in use, disconnecting other user."); existingHandler.close(); storedServerChannel.setConnectedHandler(this, true); state = storedServerChannel.getOrCreateState(wallet, broadcaster); step = InitStep.CHANNEL_OPEN; conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
/** * Stores this channel's state in the wallet as a part of a {@link StoredPaymentChannelServerStates} wallet * extension and keeps it up-to-date each time payment is incremented. This will be automatically removed when * a call to {@link PaymentChannelV1ServerState#close()} completes successfully. A channel may only be stored after it * has fully opened (ie state == State.READY). * * @param connectedHandler Optional {@link PaymentChannelServer} object that manages this object. This will * set the appropriate pointer in the newly created {@link StoredServerChannel} before it is * committed to wallet. If set, closing the state object will propagate the close to the * handler which can then do a TCP disconnect. */ public synchronized void storeChannelInWallet(@Nullable PaymentChannelServer connectedHandler) { stateMachine.checkState(State.READY); if (storedServerChannel != null) return; log.info("Storing state with contract hash {}.", getContract().getHash()); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.addOrGetExistingExtension(new StoredPaymentChannelServerStates(wallet, broadcaster)); storedServerChannel = new StoredServerChannel(this, getMajorVersion(), getContract(), getClientOutput(), getExpiryTime(), serverKey, getClientKey(), bestValueToMe, bestValueSignature); if (connectedHandler != null) checkState(storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler); channels.putChannel(storedServerChannel); }
@Override public void channelOpen(Sha256Hash channelId) { log.info("Channel open for {}: {}.", clientAddress, channelId); // Try to get the state object from the stored state set in our wallet PaymentChannelServerState state = null; try { StoredPaymentChannelServerStates storedStates = (StoredPaymentChannelServerStates) appKit.wallet().getExtensions().get(StoredPaymentChannelServerStates.class.getName()); state = storedStates.getChannel(channelId).getOrCreateState(appKit.wallet(), appKit.peerGroup()); } catch (VerificationException e) { // This indicates corrupted data, and since the channel was just opened, cannot happen throw new RuntimeException(e); } log.info(" with a maximum value of {}, expiring at UNIX timestamp {}.", // The channel's maximum value is the value of the multisig contract which locks in some // amount of money to the channel state.getContract().getOutput(0).getValue(), // The channel expires at some offset from when the client's refund transaction becomes // spendable. state.getExpiryTime() + StoredPaymentChannelServerStates.CHANNEL_EXPIRE_OFFSET); }
clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray()); StoredServerChannel channel = new StoredServerChannel(null, majorVersion, params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
StoredServerChannel storedServerChannel = channels.getChannel(contractHash); if (storedServerChannel != null) { final PaymentChannelServer existingHandler = storedServerChannel.setConnectedHandler(this, false); if (existingHandler != this) { log.warn(" ... and that channel is already in use, disconnecting other user."); existingHandler.close(); storedServerChannel.setConnectedHandler(this, true); state = storedServerChannel.getOrCreateState(wallet, broadcaster); step = InitStep.CHANNEL_OPEN; conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
/** * Stores this channel's state in the wallet as a part of a {@link StoredPaymentChannelServerStates} wallet * extension and keeps it up-to-date each time payment is incremented. This will be automatically removed when * a call to {@link PaymentChannelV1ServerState#close()} completes successfully. A channel may only be stored after it * has fully opened (ie state == State.READY). * * @param connectedHandler Optional {@link PaymentChannelServer} object that manages this object. This will * set the appropriate pointer in the newly created {@link StoredServerChannel} before it is * committed to wallet. If set, closing the state object will propagate the close to the * handler which can then do a TCP disconnect. */ public synchronized void storeChannelInWallet(@Nullable PaymentChannelServer connectedHandler) { stateMachine.checkState(State.READY); if (storedServerChannel != null) return; log.info("Storing state with contract hash {}.", getContract().getHash()); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.addOrGetExistingExtension(new StoredPaymentChannelServerStates(wallet, broadcaster)); storedServerChannel = new StoredServerChannel(this, getMajorVersion(), getContract(), getClientOutput(), getExpiryTime(), serverKey, getClientKey(), bestValueToMe, bestValueSignature); if (connectedHandler != null) checkState(storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler); channels.putChannel(storedServerChannel); }
PaymentChannelServerState serverState = storedServerChannel.getOrCreateState(serverWallet, mockBroadcaster);
clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray()); StoredServerChannel channel = new StoredServerChannel(null, majorVersion, params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
/** * <p>Closes the given channel using {@link ServerConnectionEventHandler#closeChannel()} and * {@link PaymentChannelV1ServerState#close()} to notify any connected client of channel closure and to complete and * broadcast the latest payment transaction.</p> * * <p>Removes the given channel from this set of {@link StoredServerChannel}s and notifies the wallet of a change to * this wallet extension.</p> */ public void closeChannel(StoredServerChannel channel) { lock.lock(); try { if (mapChannels.remove(channel.contract.getHash()) == null) return; } finally { lock.unlock(); } synchronized (channel) { channel.closeConnectedHandler(); try { TransactionBroadcaster broadcaster = getBroadcaster(); channel.getOrCreateState(wallet, broadcaster).close(); } catch (InsufficientMoneyException e) { log.error("Exception when closing channel", e); } catch (VerificationException e) { log.error("Exception when closing channel", e); } channel.state = null; } updatedChannel(channel); }
StoredServerChannel storedServerChannel = channels.getChannel(contractHash); if (storedServerChannel != null) { final PaymentChannelServer existingHandler = storedServerChannel.setConnectedHandler(this, false); if (existingHandler != this) { log.warn(" ... and that channel is already in use, disconnecting other user."); existingHandler.close(); storedServerChannel.setConnectedHandler(this, true); state = storedServerChannel.getOrCreateState(wallet, broadcaster); step = InitStep.CHANNEL_OPEN; conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
/** * Stores this channel's state in the wallet as a part of a {@link StoredPaymentChannelServerStates} wallet * extension and keeps it up-to-date each time payment is incremented. This will be automatically removed when * a call to {@link PaymentChannelV1ServerState#close()} completes successfully. A channel may only be stored after it * has fully opened (ie state == State.READY). * * @param connectedHandler Optional {@link PaymentChannelServer} object that manages this object. This will * set the appropriate pointer in the newly created {@link StoredServerChannel} before it is * committed to wallet. If set, closing the state object will propagate the close to the * handler which can then do a TCP disconnect. */ public synchronized void storeChannelInWallet(@Nullable PaymentChannelServer connectedHandler) { stateMachine.checkState(State.READY); if (storedServerChannel != null) return; log.info("Storing state with contract hash {}.", getContract().getHash()); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.addOrGetExistingExtension(new StoredPaymentChannelServerStates(wallet, broadcaster)); storedServerChannel = new StoredServerChannel(this, getMajorVersion(), getContract(), getClientOutput(), getExpiryTime(), serverKey, getClientKey(), bestValueToMe, bestValueSignature); if (connectedHandler != null) checkState(storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler); channels.putChannel(storedServerChannel); }
protected synchronized void updateChannelInWallet() { if (storedServerChannel != null) { storedServerChannel.updateValueToMe(bestValueToMe, bestValueSignature); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID); channels.updatedChannel(storedServerChannel); } }
StoredServerChannel storedServerChannel = channels.getChannel(state.getContract().getHash()); if (storedServerChannel != null) { storedServerChannel.clearConnectedHandler();
clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray()); StoredServerChannel channel = new StoredServerChannel(null, majorVersion, params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
/** * <p>Closes the given channel using {@link ServerConnectionEventHandler#closeChannel()} and * {@link PaymentChannelV1ServerState#close()} to notify any connected client of channel closure and to complete and * broadcast the latest payment transaction.</p> * * <p>Removes the given channel from this set of {@link StoredServerChannel}s and notifies the wallet of a change to * this wallet extension.</p> */ public void closeChannel(StoredServerChannel channel) { lock.lock(); try { if (mapChannels.remove(channel.contract.getHash()) == null) return; } finally { lock.unlock(); } synchronized (channel) { channel.closeConnectedHandler(); try { TransactionBroadcaster broadcaster = getBroadcaster(); channel.getOrCreateState(wallet, broadcaster).close(); } catch (InsufficientMoneyException e) { log.error("Exception when closing channel", e); } catch (VerificationException e) { log.error("Exception when closing channel", e); } channel.state = null; } updatedChannel(channel); }
StoredServerChannel storedServerChannel = channels.getChannel(contractHash); if (storedServerChannel != null) { final PaymentChannelServer existingHandler = storedServerChannel.setConnectedHandler(this, false); if (existingHandler != this) { log.warn(" ... and that channel is already in use, disconnecting other user."); existingHandler.close(); storedServerChannel.setConnectedHandler(this, true); state = storedServerChannel.getOrCreateState(wallet, broadcaster); step = InitStep.CHANNEL_OPEN; conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
/** * Stores this channel's state in the wallet as a part of a {@link StoredPaymentChannelServerStates} wallet * extension and keeps it up-to-date each time payment is incremented. This will be automatically removed when * a call to {@link PaymentChannelV1ServerState#close()} completes successfully. A channel may only be stored after it * has fully opened (ie state == State.READY). * * @param connectedHandler Optional {@link PaymentChannelServer} object that manages this object. This will * set the appropriate pointer in the newly created {@link StoredServerChannel} before it is * committed to wallet. If set, closing the state object will propagate the close to the * handler which can then do a TCP disconnect. */ public synchronized void storeChannelInWallet(@Nullable PaymentChannelServer connectedHandler) { stateMachine.checkState(State.READY); if (storedServerChannel != null) return; log.info("Storing state with contract hash {}.", getContract().getHash()); StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates) wallet.addOrGetExistingExtension(new StoredPaymentChannelServerStates(wallet, broadcaster)); storedServerChannel = new StoredServerChannel(this, getMajorVersion(), getContract(), getClientOutput(), getExpiryTime(), serverKey, getClientKey(), bestValueToMe, bestValueSignature); if (connectedHandler != null) checkState(storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler); channels.putChannel(storedServerChannel); }