Esempio n. 1
0
  /**
   * Process an individual element from the document.
   *
   * @param elem the element to be processed.
   * @return true if the element was recognized, otherwise false.
   */
  protected boolean handleElement(TextElement elem) {
    if (elem.getName().equals("PeerGroupID")) {
      try {
        URI gID = new URI(elem.getTextValue());
        ID pgid = IDFactory.fromURI(gID);

        if (!pgid.equals(getPeerGroupID())) {
          throw new IllegalArgumentException(
              "Operation is from a different group. " + pgid + " != " + getPeerGroupID());
        }
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Unusable ID in advertisement: " + elem.getTextValue());
      }
      return true;
    }

    if (elem.getName().equals("PeerID")) {
      try {
        URI pID = new URI(elem.getTextValue());
        ID pid = IDFactory.fromURI(pID);

        if (!pid.equals(getPeerID())) {
          throw new IllegalArgumentException(
              "Operation is from a different group. " + pid + " != " + getPeerID());
        }
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Bad Peer ID in advertisement: " + elem.getTextValue());
      } catch (ClassCastException badID) {
        throw new IllegalArgumentException("Id is not a peer id: " + elem.getTextValue());
      }
      return true;
    }

    if (elem.getName().equals("Method")) {
      setMethod(elem.getTextValue());
      return true;
    }

    if (elem.getName().equals("IdentityInfo")) {
      Enumeration firstChild = elem.getChildren();

      if (!firstChild.hasMoreElements()) {
        throw new IllegalArgumentException("Missing identity info");
      }

      identityInfo = StructuredDocumentUtils.copyAsDocument((Element) firstChild.nextElement());

      return true;
    }

    // element was not handled
    return false;
  }
Esempio n. 2
0
  /** {@inheritDoc} */
  public void initializeFrom(Element element) throws DocumentSerializationException {
    for (Enumeration e = element.getChildren(); e.hasMoreElements(); ) {
      Element serviceElement = (TextElement) e.nextElement();
      String tagName = (String) serviceElement.getKey();

      if (tagName.equals("service")) {
        try {
          ModuleClassID moduleClassID =
              (ModuleClassID)
                  IDFactory.fromURI(
                      new URI(
                          DocumentSerializableUtilities.getString(
                              serviceElement, "moduleClassID", "ERROR")));

          try {
            ServiceMonitorFilter serviceMonitorFilter =
                MonitorResources.createServiceMonitorFilter(moduleClassID);
            serviceMonitorFilter.init(moduleClassID);
            Element serviceMonitorFilterElement =
                DocumentSerializableUtilities.getChildElement(serviceElement, "serviceFilter");
            serviceMonitorFilter.initializeFrom(serviceMonitorFilterElement);
            serviceMonitorFilters.put(moduleClassID, serviceMonitorFilter);
          } catch (Exception ex) {
            if (unknownModuleClassIDs == null) unknownModuleClassIDs = new LinkedList();

            unknownModuleClassIDs.add(moduleClassID);
          }
        } catch (URISyntaxException jex) {
          throw new DocumentSerializationException("Can't get ModuleClassID", jex);
        }
      }
    }
  }
  /* this test is particularly slow running for the in memory srdi index test, which
   * perhaps isn't optimised for this kind of multi-threaded brutality.
   * FIXME: revisit this, improve performance of in-memory index so that this can be
   * run.
   */
  @Ignore
  @Test
  public void testSeparateGroupConcurrentSafety() throws Exception {
    Srdi[] indices = new Srdi[NUM_INDICES * NUM_GROUPS];
    for (int groupNum = 0; groupNum < NUM_GROUPS; groupNum++) {
      PeerGroup group = createGroup(IDFactory.newPeerGroupID(), "group" + groupNum);
      for (int indexNum = 0; indexNum < NUM_INDICES; indexNum++) {
        indices[NUM_INDICES * groupNum + indexNum] =
            new Srdi(createBackend(group, "index" + indexNum), Srdi.NO_AUTO_GC, executorService);
      }
    }

    randomLoadTest(indices);
  }
