Beispiel #1
0
 public SimpleFieldSet exportFieldSet(Config.RequestType configRequestType, boolean withDefaults) {
   SimpleFieldSet fs = new SimpleFieldSet(true);
   @SuppressWarnings("unchecked")
   Map.Entry<String, Option<?>>[] entries = new Map.Entry[map.size()];
   // FIXME is any locking at all necessary here? After it has finished init, it's constant...
   synchronized (this) {
     entries = map.entrySet().toArray(entries);
   }
   if (logMINOR) Logger.minor(this, "Prefix=" + prefix);
   for (Map.Entry<String, Option<?>> entry : entries) {
     String key = entry.getKey();
     Option<?> o = entry.getValue();
     if (logMINOR)
       Logger.minor(
           this, "Key=" + key + " value=" + o.getValueString() + " default=" + o.isDefault());
     if (configRequestType == Config.RequestType.CURRENT_SETTINGS
         && (!withDefaults)
         && o.isDefault()
         && (!o.forceWrite)) {
       if (logMINOR) Logger.minor(this, "Skipping " + key + " - " + o.isDefault());
       continue;
     }
     switch (configRequestType) {
       case CURRENT_SETTINGS:
         fs.putSingle(key, o.getValueString());
         break;
       case DEFAULT_SETTINGS:
         fs.putSingle(key, o.getDefault());
         break;
       case SORT_ORDER:
         fs.put(key, o.getSortOrder());
         break;
       case EXPERT_FLAG:
         fs.put(key, o.isExpert());
         break;
       case FORCE_WRITE_FLAG:
         fs.put(key, o.isForcedWrite());
         break;
       case SHORT_DESCRIPTION:
         fs.putSingle(key, o.getLocalisedShortDesc());
         break;
       case LONG_DESCRIPTION:
         fs.putSingle(key, o.getLocalisedLongDesc());
         break;
       case DATA_TYPE:
         fs.putSingle(key, o.getDataTypeStr());
         break;
       default:
         Logger.error(this, "Unknown config request type value: " + configRequestType);
         break;
     }
     if (logMINOR)
       Logger.minor(this, "Key=" + prefix + '.' + key + " value=" + o.getValueString());
   }
   return fs;
 }
Beispiel #2
0
  // This is distinct from the ClientGetMessage code, as later on it will be radically
  // different (it can store detailed state).
  @Override
  public synchronized SimpleFieldSet getFieldSet() {
    SimpleFieldSet fs = new SimpleFieldSet(false); // we will need multi-level later...
    fs.putSingle("Type", "GET");
    fs.putSingle("URI", uri.toString(false, false));
    fs.putSingle("Identifier", identifier);
    fs.putSingle("Verbosity", Integer.toString(verbosity));
    fs.putSingle("PriorityClass", Short.toString(priorityClass));
    fs.putSingle("ReturnType", ClientGetMessage.returnTypeString(returnType));
    fs.putSingle("Persistence", persistenceTypeString(persistenceType));
    fs.putSingle("ClientName", client.name);
    if (targetFile != null) fs.putSingle("Filename", targetFile.getPath());
    if (tempFile != null) fs.putSingle("TempFilename", tempFile.getPath());
    if (clientToken != null) fs.putSingle("ClientToken", clientToken);
    fs.putSingle("IgnoreDS", Boolean.toString(fctx.ignoreStore));
    fs.putSingle("DSOnly", Boolean.toString(fctx.localRequestOnly));
    fs.putSingle("MaxRetries", Integer.toString(fctx.maxNonSplitfileRetries));
    fs.putSingle("Finished", Boolean.toString(finished));
    fs.putSingle("Succeeded", Boolean.toString(succeeded));
    if (fctx.allowedMIMETypes != null)
      fs.putOverwrite(
          "AllowedMIMETypes",
          (String[]) fctx.allowedMIMETypes.toArray(new String[fctx.allowedMIMETypes.size()]));
    if (finished) {
      if (succeeded) {
        fs.putSingle("FoundDataLength", Long.toString(foundDataLength));
        fs.putSingle("FoundDataMimeType", foundDataMimeType);
        if (postFetchProtocolErrorMessage != null) {
          fs.put("PostFetchProtocolError", postFetchProtocolErrorMessage.getFieldSet());
        }
      } else {
        if (getFailedMessage != null) {
          fs.put("GetFailed", getFailedMessage.getFieldSet(false));
        }
      }
    }
    // Return bucket
    if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT
        && !(succeeded == false && returnBucket == null)) {
      bucketToFS(fs, "ReturnBucket", false, returnBucket);
    }
    fs.putSingle("Global", Boolean.toString(client.isGlobalQueue));
    fs.put("BinaryBlob", binaryBlob);
    fs.put("StartupTime", startupTime);
    if (finished) fs.put("CompletionTime", completionTime);

    return fs;
  }
  /**
   * Get a set of introduction puzzle IDs which the given own identity might solve.
   *
   * <p>The puzzle's data is not returned because when generating HTML for displaying the puzzles we
   * must reference them with a IMG-tag and we cannot embed the data of the puzzles in the IMG-tag
   * because embedding image-data has only recently been added to browsers and many do not support
   * it yet.
   *
   * @param ownIdentity The identity which wants to solve the puzzles.
   * @param amount The amount of puzzles to request.
   * @return A list of the IDs of the puzzles. The amount might be less than the requested amount
   *     and even zero if WoT has not downloaded puzzles yet.
   * @throws Exception
   */
  public List<String> getIntroductionPuzzles(WoTOwnIdentity ownIdentity, int amount)
      throws Exception {
    ArrayList<String> puzzleIDs = new ArrayList<String>(amount + 1);

    SimpleFieldSet params = new SimpleFieldSet(true);
    params.putOverwrite("Message", "GetIntroductionPuzzles");
    params.putOverwrite("Identity", ownIdentity.getID());
    params.putOverwrite("Type", "Captcha"); // TODO: Don't hardcode the String
    params.put("Amount", amount);

    try {
      SimpleFieldSet result = sendFCPMessageBlocking(params, null, "IntroductionPuzzles").params;

      for (int idx = 0; ; idx++) {
        String id = result.get("Puzzle" + idx);

        if (id == null
            || id.equals("")) /* TODO: Figure out whether the second condition is necessary */
          break;

        puzzleIDs.add(id);
      }
    } catch (PluginNotFoundException e) {
      Logger.error(this, "Getting puzzles failed", e);
    }

    return puzzleIDs;
  }
