public void handleRequestJar(Message m, final PeerNode source, final boolean isExt) {
final String name = isExt ? "ext" : "main";
Message msg;
final BulkTransmitter bt;
final FileRandomAccessBuffer raf;
if (source.isOpennet() && updateManager.dontAllowUOM()) {
Logger.normal(this, "Peer " + source
+ " asked us for the blob file for " + name
+ "; We are a seenode, so we ignore it!");
return;
}
// Do we have the data?
int version = isExt ? NodeUpdateManager.TRANSITION_VERSION_EXT : NodeUpdateManager.TRANSITION_VERSION;
File data = isExt ? updateManager.getTransitionExtBlob() : updateManager.getTransitionMainBlob();
if(data == null) {
Logger.normal(this, "Peer " + source + " asked us for the blob file for the "+name+" jar but we don't have it!");
// Probably a race condition on reconnect, hopefully we'll be asked again
return;
}
final long uid = m.getLong(DMT.UID);
if(!source.sendingUOMJar(isExt)) {
Logger.error(this, "Peer "+source+" asked for UOM "+(isExt?"ext":"main")+" jar twice");
return;
}
try {
try {
raf = new FileRandomAccessBuffer(data, true);
} catch(FileNotFoundException e) {
Logger.error(this, "Peer " + source + " asked us for the blob file for the "+name+" jar, we have downloaded it but don't have the file even though we did have it when we checked!: " + e, e);
return;
} catch(IOException e) {
Logger.error(this, "Peer " + source + " asked us for the blob file for the "+name+" jar, we have downloaded it but can't read the file on disk!: " + e, e);
return;
}
final PartiallyReceivedBulk prb;
long length;
length = raf.size();
prb = new PartiallyReceivedBulk(updateManager.node.getUSM(), length,
Node.PACKET_SIZE, raf, true);
try {
bt = new BulkTransmitter(prb, source, uid, false, updateManager.ctr, true);
} catch(DisconnectedException e) {
Logger.error(this, "Peer " + source + " asked us for the blob file for the "+name+" jar, then disconnected: " + e, e);
raf.close();
return;
}
msg =
isExt ? DMT.createUOMSendingExtra(uid, length, NodeUpdateManager.transitionExtJarURIAsUSK.toString(), version) :
DMT.createUOMSendingMain(uid, length, NodeUpdateManager.transitionMainJarURIAsUSK.toString(), version);
} catch (RuntimeException e) {
source.finishedSendingUOMJar(isExt);
throw e;
} catch (Error e) {
source.finishedSendingUOMJar(isExt);
throw e;
}
final Runnable r = new Runnable() {
@Override
public void run() {
try {
if(!bt.send())
Logger.error(this, "Failed to send "+name+" jar blob to " + source.userToString() + " : " + bt.getCancelReason());
else
Logger.normal(this, "Sent "+name+" jar blob to " + source.userToString());
raf.close();
} catch (DisconnectedException e) {
// Not much we can do.
} finally {
source.finishedSendingUOMJar(isExt);
raf.close();
}
}
};
try {