Beispiel #1
0
 /**
  * @param currentUser
  * @param currentTopic
  */
 public TextConf(User currentUser, Topic currentTopic, TextConfObserver obs) {
   this.currentUser = currentUser;
   this.currentTopic = currentTopic;
   this.observer = obs;
   this.setLogging(Level.WARNING);
   UserConfiguration.setUserName(this.currentUser.getUserName());
   _namespaceStr = BASE_NAMESPACE + "/" + currentTopic.getTopicName();
   _userToDigestHash = new HashMap<PublisherPublicKeyDigest, User>();
   try {
     _namespace = ContentName.fromURI(_namespaceStr);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {

    CCNTestHelper testHelper = new CCNTestHelper(GroupRecursiveKeyUpdateTestRepo.class);
    directoryBase = testHelper.getTestNamespace("testInOrder");
    userNamespace =
        GroupAccessControlProfile.userNamespaceName(UserConfiguration.defaultNamespace());
    groupNamespace =
        GroupAccessControlProfile.groupNamespaceName(UserConfiguration.defaultNamespace());
    userKeyStorePrefix = ContentName.fromNative(UserConfiguration.defaultNamespace(), "_keystore_");

    // create user identities with TestUserData
    td = new CreateUserData(userKeyStorePrefix, numberOfusers, true, "password".toCharArray());
    td.publishUserKeysToRepository(userNamespace);
    friendlyNames = td.friendlyNames().toArray(new String[0]);

    // create ACM
    handle = td.getHandleForUser(friendlyNames[1]);
    acm = new GroupAccessControlManager(directoryBase, groupNamespace, userNamespace, handle);
    acm.publishMyIdentity(
        ContentName.fromNative(userNamespace, friendlyNames[1]),
        handle.keyManager().getDefaultPublicKey());
  }
Beispiel #3
0
  /**
   * This actual CCN loop to send/receive messages. Called by the UI class. This method blocks! If
   * the UI is not multi-threaded, you should start a thread to hold listen().
   *
   * <p>When shutdown() is called, listen() will exit.
   *
   * @throws ConfigurationException
   * @throws IOException
   * @throws MalformedContentNameStringException
   */
  public void listen()
      throws ConfigurationException, IOException, MalformedContentNameStringException,
          RuntimeException {

    // Also publish your keys under the chat "channel name" namespace
    if (_namespace.toString().startsWith("ccnx:/")) {
      UserConfiguration.setDefaultNamespacePrefix(_namespace.toString().substring(5));
    } else {
      UserConfiguration.setDefaultNamespacePrefix(_namespace.toString());
    }

    CCNHandle tempReadHandle = CCNHandle.getHandle();

    // Writing must be on a different handle, to enable us to read back text
    // we have
    // written when nobody else is reading.
    CCNHandle tempWriteHandle = CCNHandle.open();

    _readString = new CCNStringObject(_namespace, (String) null, SaveType.RAW, tempReadHandle);
    _readString.updateInBackground(true);

    String introduction = UserConfiguration.userName() + " has entered " + _namespace;
    _writeString = new CCNStringObject(_namespace, introduction, SaveType.RAW, tempWriteHandle);
    _writeString.save();

    // Publish the user's friendly name as a speaker if needed
    // AND if this topic doesn't already have a speaker!
    if (this.currentUser.isSpeaker()) {
      if (this.userList.getSpeaker() == null
          || this.userList.getSpeaker().equals(this.currentUser)) {
        String friendlyNameNamespaceStr = _namespaceStr + TextConf.SPEAKER_COMPONENT;
        _spkrNamespace =
            KeyProfile.keyName(
                ContentName.fromURI(friendlyNameNamespaceStr), _writeString.getContentPublisher());
        Log.info("**** Speaker Namespace is " + _spkrNamespace);

        // read the string here.....
        _readNameString =
            new CCNStringObject(_spkrNamespace, (String) null, SaveType.RAW, tempReadHandle);
        _readNameString.updateInBackground(true);

        String publishedNameStr = UserConfiguration.userName();
        Log.info("*****I am adding my own speaker name as " + publishedNameStr);
        _writeNameString =
            new CCNStringObject(_spkrNamespace, publishedNameStr, SaveType.RAW, tempWriteHandle);
        _writeNameString.save();
      } else {
        throw new RuntimeException(
            "The conference topic "
                + this.currentTopic.getTopicName()
                + " already has a Speaker ("
                + this.userList.getSpeaker().getUserName()
                + ")!!!");
      }
    } else {
      // If the current user isn't a speaker, then they can't join a conference
      // that doesn't have one (i.e. they can't create a conference)
      if (this.userList.speaker == null) {
        throw new RuntimeException(
            "The conference topic "
                + this.currentTopic.getTopicName()
                + " doesn't have a Speaker yet so it isn't accepting non-Speakers!!!");
      }
    }

    // Publish the user's friendly name under a new ContentName
    String friendlyNameNamespaceStr = _namespaceStr + TextConf.MEMBER_COMPONENT;
    _userNamespace =
        KeyProfile.keyName(
            ContentName.fromURI(friendlyNameNamespaceStr), _writeString.getContentPublisher());
    Log.info("**** Friendly Namespace is " + _userNamespace);

    // read the string here.....
    _readNameString =
        new CCNStringObject(_userNamespace, (String) null, SaveType.RAW, tempReadHandle);
    _readNameString.updateInBackground(true);

    String publishedNameStr = UserConfiguration.userName();
    Log.info("*****I am adding my own friendly name as " + publishedNameStr);
    _writeNameString =
        new CCNStringObject(_userNamespace, publishedNameStr, SaveType.RAW, tempWriteHandle);
    _writeNameString.save();

    try {
      addNameToHash(_writeNameString.getContentPublisher(), _writeNameString.string());
    } catch (IOException e) {
      System.err.println("Unable to read from " + _writeNameString + "for writing to hashMap");
      e.printStackTrace();
    }

    // Need to do synchronization for updates that come in while we're
    // processing last one.

    while (!_finished) {
      try {
        synchronized (_readString) {
          _readString.wait(CYCLE_TIME);
        }
      } catch (InterruptedException e) {
      }

      if (_readString.isSaved()) {
        Timestamp thisUpdate = _readString.getVersion();
        if ((null == _lastUpdate) || thisUpdate.after(_lastUpdate)) {
          Log.info(
              "Got an update from "
                  + _readString.getBaseName().toURIString()
                  + ": "
                  + _readString.getVersion()
                  + "..."
                  + _readString.string());
          _lastUpdate = thisUpdate;

          // lookup friendly name to display for this user.....
          User userFriendlyName =
              getFriendlyName(_readString.getContentPublisher(), tempReadHandle, tempWriteHandle);

          if (!userFriendlyName.equals(this.currentUser)) {
            messageReceived(userFriendlyName, thisUpdate, _readString.string());
          }
        }
      }
    }
  }