protected void remove() { Long l = uid; synchronized(DarknetPeerNode.this) { myFileOffersByUID.remove(l); hisFileOffersByUID.remove(l); } data.close(); }
public void abort(int errCode, String why) { if(logMINOR) Logger.normal(this, "Aborting "+this+": "+errCode+" : "+why+" first missing is "+blocksReceived.firstZero(0), new Exception("debug")); BulkTransmitter[] notifyBTs; BulkReceiver notifyBR; synchronized(this) { _aborted = true; _abortReason = errCode; _abortDescription = why; notifyBTs = transmitters; notifyBR = recv; } if(notifyBTs != null) { for(BulkTransmitter notifyBT: notifyBTs) { notifyBT.onAborted(); } } if(notifyBR != null) notifyBR.onAborted(); raf.close(); }
/** Test that after closing a RandomAccessBuffer we cannot read from it or write to it */ protected void innerTestClose(long sz) throws IOException { RandomAccessBuffer raf = construct(sz); raf.close(); byte[] buf = new byte[(int)Math.min(1024, sz)]; readWriteMustFail(raf, 0L, buf, 0, buf.length); raf.free(); }
@Override public void run() { if(logMINOR) Logger.minor(this, "Received file"); try { if(!receiver.receive()) { String err = "Failed to receive "+this; Logger.error(this, err); System.err.println(err); onReceiveFailure(); } else { data.close(); if(!dest.renameTo(node.clientCore.downloadsDir().file(baseFilename))){ Logger.error(this, "Failed to rename "+dest.getName()+" to remove .part suffix."); } onReceiveSuccess(); } } catch (Throwable t) { Logger.error(this, "Caught "+t+" receiving file", t); onReceiveFailure(); } finally { remove(); } if(logMINOR) Logger.minor(this, "Received file"); } }, "Receiver for bulk transfer "+uid+":"+filename);
/** Create an array, fill it with random numbers, write it sequentially to the * RandomAccessBuffer, then read randomly and compare. */ protected void innerTestArray(int len, Random r, boolean readOnly) throws IOException { if(len == 0) return; byte[] buf = new byte[len]; r.nextBytes(buf); RandomAccessBuffer raf = construct(len); raf.pwrite(0L, buf, 0, buf.length); for(int i=0;i<100;i++) { int end = len == 1 ? 1 : r.nextInt(len)+1; int start = r.nextInt(end); checkArraySectionEqualsReadData(buf, raf, start, end, readOnly); } checkArraySectionEqualsReadData(buf, raf, 0, len, readOnly); if(len > 1) checkArraySectionEqualsReadData(buf, raf, 1, len-1, readOnly); raf.close(); raf.free(); }
private void innerTestSize(long sz) throws IOException { RandomAccessBuffer raf = construct(sz); assertEquals(raf.size(), sz); raf.close(); raf.free(); }
@Override public void run() { try { if(!bt.send()) Logger.error(this, "Failed to send revocation key blob to " + source.userToString() + " : " + bt.getCancelReason()); else Logger.normal(this, "Sent revocation key blob to " + source.userToString()); } catch (DisconnectedException e) { // Not much we can do here either. Logger.warning(this, "Failed to send revocation key blob (disconnected) to " + source.userToString() + " : " + bt.getCancelReason()); } finally { data.close(); } } };
raf.close(); raf.free();
/** Create an array, fill it with random numbers, write it sequentially to the * RandomAccessBuffer, then read randomly and compare. */ protected void innerTestArrayMigration(int len, Random r) throws IOException { if(len == 0) return; byte[] buf = new byte[len]; r.nextBytes(buf); RandomAccessBuffer raf = construct(len); TempRandomAccessBuffer t = (TempRandomAccessBuffer) raf; assertFalse(t.hasMigrated()); assertEquals(factory.getRamUsed(), len); t.migrateToDisk(); assertTrue(t.hasMigrated()); assertEquals(factory.getRamUsed(), 0); raf.pwrite(0L, buf, 0, buf.length); checkArrayInner(buf, raf, len, r); raf.close(); raf.free(); }
} catch(DisconnectedException e) { Logger.error(this, "Peer " + source + " asked us for the blob file for the revocation key, then disconnected: " + e, e); data.close(); return true;
readWriteMustFail(raf, sz+1025, buf, 0, buf.length); // 1KB in readWriteMustFail(raf, sz+buf.length, buf, 0, buf.length); raf.close(); raf.free();