コード例 #1
0
 private void addRequest(FreenetURI uri) {
   if (isRunning) {
     FetchContext mFetchContext = mFetcher.getFetchContext();
     mFetchContext.allowSplitfiles = true; // FIXME: disable as soon as its fixed!
     mFetchContext.canWriteClientCache = true;
     mFetchContext.dontEnterImplicitArchives = true; // ?
     mFetchContext.filterData = false; // ?
     mFetchContext.followRedirects = false;
     mFetchContext.ignoreStore = false;
     // final? mFetchContext.ignoreTooManyPathComponents = false;
     mFetchContext.ignoreUSKDatehints = true; // ?
     mFetchContext.localRequestOnly = false;
     mFetchContext.maxArchiveLevels = 0; // ?
     mFetchContext.maxArchiveRestarts = 0; // ?
     mFetchContext.maxCheckBlocksPerSegment = 0; // ?
     mFetchContext.maxDataBlocksPerSegment = 0; // ?
     // mFetchContext.maxMetadataSize = ?
     // cooldown for 30 minutes, wtf? this is a real time chat plugin.
     // mFetchContext.maxNonSplitfileRetries = -1;
     mFetchContext.maxNonSplitfileRetries = 2;
     // mFetchContext.maxOutputLength = 1024 ?
     mFetchContext.maxRecursionLevel = 0; // ?
     mFetchContext.maxSplitfileBlockRetries = 0;
     // mFetchContext.maxTempLength = ?
     // final? mFetchContext.maxUSKRetries = -1; //?
     // mFetchContext.overrideMIME = "text/plain"; //?
     // mFetchContext.prefetchHook = ?
     // mFetchContext.returnZIPManifests = true ?
     // mFetchContext.tagReplacer = ?
     // mFetchContext.setCooldownRetries(cooldownRetries);
     // mFetchContext.setCooldownTime(cooldownTime);
     try {
       mFetcher.fetch(uri, this, this, mFetchContext, (short) 1);
     } catch (FetchException e) {
       System.err.println(
           "[Async_AnnounceFetcher]::addRequest() FetchException: " + e.getMessage());
     }
   }
 }
コード例 #2
0
ファイル: ClientGet.java プロジェクト: platy/fred-staging
  /**
   * Create one for a global-queued request not made by FCP.
   *
   * @throws IdentifierCollisionException
   * @throws NotAllowedException
   * @throws IOException
   */
  public ClientGet(
      FCPClient globalClient,
      FreenetURI uri,
      boolean dsOnly,
      boolean ignoreDS,
      int maxSplitfileRetries,
      int maxNonSplitfileRetries,
      long maxOutputLength,
      short returnType,
      boolean persistRebootOnly,
      String identifier,
      int verbosity,
      short prioClass,
      File returnFilename,
      File returnTempFilename,
      boolean writeToClientCache,
      FCPServer server,
      ObjectContainer container)
      throws IdentifierCollisionException, NotAllowedException, IOException {
    super(
        uri,
        identifier,
        verbosity,
        null,
        globalClient,
        prioClass,
        (persistRebootOnly ? ClientRequest.PERSIST_REBOOT : ClientRequest.PERSIST_FOREVER),
        null,
        true,
        container);

    fctx = new FetchContext(server.defaultFetchContext, FetchContext.IDENTICAL_MASK, false, null);
    fctx.eventProducer.addEventListener(this);
    fctx.localRequestOnly = dsOnly;
    fctx.ignoreStore = ignoreDS;
    fctx.maxNonSplitfileRetries = maxNonSplitfileRetries;
    fctx.maxSplitfileBlockRetries = maxSplitfileRetries;
    fctx.maxOutputLength = maxOutputLength;
    fctx.maxTempLength = maxOutputLength;
    fctx.canWriteClientCache = writeToClientCache;
    Bucket ret = null;
    this.returnType = returnType;
    binaryBlob = false;
    if (returnType == ClientGetMessage.RETURN_TYPE_DISK) {
      this.targetFile = returnFilename;
      this.tempFile = returnTempFilename;
      if (!(server.core.allowDownloadTo(returnTempFilename)
          && server.core.allowDownloadTo(returnFilename))) throw new NotAllowedException();
      ret = new FileBucket(returnTempFilename, false, true, false, false, false);
    } else if (returnType == ClientGetMessage.RETURN_TYPE_NONE) {
      targetFile = null;
      tempFile = null;
      ret = new NullBucket();
    } else {
      targetFile = null;
      tempFile = null;
      if (persistenceType == PERSIST_FOREVER)
        ret = server.core.persistentTempBucketFactory.makeBucket(maxOutputLength);
      else ret = server.core.tempBucketFactory.makeBucket(maxOutputLength);
    }
    returnBucket = ret;
    getter = new ClientGetter(this, uri, fctx, priorityClass, lowLevelClient, returnBucket, null);
  }
