Esempio n. 1
0
 public void addIncomingConnection(IConnection conn) {
   PeerState state = fsm.getState(PeerState.class);
   if (DOWN == state || INITIAL == state) {
     conn.addConnectionListener(connListener);
     logger.debug("Append external connection {}", conn.getKey());
   } else {
     logger.debug("Releasing connection {}", conn.getKey());
     incConnections.remove(conn.getKey());
     try {
       conn.release();
     } catch (IOException e) {
       logger.debug("Can not close external connection", e);
     } finally {
       logger.debug("Close external connection");
     }
   }
 }
Esempio n. 2
0
    public int processCerMessage(String key, IMessage message) {
      logger.debug("Processing CER");

      int resultCode = ResultCode.SUCCESS;
      try {
        if (connection == null || !connection.isConnected()) {
          connection = incConnections.get(key);
        }
        // Process cer
        Set<ApplicationId> newAppId = getCommonApplicationIds(message);
        if (newAppId.isEmpty()) {
          logger.debug(
              "Processing CER failed... no common application, message AppIps {}",
              message.getApplicationIdAvps());
          return ResultCode.NO_COMMON_APPLICATION;
        }
        // Handshake
        if (!connection.getKey().equals(key)) { // received cer by other connection
          logger.debug("CER received by other connection {}", key);

          switch (fsm.getState(PeerState.class)) {
            case DOWN:
              resultCode = ResultCode.SUCCESS;
              break;
            case INITIAL:
              boolean isLocalWin = false;
              if (isElection)
                try {
                  isLocalWin =
                      metaData
                              .getLocalPeer()
                              .getUri()
                              .getFQDN()
                              .compareTo(message.getAvps().getAvp(Avp.ORIGIN_HOST).getOctetString())
                          <= 0;
                } catch (Exception exc) {
                  isLocalWin = true;
                }

              logger.debug("local peer is win - {}", isLocalWin);

              resultCode = 0;
              if (isLocalWin) {
                IConnection c = incConnections.get(key);
                c.remConnectionListener(connListener);
                c.disconnect();
                incConnections.remove(key);
              } else {
                connection.disconnect(); // close current connection and work with other connection
                connection.remConnectionListener(connListener);
                connection = incConnections.remove(key);
                resultCode = ResultCode.SUCCESS;
              }
              break;
          }
        } else {
          logger.debug("CER received by current connection");
          if (fsm.getState(PeerState.class).equals(INITIAL)) // received cer by current connection
          resultCode = 0; // NOP
          incConnections.remove(key);
        }
        if (resultCode == ResultCode.SUCCESS) {
          commonApplications.clear();
          commonApplications.addAll(newAppId);
          fillIPAddressTable(message);
        }
      } catch (Exception exc) {
        logger.debug("Can not process CER", exc);
      }
      logger.debug("CER result {}", resultCode);

      return resultCode;
    }