Fix local server for multiple applications
[anna.git] / include / anna / diameter.comm / ClientSession.hpp
index 805b8d7..6df8a85 100644 (file)
@@ -1,37 +1,9 @@
-// ANNA - Anna is Not Nothingness Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// http://redmine.teslayout.com/projects/anna-suite
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     *  Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-//          cisco.tierra@gmail.com
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
 
 
 #ifndef anna_diameter_comm_ClientSession_hpp
@@ -79,7 +51,7 @@ class Server;
 class ClientSession : public Session {
 
   // Helper:
-  static std::string getKey(const std::string & addr, int port, int socketId) throw() {
+  static std::string getKey(const std::string & addr, int port, int socketId) {
     return (anna::functions::asString("%s:%d|%d", addr.c_str(), port, socketId));
   }
 
@@ -91,7 +63,7 @@ public:
   ClientSession();
 
 
-  /* virtual */void initialize() throw();
+  /* virtual */void initialize() ;
 
   /**
    * Default watchdog period for the diameter client-session health.
@@ -101,49 +73,49 @@ public:
   /**
      Client session key: <address ip or hostname>:<remote port>|<socket id: 0..N-1>
   */
-  std::string getKey() const throw() { return ClientSession::getKey(getAddress(), getPort(), getSocketId()); }
+  std::string getKey() const { return ClientSession::getKey(getAddress(), getPort(), getSocketId()); }
 
   /**
      Diameter server address (IPv4 or hostname)
      \return Diameter server address
   */
-  /* virtual */const std::string& getAddress() const throw();
+  /* virtual */const std::string& getAddress() const ;
 
   /**
      Diameter server listen port
      \return Diameter server listen port
   */
-  /* virtual */int getPort() const throw();
+  /* virtual */int getPort() const ;
 
   /**
      Diameter parent server.
      \return Diameter parent server.
   */
-  const Server *getParent() const throw() { return a_parent; }
+  const Server *getParent() const { return a_parent; }
 
   /**
      Diameter server created at diameter::comm::Engine::createClientSession.
      \return Diameter server
   */
-  anna::comm::Server * getServer() throw() { return a_server; }
+  anna::comm::Server * getServer() { return a_server; }
 
   /**
      Disables server resource (avoid the use of the server)
   */
-  void disable() throw() { a_server->disable(); }
+  void disable() { a_server->disable(); }
 
   /**
      Sets auto recovery indicator. When a connection is lost, by default it will be recovered automatically.
      \param autoRecovery Auto recovery indicator. TRue by default.
   */
-  void setAutoRecovery(bool autoRecovery = true) throw() { a_autoRecovery = autoRecovery; a_server->setAutoRecovery(autoRecovery); }
+  void setAutoRecovery(bool autoRecovery = true) { a_autoRecovery = autoRecovery; a_server->setAutoRecovery(autoRecovery); }
 
   /**
      Gets the auto recovery indicator for the client connection (client-session).
 
      @return Auto recovery indicator.
   */
-  bool getAutoRecovery() const throw() { return a_autoRecovery; }
+  bool getAutoRecovery() const { return a_autoRecovery; }
 
   /**
      Sets the milliseconds wait to achieve a client connection to server by mean connect primitive.
@@ -152,55 +124,47 @@ public:
 
      \param maxConnectionDelay Milliseconds wait to get connection
   */
-  void setMaxConnectionDelay(const anna::Millisecond & maxConnectionDelay) throw() { a_server->setMaxConnectionDelay(maxConnectionDelay); }
+  void setMaxConnectionDelay(const anna::Millisecond & maxConnectionDelay) { a_server->setMaxConnectionDelay(maxConnectionDelay); }
 
   /**
      Gets the milliseconds wait to achieve a client connection to server by mean connect primitive.
 
      \return Milliseconds wait to get connection
   */
-  const anna::Millisecond & getMaxConnectionDelay() throw() { return a_server->getMaxConnectionDelay(); }
-
-  /**
-   * Sets CER and DWR diameter messages to be used over created client-sessions
-   *
-   * @param cer Capabilities-Exchange-Request message (encoded) for the client-sessions bind.
-   * @param dwr Device-Watchdog-Request message (encoded) for the client-sessions keep-alive.
-   */
-  void setCERandDWR(const anna::DataBlock & cer, const anna::DataBlock & dwr) throw(anna::RuntimeException);
+  const anna::Millisecond & getMaxConnectionDelay() { return a_server->getMaxConnectionDelay(); }
 
   // Internal
-  void bind() throw(anna::RuntimeException);
+  void bind() noexcept(false);
 
-  /* virtual */const Response* send(const Message* message) throw(anna::RuntimeException);
-  /* virtual */bool unbind(bool forceDisconnect /* se usa en timer, para el actionTimer del tipo SessionUnbind, etc. */ = false) throw(anna::RuntimeException); // returns true if done at call time (no pendings or ignore pendings, except Disconnecting state by mean DPR/DPA)
+  /* virtual */const Response* send(const Message* message) noexcept(false);
+  /* virtual */bool unbind(bool forceDisconnect /* se usa en timer, para el actionTimer del tipo SessionUnbind, etc. */ = false) noexcept(false); // returns true if done at call time (no pendings or ignore pendings, except Disconnecting state by mean DPR/DPA)
 
   /**
      Deny resource for delivery restriction
   */
-  void hide() throw() { a_hidden = true; }
+  void hide() { a_hidden = true; }
 
   /**
      Allow resource for delivery permission
   */
-  void show() throw() { a_hidden = false; }
+  void show() { a_hidden = false; }
 
   /**
      Returns true when client session resource is hidden for application messages delivery
   */
-  bool hidden() const throw() { return a_hidden; }
+  bool hidden() const { return a_hidden; }
 
   /**
      Returns true when client session resource is shown for application messages delivery
   */
-  bool shown() const throw() { return !a_hidden; }
+  bool shown() const { return !a_hidden; }
 
 
   /**
      Class string representation
      \return String with relevant information for this instance.
   */
-  /* virtual */std::string asString() const throw();
+  /* virtual */std::string asString() const ;
 
 
   /**
@@ -208,7 +172,7 @@ public:
      \param parent Parent XML node on which hold this instance information.
      \return XML document with relevant information for this instance.
   */
-  /* virtual */anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
+  /* virtual */anna::xml::Node* asXML(anna::xml::Node* parent) const ;
 
 
 private:
@@ -220,6 +184,7 @@ private:
   Server *a_parent;
 
   // ClientSession messages:
+  Engine *a_engine; // it is unique for a client session (not in server session, which have one per origin host)
   Message a_cer;
   Message a_dwr;
 
@@ -238,19 +203,19 @@ private:
     };
   };
   WatchdogState::_v a_watchdogState;