コード例 #3
0
ファイル: ClientGet.java プロジェクト: platy/fred-staging
  /**
   * Create a ClientGet from a request serialized to a SimpleFieldSet. Can throw, and does minimal
   * verification, as is dealing with data supposedly serialized out by the node.
   *
   * @throws IOException
   * @throws FetchException
   */
  public ClientGet(SimpleFieldSet fs, FCPClient client2, FCPServer server)
      throws IOException, FetchException {
    super(fs, client2);

    returnType = ClientGetMessage.parseValidReturnType(fs.get("ReturnType"));
    String f = fs.get("Filename");
    if (f != null) targetFile = new File(f);
    else targetFile = null;
    f = fs.get("TempFilename");
    if (f != null) tempFile = new File(f);
    else tempFile = null;
    boolean ignoreDS = Fields.stringToBool(fs.get("IgnoreDS"), false);
    boolean dsOnly = Fields.stringToBool(fs.get("DSOnly"), false);
    int maxRetries = Integer.parseInt(fs.get("MaxRetries"));
    fctx = new FetchContext(server.defaultFetchContext, FetchContext.IDENTICAL_MASK, false, null);
    fctx.eventProducer.addEventListener(this);
    // ignoreDS
    fctx.localRequestOnly = dsOnly;
    fctx.ignoreStore = ignoreDS;
    fctx.maxNonSplitfileRetries = maxRetries;
    fctx.maxSplitfileBlockRetries = maxRetries;
    binaryBlob = Fields.stringToBool(fs.get("BinaryBlob"), false);
    succeeded = Fields.stringToBool(fs.get("Succeeded"), false);
    if (finished) {
      if (succeeded) {
        foundDataLength = Long.parseLong(fs.get("FoundDataLength"));
        foundDataMimeType = fs.get("FoundDataMimeType");
        SimpleFieldSet fs1 = fs.subset("PostFetchProtocolError");
        if (fs1 != null) postFetchProtocolErrorMessage = new ProtocolErrorMessage(fs1);
      } else {
        getFailedMessage = new GetFailedMessage(fs.subset("GetFailed"), false);
      }
    }
    Bucket ret = null;
    if (returnType == ClientGetMessage.RETURN_TYPE_DISK) {
      if (succeeded) {
        ret = new FileBucket(targetFile, false, true, false, false, false);
      } else {
        ret = new FileBucket(tempFile, false, true, false, false, false);
      }
    } else if (returnType == ClientGetMessage.RETURN_TYPE_NONE) {
      ret = new NullBucket();
    } else if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT) {
      try {
        ret =
            SerializableToFieldSetBucketUtil.create(
                fs.subset("ReturnBucket"),
                server.core.random,
                server.core.persistentTempBucketFactory);
        if (ret == null) throw new CannotCreateFromFieldSetException("ret == null");
      } catch (CannotCreateFromFieldSetException e) {
        Logger.error(this, "Cannot read: " + this + " : " + e, e);
        try {
          // Create a new temp bucket
          if (persistenceType == PERSIST_FOREVER)
            ret = server.core.persistentTempBucketFactory.makeBucket(fctx.maxOutputLength);
          else ret = server.core.tempBucketFactory.makeBucket(fctx.maxOutputLength);
        } catch (IOException e1) {
          Logger.error(this, "Cannot create bucket for temp storage: " + e, e);
          getter = null;
          returnBucket = null;
          throw new FetchException(FetchException.BUCKET_ERROR, e);
        }
      }
    } else {
      throw new IllegalArgumentException();
    }
    if (succeeded) {
      if (foundDataLength < ret.size()) {
        Logger.error(this, "Failing " + identifier + " because lost data");
        succeeded = false;
      }
    }
    if (ret == null)
      Logger.error(
          this, "Impossible: ret = null in SFS constructor for " + this, new Exception("debug"));
    returnBucket = ret;

    String[] allowed = fs.getAll("AllowedMIMETypes");
    if (allowed != null) {
      fctx.allowedMIMETypes = new HashSet<String>();
      for (String a : allowed) fctx.allowedMIMETypes.add(a);
    }

    getter =
        new ClientGetter(
            this,
            uri,
            fctx,
            priorityClass,
            lowLevelClient,
            binaryBlob ? new NullBucket() : returnBucket,
            binaryBlob ? returnBucket : null);

    if (finished && succeeded)
      allDataPending =
          new AllDataMessage(
              returnBucket,
              identifier,
              global,
              startupTime,
              completionTime,
              this.foundDataMimeType);
  }
