Пример #1
0
 public Content get(Key key) throws Exception {
   // TODO retrieve the bkp address, then look at their content
   // if the content is a link (LINK:<key>), then recursively retrieve the
   // content
   // of the link.
   // JLG.debug("getFromKey:" + key);
   Content result = null;
   Queue<Address> queue = new LinkedList<Address>();
   Address[] address = getAddressList(key);
   Content[] contentArray = new Content[address.length];
   for (int i = 0; i < address.length; i++) {
     contentArray[i] = get(address[i]);
     if (contentArray[i] == null) {
       queue.offer(address[i]);
       // TODO reassign content to address
     } else {
       result = contentArray[i];
     }
   }
   if (result == null) {
     return null;
   }
   if (result.isLink()) {
     Link link = (Link) result;
     // JLG.debug("key " + key + " is a link on " + link.getTargetKey());
     result = get(link.getTargetKey());
   }
   return result;
 }
Пример #2
0
  public void setWithLink(OCPUser user, Content data, Link link) throws Exception {
    // if a link already exists with the same key, then delete it.
    Key key = link.getKey();
    if (exists(key)) {
      // remove both the link and its targets recursively
      remove(user, key);
    }

    Key targetKey = link.getTargetKey();
    if (exists(targetKey)) {
      remove(user, targetKey);
    }

    // check that the link targetKey is the data key
    checkLink(data, link);

    Address[] address = getAddressList(key);
    for (byte i = 0; i < address.length; i++) {
      store(address[i], link);
    }

    address = getAddressList(targetKey);
    for (byte i = 0; i < address.length; i++) {
      store(address[i], data);
    }
  }
Пример #3
0
 public void remove(OCPUser user, Key key) throws Exception {
   if (isLink(key)) {
     Link link = getLink(key);
     remove(user, link.getTargetKey());
   }
   // remove the address corresponding to the key.
   Address[] address = getAddressList(key);
   for (byte i = 0; i < address.length; i++) {
     // sign the address
     byte[] addressSignature = user.sign(this, address[i].getBytes());
     remove(address[i], addressSignature);
   }
 }
Пример #4
0
 private void checkLink(Content data, Link link) throws Exception {
   if (!data.getKey(this).equals(link.getTargetKey())) {
     throw new Exception("Link corrupted.");
   }
 }