Package tigase.server

Examples of tigase.server.Packet


      session.processPacket(packet, out_results);
      addOutPackets(out_results, session);
    } else {
      log.warning("Session does not exist for packet: " + packet.toString());
      try {
        Packet error =
            Authorization.ITEM_NOT_FOUND.getResponseMessage(packet,
              "The user connection is no longer active.", true);
        addOutPacket(error);
      } catch (PacketErrorTypeException e) {
        log.finest("Ups, already error packet. Dropping it to prevent infinite loop.");
      }
      // In case the SessionManager lost synchronization for any reason, let's
      // notify it that the user connection no longer exists.
      Packet command = Command.STREAM_CLOSED.getPacket(null, null,
        StanzaType.set, "bosh-missing-1");
      command.setFrom(packet.getTo());
      command.setTo(packet.getFrom());
      log.fine("Sending a command to close the remote session for non-existen Bosh connection: " + command.toString());
      addOutPacket(command);
    }
  }
View Full Code Here


    return null;
  }

  public Queue<Packet> processSocketData(XMPPIOService srv) {
    BoshIOService serv = (BoshIOService)srv;
    Packet p = null;
    while ((p = serv.getReceivedPackets().poll()) != null) {
      log.finer("Processing packet: " + p.getElemName()
        + ", type: " + p.getType());
      log.finest("Processing socket data: " + p.toString());
      String sid_str = p.getAttribute(SID_ATTR);
      UUID sid = null;
      try {
        Queue<Packet> out_results = new LinkedList<Packet>();
        BoshSession bs = null;
        if (sid_str == null) {
          String hostname = p.getAttribute("to");
          if (hostname != null && isLocalDomain(hostname)) {
            bs = new BoshSession(getDefHostName(),
              routings.computeRouting(hostname), this);
            sid = bs.getSid();
            sessions.put(sid, bs);
View Full Code Here

      // The best option would be to drop the packet if it is already an
      // error - remote-server-not-found....
      // For dialback packet just ignore the error completely as it means
      // remote server tries to connect from domain which doesn't exist
      // in DNS so no further action should be performed.
      Packet p = null;
      while ((p = waitingPackets.poll()) != null) {
        if (p.getElement().getXMLNS() != XMLNS_DB_VAL) {
          try {
            addOutPacket(
              Authorization.REMOTE_SERVER_NOT_FOUND.getResponseMessage(p,
              "S2S - destination host not found", true));
          } catch (PacketErrorTypeException e) {
            log.warning("Packet: " + p.toString() + " processing exception: " + e);
          }
        }
      }
      conns.stopAll();
      //connectionsByLocalRemote.remove(cid);
View Full Code Here

    return cid;
  }

  public Queue<Packet> processSocketData(XMPPIOService serv) {
    Queue<Packet> packets = serv.getReceivedPackets();
    Packet p = null;
    while ((p = packets.poll()) != null) {
//       log.finer("Processing packet: " + p.getElemName()
//         + ", type: " + p.getType());
      if (p.getElement().getXMLNS() == null) {
        p.getElement().setXMLNS("jabber:client");
      }
      log.finest("Processing socket data: " + p.toString());

      if (p.getElement().getXMLNS() == XMLNS_DB_VAL) {
        processDialback(p, serv);
      } else {
        if (p.getElemName() == "error") {
          processStreamError(p, serv);
          return null;
        } else {
          if (checkPacket(p, serv)) {
            log.finest("Adding packet out: " + p.getStringData());
            addOutPacket(p);
          } else {
            return null;
          }
        }
View Full Code Here

  private void bouncePacketsBack(Authorization author, String cid) {
    ServerConnections serv_conns = getServerConnections(cid);
    if (serv_conns != null) {
      Queue<Packet> waiting =  serv_conns.getWaitingPackets();
      Packet p = null;
      while ((p = waiting.poll()) != null) {
        log.finest("Sending packet back: " + p.getStringData());
        try {
          addOutPacket(author.getResponseMessage(p, "S2S - not delivered", true));
        } catch (PacketErrorTypeException e) {
          log.warning("Packet processing exception: " + e);
        }
View Full Code Here

      } // end of try-catch
      serv_conns.putDBKey(remote_id, key);
      Element elem = new Element(DB_RESULT_EL_NAME, key,
        new String[] {"from", "to", XMLNS_DB_ATT},
        new String[] {local_hostname, remote_hostname, XMLNS_DB_VAL});
      serv_conns.addControlPacket(new Packet(elem));
      serv_conns.sendAllControlPackets();
      return null;
    }
    case accept: {
      String remote_hostname =
View Full Code Here

          // <db:result> with CDATA containing KEY
          Element elem = new Element(DB_VERIFY_EL_NAME, db_key,
            new String[] {"id", "to", "from", XMLNS_DB_ATT},
            new String[] {session_id, remote_hostname, local_hostname,
                          XMLNS_DB_VAL});
          Packet result = new Packet(elem);
          if (serv_conns == null) {
            serv_conns = createNewServerConnections(cid, null);
          }
          //serv_conns.putDBKey(session_id, db_key);
          serv.getSessionData().put("remote-hostname", remote_hostname);
          serv.getSessionData().put("local-hostname", local_hostname);
          log.finest("cid: " + cid + ", sessionId: " + session_id
            + ", Counters: ioservices: " + countIOServices()
            + ", s2s connections: " + countOpenConnections());
          if (!serv_conns.sendControlPacket(result)
            && serv_conns.needsConnection()) {
            createServerConnection(cid, result, serv_conns);
          }
        } else {
          // Incorrect dialback packet, it happens for some servers....
          // I don't know yet what software they use.
          // Let's just disconnect and signal unrecoverable conection error
          log.finer("Incorrect diablack packet: " + packet.getStringData());
          bouncePacketsBack(Authorization.SERVICE_UNAVAILABLE, cid);
          generateStreamError("bad-format", serv);
        }
      } else {
        // <db:result> with type 'valid' or 'invalid'
        // It means that session has been validated now....
        //XMPPIOService connect_serv = handshakingByHost_Type.get(connect_jid);
        switch (packet.getType()) {
        case valid:
          log.finer("Connection: " + cid
            + " is valid, adding to available services.");
          serv_conns.handleDialbackSuccess();
          break;
        default:
          log.finer("Connection: " + cid + " is invalid!! Stopping...");
          serv_conns.handleDialbackFailure();
          break;
        } // end of switch (packet.getType())
      } // end of if (packet.getType() != null) else
    } // end of if (packet != null && packet.getElemName().equals("db:result"))

    // <db:verify> with type 'valid' or 'invalid'
    if ((packet.getElemName() == VERIFY_EL_NAME)
      || (packet.getElemName() == DB_VERIFY_EL_NAME)) {
      if (packet.getElemId() != null) {

        String forkey_session_id = packet.getElemId();
        if (packet.getType() == null) {
          // When type is NULL then it means this packet contains
          // data for verification
          if (packet.getElemId() != null && packet.getElemCData() != null) {
            String db_key = packet.getElemCData();
            // This might be the first dialback packet from remote server
//             serv.getSessionData().put("remote-hostname", remote_hostname);
//             serv.getSessionData().put("local-hostname", local_hostname);
//             serv_conns.addIncoming(session_id, serv);
//             log.finest("cid: " + cid + ", sessionId: " + session_id
//               + ", Counters: ioservices: " + countIOServices()
//               + ", s2s connections: " + countOpenConnections());
            //initServiceMapping(local_hostname, remote_hostname, accept_jid, serv);

            String local_key = getLocalDBKey(cid, db_key, forkey_session_id,
              session_id);

            if (local_key == null) {
              log.fine("db key is not availablefor session ID: " + forkey_session_id
                + ", key for validation: " + db_key);
            } else {
              log.fine("Local key for cid=" + cid + " is " + local_key);
              sendVerifyResult(local_hostname, remote_hostname, forkey_session_id,
                db_key.equals(local_key), serv_conns, session_id);
            }
          } // end of if (packet.getElemName().equals("db:verify"))
        else {
          // Type is not null so this is packet with verification result.
          // If the type is valid it means accept connection has been
          // validated and we can now receive data from this channel.

          Element elem = new Element(DB_RESULT_EL_NAME,
            new String[] {"type", "to", "from", XMLNS_DB_ATT},
            new String[] {packet.getType().toString(),
                          remote_hostname, local_hostname,
                          XMLNS_DB_VAL});

          sendToIncoming(forkey_session_id, new Packet(elem));
          validateIncoming(forkey_session_id,
            (packet.getType() == StanzaType.valid));

        } // end of if (packet.getType() == null) else
      } else {
View Full Code Here

    boolean valid, ServerConnections serv_conns, String asking_sessionId) {
    String type = (valid ? "valid" : "invalid");
    Element result_el = new Element(DB_VERIFY_EL_NAME,
      new String[] {"from", "to", "id", "type", XMLNS_DB_ATT},
      new String[] {from, to, forkey_sessionId, type, XMLNS_DB_VAL});
    Packet result = new Packet(result_el);
    if (!sendToIncoming(asking_sessionId, result)) {
      log.warning("Can not send verification packet back: " + result.toString());
    }
  }
View Full Code Here

  }

  public void prepareWarning(String text, Queue<Packet> results,
          Object warning) {
    if (!warningsSent.contains(warning)) {
      Packet result = Packet.getMessage("", jid, StanzaType.normal,
              "Warning! High resource usage alert from: " +
              getClass().getSimpleName() + "\n" +
              new Date() + " - " + text,
              "System Monitor Alert", null);
      results.add(result);
View Full Code Here

  }

  public void prepareCalmDown(String text, Queue<Packet> results,
          Object warning) {
    if (warningsSent.contains(warning)) {
      Packet result = Packet.getMessage("", jid, StanzaType.normal,
              "Calm down! Resource usage notification from: " +
              getClass().getSimpleName() + "\n" +
              new Date() + " - " + text,
              "System Monitor Alert", null);
      results.add(result);
View Full Code Here

TOP

Related Classes of tigase.server.Packet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.