3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 02:05:53 +00:00

Peer: Add a version handshake future.

This commit is contained in:
Mike Hearn 2014-08-28 14:26:20 +02:00
parent 0ddbbfd5a4
commit d9be6a62d2
3 changed files with 11 additions and 0 deletions

View File

@ -27,6 +27,9 @@ import static com.google.common.base.Preconditions.checkArgument;
public class InventoryMessage extends ListMessage {
private static final long serialVersionUID = -7050246551646107066L;
/** A hard coded constant in the protocol. */
public static final int MAX_INV_SIZE = 50000;
public InventoryMessage(NetworkParameters params, byte[] bytes) throws ProtocolException {
super(params, bytes);
}

View File

@ -143,6 +143,7 @@ public class Peer extends PeerSocketHandler {
// A settable future which completes (with this) when the connection is open
private final SettableFuture<Peer> connectionOpenFuture = SettableFuture.create();
private final SettableFuture<Peer> versionHandshakeFuture = SettableFuture.create();
// A future representing the results of doing a getUTXOs call.
@Nullable private SettableFuture<UTXOsMessage> utxosFuture;
@ -305,6 +306,10 @@ public class Peer extends PeerSocketHandler {
return connectionOpenFuture;
}
public ListenableFuture<Peer> getVersionHandshakeFuture() {
return versionHandshakeFuture;
}
@Override
protected void processMessage(Message m) throws Exception {
// Allow event listeners to filter the message stream. Listeners are allowed to drop messages by
@ -418,6 +423,7 @@ public class Peer extends PeerSocketHandler {
// Shut down the channel
throw new ProtocolException("Peer does not have a copy of the block chain.");
}
versionHandshakeFuture.set(this);
}
private void startFilteredBlock(FilteredBlock m) {

View File

@ -166,11 +166,13 @@ public class TestWithNetworkConnections {
InboundMessageQueuer writeTarget = newPeerWriteTargetQueue.take();
writeTarget.peer = peer;
// Complete handshake with the peer - send/receive version(ack)s, receive bloom filter
checkState(!peer.getVersionHandshakeFuture().isDone());
writeTarget.sendMessage(versionMessage);
writeTarget.sendMessage(new VersionAck());
try {
checkState(writeTarget.nextMessageBlocking() instanceof VersionMessage);
checkState(writeTarget.nextMessageBlocking() instanceof VersionAck);
checkState(peer.getVersionHandshakeFuture().isDone());
synchronized (doneConnecting) {
doneConnecting.set(true);
}