-  void setWatchdogState(WatchdogState::_v wState) throw();
+  void setWatchdogState(WatchdogState::_v wState) ;
 
-  /* virtual */void expire(anna::timex::Engine *timeController) throw(anna::RuntimeException);
-  void setWatchdogPeriod(const anna::Millisecond & watchdogPeriod) throw();
+  /* virtual */void expire(anna::timex::Engine *timeController) noexcept(false);
+  void setWatchdogPeriod(const anna::Millisecond & watchdogPeriod) ;
 
-  /*virtual*/ void timerStopped() throw();
-  /*virtual*/ void timerStarted() throw();
+  /*virtual*/ void timerStopped() ;
+  /*virtual*/ void timerStarted() ;
 
 
   // Activity:
-  /* virtual */void updateIncomingActivityTime() throw();
-  /* virtual */void updateOutgoingActivityTime() throw();
-  void countSendings(const diameter::CommandId & cid, bool ok) throw();
+  /* virtual */void updateIncomingActivityTime() ;
+  /* virtual */void updateOutgoingActivityTime() ;
+  void countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok) ;
 
   // Handlers:
   /**
@@ -258,45 +223,64 @@ private:
 
      When notified, ANNA.diameter.comm generates an diameter::comm::ClientSession::eventResponse for every request with pending answers.
   */
-  void eventPeerShutdown() throw();
+  void eventPeerShutdown() ;
+
+  /**
+     Handler about a request retransmission over the session.
+
+     \param request Message retransmitted
+  */
+  void eventRequestRetransmission(Message *request) ;
 
   /**
      Handler for diameter server (client-session) responses
 
      \param response Answer container object for corresponding diameter request
+     \param myNode Own origin host
   */
-  void eventResponse(const Response& response) throw(anna::RuntimeException);
+  void eventResponse(const Response& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false);
 
   /**
      Handler for diameter server (client-session) requests
 
      \param request Request data block object for corresponding diameter reception
+     \param myNode Own origin host
   */
-  void eventRequest(const anna::DataBlock& request) throw(anna::RuntimeException);
-  //void eventRequest(const Message& request) throw(anna::RuntimeException);
+  void eventRequest(const anna::DataBlock& request, const anna::diameter::comm::OriginHost *myNode) noexcept(false);
+  //void eventRequest(const Message& request) noexcept(false);
 
   /**
      Handler for diameter server (client-session) responses out of context
 
      \param response Answer data block object without context match
+     \param myNode Own origin host
   */
-  void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException);
+  void eventUnknownResponse(const anna::DataBlock& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false);
+
+  /**
+     Handler for diameter server (client-session) Disconnect-Peer-Answer messages
+
+     \param response Answer data block object without context match
+     \param myNode Own origin host
+  */
+  void eventDPA(const anna::DataBlock& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false);
+
 
 
   /**
   * Handlers for receptions
   */
-  /* virtual */void receive(const anna::comm::Message& message) throw(anna::RuntimeException);
-  /* virtual */void finalize() throw();
-  void recover() throw();
+  /* virtual */void receive(const anna::comm::Message& message) noexcept(false);
+  /* virtual */void finalize() ;
+  void recover() ;
 
-  /* virtual */void expireResponse(Response*) throw();
-  /* virtual */void setState(State::_v state) throw();
+  /* virtual */void expireResponse(Response*) ;
+  /* virtual */void setState(State::_v state) ;
 
-  void sendDWAToServer(const anna::DataBlock& dwrDB) throw(anna::RuntimeException); // non-usual behaviour, but DWR could be received from server
+  void sendDWAToServer(const anna::DataBlock& dwrDB) noexcept(false); // non-usual behaviour, but DWR could be received from server
 
   // helpers
-  static const char* asText(const WatchdogState::_v) throw();
+  static const char* asText(const WatchdogState::_v) ;
 
 
   friend class Server;