Beispiel #4
0
 @Override
 public void onGeneratedURI(FreenetURI uri, BaseClientPutter state, ObjectContainer container) {
   if (logMINOR) Logger.minor(this, "Generated URI for " + darknetOpennetString + " ARK: " + uri);
   long l = uri.getSuggestedEdition();
   if (l < crypto.myARKNumber) {
     Logger.error(
         this,
         "Inserted "
             + darknetOpennetString
             + " ARK edition # lower than attempted: "
             + l
             + " expected "
             + crypto.myARKNumber);
   } else if (l > crypto.myARKNumber) {
     if (logMINOR)
       Logger.minor(
           this,
           darknetOpennetString + " ARK number moving from " + crypto.myARKNumber + " to " + l);
     crypto.myARKNumber = l;
     if (crypto.isOpennet) node.writeOpennetFile();
     else node.writeNodeFile();
     // We'll broadcast the new ARK edition to our connected peers via a differential node
     // reference
     SimpleFieldSet fs = new SimpleFieldSet(true);
     fs.put("ark.number", crypto.myARKNumber);
     node.peers.locallyBroadcastDiffNodeRef(fs, !crypto.isOpennet, crypto.isOpennet);
   }
 }
 public SimpleFieldSet toFieldSet() {
   if (freed) {
     Logger.error(this, "Cannot serialize because already freed: " + this);
     return null;
   }
   SimpleFieldSet fs = new SimpleFieldSet(false);
   fs.putSingle("Type", "DelayedFreeBucket");
   if (bucket instanceof SerializableToFieldSetBucket) {
     fs.put("Underlying", ((SerializableToFieldSetBucket) bucket).toFieldSet());
   } else {
     Logger.error(this, "Cannot serialize underlying bucket: " + bucket);
     return null;
   }
   return fs;
 }
 /** Persist the throttle data to a SimpleFieldSet. */
 SimpleFieldSet persistToFieldSet() {
   SimpleFieldSet fs = new SimpleFieldSet(false);
   fs.put("ThrottleWindow", throttleWindowBulk.exportFieldSet(false));
   fs.put("ThrottleWindowRT", throttleWindowRT.exportFieldSet(false));
   fs.put("ThrottleWindowCHK", throttleWindowCHK.exportFieldSet(false));
   fs.put("ThrottleWindowSSK", throttleWindowCHK.exportFieldSet(false));
   fs.put("CHKRequestThrottle", chkRequestThrottleBulk.exportFieldSet());
   fs.put("SSKRequestThrottle", sskRequestThrottleBulk.exportFieldSet());
   fs.put("CHKInsertThrottle", chkInsertThrottleBulk.exportFieldSet());
   fs.put("SSKInsertThrottle", sskInsertThrottleBulk.exportFieldSet());
   fs.put("CHKRequestThrottleRT", chkRequestThrottleRT.exportFieldSet());
   fs.put("SSKRequestThrottleRT", sskRequestThrottleRT.exportFieldSet());
   fs.put("CHKInsertThrottleRT", chkInsertThrottleRT.exportFieldSet());
   fs.put("SSKInsertThrottleRT", sskInsertThrottleRT.exportFieldSet());
   return fs;
 }
 public SimpleFieldSet exportFieldSet() {
   SimpleFieldSet fs = new SimpleFieldSet(false);
   fs.put("RoundTripTime", roundTripTime.exportFieldSet(false));
   return fs;
 }