mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 11:15:51 +00:00
Peer: Add a version handshake future.
This commit is contained in:
parent
0ddbbfd5a4
commit
d9be6a62d2
@ -27,6 +27,9 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
public class InventoryMessage extends ListMessage {
|
public class InventoryMessage extends ListMessage {
|
||||||
private static final long serialVersionUID = -7050246551646107066L;
|
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 {
|
public InventoryMessage(NetworkParameters params, byte[] bytes) throws ProtocolException {
|
||||||
super(params, bytes);
|
super(params, bytes);
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
|
|
||||||
// A settable future which completes (with this) when the connection is open
|
// A settable future which completes (with this) when the connection is open
|
||||||
private final SettableFuture<Peer> connectionOpenFuture = SettableFuture.create();
|
private final SettableFuture<Peer> connectionOpenFuture = SettableFuture.create();
|
||||||
|
private final SettableFuture<Peer> versionHandshakeFuture = SettableFuture.create();
|
||||||
// A future representing the results of doing a getUTXOs call.
|
// A future representing the results of doing a getUTXOs call.
|
||||||
@Nullable private SettableFuture<UTXOsMessage> utxosFuture;
|
@Nullable private SettableFuture<UTXOsMessage> utxosFuture;
|
||||||
|
|
||||||
@ -305,6 +306,10 @@ public class Peer extends PeerSocketHandler {
|
|||||||
return connectionOpenFuture;
|
return connectionOpenFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListenableFuture<Peer> getVersionHandshakeFuture() {
|
||||||
|
return versionHandshakeFuture;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processMessage(Message m) throws Exception {
|
protected void processMessage(Message m) throws Exception {
|
||||||
// Allow event listeners to filter the message stream. Listeners are allowed to drop messages by
|
// 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
|
// Shut down the channel
|
||||||
throw new ProtocolException("Peer does not have a copy of the block chain.");
|
throw new ProtocolException("Peer does not have a copy of the block chain.");
|
||||||
}
|
}
|
||||||
|
versionHandshakeFuture.set(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startFilteredBlock(FilteredBlock m) {
|
private void startFilteredBlock(FilteredBlock m) {
|
||||||
|
@ -166,11 +166,13 @@ public class TestWithNetworkConnections {
|
|||||||
InboundMessageQueuer writeTarget = newPeerWriteTargetQueue.take();
|
InboundMessageQueuer writeTarget = newPeerWriteTargetQueue.take();
|
||||||
writeTarget.peer = peer;
|
writeTarget.peer = peer;
|
||||||
// Complete handshake with the peer - send/receive version(ack)s, receive bloom filter
|
// Complete handshake with the peer - send/receive version(ack)s, receive bloom filter
|
||||||
|
checkState(!peer.getVersionHandshakeFuture().isDone());
|
||||||
writeTarget.sendMessage(versionMessage);
|
writeTarget.sendMessage(versionMessage);
|
||||||
writeTarget.sendMessage(new VersionAck());
|
writeTarget.sendMessage(new VersionAck());
|
||||||
try {
|
try {
|
||||||
checkState(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
checkState(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
||||||
checkState(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
checkState(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
||||||
|
checkState(peer.getVersionHandshakeFuture().isDone());
|
||||||
synchronized (doneConnecting) {
|
synchronized (doneConnecting) {
|
||||||
doneConnecting.set(true);
|
doneConnecting.set(true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user