public static void estimateKeyDerivationTime() {
   // This is run in the background after startup. If we haven't recorded it before, do a key
   // derivation to see
   // how long it takes. This helps us produce better progress feedback, as on Windows we don't
   // currently have a
   // native Scrypt impl and the Java version is ~3 times slower, plus it depends a lot on CPU
   // speed.
   checkGuiThread();
   estimatedKeyDerivationTime = Main.instance.prefs.getExpectedKeyDerivationTime();
   if (estimatedKeyDerivationTime == null) {
     new Thread(
             () -> {
               log.info("Doing background test key derivation");
               KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS);
               long start = System.currentTimeMillis();
               scrypt.deriveKey("test password");
               long msec = System.currentTimeMillis() - start;
               log.info("Background test key derivation took {}msec", msec);
               Platform.runLater(
                   () -> {
                     estimatedKeyDerivationTime = Duration.ofMillis(msec);
                     Main.instance.prefs.setExpectedKeyDerivationTime(estimatedKeyDerivationTime);
                   });
             })
         .start();
   }
 }
  private static long getDelayMilliseconds(Command command) {
    final Schedule schedule = command.getContext().getSchedule();
    final Duration delay = schedule.getDelay();
    final long delaySec = delay.getSeconds();
    final long delayMillisFraction = delay.getNanos() / NANOS_IN_MILLISECOND;

    /**
     * Maximum value of {@link Duration#getSeconds()} is <a
     * href="https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto"+315,576,000,000.</a>.
     *
     * <p>{@link Long.MAX_VALUE} is +9,223,372,036,854,775,807. That's why it is safe to multiply
     * {@code delaySec * MILLIS_IN_SECOND}.
     */
    final long absoluteMillis = delaySec * MILLIS_IN_SECOND + delayMillisFraction;
    return absoluteMillis;
  }
Exemplo n.º 3
0
 /**
  *
  *
  * <pre>
  * Clients should wait at least this long between retrying the same request.
  * </pre>
  *
  * <code>optional .google.protobuf.Duration retry_delay = 1;</code>
  */
 public com.google.protobuf.DurationOrBuilder getRetryDelayOrBuilder() {
   if (retryDelayBuilder_ != null) {
     return retryDelayBuilder_.getMessageOrBuilder();
   } else {
     return retryDelay_ == null
         ? com.google.protobuf.Duration.getDefaultInstance()
         : retryDelay_;
   }
 }
Exemplo n.º 4
0
    /**
     *
     *
     * <pre>
     * Clients should wait at least this long between retrying the same request.
     * </pre>
     *
     * <code>optional .google.protobuf.Duration retry_delay = 1;</code>
     */
    public Builder mergeRetryDelay(com.google.protobuf.Duration value) {
      if (retryDelayBuilder_ == null) {
        if (retryDelay_ != null) {
          retryDelay_ =
              com.google.protobuf.Duration.newBuilder(retryDelay_).mergeFrom(value).buildPartial();
        } else {
          retryDelay_ = value;
        }
        onChanged();
      } else {
        retryDelayBuilder_.mergeFrom(value);
      }

      return this;
    }
Exemplo n.º 5
0
  private RetryInfo(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    this();
    int mutable_bitField0_ = 0;
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default:
            {
              if (!input.skipField(tag)) {
                done = true;
              }
              break;
            }
          case 10:
            {
              com.google.protobuf.Duration.Builder subBuilder = null;
              if (retryDelay_ != null) {
                subBuilder = retryDelay_.toBuilder();
              }
              retryDelay_ =
                  input.readMessage(com.google.protobuf.Duration.parser(), extensionRegistry);
              if (subBuilder != null) {
                subBuilder.mergeFrom(retryDelay_);
                retryDelay_ = subBuilder.buildPartial();
              }

              break;
            }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this);
    } finally {
      makeExtensionsImmutable();
    }
  }
Exemplo n.º 6
0
 /**
  *
  *
  * <pre>
  * Clients should wait at least this long between retrying the same request.
  * </pre>
  *
  * <code>optional .google.protobuf.Duration retry_delay = 1;</code>
  */
 public com.google.protobuf.Duration getRetryDelay() {
   return retryDelay_ == null ? com.google.protobuf.Duration.getDefaultInstance() : retryDelay_;
 }