org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason Java Examples

The following examples show how to use org.bitcoinj.protocols.channels.PaymentChannelCloseException.CloseReason. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PaymentChannelClient.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(lock.isHeldByCurrentThread());
    if (msg.hasSettlement()) {
        Transaction settleTx = wallet.getParams().getDefaultSerializer().makeTransaction(msg.getSettlement().getTx().toByteArray());
        log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
        // TODO: set source
        if (state != null && state().isSettlementTransaction(settleTx)) {
            // The wallet has a listener on it that the state object will use to do the right thing at this
            // point (like watching it for confirmations). The tx has been checked by now for syntactical validity
            // and that it correctly spends the multisig contract.
            wallet.receivePending(settleTx, null);
        }
    } else {
        log.info("CLOSE message received without settlement tx");
    }
    if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    else
        conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
    step = InitStep.CHANNEL_CLOSED;
}
 
Example #2
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
    // Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
    // close() on us here below via the stored channel state.
    // TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
    channelSettling = true;
    ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
    ListenableFuture<Transaction> result;
    if (keyFuture != null) {
        result = Futures.transformAsync(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
            @Override
            public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
                return state.close(userKey);
            }
        });
    } else {
        result = state.close();
    }
    Futures.addCallback(result, new FutureCallback<Transaction>() {
 
Example #3
Source File: PaymentChannelClient.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(lock.isHeldByCurrentThread());
    if (msg.hasSettlement()) {
        Transaction settleTx = wallet.getParams().getDefaultSerializer().makeTransaction(msg.getSettlement().getTx().toByteArray());
        log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
        // TODO: set source
        if (state != null && state().isSettlementTransaction(settleTx)) {
            // The wallet has a listener on it that the state object will use to do the right thing at this
            // point (like watching it for confirmations). The tx has been checked by now for syntactical validity
            // and that it correctly spends the multisig contract.
            wallet.receivePending(settleTx, null);
        }
    } else {
        log.info("CLOSE message received without settlement tx");
    }
    if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    else
        conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
    step = InitStep.CHANNEL_CLOSED;
}
 
Example #4
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
    // Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
    // close() on us here below via the stored channel state.
    // TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
    channelSettling = true;
    ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
    ListenableFuture<Transaction> result;
    if (keyFuture != null) {
        result = Futures.transformAsync(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
            @Override
            public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
                return state.close(userKey);
            }
        });
    } else {
        result = state.close();
    }
    Futures.addCallback(result, new FutureCallback<Transaction>() {
 
Example #5
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void settlePayment(final CloseReason clientRequestedClose) throws InsufficientMoneyException {
    // Setting channelSettling here prevents us from sending another CLOSE when state.close() calls
    // close() on us here below via the stored channel state.
    // TODO: Strongly separate the lifecycle of the payment channel from the TCP connection in these classes.
    channelSettling = true;
    ListenableFuture<KeyParameter> keyFuture = conn.getUserKey();
    ListenableFuture<Transaction> result;
    if (keyFuture != null) {
        result = Futures.transformAsync(conn.getUserKey(), new AsyncFunction<KeyParameter, Transaction>() {
            @Override
            public ListenableFuture<Transaction> apply(KeyParameter userKey) throws Exception {
                return state.close(userKey);
            }
        });
    } else {
        result = state.close();
    }
    Futures.addCallback(result, new FutureCallback<Transaction>() {
 
Example #6
Source File: PaymentChannelClient.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@GuardedBy("lock")
private void receiveClose(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(lock.isHeldByCurrentThread());
    if (msg.hasSettlement()) {
        Transaction settleTx = wallet.getParams().getDefaultSerializer().makeTransaction(msg.getSettlement().getTx().toByteArray());
        log.info("CLOSE message received with settlement tx {}", settleTx.getHash());
        // TODO: set source
        if (state != null && state().isSettlementTransaction(settleTx)) {
            // The wallet has a listener on it that the state object will use to do the right thing at this
            // point (like watching it for confirmations). The tx has been checked by now for syntactical validity
            // and that it correctly spends the multisig contract.
            wallet.receivePending(settleTx, null);
        }
    } else {
        log.info("CLOSE message received without settlement tx");
    }
    if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    else
        conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
    step = InitStep.CHANNEL_CLOSED;
}
 
Example #7
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>Closes the connection by generating a settle message for the client and calls
 * {@link ServerConnection#destroyConnection(CloseReason)}. Note that this does not broadcast
 * the payment transaction and the client may still resume the same channel if they reconnect</p>
 * <p>
 * <p>Note that {@link PaymentChannelServer#connectionClosed()} must still be called after the connection fully
 * closes.</p>
 */
public void close() {
    lock.lock();
    try {
        if (connectionOpen && !channelSettling) {
            final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
            msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
            conn.sendToClient(msg.build());
            conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
        }
    } finally {
        lock.unlock();
    }
}
 
Example #8
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveCloseMessage() throws InsufficientMoneyException {
    log.info("Got CLOSE message, closing channel");
    if (state != null) {
        settlePayment(CloseReason.CLIENT_REQUESTED_CLOSE);
    } else {
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    }
}
 
Example #9
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private void error(String message, Protos.Error.ErrorCode errorCode, CloseReason closeReason) {
    log.error(message);
    Protos.Error.Builder errorBuilder;
    errorBuilder = Protos.Error.newBuilder()
            .setCode(errorCode)
            .setExplanation(message);
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setError(errorBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.ERROR)
            .build());
    conn.destroyConnection(closeReason);
}
 
Example #10
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>Closes the connection by generating a settle message for the client and calls
 * {@link ServerConnection#destroyConnection(CloseReason)}. Note that this does not broadcast
 * the payment transaction and the client may still resume the same channel if they reconnect</p>
 * <p>
 * <p>Note that {@link PaymentChannelServer#connectionClosed()} must still be called after the connection fully
 * closes.</p>
 */
public void close() {
    lock.lock();
    try {
        if (connectionOpen && !channelSettling) {
            final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
            msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
            conn.sendToClient(msg.build());
            conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
        }
    } finally {
        lock.unlock();
    }
}
 
Example #11
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveCloseMessage() throws InsufficientMoneyException {
    log.info("Got CLOSE message, closing channel");
    if (state != null) {
        settlePayment(CloseReason.CLIENT_REQUESTED_CLOSE);
    } else {
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    }
}
 
Example #12
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private void error(String message, Protos.Error.ErrorCode errorCode, CloseReason closeReason) {
    log.error(message);
    Protos.Error.Builder errorBuilder;
    errorBuilder = Protos.Error.newBuilder()
            .setCode(errorCode)
            .setExplanation(message);
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setError(errorBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.ERROR)
            .build());
    conn.destroyConnection(closeReason);
}
 
Example #13
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>Closes the connection by generating a settle message for the client and calls
 * {@link PaymentChannelServer.ServerConnection#destroyConnection(PaymentChannelCloseException.CloseReason)}. Note that this does not broadcast
 * the payment transaction and the client may still resume the same channel if they reconnect</p>
 * <p>
 * <p>Note that {@link PaymentChannelServer#connectionClosed()} must still be called after the connection fully
 * closes.</p>
 */
public void close() {
    lock.lock();
    try {
        if (connectionOpen && !channelSettling) {
            final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
            msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
            conn.sendToClient(msg.build());
            conn.destroyConnection(CloseReason.SERVER_REQUESTED_CLOSE);
        }
    } finally {
        lock.unlock();
    }
}
 
Example #14
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveCloseMessage() throws InsufficientMoneyException {
    log.info("Got CLOSE message, closing channel");
    if (state != null) {
        settlePayment(CloseReason.CLIENT_REQUESTED_CLOSE);
    } else {
        conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
    }
}
 
Example #15
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void error(String message, Protos.Error.ErrorCode errorCode, CloseReason closeReason) {
    log.error(message);
    Protos.Error.Builder errorBuilder;
    errorBuilder = Protos.Error.newBuilder()
            .setCode(errorCode);
    if (message != null)
        errorBuilder.setExplanation(message);
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setError(errorBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.ERROR)
            .build());
    conn.destroyConnection(closeReason);
}
 
Example #16
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
@GuardedBy("lock")
private void receiveVersionMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_CLIENT_VERSION && msg.hasClientVersion());
    final Protos.ClientVersion clientVersion = msg.getClientVersion();
    majorVersion = clientVersion.getMajor();
    if (!SERVER_VERSIONS.containsKey(majorVersion)) {
        error("This server needs one of protocol versions " + SERVER_VERSIONS.keySet() + " , client offered " + majorVersion,
                Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
        return;
    }

    Protos.ServerVersion.Builder versionNegotiationBuilder = Protos.ServerVersion.newBuilder()
            .setMajor(majorVersion).setMinor(SERVER_VERSIONS.get(majorVersion));
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
            .setServerVersion(versionNegotiationBuilder)
            .build());
    ByteString reopenChannelContractHash = clientVersion.getPreviousChannelContractHash();
    if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
        Sha256Hash contractHash = Sha256Hash.wrap(reopenChannelContractHash.toByteArray());
        log.info("New client that wants to resume {}", contractHash);
        StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
                wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
        if (channels != null) {
            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);
                }

                log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
                state = storedServerChannel.getOrCreateState(wallet, broadcaster);
                step = InitStep.CHANNEL_OPEN;
                conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
                        .setType(Protos.TwoWayChannelMessage.MessageType.CHANNEL_OPEN)
                        .build());
                conn.channelOpen(contractHash);
                return;
            } else {
                log.error(" ... but we do not have any record of that contract! Resume failed.");
            }
        } else {
            log.error(" ... but we do not have any stored channels! Resume failed.");
        }
    }
    log.info("Got initial version message, responding with VERSIONS and INITIATE: min value={}",
            minAcceptedChannelSize.value);

    myKey = new ECKey();
    wallet.freshReceiveKey();

    expireTime = Utils.currentTimeSeconds() + truncateTimeWindow(clientVersion.getTimeWindowSecs());
    switch (majorVersion) {
        case 1:
            step = InitStep.WAITING_ON_UNSIGNED_REFUND;
            break;
        case 2:
            step = InitStep.WAITING_ON_CONTRACT;
            break;
        default:
            error("Protocol version " + majorVersion + " not supported", Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
            break;
    }

    Protos.Initiate.Builder initiateBuilder = Protos.Initiate.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setExpireTimeSecs(expireTime)
            .setMinAcceptedChannelSize(minAcceptedChannelSize.value)
            .setMinPayment(minPayment.value);

    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setInitiate(initiateBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.INITIATE)
            .build());
}
 
Example #17
Source File: PaymentChannelClient.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private void setIncreasePaymentFutureIfNeeded(PaymentChannelCloseException.CloseReason reason, String message) {
    if (increasePaymentFuture != null && !increasePaymentFuture.isDone()) {
        increasePaymentFuture.setException(new PaymentChannelCloseException(message, reason));
    }
}
 
Example #18
Source File: PaymentChannelClient.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private void setIncreasePaymentFutureIfNeeded(PaymentChannelCloseException.CloseReason reason, String message) {
    if (increasePaymentFuture != null && !increasePaymentFuture.isDone()) {
        increasePaymentFuture.setException(new PaymentChannelCloseException(message, reason));
    }
}
 
Example #19
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
@GuardedBy("lock")
private void receiveVersionMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_CLIENT_VERSION && msg.hasClientVersion());
    final Protos.ClientVersion clientVersion = msg.getClientVersion();
    majorVersion = clientVersion.getMajor();
    if (!SERVER_VERSIONS.containsKey(majorVersion)) {
        error("This server needs one of protocol versions " + SERVER_VERSIONS.keySet() + " , client offered " + majorVersion,
                Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
        return;
    }

    Protos.ServerVersion.Builder versionNegotiationBuilder = Protos.ServerVersion.newBuilder()
            .setMajor(majorVersion).setMinor(SERVER_VERSIONS.get(majorVersion));
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
            .setServerVersion(versionNegotiationBuilder)
            .build());
    ByteString reopenChannelContractHash = clientVersion.getPreviousChannelContractHash();
    if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
        Sha256Hash contractHash = Sha256Hash.wrap(reopenChannelContractHash.toByteArray());
        log.info("New client that wants to resume {}", contractHash);
        StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
                wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
        if (channels != null) {
            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);
                }

                log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
                state = storedServerChannel.getOrCreateState(wallet, broadcaster);
                step = InitStep.CHANNEL_OPEN;
                conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
                        .setType(Protos.TwoWayChannelMessage.MessageType.CHANNEL_OPEN)
                        .build());
                conn.channelOpen(contractHash);
                return;
            } else {
                log.error(" ... but we do not have any record of that contract! Resume failed.");
            }
        } else {
            log.error(" ... but we do not have any stored channels! Resume failed.");
        }
    }
    log.info("Got initial version message, responding with VERSIONS and INITIATE: min value={}",
            minAcceptedChannelSize.value);

    myKey = new ECKey();
    wallet.freshReceiveKey();

    expireTime = Utils.currentTimeSeconds() + truncateTimeWindow(clientVersion.getTimeWindowSecs());
    switch (majorVersion) {
        case 1:
            step = InitStep.WAITING_ON_UNSIGNED_REFUND;
            break;
        case 2:
            step = InitStep.WAITING_ON_CONTRACT;
            break;
        default:
            error("Protocol version " + majorVersion + " not supported", Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
            break;
    }

    Protos.Initiate.Builder initiateBuilder = Protos.Initiate.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setExpireTimeSecs(expireTime)
            .setMinAcceptedChannelSize(minAcceptedChannelSize.value)
            .setMinPayment(minPayment.value);

    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setInitiate(initiateBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.INITIATE)
            .build());
}
 
