mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-01 21:17:13 +00:00
Peer: utility for requesting addr data
This commit is contained in:
@@ -132,6 +132,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
SettableFuture future;
|
SettableFuture future;
|
||||||
}
|
}
|
||||||
private final CopyOnWriteArrayList<GetDataRequest> getDataFutures;
|
private final CopyOnWriteArrayList<GetDataRequest> getDataFutures;
|
||||||
|
@GuardedBy("getAddrFutures") private final LinkedList<SettableFuture<AddressMessage>> getAddrFutures;
|
||||||
|
|
||||||
// Outstanding pings against this peer and how long the last one took to complete.
|
// Outstanding pings against this peer and how long the last one took to complete.
|
||||||
private final ReentrantLock lastPingTimesLock = new ReentrantLock();
|
private final ReentrantLock lastPingTimesLock = new ReentrantLock();
|
||||||
@@ -207,6 +208,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
this.vDownloadData = chain != null;
|
this.vDownloadData = chain != null;
|
||||||
this.getDataFutures = new CopyOnWriteArrayList<GetDataRequest>();
|
this.getDataFutures = new CopyOnWriteArrayList<GetDataRequest>();
|
||||||
this.eventListeners = new CopyOnWriteArrayList<PeerListenerRegistration>();
|
this.eventListeners = new CopyOnWriteArrayList<PeerListenerRegistration>();
|
||||||
|
this.getAddrFutures = new LinkedList<SettableFuture<AddressMessage>>();
|
||||||
this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
this.fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
||||||
this.isAcked = false;
|
this.isAcked = false;
|
||||||
this.pendingPings = new CopyOnWriteArrayList<PendingPing>();
|
this.pendingPings = new CopyOnWriteArrayList<PendingPing>();
|
||||||
@@ -355,6 +357,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
// We don't care about addresses of the network right now. But in future,
|
// We don't care about addresses of the network right now. But in future,
|
||||||
// we should save them in the wallet so we don't put too much load on the seed nodes and can
|
// we should save them in the wallet so we don't put too much load on the seed nodes and can
|
||||||
// properly explore the network.
|
// properly explore the network.
|
||||||
|
processAddressMessage((AddressMessage) m);
|
||||||
} else if (m instanceof HeadersMessage) {
|
} else if (m instanceof HeadersMessage) {
|
||||||
processHeaders((HeadersMessage) m);
|
processHeaders((HeadersMessage) m);
|
||||||
} else if (m instanceof AlertMessage) {
|
} else if (m instanceof AlertMessage) {
|
||||||
@@ -399,6 +402,16 @@ public class Peer extends PeerSocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processAddressMessage(AddressMessage m) {
|
||||||
|
SettableFuture<AddressMessage> future;
|
||||||
|
synchronized (getAddrFutures) {
|
||||||
|
future = getAddrFutures.poll();
|
||||||
|
if (future == null) // Not an addr message we are waiting for.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
future.set(m);
|
||||||
|
}
|
||||||
|
|
||||||
private void processVersionMessage(VersionMessage m) throws ProtocolException {
|
private void processVersionMessage(VersionMessage m) throws ProtocolException {
|
||||||
if (vPeerVersionMessage != null)
|
if (vPeerVersionMessage != null)
|
||||||
throw new ProtocolException("Got two version messages from peer");
|
throw new ProtocolException("Got two version messages from peer");
|
||||||
@@ -1173,6 +1186,16 @@ public class Peer extends PeerSocketHandler {
|
|||||||
return req.future;
|
return req.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sends a getaddr request to the peer and returns a future that completes with the answer once the peer has replied. */
|
||||||
|
public ListenableFuture<AddressMessage> getAddr() {
|
||||||
|
SettableFuture<AddressMessage> future = SettableFuture.create();
|
||||||
|
synchronized (getAddrFutures) {
|
||||||
|
getAddrFutures.add(future);
|
||||||
|
}
|
||||||
|
sendMessage(new GetAddrMessage(params));
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any
|
* When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any
|
||||||
* transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such
|
* transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such
|
||||||
|
|||||||
Reference in New Issue
Block a user