InsertTag thisTag = forkedRequestTag;
if(forkedRequestTag == null) thisTag = origTag;
// Send the headers and data
Message headersMsg = DMT.createFNPSSKInsertRequestHeaders(uid, headers, realTimeFlag);
Message dataMsg = DMT.createFNPSSKInsertRequestData(uid, data, realTimeFlag);
try {
next.sendAsync(headersMsg, null, this);
next.sendSync(dataMsg, this, realTimeFlag);
sentPayload(data.length);
} catch (NotConnectedException e1) {
if(logMINOR) Logger.minor(this, "Not connected to "+next);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
} catch (SyncSendWaitedTooLongException e) {
Logger.error(this, "Waited too long to send "+dataMsg+" to "+next+" on "+this);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
}
// Do we need to send them the pubkey?
if(needPubKey) {
Message pkMsg = DMT.createFNPSSKPubKey(uid, pubKey, realTimeFlag);
try {
next.sendSync(pkMsg, this, realTimeFlag);
} catch (NotConnectedException e) {
if(logMINOR) Logger.minor(this, "Node disconnected while sending pubkey: "+next);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
} catch (SyncSendWaitedTooLongException e) {
Logger.warning(this, "Took too long to send pubkey to "+next+" on "+this);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
}
// Wait for the SSKPubKeyAccepted
// FIXME doubled the timeout because handling it properly would involve forking.
MessageFilter mf1 = MessageFilter.create().setSource(next).setField(DMT.UID, uid).setTimeout(ACCEPTED_TIMEOUT*2).setType(DMT.FNPSSKPubKeyAccepted);
Message newAck;
try {
newAck = node.usm.waitFor(mf1, this);
} catch (DisconnectedException e) {
if(logMINOR) Logger.minor(this, "Disconnected from "+next);
next.noLongerRoutingTo(thisTag, false);
routeRequests();
return;
}
if(newAck == null) {
handleNoPubkeyAccepted(next, thisTag);
// Try another peer
routeRequests();
return;
}
}
// We have sent them the pubkey, and the data.
// Wait for the response.
MessageFilter mf = makeSearchFilter(next, calculateTimeout(htl));
while (true) {
Message msg;
try {
msg = node.usm.waitFor(mf, this);
} catch (DisconnectedException e) {
Logger.normal(this, "Disconnected from " + next
+ " while waiting for InsertReply on " + this);