*If we have no peers, hook on when we have a peer and recurse
*If we have a peer, loop over the peer list, and see if we have any syncable peers. If not, loop again, and hook on the peers open event
This commit is contained in:
parent
f3edce42fa
commit
61d385897a
24
src/index.ts
24
src/index.ts
|
@ -21,12 +21,32 @@ let proxy: HandshakeProxy;
|
||||||
|
|
||||||
function resolveWithPeers(resolve: Function) {
|
function resolveWithPeers(resolve: Function) {
|
||||||
if (!proxy.node.pool.peers.head()) {
|
if (!proxy.node.pool.peers.head()) {
|
||||||
proxy.node.pool.once("peer", () => {
|
proxy.node.pool.on("peer", () => {
|
||||||
resolve(null);
|
resolveWithPeers(resolve);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let syncable = false;
|
||||||
|
|
||||||
|
for (let peer = proxy.node.pool.peers.head(); peer; peer = peer.next) {
|
||||||
|
if (proxy.node.pool.isSyncable(peer)) {
|
||||||
|
syncable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!syncable) {
|
||||||
|
for (let peer = proxy.node.pool.peers.head(); peer; peer = peer.next) {
|
||||||
|
const listener = () => {
|
||||||
|
peer.off("open", listener);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
peer.on("open", listener);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue