Package freenet.client.InsertContext

Examples of freenet.client.InsertContext.CompatibilityMode


      forceCryptoKey = new byte[32];
      context.random.nextBytes(forceCryptoKey);
    }
    this.forceCryptoKey = forceCryptoKey;
   
    CompatibilityMode mode = ctx.getCompatibilityMode();
    if(!(mode == CompatibilityMode.COMPAT_CURRENT || mode.ordinal() >= CompatibilityMode.COMPAT_1416.ordinal()))
      this.cryptoAlgorithm = Key.ALGO_AES_PCFB_256_SHA256;
    else
      this.cryptoAlgorithm = Key.ALGO_AES_CTR_256_SHA256;
    runningPutHandlers = new HashSet<PutHandler>();
    putHandlersWaitingForMetadata = new HashSet<PutHandler>();
View Full Code Here


          return;
        }
        final boolean compress = request.getPartAsStringFailsafe("compress", 128).length() > 0;
        final String identifier = file.getFilename() + "-fred-" + System.currentTimeMillis();
        final String compatibilityMode = request.getPartAsStringFailsafe("compatibilityMode", 100);
        final CompatibilityMode cmode;
        if(compatibilityMode.equals(""))
          cmode = CompatibilityMode.COMPAT_DEFAULT.intern();
        else
          cmode = CompatibilityMode.valueOf(compatibilityMode).intern();
        String s = request.getPartAsStringFailsafe("overrideSplitfileKey", 65);
        final byte[] overrideSplitfileKey;
        if(s != null && !s.equals(""))
          overrideSplitfileKey = HexUtil.hexToBytes(s);
        else
          overrideSplitfileKey = null;
        final String fnam;
        if(insertURI.getKeyType().equals("CHK") || keyType.equals("SSK"))
          fnam = file.getFilename();
        else
          fnam = null;
        /* copy bucket data */
        final RandomAccessBucket copiedBucket = core.persistentTempBucketFactory.makeBucket(file.getData().size());
        BucketTools.copy(file.getData(), copiedBucket);
        final CountDownLatch done = new CountDownLatch(1);
        try {
          core.clientLayerPersister.queue(new PersistentJob() {

            @Override
            public String toString() {
              return "QueueToadlet StartInsert";
            }

            @Override
            public boolean run(ClientContext context) {
              try {
              final ClientPut clientPut;
              try {
                clientPut = new ClientPut(fcp.getGlobalForeverClient(), insertURI, identifier, Integer.MAX_VALUE, null, RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS, Persistence.FOREVER, null, false, !compress, -1, UploadFrom.DIRECT, null, file.getContentType(), copiedBucket, null, fnam, false, false, Node.FORK_ON_CACHEABLE_DEFAULT, HighLevelSimpleClientImpl.EXTRA_INSERTS_SINGLE_BLOCK, HighLevelSimpleClientImpl.EXTRA_INSERTS_SPLITFILE_HEADER, false, cmode, overrideSplitfileKey, false, fcp.core);
                if(clientPut != null)
                  try {
                    fcp.startBlocking(clientPut, context);
                  } catch (IdentifierCollisionException e) {
                    Logger.error(this, "Cannot put same file twice in same millisecond");
                    writePermanentRedirect(ctx, "Done", path());
                    return false;
                  }
                writePermanentRedirect(ctx, "Done", path());
                return true;
              } catch (IdentifierCollisionException e) {
                Logger.error(this, "Cannot put same file twice in same millisecond");
                writePermanentRedirect(ctx, "Done", path());
                return false;
              } catch (NotAllowedException e) {
                writeError(l10n("errorAccessDenied"), l10n("errorAccessDeniedFile", "file", file.getFilename()), ctx, false, true);
                return false;
              } catch (FileNotFoundException e) {
                writeError(l10n("errorNoFileOrCannotRead"), l10n("errorAccessDeniedFile", "file", file.getFilename()), ctx, false, true);
                return false;
              } catch (MalformedURLException mue1) {
                writeError(l10n("errorInvalidURI"), l10n("errorInvalidURIToU"), ctx, false, true);
                return false;
              } catch (MetadataUnresolvedException e) {
                Logger.error(this, "Unresolved metadata in starting insert from data uploaded from browser: "+e, e);
                writePermanentRedirect(ctx, "Done", path());
                return false;
                // FIXME should this be a proper localised message? It shouldn't happen... but we'd like to get reports if it does.
              } catch (Throwable t) {
                writeInternalError(t, ctx);
                return false;
              } finally {
                done.countDown();
              }
              } catch (IOException e) {
                // Ignore
                return false;
              } catch (ToadletContextClosedException e) {
                // Ignore
                return false;
              }
            }

          }, NativeThread.HIGH_PRIORITY+1);
        } catch (PersistenceDisabledException e1) {
          sendPersistenceDisabledError(ctx);
          return;
        }
        while (done.getCount() > 0) {
          try {
            done.await();
          } catch (InterruptedException e) {
            // Ignore
          }
        }
        return;
      } else if (request.isPartSet(LocalFileBrowserToadlet.selectFile)) {
        final String filename = request.getPartAsStringFailsafe("filename", MAX_FILENAME_LENGTH);
        if(logMINOR) Logger.minor(this, "Inserting local file: "+filename);
        final File file = new File(filename);
        final String identifier = file.getName() + "-fred-" + System.currentTimeMillis();
        final String contentType = DefaultMIMETypes.guessMIMEType(filename, false);
        final FreenetURI furi;
        final String key = request.getPartAsStringFailsafe("key", MAX_KEY_LENGTH);
        final boolean compress = request.isPartSet("compress");
        final String compatibilityMode = request.getPartAsStringFailsafe("compatibilityMode", 100);
        final CompatibilityMode cmode;
        if(compatibilityMode.equals(""))
          cmode = CompatibilityMode.COMPAT_DEFAULT;
        else
          cmode = CompatibilityMode.valueOf(compatibilityMode);
        String s = request.getPartAsStringFailsafe("overrideSplitfileKey", 65);
View Full Code Here

      synchronized(this) {
        // Don't delete them because they are being passed on.
        origHashes = null;
      }
    } else {
      CompatibilityMode cmode = ctx.getCompatibilityMode();
      boolean allowSizes = (cmode == CompatibilityMode.COMPAT_CURRENT || cmode.ordinal() >= CompatibilityMode.COMPAT_1255.ordinal());
      if(metadata) allowSizes = false;
      SplitHandler sh = new SplitHandler(origSize, compressedDataSize, allowSizes);
      SplitFileInserter sfi = new SplitFileInserter(persistent, parent, sh,
              dataRAF, shouldFreeData, ctx, context, origSize, bestCodec,
              block.clientMetadata, metadata, archiveType, cryptoAlgorithm, forceCryptoKey,
View Full Code Here

      throw new InsertException(InsertExceptionMode.INVALID_URI, "Unknown key type: "+type, null);
    }
   
    // We always want SHA256, even for small files.
    long wantHashes = 0;
    CompatibilityMode cmode = ctx.getCompatibilityMode();
    boolean atLeast1254 = (cmode == CompatibilityMode.COMPAT_CURRENT || cmode.ordinal() >= CompatibilityMode.COMPAT_1255.ordinal());
    if(atLeast1254) {
      // We verify this. We want it for *all* files.
      wantHashes |= HashType.SHA256.bitmask;
      // FIXME: If the user requests it, calculate the others for small files.
      // FIXME maybe the thresholds should be configurable.
View Full Code Here

    int req = 0;
    int total = 0;
    long data = 0;
    long compressed = 0;
    boolean topDontCompress = false;
    CompatibilityMode topCompatibilityMode = CompatibilityMode.COMPAT_UNKNOWN;
    if(allowTopBlocks) {
      req = parent.getMinSuccessFetchBlocks();
      total = parent.totalBlocks;
      topDontCompress = ctx.dontCompress;
      topCompatibilityMode = ctx.getCompatibilityMode();
View Full Code Here

        InsertException ex = new InsertException(InsertExceptionMode.BUCKET_ERROR, e1, null);
        fail(ex, context);
        return;
      }
      ClientMetadata m = meta.getClientMetadata();
      CompatibilityMode cmode = ctx.getCompatibilityMode();
      if(!(cmode == CompatibilityMode.COMPAT_CURRENT || cmode.ordinal() >= CompatibilityMode.COMPAT_1255.ordinal()))
        m = null;
      if(metadataThreshold > 0 && metaBytes.length < metadataThreshold) {
        // FIXME what to do about m ???
        // I.e. do the other layers of metadata already include the content type?
        // It's probably already included in the splitfile, but need to check that, and test it.
View Full Code Here

   */
  public boolean start(boolean restart, ClientContext context) throws InsertException {
    if(logMINOR)
      Logger.minor(this, "Starting "+this+" for "+targetURI);
    byte cryptoAlgorithm;
    CompatibilityMode mode = ctx.getCompatibilityMode();
    if(!(mode == CompatibilityMode.COMPAT_CURRENT || mode.ordinal() >= CompatibilityMode.COMPAT_1416.ordinal()))
      cryptoAlgorithm = Key.ALGO_AES_PCFB_256_SHA256;
    else
      cryptoAlgorithm = Key.ALGO_AES_CTR_256_SHA256;
    try {
      this.targetURI.checkInsertURI();
View Full Code Here

    // randomised keys. This substantially improves security by making it impossible to identify blocks
    // even if you know the content. In the user interface, we will offer the option of inserting as a
    // random SSK to take advantage of this.
    boolean randomiseSplitfileKeys = targetURI.isSSK() || targetURI.isKSK() || targetURI.isUSK();
    if(randomiseSplitfileKeys) {
      CompatibilityMode cmode = ctx.getCompatibilityMode();
      if(!(cmode == CompatibilityMode.COMPAT_CURRENT || cmode.ordinal() >= CompatibilityMode.COMPAT_1255.ordinal()))
        randomiseSplitfileKeys = false;
    }
    return randomiseSplitfileKeys;
  }
View Full Code Here

  }

  /** Return a best-guess compatibility mode, guaranteed not to be
   * COMPAT_UNKNOWN or COMPAT_CURRENT. */
  public CompatibilityMode guessCompatibilityMode() {
    CompatibilityMode mode = getTopCompatibilityMode();
    if(mode != CompatibilityMode.COMPAT_UNKNOWN) return mode;
    CompatibilityMode min = minCompatMode;
    CompatibilityMode max = maxCompatMode;
    if(max == CompatibilityMode.COMPAT_CURRENT)
      max = CompatibilityMode.latest();
    if(min == max) return min;
    if(min == CompatibilityMode.COMPAT_UNKNOWN &&
        max != CompatibilityMode.COMPAT_UNKNOWN)
View Full Code Here

        if(decompressors.size() > 1) {
            Logger.error(this, "Multiple decompressors: "+decompressors.size()+" - this is almost certainly a bug", new Exception("debug"));
        }
        this.clientMetadata = clientMetadata == null ? new ClientMetadata() : clientMetadata.clone(); // copy it as in SingleFileFetcher
        SplitFileSegmentKeys[] segmentKeys = metadata.getSegmentKeys();
        CompatibilityMode minCompatMode = metadata.getMinCompatMode();
        CompatibilityMode maxCompatMode = metadata.getMaxCompatMode();

        int crossCheckBlocks = metadata.getCrossCheckBlocks();
       
        maxRetries = origFetchContext.maxSplitfileBlockRetries;
        cooldownTries = origFetchContext.getCooldownRetries();
        cooldownLength = origFetchContext.getCooldownTime();
        this.splitfileSingleCryptoAlgorithm = metadata.getSplitfileCryptoAlgorithm();
        splitfileSingleCryptoKey = metadata.getSplitfileCryptoKey();
       
        // These are approximate values, the number of blocks per segment varies.
        int blocksPerSegment = metadata.getDataBlocksPerSegment();
        int checkBlocksPerSegment = metadata.getCheckBlocksPerSegment();
       
        int splitfileDataBlocks = 0;
        int splitfileCheckBlocks = 0;
       
        long storedBlocksLength = 0;
        long storedKeysLength = 0;
        long storedSegmentStatusLength = 0;
        /** Only non-zero if the cross-check blocks are stored separately i.e. if completeViaTruncation */
        long storedCrossCheckBlocksLength = 0;

        for(SplitFileSegmentKeys keys : segmentKeys) {
            int dataBlocks = keys.getDataBlocks();
            // Here data blocks include cross-segment blocks.
            int checkBlocks = keys.getCheckBlocks();
            splitfileDataBlocks += dataBlocks;
            splitfileCheckBlocks += checkBlocks;
            storedKeysLength +=
                SplitFileFetcherSegmentStorage.storedKeysLength(dataBlocks, checkBlocks, splitfileSingleCryptoKey != null, checksumLength);
            storedSegmentStatusLength +=
                SplitFileFetcherSegmentStorage.paddedStoredSegmentStatusLength(dataBlocks - crossCheckBlocks, checkBlocks,
                        crossCheckBlocks, maxRetries != -1, checksumLength, persistent);
        }
       
        int totalCrossCheckBlocks = segmentKeys.length * crossCheckBlocks;
        splitfileDataBlocks -= totalCrossCheckBlocks;
        if(completeViaTruncation) {
            storedCrossCheckBlocksLength = totalCrossCheckBlocks * CHKBlock.DATA_LENGTH;
            storedBlocksLength = splitfileDataBlocks * CHKBlock.DATA_LENGTH;
        } else {
            storedCrossCheckBlocksLength = 0;
            storedBlocksLength = (splitfileDataBlocks + totalCrossCheckBlocks) * CHKBlock.DATA_LENGTH;
        }
       
        int segmentCount = metadata.getSegmentCount();
       
        if(splitfileType == SplitfileAlgorithm.NONREDUNDANT) {
            if(splitfileCheckBlocks > 0) {
                Logger.error(this, "Splitfile type is SPLITFILE_NONREDUNDANT yet "+splitfileCheckBlocks+" check blocks found!! : "+this);
                throw new FetchException(FetchExceptionMode.INVALID_METADATA, "Splitfile type is non-redundant yet have "+splitfileCheckBlocks+" check blocks");
            }
        } else if(splitfileType == SplitfileAlgorithm.ONION_STANDARD) {
           
            boolean dontCompress = decompressors.isEmpty();
            if(topCompatibilityMode != 0) {
                // If we have top compatibility mode, then we can give a definitive answer immediately, with the splitfile key, with dontcompress, etc etc.
                if(minCompatMode == CompatibilityMode.COMPAT_UNKNOWN ||
                        !(minCompatMode.ordinal() > topCompatibilityMode || maxCompatMode.ordinal() < topCompatibilityMode)) {
                    minCompatMode = maxCompatMode = CompatibilityMode.values()[topCompatibilityMode];
                    dontCompress = topDontCompress;
                } else
                    throw new FetchException(FetchExceptionMode.INVALID_METADATA, "Top compatibility mode is incompatible with detected compatibility mode");
            }
View Full Code Here

TOP

Related Classes of freenet.client.InsertContext.CompatibilityMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.