Example #1
0
  /**
   * Notifies this <tt>ResponseCollector</tt> that a transaction described by the specified
   * <tt>BaseStunMessageEvent</tt> has failed. The possible reasons for the failure include
   * timeouts, unreachable destination, etc.
   *
   * @param event the <tt>BaseStunMessageEvent</tt> which describes the failed transaction and the
   *     runtime type of which specifies the failure reason
   * @see AbstractResponseCollector#processFailure(BaseStunMessageEvent)
   */
  @Override
  protected void processFailure(BaseStunMessageEvent event) {
    TransactionID transactionID = event.getTransactionID();

    logger.finest("A transaction expired: tranid=" + transactionID);
    logger.finest("localAddr=" + hostCandidate);

    /*
     * Clean up for the purposes of the workaround which determines the STUN
     * Request to which a STUN Response responds.
     */
    Request request;

    synchronized (requests) {
      request = requests.remove(transactionID);
    }
    if (request == null) {
      Message message = event.getMessage();

      if (message instanceof Request) request = (Request) message;
    }

    boolean completedResolvingCandidate = true;
    try {
      if (processErrorOrFailure(null, request, transactionID)) completedResolvingCandidate = false;
    } finally {
      if (completedResolvingCandidate) completedResolvingCandidate(request, null);
    }
  }
  public void dispatchEvent(XEvent xev) {
    if (eventLog.isLoggable(Level.FINEST)) eventLog.finest(xev.toString());
    int type = xev.get_type();

    if (isDisposed()) {
      return;
    }

    switch (type) {
      case VisibilityNotify:
        handleVisibilityEvent(xev);
        break;
      case ClientMessage:
        handleClientMessage(xev);
        break;
      case Expose:
      case GraphicsExpose:
        handleExposeEvent(xev);
        break;
      case ButtonPress:
      case ButtonRelease:
        handleButtonPressRelease(xev);
        break;

      case MotionNotify:
        handleMotionNotify(xev);
        break;
      case KeyPress:
        handleKeyPress(xev);
        break;
      case KeyRelease:
        handleKeyRelease(xev);
        break;
      case EnterNotify:
      case LeaveNotify:
        handleXCrossingEvent(xev);
        break;
      case ConfigureNotify:
        handleConfigureNotifyEvent(xev);
        break;
      case MapNotify:
        handleMapNotifyEvent(xev);
        break;
      case UnmapNotify:
        handleUnmapNotifyEvent(xev);
        break;
      case ReparentNotify:
        handleReparentNotifyEvent(xev);
        break;
      case PropertyNotify:
        handlePropertyNotify(xev);
        break;
      case DestroyNotify:
        handleDestroyNotify(xev);
        break;
      case CreateNotify:
        handleCreateNotify(xev);
        break;
    }
  }
Example #3
0
  /**
   * Takes the provided array of objects and stores the contents in the back-end database. The array
   * is expected to contain the following objects:
   *
   * <ul>
   *   <li>0 - Severity (String)
   *   <li>1 - PSE node name (String)
   *   <li>2 - Link ID (String)
   *   <li>3 - Received Error Message (String)
   *   <li>4 - Date received from the PSE (String)
   *   <li>5 - The universally unique identifier of the message (String)
   * </ul>
   *
   * @param dataToStore An object array in the format mentioned above.
   */
  public void storeDataInDb(Object[] dataToStore) {
    final int WORKED_OK = 1;
    final int DISCOVERED_NEW_LINK = 2;
    final int DISCOVERED_DUPLICATES = 3;
    final int ERROR_ENCOUNTERED = 4;
    final int NO_ENTRIES_FOUND = 5;
    final int DISCOVERED_LINK_MESSAGE = 6;

    DbInterface dbI = new DbInterface(originatingPort);
    int x = dbI.storeMessage(formattedMessage);
    switch (x) {
      case WORKED_OK:
        {
          // storeMessage worked without any problems.
          log.finest("Message saved in the database with a UUID of: " + formattedMessage[5]);
          String msg = (String) formattedMessage[3];
          Object[] linkState = new Object[3];
          linkState[0] = formattedMessage[1];
          linkState[1] = formattedMessage[2];
          linkState[2] = new Integer(LINK_STATE_UNKNOWN);
          if (msg.equals("LINK DOWN")) {
            linkState[2] = new Integer(LINK_STATE_DOWN);
            parent.setLinkData(linkState);
          }
          if (msg.equals("LINK UP")) {
            linkState[2] = new Integer(LINK_STATE_UP);
            parent.setLinkData(linkState);
          }
          break;
        }
      case DISCOVERED_NEW_LINK:
        {
          // storeMessage detected that this link was from a new link not in the database.
          String msg = (String) formattedMessage[3];
          if (msg.equals("LINK DOWN")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_DOWN);
          } else if (msg.equals("LINK UP")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UP);
          } else {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UNKNOWN);
          }
          break;
        }
      case DISCOVERED_DUPLICATES:
        {
          // storeMessage detected duplicates in the database. Generate a warning to the user.
          log.severe(
              "Duplicates in the index of tblCodexLinks were detected while trying to save the received message.");
          System.err.println(
              "Duplicates were detected in the index of tblCodexLinks. Your database may be corrupt.");
          break;
        }
      case ERROR_ENCOUNTERED:
        {
          // storeMessage encountered an exception
          log.warning(
              "storeMessage() encountered an exception. The message it was trying to save may not have been entered into the database.");
          System.err.println(
              "An exception was detected while trying to save the message in the database. The data may not have been saved, please check the logs for more information.");
          break;
        }
      case DISCOVERED_LINK_MESSAGE:
        {
          String msg = (String) formattedMessage[3];
          if (msg.equals("LINK DOWN")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_DOWN);
          } else if (msg.equals("LINK UP")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UP);
          } else {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UNKNOWN);
          }
          break;
        }
      default:
        {
          // storeMessage returned a value that wasn't recognised
          log.warning("storeMessage returned an unexpected value: " + x);
          break;
        }
    }
  }