Esempio n. 4
0
  /**
   * {@inheritDoc}
   *
   * @param raw Description of the Parameter
   * @return Description of the Return Value
   */
  protected boolean handleElement(Element raw) {

    if (super.handleElement(raw)) {
      return true;
    }

    XMLElement elem = (XMLElement) raw;

    if (DEST_PID_TAG.equals(elem.getName())) {
      try {
        URI pID = new URI(elem.getTextValue());

        setDestPeerID((PeerID) IDFactory.fromURI(pID));
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Bad PeerID in advertisement");
      } catch (ClassCastException badID) {
        throw new IllegalArgumentException("ID in advertisement is not a peer id");
      }
      return true;
    }

    if (elem.getName().equals("Dst")) {
      for (Enumeration eachXpt = elem.getChildren(); eachXpt.hasMoreElements(); ) {
        TextElement aXpt = (TextElement) eachXpt.nextElement();

        AccessPointAdvertisement xptAdv =
            (AccessPointAdvertisement) AdvertisementFactory.newAdvertisement(aXpt);

        setDest(xptAdv);
      }
      return true;
    }

    if (elem.getName().equals("Hops")) {
      Vector hops = new Vector();

      for (Enumeration eachXpt = elem.getChildren(); eachXpt.hasMoreElements(); ) {
        TextElement aXpt = (TextElement) eachXpt.nextElement();

        AccessPointAdvertisement xptAdv =
            (AccessPointAdvertisement) AdvertisementFactory.newAdvertisement(aXpt);

        hops.addElement(xptAdv);
      }
      setHops(hops);
      return true;
    }

    return false;
  }
Esempio n. 5
0
  /**
   * Returns the ID of the provided certificate or null if the certificate is not found in the
   * keystore.
   *
   * @param cert The certificate who's ID is desired.
   * @return The ID of the certificate or <tt>null</tt> if no matching Certificate was found.
   * @throws KeyStoreException When the wrong keystore has been provided.
   * @throws IOException For errors related to processing the keystore.
   */
  public ID getTrustedCertificateID(X509Certificate cert) throws KeyStoreException, IOException {

    String anAlias = null;

    synchronized (keystore_manager) {
      KeyStore store = keystore_manager.loadKeyStore(keystore_password);

      anAlias = store.getCertificateAlias(cert);
    }

    // not found.
    if (null == anAlias) {
      return null;
    }

    try {
      URI id = new URI(anAlias);

      return IDFactory.fromURI(id);
    } catch (URISyntaxException badID) {
      return null;
    }
  }
  /** {@inheritDoc} */
  public void initializeFrom(Element element) throws DocumentSerializationException {
    for (Enumeration e = element.getChildren(); e.hasMoreElements(); ) {
      Element childElement = (TextElement) e.nextElement();
      String tagName = (String) childElement.getKey();

      if (tagName.equals("transportMetric")) {
        TransportMetric transportMetric =
            (TransportMetric)
                DocumentSerializableUtilities.getDocumentSerializable(
                    childElement, TransportMetric.class);
        transportMetrics.add(transportMetric);
      }
      if (tagName.equals("moduleClassID")) {
        try {
          moduleClassID =
              (ModuleClassID)
                  IDFactory.fromURI(new URI(DocumentSerializableUtilities.getString(childElement)));
        } catch (URISyntaxException jex) {
          throw new DocumentSerializationException("Can't read moduleClassID", jex);
        }
      }
    }
  }
Esempio n. 7
0
  /**
   * Returns the list of root certificates for which there is an associated local private key.
   *
   * @param store_password The passphrase used to unlock the keystore may be {@code null} for
   *     keystores with no passphrase.
   * @return an array of the available keys. May be an empty array.
   * @throws KeyStoreException When the wrong keystore has been provided.
   * @throws IOException For errors related to processing the keystore.
   */
  ID[] getKeysList(char[] store_password) throws KeyStoreException, IOException {
    List<ID> keyedRootsList = new ArrayList<ID>();

    synchronized (keystore_manager) {
      KeyStore store = keystore_manager.loadKeyStore(store_password);

      Enumeration<String> eachAlias = store.aliases();

      while (eachAlias.hasMoreElements()) {
        String anAlias = eachAlias.nextElement();

        if (store.isKeyEntry(anAlias)) {
          try {
            URI id = new URI(anAlias);

            keyedRootsList.add(IDFactory.fromURI(id));
          } catch (URISyntaxException badID) { // ignored
          }
        }
      }

      return keyedRootsList.toArray(new ID[keyedRootsList.size()]);
    }
  }
public class Edge_Quinisela_At_The_Other_End implements PipeMsgListener {

  public static final String Name = "Edge Quinisela, at the other end";
  public static final int TcpPort = 9725;
  public static final PeerID PID =
      IDFactory.newPeerID(PeerGroupID.defaultNetPeerGroupID, Name.getBytes());
  public static final File ConfigurationFile =
      new File("." + System.getProperty("file.separator") + Name);

  public void pipeMsgEvent(PipeMsgEvent PME) {

    // We received a message
    Message ReceivedMessage = PME.getMessage();
    String TheText = ReceivedMessage.getMessageElement("DummyNameSpace", "HelloElement").toString();

    // Notifying the user
    Tools.PopInformationMessage(Name, "Received message:\n\n" + TheText);
  }