Example #20
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@GuardedBy("lock")
private void receiveVersionMessage(Protos.TwoWayChannelMessage msg) throws VerificationException {
    checkState(step == InitStep.WAITING_ON_CLIENT_VERSION && msg.hasClientVersion());
    final Protos.ClientVersion clientVersion = msg.getClientVersion();
    majorVersion = clientVersion.getMajor();
    if (!SERVER_VERSIONS.containsKey(majorVersion)) {
        error("This server needs one of protocol versions " + SERVER_VERSIONS.keySet() + " , client offered " + majorVersion,
                Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
        return;
    }

    Protos.ServerVersion.Builder versionNegotiationBuilder = Protos.ServerVersion.newBuilder()
            .setMajor(majorVersion).setMinor(SERVER_VERSIONS.get(majorVersion));
    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
            .setServerVersion(versionNegotiationBuilder)
            .build());
    ByteString reopenChannelContractHash = clientVersion.getPreviousChannelContractHash();
    if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
        Sha256Hash contractHash = Sha256Hash.wrap(reopenChannelContractHash.toByteArray());
        log.info("New client that wants to resume {}", contractHash);
        StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
                wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
        if (channels != null) {
            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);
                }

                log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
                state = storedServerChannel.getOrCreateState(wallet, broadcaster);
                step = InitStep.CHANNEL_OPEN;
                conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
                        .setType(Protos.TwoWayChannelMessage.MessageType.CHANNEL_OPEN)
                        .build());
                conn.channelOpen(contractHash);
                return;
            } else {
                log.error(" ... but we do not have any record of that contract! Resume failed.");
            }
        } else {
            log.error(" ... but we do not have any stored channels! Resume failed.");
        }
    }
    log.info("Got initial version message, responding with VERSIONS and INITIATE: min value={}",
            minAcceptedChannelSize.value);

    myKey = new ECKey();
    wallet.freshReceiveKey();

    expireTime = Utils.currentTimeSeconds() + truncateTimeWindow(clientVersion.getTimeWindowSecs());
    switch (majorVersion) {
        case 1:
            step = InitStep.WAITING_ON_UNSIGNED_REFUND;
            break;
        case 2:
            step = InitStep.WAITING_ON_CONTRACT;
            break;
        default:
            error("Protocol version " + majorVersion + " not supported", Protos.Error.ErrorCode.NO_ACCEPTABLE_VERSION, CloseReason.NO_ACCEPTABLE_VERSION);
            break;
    }

    Protos.Initiate.Builder initiateBuilder = Protos.Initiate.newBuilder()
            .setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
            .setExpireTimeSecs(expireTime)
            .setMinAcceptedChannelSize(minAcceptedChannelSize.value)
            .setMinPayment(minPayment.value);

    conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
            .setInitiate(initiateBuilder)
            .setType(Protos.TwoWayChannelMessage.MessageType.INITIATE)
            .build());
}
 
