* - FNPRejectTimeout - we took too long to send the DataInsert
* - FNPDataInsertRejected - the insert was invalid
*/
int searchTimeout = calculateTimeout(htl);
MessageFilter mfInsertReply = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPInsertReply);
MessageFilter mfRejectedOverload = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedOverload);
MessageFilter mfRouteNotFound = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRouteNotFound);
MessageFilter mfDataInsertRejected = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPDataInsertRejected);
MessageFilter mfTimeout = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedTimeout);
MessageFilter mf = mfInsertReply.or(mfRouteNotFound.or(mfDataInsertRejected.or(mfTimeout.or(mfRejectedOverload))));
InsertTag thisTag = forkedRequestTag;
if(forkedRequestTag == null) thisTag = origTag;
if(logMINOR) Logger.minor(this, "Sending DataInsert");
try {
next.sendSync(dataInsert, this, realTimeFlag);
} catch (NotConnectedException e1) {
if(logMINOR) Logger.minor(this, "Not connected sending DataInsert: "+next+" for "+uid);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
} catch (SyncSendWaitedTooLongException e) {
Logger.error(this, "Unable to send "+dataInsert+" to "+next+" in a reasonable time");
// Other side will fail. No need to do anything.
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
}
if(logMINOR) Logger.minor(this, "Sending data");
final BackgroundTransfer transfer =
startBackgroundTransfer(next, prb, thisTag);
// Once the transfer has started, we only unlock the tag after the transfer completes (successfully or not).
while (true) {
Message msg;
if(failIfReceiveFailed(thisTag, next)) {
// The transfer has started, it will be cancelled.
transfer.onCompleted();
return;
}
try {
msg = node.usm.waitFor(mf, this);
} catch (DisconnectedException e) {
Logger.normal(this, "Disconnected from " + next
+ " while waiting for InsertReply on " + this);
transfer.onDisconnect(next);
break;
}
if(failIfReceiveFailed(thisTag, next)) {
// The transfer has started, it will be cancelled.
transfer.onCompleted();
return;
}
if (msg == null) {
Logger.warning(this, "Timeout on insert "+this+" to "+next);
// First timeout.
// Could be caused by the next node, or could be caused downstream.
next.localRejectedOverload("AfterInsertAcceptedTimeout2", realTimeFlag);
forwardRejectedOverload();
synchronized(this) {
status = TIMED_OUT;
notifyAll();
}
// Wait for the second timeout off-thread.
// FIXME wait asynchronously.
final InsertTag tag = thisTag;
final PeerNode waitingFor = next;
final short htl = this.htl;
Runnable r = new Runnable() {
@Override
public void run() {
// We do not need to unlock the tag here.
// That will happen in the BackgroundTransfer, which has already started.
// FIXME factor out
int searchTimeout = calculateTimeout(htl);
MessageFilter mfInsertReply = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPInsertReply);
MessageFilter mfRejectedOverload = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedOverload);
MessageFilter mfRouteNotFound = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRouteNotFound);
MessageFilter mfDataInsertRejected = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPDataInsertRejected);
MessageFilter mfTimeout = MessageFilter.create().setSource(waitingFor).setField(DMT.UID, uid).setTimeout(searchTimeout).setType(DMT.FNPRejectedTimeout);
MessageFilter mf = mfInsertReply.or(mfRouteNotFound.or(mfDataInsertRejected.or(mfTimeout.or(mfRejectedOverload))));
while (true) {
Message msg;