Ejemplo n.º 1
0
 protected static ClientKeyBlock innerEncode(
     RandomSource random,
     FreenetURI uri,
     Bucket sourceData,
     boolean isMetadata,
     short compressionCodec,
     int sourceLength,
     String compressorDescriptor)
     throws InsertException, CHKEncodeException, IOException, SSKEncodeException,
         MalformedURLException, InvalidCompressionCodecException {
   String uriType = uri.getKeyType();
   if (uriType.equals("CHK")) {
     return ClientCHKBlock.encode(
         sourceData,
         isMetadata,
         compressionCodec == -1,
         compressionCodec,
         sourceLength,
         compressorDescriptor);
   } else if (uriType.equals("SSK") || uriType.equals("KSK")) {
     InsertableClientSSK ik = InsertableClientSSK.create(uri);
     return ik.encode(
         sourceData,
         isMetadata,
         compressionCodec == -1,
         compressionCodec,
         sourceLength,
         random,
         compressorDescriptor);
   } else {
     throw new InsertException(InsertException.INVALID_URI, "Unknown keytype " + uriType, null);
   }
 }
Ejemplo n.º 2
0
  private void startInserter() {
    if (!canStart) {
      if (logMINOR) Logger.minor(this, darknetOpennetString + " ARK inserter can't start yet");
      return;
    }

    if (logMINOR) Logger.minor(this, "starting " + darknetOpennetString + " ARK inserter");

    SimpleFieldSet fs = crypto.exportPublicFieldSet(false, false, true);

    // Remove some unnecessary fields that only cause collisions.

    // Delete entire ark.* field for now. Changing this and automatically moving to the new may be
    // supported in future.
    fs.removeSubset("ark");
    fs.removeValue("location");
    fs.removeValue("sig");
    // fs.remove("version"); - keep version because of its significance in reconnection

    String s = fs.toString();

    byte[] buf;
    try {
      buf = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
    }

    Bucket b = new SimpleReadOnlyArrayBucket(buf);

    long number = crypto.myARKNumber;
    InsertableClientSSK ark = crypto.myARK;
    FreenetURI uri = ark.getInsertURI().setKeyType("USK").setSuggestedEdition(number);

    if (logMINOR)
      Logger.minor(
          this, "Inserting " + darknetOpennetString + " ARK: " + uri + "  contents:\n" + s);

    inserter =
        new ClientPutter(
            this,
            b,
            uri,
            new ClientMetadata("text/plain") /* it won't quite fit in an SSK anyway */,
            node.clientCore.makeClient((short) 0, true).getInsertContext(true),
            RequestStarter.INTERACTIVE_PRIORITY_CLASS,
            false,
            false,
            this,
            null,
            null,
            false);

    try {

      node.clientCore.clientContext.start(inserter, false);

      synchronized (this) {
        if (fs.get("physical.udp") == null) lastInsertedPeers = null;
        else {
          try {
            String[] all = fs.getAll("physical.udp");
            Peer[] peers = new Peer[all.length];
            for (int i = 0; i < all.length; i++) peers[i] = new Peer(all[i], false);
            lastInsertedPeers = peers;
          } catch (PeerParseException e1) {
            Logger.error(
                this,
                "Error parsing own "
                    + darknetOpennetString
                    + " ref: "
                    + e1
                    + " : "
                    + fs.get("physical.udp"),
                e1);
          } catch (UnknownHostException e1) {
            Logger.error(
                this,
                "Error parsing own "
                    + darknetOpennetString
                    + " ref: "
                    + e1
                    + " : "
                    + fs.get("physical.udp"),
                e1);
          }
        }
      }
    } catch (InsertException e) {
      onFailure(e, inserter, null);
    } catch (DatabaseDisabledException e) {
      // Impossible
    }
  }