// Only 1 ID because we are sending; we won't receive
item = addForwardedItem(uid, uid, null, pn);
if(logMINOR) Logger.minor(this, "Sending SwapRequest "+uid+" to "+pn);
MessageFilter filter1 =
MessageFilter.create().setType(DMT.FNPSwapRejected).setField(DMT.UID, uid).setSource(pn).setTimeout(TIMEOUT);
MessageFilter filter2 =
MessageFilter.create().setType(DMT.FNPSwapReply).setField(DMT.UID, uid).setSource(pn).setTimeout(TIMEOUT);
MessageFilter filter = filter1.or(filter2);
node.usm.send(pn, m, LocationManager.this);
if(logMINOR) Logger.minor(this, "Waiting for SwapReply/SwapRejected on "+uid);
Message reply;
try {
reply = node.usm.waitFor(filter, LocationManager.this);
} catch (DisconnectedException e) {
if(logMINOR) Logger.minor(this, "Disconnected while waiting for SwapReply/SwapRejected for "+uid);
return;
}
if(reply == null) {
if(pn.isRoutable() && (System.currentTimeMillis() - pn.timeLastConnectionCompleted() > TIMEOUT*2)) {
// Timed out! Abort...
Logger.error(this, "Timed out waiting for SwapRejected/SwapReply on "+uid);
}
return;
}
if(reply.getSpec() == DMT.FNPSwapRejected) {
// Failed. Abort.
if(logMINOR) Logger.minor(this, "Swap rejected on "+uid);
return;
}
// We have an FNPSwapReply, yay
// FNPSwapReply is exactly the same format as FNPSwapRequest
byte[] hisHash = ((ShortBuffer)reply.getObject(DMT.HASH)).getData();
Message confirm = DMT.createFNPSwapCommit(uid, myValue);
//confirm.addSubMessage(DMT.createFNPSwapLocations(extractUIDs(friendLocsAndUIDs)));
filter1.clearOr();
MessageFilter filter3 = MessageFilter.create().setField(DMT.UID, uid).setType(DMT.FNPSwapComplete).setTimeout(TIMEOUT).setSource(pn);
filter = filter1.or(filter3);
node.usm.send(pn, confirm, LocationManager.this);
if(logMINOR) Logger.minor(this, "Waiting for SwapComplete: uid = "+uid);