示例#1
0
  private User getFriendlyName(
      PublisherPublicKeyDigest digest, CCNHandle tempReadHandle, CCNHandle tempWriteHandle)
      throws MalformedContentNameStringException, IOException {
    User userFriendlyName = null;
    if (_userToDigestHash.containsKey(digest)) {
      userFriendlyName = _userToDigestHash.get(digest);
      Log.info("GET digest: " + digest.digest() + " --> " + userFriendlyName.getUserName());
    } else {
      Log.info("We DON'T have an entry in our hash for this " + digest);
    }

    if (userFriendlyName == null) {

      // Its not in the hashMap.. So, try and read the user's
      // friendly name from the ContentName and then add it to
      // the hashMap....
      String userNameStr = _namespaceStr + MEMBER_COMPONENT;
      _userNamespace =
          KeyProfile.keyName(ContentName.fromURI(userNameStr), _readString.getContentPublisher());

      try {
        _readNameString =
            new CCNStringObject(_userNamespace, (String) null, SaveType.RAW, tempReadHandle);
      } catch (Exception e) {
        e.printStackTrace();
      }

      _readNameString.update(WAIT_TIME_FOR_FRIENDLY_NAME);

      if (_readNameString.available()) {

        if (_readString.getContentPublisher().equals(_readNameString.getContentPublisher())) {
          userFriendlyName =
              addNameToHash(_readNameString.getContentPublisher(), _readNameString.string());
        }
      } else {
        userFriendlyName =
            new Speaker(
                "", "", _readString.getContentPublisher().shortFingerprint().substring(0, 8));
      }
    }
    return userFriendlyName;
  }
示例#2
0
 private User addNameToHash(PublisherPublicKeyDigest digest, String friendlyName) {
   Log.info("SAVE digest: " + digest.digest() + " --> " + friendlyName);
   User user = new Speaker("", "", friendlyName);
   _userToDigestHash.put(digest, user);
   return user;
 }