Example #4
0
  /**
   * Notifies this <tt>ResponseCollector</tt> that a STUN response described by the specified
   * <tt>StunResponseEvent</tt> has been received.
   *
   * @param event the <tt>StunResponseEvent</tt> which describes the received STUN response
   * @see ResponseCollector#processResponse(StunResponseEvent)
   */
  @Override
  public void processResponse(StunResponseEvent event) {
    TransactionID transactionID = event.getTransactionID();

    logger.finest("Received a message: tranid= " + transactionID);
    logger.finest("localCand= " + hostCandidate);

    /*
     * Clean up for the purposes of the workaround which determines the STUN
     * Request to which a STUN Response responds.
     */
    synchronized (requests) {
      requests.remove(transactionID);
    }

    // At long last, do start handling the received STUN Response.
    Response response = event.getResponse();
    Request request = event.getRequest();
    boolean completedResolvingCandidate = true;

    try {
      if (response.isSuccessResponse()) {
        // Authentication and Message-Integrity Mechanisms
        if (request.containsAttribute(Attribute.MESSAGE_INTEGRITY)) {
          MessageIntegrityAttribute messageIntegrityAttribute =
              (MessageIntegrityAttribute) response.getAttribute(Attribute.MESSAGE_INTEGRITY);

          /*
           * RFC 5389: If MESSAGE-INTEGRITY was absent, the response
           * MUST be discarded, as if it was never received.
           */
          if (messageIntegrityAttribute == null) return;

          UsernameAttribute usernameAttribute =
              (UsernameAttribute) request.getAttribute(Attribute.USERNAME);

          /*
           * For a request or indication message, the agent MUST
           * include the USERNAME and MESSAGE-INTEGRITY attributes in
           * the message.
           */
          if (usernameAttribute == null) return;
          if (!harvester
              .getStunStack()
              .validateMessageIntegrity(
                  messageIntegrityAttribute,
                  LongTermCredential.toString(usernameAttribute.getUsername()),
                  !request.containsAttribute(Attribute.REALM)
                      && !request.containsAttribute(Attribute.NONCE),
                  event.getRawMessage())) return;
        }

        processSuccess(response, request, transactionID);
      } else {
        ErrorCodeAttribute errorCodeAttr =
            (ErrorCodeAttribute) response.getAttribute(Attribute.ERROR_CODE);

        if ((errorCodeAttr != null) && (errorCodeAttr.getErrorClass() == 4)) {
          try {
            switch (errorCodeAttr.getErrorNumber()) {
              case 1: // 401 Unauthorized
                if (processUnauthorized(response, request, transactionID))
                  completedResolvingCandidate = false;
                break;
              case 38: // 438 Stale Nonce
                if (processStaleNonce(response, request, transactionID))
                  completedResolvingCandidate = false;
                break;
            }
          } catch (StunException sex) {
            completedResolvingCandidate = true;
          }
        }
        if (completedResolvingCandidate && processErrorOrFailure(response, request, transactionID))
          completedResolvingCandidate = false;
      }
    } finally {
      if (completedResolvingCandidate) completedResolvingCandidate(request, response);
    }
  }
  public LoginPanel(Image img, ActionListener listener) {
    super(null);
    this.listener = listener;
    if (img == null) {
      InputStream inData = getClass().getResourceAsStream("/resources/background.gif");
      BufferedImage back = null;
      if (inData != null)
        try {
          back = ImageIO.read(inData);
        } catch (IOException e) {
          loger.finest("LoginPanel class can't get the background image");
        }
      this.background = back;
    }

    setLayout(null);
    JPanel logingPanel = new JPanel();
    loginTitle = new JLabel("Autentificare");
    logingPanel.setSize(250, 150);
    logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2));
    logingPanel.setLayout(null);
    loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20);
    logingPanel.add(loginTitle);
    JLabel loginUser = new JLabel("Utilizator");
    loginUser.setBounds(
        80 - loginUser.getPreferredSize().width,
        40,
        loginUser.getPreferredSize().width,
        loginUser.getPreferredSize().height);
    logingPanel.add(loginUser);
    user = new JTextField(10);
    user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height);
    // user.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(user);
    JLabel loginPass = new JLabel("Parola");
    loginPass.setBounds(
        80 - loginPass.getPreferredSize().width,
        80,
        loginPass.getPreferredSize().width,
        loginPass.getPreferredSize().height);
    logingPanel.add(loginPass);
    // JTextField pass = new JTextField(10);
    pass = new JPasswordField(10);
    pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height);
    pass.addKeyListener(this);
    // pass.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(pass);
    JButton loginButton = new JButton("Start");
    loginButton.setActionCommand("LOGIN");
    loginButton.setBounds(
        60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height);
    // loginButton.setOpaque(false);
    loginButton.setFocusPainted(false);
    // loginButton.setContentAreaFilled(false);
    // loginButton.setBorderPainted(false);
    loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    loginButton.addActionListener(listener);
    logingPanel.add(loginButton);

    add(logingPanel);
  }