  public static void main(String[] args) {

    try {

      // Removing any existing configuration?
      Tools.CheckForExistingConfigurationDeletion(Name, ConfigurationFile);

      // Creation of network manager
      NetworkManager MyNetworkManager =
          new NetworkManager(NetworkManager.ConfigMode.EDGE, Name, ConfigurationFile.toURI());

      // Retrieving the network configurator
      NetworkConfigurator MyNetworkConfigurator = MyNetworkManager.getConfigurator();

      // Checking if RendezVous_Adelaide_At_One_End should be a seed
      MyNetworkConfigurator.clearRendezvousSeeds();
      String TheSeed =
          "tcp://"
              + InetAddress.getLocalHost().getHostAddress()
              + ":"
              + RendezVous_Adelaide_At_One_End.TcpPort;
      Tools.CheckForRendezVousSeedAddition(Name, TheSeed, MyNetworkConfigurator);

      // Setting Configuration
      MyNetworkConfigurator.setTcpPort(TcpPort);
      MyNetworkConfigurator.setTcpEnabled(true);
      MyNetworkConfigurator.setTcpIncoming(true);
      MyNetworkConfigurator.setTcpOutgoing(true);

      // Setting the Peer ID
      Tools.PopInformationMessage(Name, "Setting the peer ID to :\n\n" + PID.toString());
      MyNetworkConfigurator.setPeerID(PID);

      // Starting the JXTA network
      Tools.PopInformationMessage(
          Name,
          "Start the JXTA network and to wait for a rendezvous connection with\n"
              + RendezVous_Adelaide_At_One_End.Name
              + " for maximum 2 minutes");
      PeerGroup NetPeerGroup = MyNetworkManager.startNetwork();

      // Disabling any rendezvous autostart
      NetPeerGroup.getRendezVousService().setAutoStart(false);

      if (MyNetworkManager.waitForRendezvousConnection(120000)) {
        Tools.popConnectedRendezvous(NetPeerGroup.getRendezVousService(), Name);
      } else {
        Tools.PopInformationMessage(Name, "Did not connect to a rendezvous");
      }

      // Preparing the listener and Creating the BiDiPipe
      PipeMsgListener MyListener = new Edge_Quinisela_At_The_Other_End();
      JxtaBiDiPipe MyBiDiPipe =
          new JxtaBiDiPipe(
              NetPeerGroup,
              RendezVous_Adelaide_At_One_End.GetPipeAdvertisement(),
              30000,
              MyListener);

      if (MyBiDiPipe.isBound()) {

        Tools.PopInformationMessage(Name, "Bidirectional pipe created!");

        // Sending a hello message !!!
        Message MyMessage = new Message();
        StringMessageElement MyStringMessageElement =
            new StringMessageElement("HelloElement", "Hello from " + Name, null);
        MyMessage.addMessageElement("DummyNameSpace", MyStringMessageElement);

        MyBiDiPipe.sendMessage(MyMessage);

        // Sleeping for 10 seconds
        Tools.GoToSleep(10000);

        // Sending a goodbye message !!!
        MyMessage = new Message();
        MyStringMessageElement =
            new StringMessageElement("HelloElement", "Goodbye from " + Name, null);
        MyMessage.addMessageElement("DummyNameSpace", MyStringMessageElement);

        MyBiDiPipe.sendMessage(MyMessage);

        // Sleeping for 10 seconds
        Tools.GoToSleep(10000);
      }

      // Closing the bidipipe
      MyBiDiPipe.close();

      // Stopping the network
      Tools.PopInformationMessage(Name, "Stop the JXTA network");
      MyNetworkManager.stopNetwork();

    } catch (IOException Ex) {

      // Raised when access to local file and directories caused an error
      Tools.PopErrorMessage(Name, Ex.toString());

    } catch (PeerGroupException Ex) {

      // Raised when the net peer group could not be created
      Tools.PopErrorMessage(Name, Ex.toString());
    }
  }
}
  private void initialize(Element root) {

    if (!TextElement.class.isInstance(root))
      throw new IllegalArgumentException(getClass().getName() + " only supports TextElement");

    TextElement doc = (TextElement) root;

    if (!doc.getName().equals(paramTag))
      throw new IllegalArgumentException(
          "Could not construct : "
              + getClass().getName()
              + "from doc containing a "
              + doc.getName());

    // set defaults
    servicesTable = new Hashtable();
    protosTable = new Hashtable();
    appsTable = new Hashtable();

    int appCount = 0;
    Enumeration modules = doc.getChildren();
    while (modules.hasMoreElements()) {
      Hashtable theTable;

      TextElement module = (TextElement) modules.nextElement();
      String tagName = module.getName();
      if (tagName.equals(svcTag)) {
        theTable = servicesTable;
      } else if (tagName.equals(appTag)) {
        theTable = appsTable;
      } else if (tagName.equals(protoTag)) {
        theTable = protosTable;
      } else continue;

      ModuleSpecID specID = null;
      ModuleClassID classID = null;
      ModuleImplAdvertisement inLineAdv = null;

      try {
        if (module.getTextValue() != null) {
          specID = (ModuleSpecID) IDFactory.fromURL(IDFactory.jxtaURL(module.getTextValue()));
        }

        // Check for children anyway.
        Enumeration fields = module.getChildren();
        while (fields.hasMoreElements()) {
          TextElement field = (TextElement) fields.nextElement();
          if (field.getName().equals(mcidTag)) {
            classID = (ModuleClassID) IDFactory.fromURL(IDFactory.jxtaURL(field.getTextValue()));
            continue;
          }
          if (field.getName().equals(msidTag)) {
            specID = (ModuleSpecID) IDFactory.fromURL(IDFactory.jxtaURL(field.getTextValue()));
            continue;
          }
          if (field.getName().equals(miaTag)) {
            inLineAdv = (ModuleImplAdvertisement) AdvertisementFactory.newAdvertisement(field);
            continue;
          }
        }
      } catch (Exception any) {
        if (LOG.isEnabledFor(Level.WARN)) LOG.warn("Broken entry; skipping", any);
        continue;
      }

      if (inLineAdv == null && specID == null) {
        if (LOG.isEnabledFor(Level.WARN)) LOG.warn("Insufficent entry; skipping");
        continue;
      }

      Object theValue;
      if (inLineAdv == null) {
        theValue = specID;
      } else {
        specID = inLineAdv.getModuleSpecID();
        theValue = inLineAdv;
      }
      if (classID == null) {
        classID = specID.getBaseClass();
      }

      // For applications, the role does not matter. We just create
      // a unique role ID on the fly.
      // When outputing the add we get rid of it to save space.

      if (theTable == appsTable) {
        // Only the first (or only) one may use the base class.
        if (appCount++ != 0) {
          classID = IDFactory.newModuleClassID(classID);
        }
      }
      theTable.put(classID, theValue);
    }
  }