Example #21
Source File: PaymentChannelClient.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private void setIncreasePaymentFutureIfNeeded(PaymentChannelCloseException.CloseReason reason, String message) {
    if (increasePaymentFuture != null && !increasePaymentFuture.isDone()) {
        increasePaymentFuture.setException(new PaymentChannelCloseException(message, reason));
    }
}
 
Example #22
Source File: PaymentChannelServer.java    From green_android with GNU General Public License v3.0 2 votes vote down vote up
/**
 * <p>Requests that the connection to the client be closed</p>
 *
 * <p>Called while holding a lock on the {@link PaymentChannelServer} object - be careful about reentrancy</p>
 *
 * @param reason The reason for the closure, see the individual values for more details.
 *               It is usually safe to ignore this value.
 */
void destroyConnection(CloseReason reason);
 
Example #23
Source File: PaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 2 votes vote down vote up
/**
 * <p>Requests that the connection to the client be closed</p>
 *
 * <p>Called while holding a lock on the {@link PaymentChannelServer} object - be careful about reentrancy</p>
 *
 * @param reason The reason for the closure, see the individual values for more details.
 *               It is usually safe to ignore this value.
 */
void destroyConnection(CloseReason reason);
 
Example #24
Source File: PaymentChannelServer.java    From bcm-android with GNU General Public License v3.0 2 votes vote down vote up
/**
 * <p>Requests that the connection to the client be closed</p>
 * <p>
 * <p>Called while holding a lock on the {@link PaymentChannelServer} object - be careful about reentrancy</p>
 *
 * @param reason The reason for the closure, see the individual values for more details.
 *               It is usually safe to ignore this value.
 */
void destroyConnection(CloseReason reason);