Example #6
0
 /**
  * Initialises the class and internal logger. Uses the supplied arguments to receive data from the
  * application and add data to the charts dynamically.
  *
  * @param title The title of the charts on display. Whether the displayed data is for <code>new
  *     </code> or <code>old</code> links. That is whether the data is for newly discovered links
  *     or existing (old) links already stored within the database.
  * @param parent The instance of <code>COMPortClient</code> that acts as the data source for the
  *     charts.
  */
 public LinkChart(String title, COMPortClient parent) {
   super("Charts", true, true, true, true);
   super.setLayer(1);
   identifier = title.toLowerCase();
   // Obtain an instance of Logger for the class
   log = LoggerFactory.getLogger(className);
   owner = parent;
   // Setup a hashtable to hold the values for up, down and unknown link states
   Hashtable<String, Integer> linkStats = new Hashtable<String, Integer>();
   if (identifier.equals("old")) {
     this.setTitle("Recognised Link Status on " + owner.getPortName() + ":");
     // Get the current figures from the link table
     linkStats = ((LinkTable) owner.getLinkTable().getModel()).getInitialFigures();
   } else if (identifier.equals("new")) {
     this.setTitle("Discovered Link Status on " + owner.getPortName() + ":");
     linkStats = ((LinkTable) owner.getNewLinkTable().getModel()).getInitialFigures();
   } else {
     // If the identifier was set to something other than old or new then it's not right.
     log.warning("An instance of LinkChart has been created for an unknown purpose.");
     return;
   }
   // Initialise the dataset for the pie chart
   dpdCurrentData = new DefaultPieDataset();
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   // Initialise the dataset for the line chart
   dcdPreviousData = new DefaultCategoryDataset();
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
   // Set the variables we need for holding the charts
   JFreeChart jfcCurrentStatus; // This will be displayed as a pie chart
   JFreeChart jfcPreviousStatus; // This will be displayed as a line chart
   ChartPanel cpCurrent; // Chartpanels hold the JFreeChart
   ChartPanel cpPrevious;
   // Use the factory to create the charts
   jfcCurrentStatus =
       ChartFactory.createPieChart("Current Status", dpdCurrentData, true, true, false);
   jfcPreviousStatus =
       ChartFactory.createLineChart(
           "Previous Status",
           "Time received",
           "Number of Links",
           dcdPreviousData,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   // Add them to the chart panels
   cpCurrent = new ChartPanel(jfcCurrentStatus);
   cpPrevious = new ChartPanel(jfcPreviousStatus);
   // Add the chart panels to the content pane
   this.add(cpCurrent, BorderLayout.EAST);
   this.add(cpPrevious, BorderLayout.WEST);
   // Change the layout to show them next to each other
   this.setLayout(new GridLayout(1, 2));
   // Add a listener to the window
   this.addInternalFrameListener(new CloseLinkChart(this));
   log.finest("Adding frame to the desktop");
   // Set the window properties and display it
   Client.getJNWindow().addToDesktop(this);
   this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   this.setSize(650, 400);
   this.setVisible(true);
   owner.addChartWindow(title, this);
 }