Ejemplo n.º 1
0
  @Override
  public synchronized void addIdentifier(String key, UUID value) throws InputOutputException {
    SecuredDhtPathElement keyDhtPathElement =
        new SecuredDhtPathElement(
            this.username,
            Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + key),
            this.domainKey);

    SecuredDhtPathElement valueDhtPathElement =
        new SecuredDhtPathElement(
            this.username,
            Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + value),
            this.domainKey);

    byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
    byte[] valueBytes = value.toString().getBytes(StandardCharsets.UTF_8);

    // store key and value
    this.storageAdapter.persist(StorageType.FILE, keyDhtPathElement, valueBytes);
    this.storageAdapter.persist(StorageType.FILE, valueDhtPathElement, keyBytes);
  }
Ejemplo n.º 2
0
  @Override
  public synchronized void removeIdentifier(String key) throws InputOutputException {
    SecuredDhtPathElement keyDhtPathElement =
        new SecuredDhtPathElement(
            this.username,
            Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + key),
            this.domainKey);

    // try to get associated value
    UUID value = this.getValue(key);
    if (null != value) {
      // there is a value associated -> remove it too
      SecuredDhtPathElement valueDhtPathElement =
          new SecuredDhtPathElement(
              this.username,
              Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + value),
              this.domainKey);

      this.storageAdapter.delete(valueDhtPathElement);
    }

    this.storageAdapter.delete(keyDhtPathElement);
  }
Ejemplo n.º 3
0
  @Override
  public synchronized UUID getValue(String key) throws InputOutputException {
    SecuredDhtPathElement keyDhtPathElement =
        new SecuredDhtPathElement(
            this.username,
            Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + key),
            this.domainKey);

    byte[] uuidStringBytes = this.storageAdapter.read(keyDhtPathElement);

    if (0 == uuidStringBytes.length) {
      return null;
    }

    return UUID.fromString(new String(uuidStringBytes, StandardCharsets.UTF_8));
  }
Ejemplo n.º 4
0
  @Override
  public synchronized String getKey(UUID value) throws InputOutputException {
    SecuredDhtPathElement valueDhtPathElement =
        new SecuredDhtPathElement(
            this.username,
            Hash.hash(HashingAlgorithm.SHA_256, this.identifierContentKey + value),
            this.domainKey);

    byte[] keyStringBytes = this.storageAdapter.read(valueDhtPathElement);

    if (0 == keyStringBytes.length) {
      // value not found
      return null;
    }

    return new String(keyStringBytes, StandardCharsets.UTF_8);
  }