示例#1
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   FaceInstance other = (FaceInstance) obj;
   if (_action == null) {
     if (other._action != null) return false;
   } else if (!_action.equals(other._action)) return false;
   if (_ccndID == null) {
     if (other._ccndID != null) return false;
   } else if (!_ccndID.equals(other._ccndID)) return false;
   if (_faceID == null) {
     if (other._faceID != null) return false;
   } else if (!_faceID.equals(other._faceID)) return false;
   if (_ipProto == null) {
     if (other._ipProto != null) return false;
   } else if (!_ipProto.equals(other._ipProto)) return false;
   if (_host == null) {
     if (other._host != null) return false;
   } else if (!_host.equals(other._host)) return false;
   if (_port == null) {
     if (other._port != null) return false;
   } else if (!_port.equals(other._port)) return false;
   if (_multicastInterface == null) {
     if (other._multicastInterface != null) return false;
   } else if (!_multicastInterface.equals(other._multicastInterface)) return false;
   if (_multicastTTL == null) {
     if (other._multicastTTL != null) return false;
   } else if (!_multicastTTL.equals(other._multicastTTL)) return false;
   if (_lifetime == null) {
     if (other._lifetime != null) return false;
   } else if (!_lifetime.equals(other._lifetime)) return false;
   return true;
 }
示例#2
0
 /**
  * Used by NetworkObject to encode the object to a network stream.
  *
  * @see org.ccnx.ccn.impl.encoding.XMLEncodable
  */
 public void encode(XMLEncoder encoder) throws ContentEncodingException {
   if (!validate()) {
     throw new ContentEncodingException(
         "Cannot encode " + this.getClass().getName() + ": field values missing.");
   }
   encoder.writeStartElement(getElementLabel());
   if (null != _action && _action.length() != 0)
     encoder.writeElement(CCNProtocolDTags.Action, _action);
   if (null != _ccndID) {
     _ccndID.encode(encoder);
   }
   if (null != _faceID) {
     encoder.writeElement(CCNProtocolDTags.FaceID, _faceID);
   }
   if (null != _ipProto) {
     encoder.writeElement(CCNProtocolDTags.IPProto, _ipProto.value());
   }
   if (null != _host && _host.length() != 0) {
     encoder.writeElement(CCNProtocolDTags.Host, _host);
   }
   if (null != _port) {
     encoder.writeElement(CCNProtocolDTags.Port, _port);
   }
   if (null != _multicastInterface && _multicastInterface.length() != 0) {
     encoder.writeElement(CCNProtocolDTags.MulticastInterface, _multicastInterface);
   }
   if (null != _multicastTTL) {
     encoder.writeElement(CCNProtocolDTags.MulticastTTL, _multicastTTL);
   }
   if (null != _lifetime) {
     encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, _lifetime);
   }
   encoder.writeEndElement();
 }
示例#3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((_action == null) ? 0 : _action.hashCode());
   result = prime * result + ((_ccndID == null) ? 0 : _ccndID.hashCode());
   result = prime * result + ((_faceID == null) ? 0 : _faceID.hashCode());
   result = prime * result + ((_ipProto == null) ? 0 : _ipProto.hashCode());
   result = prime * result + ((_host == null) ? 0 : _host.hashCode());
   result = prime * result + ((_port == null) ? 0 : _port.hashCode());
   result =
       prime * result + ((_multicastInterface == null) ? 0 : _multicastInterface.hashCode());
   result = prime * result + ((_multicastTTL == null) ? 0 : _multicastTTL.hashCode());
   result = prime * result + ((_lifetime == null) ? 0 : _lifetime.hashCode());
   return result;
 }
示例#4
0
 /**
  * Used by NetworkObject to decode the object from a network stream.
  *
  * @see org.ccnx.ccn.impl.encoding.XMLEncodable
  */
 public void decode(XMLDecoder decoder) throws ContentDecodingException {
   decoder.readStartElement(getElementLabel());
   if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
     _action = decoder.readUTF8Element(CCNProtocolDTags.Action);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
     _ccndID = new PublisherPublicKeyDigest();
     _ccndID.decode(decoder);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
     _faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.IPProto)) {
     int pI = decoder.readIntegerElement(CCNProtocolDTags.IPProto);
     _ipProto = null;
     if (NetworkProtocol.TCP.value().intValue() == pI) {
       _ipProto = NetworkProtocol.TCP;
     } else if (NetworkProtocol.UDP.value().intValue() == pI) {
       _ipProto = NetworkProtocol.UDP;
     } else {
       throw new ContentDecodingException(
           "FaceInstance.decoder.  Invalid "
               + CCNProtocolDTags.tagToString(CCNProtocolDTags.IPProto)
               + " field: "
               + pI);
     }
   }
   if (decoder.peekStartElement(CCNProtocolDTags.Host)) {
     _host = decoder.readUTF8Element(CCNProtocolDTags.Host);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.Port)) {
     _port = decoder.readIntegerElement(CCNProtocolDTags.Port);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.MulticastInterface)) {
     _multicastInterface = decoder.readUTF8Element(CCNProtocolDTags.MulticastInterface);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.MulticastTTL)) {
     _multicastTTL = decoder.readIntegerElement(CCNProtocolDTags.MulticastTTL);
   }
   if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
     _lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
   }
   decoder.readEndElement();
 }
示例#5
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;
  }
示例#6
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;
 }