mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Payment channels: default server should not attempt to destroy the [TCP] connection after sending a CLOSE, let the client do that.
This resolves some complicated state management issues in some kinds of client (like on Android). It's also just generally a part of the work to divorce the notion of settling a channel from closing underlying protocol connections.
This commit is contained in:
parent
4b48dbfda9
commit
a051afe224
@ -298,6 +298,7 @@ public class PaymentChannelClient {
|
||||
checkState(lock.isHeldByCurrentThread());
|
||||
if (msg.hasClose()) {
|
||||
Transaction closeTx = new Transaction(wallet.getParams(), msg.getClose().getTx().toByteArray());
|
||||
log.info("CLOSE message received with final contract {}", closeTx.getHash());
|
||||
// TODO: set source
|
||||
if (state != null && state().isCloseTransaction(closeTx)) {
|
||||
// The wallet has a listener on it that the state object will use to do the right thing at this
|
||||
@ -305,6 +306,8 @@ public class PaymentChannelClient {
|
||||
// and that it correctly spends the multisig contract.
|
||||
wallet.receivePending(closeTx, null);
|
||||
}
|
||||
} else {
|
||||
log.info("CLOSE message received without final contract");
|
||||
}
|
||||
if (step == InitStep.WAITING_FOR_CHANNEL_CLOSE)
|
||||
conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
|
||||
|
@ -319,8 +319,10 @@ public class PaymentChannelServer {
|
||||
// properly and so on.
|
||||
msg.getCloseBuilder().setTx(ByteString.copyFrom(result.bitcoinSerialize()));
|
||||
}
|
||||
log.info("Sending CLOSE back with finalized broadcast contract.");
|
||||
conn.sendToClient(msg.build());
|
||||
conn.destroyConnection(CloseReason.CLIENT_REQUESTED_CLOSE);
|
||||
// The client is expected to hang up the TCP connection after we send back the
|
||||
// CLOSE message.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,8 @@ import com.google.bitcoin.protocols.niowrapper.ProtobufParser;
|
||||
import org.bitcoin.paymentchannel.Protos;
|
||||
|
||||
/**
|
||||
* A connection-specific event handler that handles events generated by client connections on a {@link PaymentChannelServerListener}
|
||||
* A connection-specific event handler that handles events generated by client connections on a
|
||||
* {@link PaymentChannelServerListener}
|
||||
*/
|
||||
public abstract class ServerConnectionEventHandler {
|
||||
private ProtobufParser connectionChannel;
|
||||
|
Loading…
Reference in New Issue
Block a user