コード例 #4
0
ファイル: ClientGet.java プロジェクト: platy/fred-staging
  public ClientGet(
      FCPConnectionHandler handler,
      ClientGetMessage message,
      FCPServer server,
      ObjectContainer container)
      throws IdentifierCollisionException, MessageInvalidException {
    super(
        message.uri,
        message.identifier,
        message.verbosity,
        handler,
        message.priorityClass,
        message.persistenceType,
        message.clientToken,
        message.global,
        container);
    // Create a Fetcher directly in order to get more fine-grained control,
    // since the client may override a few context elements.
    fctx = new FetchContext(server.defaultFetchContext, FetchContext.IDENTICAL_MASK, false, null);
    fctx.eventProducer.addEventListener(this);
    // ignoreDS
    fctx.localRequestOnly = message.dsOnly;
    fctx.ignoreStore = message.ignoreDS;
    fctx.maxNonSplitfileRetries = message.maxRetries;
    fctx.maxSplitfileBlockRetries = message.maxRetries;
    // FIXME do something with verbosity !!
    // Has already been checked
    fctx.maxOutputLength = message.maxSize;
    fctx.maxTempLength = message.maxTempSize;
    fctx.canWriteClientCache = message.writeToClientCache;

    if (message.allowedMIMETypes != null) {
      fctx.allowedMIMETypes = new HashSet<String>();
      for (String mime : message.allowedMIMETypes) fctx.allowedMIMETypes.add(mime);
    }

    this.returnType = message.returnType;
    this.binaryBlob = message.binaryBlob;
    Bucket ret = null;
    if (returnType == ClientGetMessage.RETURN_TYPE_DISK) {
      this.targetFile = message.diskFile;
      this.tempFile = message.tempFile;
      if (!(server.core.allowDownloadTo(tempFile) && server.core.allowDownloadTo(targetFile)))
        throw new MessageInvalidException(
            ProtocolErrorMessage.ACCESS_DENIED,
            "Not allowed to download to " + tempFile + " or " + targetFile,
            identifier,
            global);
      else if (!(handler.allowDDAFrom(tempFile, true) && handler.allowDDAFrom(targetFile, true)))
        throw new MessageInvalidException(
            ProtocolErrorMessage.DIRECT_DISK_ACCESS_DENIED,
            "Not allowed to download to "
                + tempFile
                + " or "
                + targetFile
                + ". You might need to do a "
                + TestDDARequestMessage.NAME
                + " first.",
            identifier,
            global);
      ret = new FileBucket(message.tempFile, false, true, false, false, false);
    } else if (returnType == ClientGetMessage.RETURN_TYPE_NONE) {
      targetFile = null;
      tempFile = null;
      ret = new NullBucket();
    } else {
      targetFile = null;
      tempFile = null;
      try {
        if (persistenceType == PERSIST_FOREVER)
          ret = server.core.persistentTempBucketFactory.makeBucket(fctx.maxOutputLength);
        else ret = server.core.tempBucketFactory.makeBucket(fctx.maxOutputLength);
      } catch (IOException e) {
        Logger.error(this, "Cannot create bucket for temp storage: " + e, e);
        getter = null;
        returnBucket = null;
        // This is *not* a FetchException since we don't register it: it's a protocol error.
        throw new MessageInvalidException(
            ProtocolErrorMessage.INTERNAL_ERROR,
            "Cannot create bucket for temporary storage (out of disk space???): " + e,
            identifier,
            global);
      }
    }
    if (ret == null)
      Logger.error(
          this, "Impossible: ret = null in FCP constructor for " + this, new Exception("debug"));
    returnBucket = ret;
    getter =
        new ClientGetter(
            this,
            uri,
            fctx,
            priorityClass,
            lowLevelClient,
            binaryBlob ? new NullBucket() : returnBucket,
            binaryBlob ? returnBucket : null);
  }