@Override public void start(ObjectContainer container, ClientContext context) { try { synchronized (this) { if (finished) return; } getter.start(container, context); if (persistenceType != PERSIST_CONNECTION && !finished) { FCPMessage msg = persistentTagMessage(container); client.queueClientRequestMessage(msg, 0, container); } synchronized (this) { started = true; } } catch (FetchException e) { synchronized (this) { started = true; } // before the failure handler onFailure(e, null, container); } catch (Throwable t) { synchronized (this) { started = true; } onFailure(new FetchException(FetchException.INTERNAL_ERROR, t), null, container); } if (persistenceType == PERSIST_FOREVER) container.store(this); // Update }
public String getMIMEType(ObjectContainer container) { if (foundDataMimeType != null) return foundDataMimeType; if (getter != null) { if (persistenceType == PERSIST_FOREVER) container.activate(getter, 1); return getter.expectedMIME(); } return null; }
public long getDataSize(ObjectContainer container) { if (foundDataLength > 0) return foundDataLength; if (getter != null) { if (persistenceType == PERSIST_FOREVER) container.activate(getter, 1); return getter.expectedSize(); } return -1; }
@Override public void onSuccess(FetchResult result, ClientGetter state, ObjectContainer container) { try { mFreenetMessageParser.addMessage( "announce", "", new String(result.asByteArray()).trim(), state.getURI().toString()); startRequestForNewEdition(); } catch (IOException e) { System.err.println("[Async_AnnounceFetcher]::onSuccess() IOException. " + e.getMessage()); e.printStackTrace(); } }
@Override public boolean canRestart() { if (!finished) { Logger.minor(this, "Cannot restart because not finished for " + identifier); return false; } if (succeeded) { Logger.minor(this, "Cannot restart because succeeded for " + identifier); return false; } return getter.canRestart(); }
@Override public void requestWasRemoved(ObjectContainer container, ClientContext context) { // if request is still running, send a GetFailed with code=cancelled if (!finished) { synchronized (this) { succeeded = false; finished = true; FetchException cancelled = new FetchException(FetchException.CANCELLED); getFailedMessage = new GetFailedMessage(cancelled, identifier, global); } trySendDataFoundOrGetFailed(null, container); } // notify client that request was removed FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global); if (persistenceType != PERSIST_CONNECTION) { if (persistenceType == PERSIST_FOREVER) container.activate(client, 1); client.queueClientRequestMessage(msg, 0, container); } freeData(container); if (persistenceType == PERSIST_FOREVER) { container.activate(fctx, 1); if (fctx.allowedMIMETypes != null) { container.activate(fctx.allowedMIMETypes, 5); container.delete(fctx.allowedMIMETypes); } fctx.removeFrom(container); getter.removeFrom(container, context); if (targetFile != null) container.delete(targetFile); if (tempFile != null) container.delete(tempFile); if (getFailedMessage != null) { container.activate(getFailedMessage, 5); getFailedMessage.removeFrom(container); } if (postFetchProtocolErrorMessage != null) { container.activate(postFetchProtocolErrorMessage, 5); postFetchProtocolErrorMessage.removeFrom(container); } if (allDataPending != null) { container.activate(allDataPending, 5); allDataPending.removeFrom(container); } if (progressPending != null) { container.activate(progressPending, 5); progressPending.removeFrom(container); } } super.requestWasRemoved(container, context); }
@Override public String toString() { String output = "Index:[ " + indexuri + " " + fetchStatus + " " + waitingOnMainIndex + "\n\t" + subIndice + (rootGetter == null ? "]" : (" GETTING(" + rootGetter.toString() + ")]")); // for (SubIndex s : subIndice) // output = output+"\n -"+s; return output; }
@Override public boolean restart(ObjectContainer container, ClientContext context) { if (!canRestart()) return false; FreenetURI redirect; synchronized (this) { finished = false; redirect = getFailedMessage == null ? null : getFailedMessage.redirectURI; if (persistenceType == PERSIST_FOREVER && getFailedMessage != null) getFailedMessage.removeFrom(container); this.getFailedMessage = null; if (persistenceType == PERSIST_FOREVER && allDataPending != null) allDataPending.removeFrom(container); this.allDataPending = null; if (persistenceType == PERSIST_FOREVER && postFetchProtocolErrorMessage != null) postFetchProtocolErrorMessage.removeFrom(container); this.postFetchProtocolErrorMessage = null; if (persistenceType == PERSIST_FOREVER && progressPending != null) progressPending.removeFrom(container); this.progressPending = null; started = false; } if (persistenceType == PERSIST_FOREVER) container.store(this); try { if (getter.restart(redirect, container, context)) { synchronized (this) { if (redirect != null) { if (persistenceType == PERSIST_FOREVER) uri.removeFrom(container); this.uri = redirect; } started = true; } if (persistenceType == PERSIST_FOREVER) container.store(this); } return true; } catch (FetchException e) { onFailure(e, null, container); return false; } }
@Override public void onFailure(FetchException e, ClientGetter state, ObjectContainer container) { switch (e.getMode()) { case FetchException.RECENTLY_FAILED: // pretty normal for polling.. just add the request again if (state.getURI().toString().contains(mStorage.getCurrentDateString())) { restartRequest(state.getURI()); } else { startRequestForNewEdition(); } break; case FetchException.DATA_NOT_FOUND: // pretty normal for polling.. just add the request again if (state.getURI().toString().contains(mStorage.getCurrentDateString())) { restartRequest(state.getURI()); } else { startRequestForNewEdition(); } break; case FetchException.ALL_DATA_NOT_FOUND: // should not possible while fetching KSKs without following redirects. ? System.err.println( "[Async_AnnounceFetcher] ALL_DATA_NOT_FOUND. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.ROUTE_NOT_FOUND: // if hit it we are trying to fetch something but the node does not have a proper // connection. // just add the request again if (state.getURI().toString().contains(mStorage.getCurrentDateString())) { restartRequest(state.getURI()); } else { startRequestForNewEdition(); } break; case FetchException.REJECTED_OVERLOAD: // just add the request again if (state.getURI().toString().contains(mStorage.getCurrentDateString())) { restartRequest(state.getURI()); } else { startRequestForNewEdition(); } break; case FetchException.INVALID_METADATA: // wtf? mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] INVALID_METADATA. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.TOO_BIG_METADATA: // wtf? mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] TOO_BIG_METADATA. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.TOO_BIG: // should not be possible while polling KSK's without following redirects mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] TOO_BIG. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.TOO_MANY_REDIRECTS: mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] TOO_MANY_REDIRECTS. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.TOO_MUCH_RECURSION: // FIXME: wtf? mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] TOO_MUCH_RECURSION. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; case FetchException.PERMANENT_REDIRECT: mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher] TOO_MUCH_RECURSION. you should not see me. ignoring this announce. " + e.getMessage() + " " + state.getURI().toString()); startRequestForNewEdition(); break; default: // now we have a serious problem. mStorage.announce_ddos += 1; System.err.println( "[Async_AnnounceFetcher]::onFailure() unknown error: " + e.getMessage() + " mode=" + e.getMode() + " ignoring this announce. uri=" + state.getURI().toString()); e.printStackTrace(); startRequestForNewEdition(); break; } }