Esempio n. 10
0
/** Simple RELAY peer. */
public class Relay_Robert {

  // Static

  public static final String Name_RELAY = "RELAY";
  public static final PeerID PID_RELAY =
      IDFactory.newPeerID(PeerGroupID.defaultNetPeerGroupID, Name_RELAY.getBytes());
  public static final int HttpPort_RELAY = 9900;
  public static final int TcpPort_RELAY = 9715;
  public static final File ConfigurationFile_RELAY =
      new File("." + System.getProperty("file.separator") + Name_RELAY);

  /** @param args the command line arguments */
  public static void main(String[] args) {

    try {

      // Removing any existing configuration?
      NetworkManager.RecursiveDelete(ConfigurationFile_RELAY);

      // Creation of the network manager
      final NetworkManager MyNetworkManager =
          new NetworkManager(
              NetworkManager.ConfigMode.RELAY, Name_RELAY, ConfigurationFile_RELAY.toURI());

      // Retrieving the network configurator
      NetworkConfigurator MyNetworkConfigurator = MyNetworkManager.getConfigurator();

      // Setting Configuration
      MyNetworkConfigurator.setUseMulticast(false);

      MyNetworkConfigurator.setTcpPort(TcpPort_RELAY);
      MyNetworkConfigurator.setTcpEnabled(true);
      MyNetworkConfigurator.setTcpIncoming(true);
      MyNetworkConfigurator.setTcpOutgoing(true);

      MyNetworkConfigurator.setHttpPort(HttpPort_RELAY);
      MyNetworkConfigurator.setHttpEnabled(true);
      MyNetworkConfigurator.setHttpIncoming(true);
      MyNetworkConfigurator.setHttpOutgoing(true);

      // Setting the Peer ID
      MyNetworkConfigurator.setPeerID(PID_RELAY);

      // Starting the JXTA network
      PeerGroup NetPeerGroup = MyNetworkManager.startNetwork();

      // Starting the connectivity monitor
      new ConnectivityMonitor(NetPeerGroup);

      // Stopping the network asynchronously
      ConnectivityMonitor.TheExecutor.schedule(
          new DelayedJxtaNetworkStopper(MyNetworkManager, "Click to stop " + Name_RELAY, "Stop"),
          0,
          TimeUnit.SECONDS);

    } catch (IOException Ex) {

      System.err.println(Ex.toString());

    } catch (PeerGroupException Ex) {

      System.err.println(Ex.toString());
    }
  }
}
Esempio n. 11
0
 /**
  * Reconstructs a ModuleSpecID from its String representation as printed by the foregoing recipes.
  *
  * @param url -- the module spec id in String form, "urn:jxta:uuid-[the big hex string]"
  * @throws URISyntaxException -- if url is messed up
  * @return -- module spec id reconstructed from String
  */
 private static ModuleSpecID buildModuleSpecID(String uri) throws URISyntaxException {
   return (ModuleSpecID) IDFactory.fromURI(new URI(uri));
 }