1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_diameter_comm_Engine_hpp
10 #define anna_diameter_comm_Engine_hpp
18 #include <anna/app/Component.hpp>
19 #include <anna/core/util/Recycler.hpp>
21 #include <anna/diameter.comm/Server.hpp>
22 #include <anna/diameter.comm/ServerSession.hpp>
23 #include <anna/config/defines.hpp>
24 #include <anna/diameter.comm/ClientSession.hpp>
25 #include <anna/diameter.comm/ServerSession.hpp>
31 //------------------------------------------------------------------------------
32 //---------------------------------------------------------------------- #define
33 //------------------------------------------------------------------------------
58 * General manager for connections to several diameter servers and from diameter clients.
60 * Optimizes creation, finding and releasing of established client-sessions to a certain number of
61 * diameter servers through entities.
62 * Optimizes creation, finding and releasing of established server-sessions from a certain number of
63 * diameter clients through local servers.
65 * Implementation example:
69 * class MyEngine : public diameter::comm::Engine {
74 * anna::Recycler<MyEntity> a_entities;
76 * anna::diameter::comm::Entity* allocateEntity () throw () { return a_entities.create (); }
78 * void releaseEntity (anna::diameter::comm::Entity* entity) throw () {
79 * MyEntity* aux = static_cast <MyEntity*> (entity);
80 * a_entities.release (aux);
84 * anna::diameter::comm::LocalServer* allocateLocalServer () throw () { return a_localServers.create (); }
86 * void releaseLocalServer (anna::diameter::comm::LocalServer* localServer) throw () {
87 * MyLocalServer* aux = static_cast <MyLocalServer*> (localServer);
88 * a_localServers.release (aux);
94 class Engine : public anna::app::Component {
98 Diameter application node realm name (used to be the site domain name).
100 @param name Diameter application node realm name. Used in order to configure the Origin-Realm for outgoing messages.
101 If not configured or empty string provided, host domainname will be set.
103 void setRealm(const std::string & name) throw();
107 Gets the configured diameter application node realm name.
109 @return Diameter application node realm name.
111 const std::string & getRealm() const throw() { return a_realm; }
115 Diameter application host name as solved by #anna::functions::getHostname()
117 @param name Host name. Used in order to configure the Origin-Host for outgoing messages.
118 If not configured or empty string provided, hostname (system name) will be set.
120 void setHost(const std::string & name) throw();
124 Gets the configured diameter application host name.
126 @return Diameter application host name.
128 const std::string & getHost() const throw() { return a_host; }
132 * Propagate auto recovery configuration to entities within engine. Recovery period is configured at
133 * #anna::comm::Communicator::setRecoveryTime. All the client client-sessions created throught #createEntity,
134 * will be created based on the engine auto-recovery value (enable by default). But you could access entities,
135 * servers or client-sessions independently to change this behaviour.
137 * @param autoRecovery Auto recovery indicator. True by default.
139 void raiseAutoRecovery(bool autoRecovery = true) throw(anna::RuntimeException);
142 * Returns automatic bind indicator for client-sessions. By default \em true will be used.
143 * \return Value for automatic connection bind.
145 bool getAutoBind() const throw() { return a_autoBind; }
148 * Sets automatic connection bind indicator for client-sessions. If not asigned, it will be \em true.
149 * \param autoBind Value for automatic connection bind.
151 * In order to change bind timer, first client-session must be created without autobind, modify time
152 * parameter and then invoking bind.
154 void setAutoBind(const bool autoBind) throw() { a_autoBind = autoBind; }
157 Sets the milliseconds wait to achieve a client connection to server by mean connect primitive.
158 This is a general value for born client-sessions over engine. Particular configuration could be done
159 through #ClientSession::setMaxConnectionDelay.
161 \param maxConnectionDelay Milliseconds wait to get connection
163 void setMaxConnectionDelay(const anna::Millisecond & maxConnectionDelay) throw() { a_maxConnectionDelay = maxConnectionDelay; }
166 Gets the milliseconds wait to achieve a client connection to server by mean connect primitive.
167 Returns the global engine value, but it could be overwritten through each client session (#ClientSession::setMaxConnectionDelay).
168 Default value is 'anna::comm::ClientSocket::DefaultMaxConnectionDelay'.
170 \return Milliseconds wait to get connection
172 const anna::Millisecond & getMaxConnectionDelay() throw() { return a_maxConnectionDelay; }
175 * Binds engine entities.
177 * @return Returns true if all client-session were successfully bound
179 bool bind() throw(anna::RuntimeException);
182 * Sets CER and DWR diameter messages to be used over created client-sessions.
183 * Its recommended to set this global configuration although it is possible to configure each client-session separately.
185 * @param cer Capabilities-Exchange-Request message (encoded) for the client-sessions bind.
186 * @param dwr Device-Watchdog-Request message (encoded) for the client-sessions keep-alive.
188 void setCERandDWR(const anna::DataBlock & cer, const anna::DataBlock & dwr) throw(anna::RuntimeException);
192 * Sets the watchdog period (DWR) for client-sessions.
193 * Its recommended to set this global configuration although it is possible to configure each client-session separately.
195 * @param wp Watchdog period.
197 void setWatchdogPeriod(const anna::Millisecond & wp) throw(anna::RuntimeException);
200 * Gets the number of client-sessions per server.
201 * \return numberOfClientSessionsPerServer Number of client-sessions per server.
203 int getNumberOfClientSessionsPerServer() const throw() { return a_numberOfClientSessionsPerServer; }
206 * Sets the number of client-sessions per server.
207 * Its recommended to set this global configuration although it is possible to configure each client-session separately.
208 * \param numberOfClientSessionsPerServer Number of client-sessions per server.
210 void setNumberOfClientSessionsPerServer(int numberOfClientSessionsPerServer) throw() { a_numberOfClientSessionsPerServer = numberOfClientSessionsPerServer; }
214 * Returns client-session instance identified by (address, port, socketId) provided.
216 * \param addr Diameter server address (ip or hostname).
217 * \param port Diameter server port.
218 * @param socketId Diameter server socket id.
219 * \param emode Action when no client-session is found with provided parameters (Throw/Ignore).
221 * \return The client-session instance identified by (address, port, socketId) provided.
223 * \warning If no client-session found, an exception is launched by default.
225 ClientSession* findClientSession(const std::string & addr, int port, int socketId, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
229 * Same as #findClientSession, but providing client session key (<address>:<port>|<socket id>)
231 ClientSession* findClientSession(const std::string & key, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
235 * Returns server instance identified by pair (address, port) provided.
237 * \param addr Diameter server address (ip or hostname).
238 * \param port Diameter server port.
239 * \param emode Action when no client-session is found with provided parameters (Throw/Ignore).
241 * \return The server instance identified by pair (address, port) provided.
243 * \warning If no server found, an exception is launched by default.
245 Server* findServer(const std::string & addr, int port, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
248 * Returns entity instance identified by internal index.
250 * \param socketList Diameter entity servers list.
251 * \param emode Action when no client-session is found with provided parameters (Throw/Ignore).
253 * \return The entity instance identified by id provided.
255 * \warning If no entity found, an exception is launched by default.
257 Entity* findEntity(const socket_v & socketList, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
260 * Returns entity instance identified by internal index.
262 * \param addr1 Diameter primary server address (ip or hostname).
263 * \param port1 Diameter primary server port.
264 * \param addr2 Diameter secondary server address (ip or hostname).
265 * \param port2 Diameter secondary server port.
266 * \param emode Action when no client-session is found with provided parameters (Throw/Ignore).
268 * \return The entity instance identified by id provided.
270 * \warning If no entity found, an exception is launched by default.
272 Entity* findEntity(const std::string & addr1, int port1, const std::string & addr2, int port2, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
275 * Creates a diameter entity with provided parameters.
277 * Depending on auto-bind configuration, capabilities exchange request will be or won't be performed over the entity client-sessions.
279 * \param socketList Diameter server priority list (priority-ordered) in order to define whole entity.
280 * @param description Optional entity description (empty by default)
282 * \return The entity created or exception when any server (address/port) already exists for another entity.
284 * \warning The entity won't be almost operative until a notification by mean 'ClientSession::eventResponse'
285 * indicates that 'ClassCode::Bind' has been correctly performed for any included client-session.
287 Entity* createEntity(const socket_v & socketList, const std::string & description = "")
288 throw(anna::RuntimeException);
291 * Creates a standard (dual) diameter entity with provided parameters.
293 * Depending on auto-bind configuration, capabilities exchange request will be or won't be performed over the entity client-sessions.
295 * \param addr1 Diameter primary server address (ip or hostname).
296 * \param port1 Diameter primary server port.
297 * \param addr2 Diameter secondary server address (ip or hostname).
298 * \param port2 Diameter secondary server port.
299 * @param description Optional entity description (empty by default)
301 * \return The standard entity created or exception when any server (address/port) already exists for another entity.
303 * \warning The entity won't be almost operative until a notification by mean 'ClientSession::eventResponse'
304 * indicates that 'ClassCode::Bind' has been correctly performed for any included client-session.
306 Entity* createEntity(const std::string & addr1, int port1, const std::string & addr2, int port2, const std::string & description = "")
307 throw(anna::RuntimeException);
311 * Returns local server instance identified by pair (address, port) provided.
313 * @param addr Diameter server socket address (ip or hostname).
314 * @param port Diameter server socket port.
315 * \param emode Action when no local server is found with provided parameters (Throw/Ignore).
317 * \return The local server instance identified by pair (address, port) provided.
319 * \warning If no local server found, an exception is launched by default.
321 LocalServer* findLocalServer(const std::string & addr, int port, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
324 * Returns server-session instance identified by INetAddress serialization provided.
326 * @param socketId Hash for Client Socket INetAddress serialization
327 * \param emode Action when no server-session is found with provided parameters (Throw/Ignore).
329 * \return The server-session instance identified by global unique socketId provided.
331 * \warning If no server-session found, an exception is launched by default.
333 ServerSession* findServerSession(int socketId, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) throw(anna::RuntimeException);
336 * Creates a diameter local server with provided parameters.
338 * Server socket address could be an IPv4 or hostname. Default port will be standard 3868 for diameter agents,
339 * but any other could be configured. Socket server could be created with any max accepted connections: zero
340 * value means temporarily disabled and negative values assume no limit (shared bind) for incomming connections.
342 * @param addr Diameter server socket address (ip or hostname).
343 * @param port Diameter server socket port (standard 3868 by default).
344 * @param maxConnections Diameter server max sessions allowed (no limit by default).
345 * @param allowedInactivityTime Max inactivity time for server sessions over the local server before being reset.
346 * @param category Optional socket server category (1 by default).
347 * @param description Optional socket server description (empty by default).
349 * \return The local server created or exception when is already created.
351 LocalServer *createLocalServer(const std::string & addr, int port = Session::DefaultPort, int maxConnections = -1, const anna::Millisecond & allowedInactivityTime = ServerSession::DefaultAllowedInactivityTime, int category = 1, const std::string & description = "")
352 throw(anna::RuntimeException);
356 Close all the engine resources (entities and local servers)
357 Optionally all resources may be freed passing true
359 @param destroy Free all engine entity resources
361 void close(bool destroy = false) throw(anna::RuntimeException) { closeEntities(destroy); closeLocalServers(destroy); }
365 Close all the engine entities (close servers, then close client-sessions within them). Depending on client-session configuration
366 ('OnDisconnect' behaviour), pending answers will be wait (graceful) or ignored (immediate-abrupt close).
367 Optionally all entities resources may be freed passing true; in this case, close is immediately performed:
368 @param destroy Free all engine entity resources
370 void closeEntities(bool destroy = false) throw(anna::RuntimeException);
374 * Close entity servers (then, client-sessions included) and optionally free resources including entity itself.
375 * If entity is null, this operation has no effect.
377 * \param entity Diameter entity to be closed.
378 * \param destroy Deletes entity over the engine and all its resources.
380 void closeEntity(Entity* entity, bool destroy = false) throw(anna::RuntimeException);
384 Close all the engine local server sockets including their children server sessions.
385 Optionally all local server resources may be freed passing true.
387 @param destroy Free all engine local servers resources and server sessions within them.
389 void closeLocalServers(bool destroy = false) throw(anna::RuntimeException);
392 * Close local server socket and its children server sessions.
393 * This is useful when detecting service lost. When service is ready to handle traffic, a new server socket would
394 * be created by mean #LocalServer::enable() and new connections could be accepted.
395 * Optionally local server resources may be freed passing true.
397 * \param localServer Local server to be closed.
398 * \param destroy Deletes local server over engine and all its resources (server sessions within it).
400 void closeLocalServer(LocalServer * localServer, bool destroy = false) throw(anna::RuntimeException);
403 Gets the number of requests messages over-the-air for entities.
405 @return OTA messages.
407 int getOTARequestsForEntities() const throw();
410 Gets the number of requests messages over-the-air for local servers.
412 @return OTA messages.
414 int getOTARequestsForLocalServers() const throw();
417 Gets the number of requests messages over-the-air for entities plus local servers.
419 @return OTA messages.
421 int getOTARequests() const throw() { return (getOTARequestsForEntities() + getOTARequestsForLocalServers()); }
424 Returns idle state (no pending answers) for entities.
428 bool idleForEntities() const throw() { return (getOTARequestsForEntities() == 0); }
431 Returns idle state (no pending answers).
435 bool idleForLocalServers() const throw() { return (getOTARequestsForLocalServers() == 0); }
438 Returns idle state (no pending answers for entities or local servers).
442 bool idle() const throw() { return (getOTARequests() == 0); }
445 Sent a message to all the engine entities.
446 It is used, i.e., in Disconnect-Peer-Request procedure over the engine.
448 \param message Message which is being sent.
450 @return Returns true (success) only when broadcast is success over all the engine entities. If any entity fails,
451 then false is returned. Broadcast try to send all over the resources in spite of any fail.
453 bool broadcastEntities(const Message*message) throw(anna::RuntimeException);
454 bool broadcastEntities(const Message& message) throw(anna::RuntimeException) { return broadcastEntities(&message); }
457 Sent a message through all the engine local servers.
458 It is used, i.e., in Disconnect-Peer-Request procedure over the engine.
460 \param message Message which is being sent.
462 @return Returns true (success) only when broadcast is success over all the engine local servers. If any local server fails,
463 then false is returned. Broadcast try to send all over the resources in spite of any fail.
465 bool broadcastLocalServers(const Message*message) throw(anna::RuntimeException);
466 bool broadcastLocalServers(const Message& message) throw(anna::RuntimeException) { return broadcastLocalServers(&message); }
469 * Class string representation
471 * @return String with class content
473 virtual std::string asString(void) const throw();
476 Class XML representation.
477 \param parent XML node over which we will put instance information.
478 \return XML documentcon with class content.
480 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
484 When there is not bound server session over the engine, this virtual method will be invoked.
485 Applications must decide to do any other tasks at this idle/isolated situation.
486 Default implementation do nothing.
488 virtual void availabilityLostForLocalServers(Engine *) const throw() {;}
491 When there is any bound server session over the engine, this virtual method will be invoked.
492 Applications must decide to do be ready for incoming traffic.
493 Default implementation do nothing.
495 virtual void availabilityRecoveredForLocalServers(Engine *) const throw() {;}
498 When there is not bound entity over the engine, this virtual method will be invoked.
499 Many applications must change communicator status to Unavailable when no engines are available.
500 Default implementation do nothing.
502 virtual void availabilityLostForEntities(Engine *) const throw() {;}
505 When there is any bound entity over the engine, this virtual method will be invoked.
506 Many applications must recover communicator status to Available when any engine are available.
507 Default implementation do nothing.
509 virtual void availabilityRecoveredForEntities(Engine *) const throw() {;}
512 When there is not bound server-session over the local server, this virtual method will be invoked.
513 Default implementation do nothing.
515 virtual void availabilityLost(LocalServer *) const throw() {;}
518 When there is any bound server-session over the local server, this virtual method will be invoked.
519 Default implementation do nothing.
521 virtual void availabilityRecovered(LocalServer *) const throw() {;}
524 When there is not bound server over the entity, this virtual method will be invoked.
525 Default implementation do nothing.
527 virtual void availabilityLost(Entity *) const throw() {;}
530 When there is any bound server over the entity, this virtual method will be invoked.
531 Default implementation do nothing.
533 virtual void availabilityRecovered(Entity *) const throw() {;}
536 When there is not bound client-session over the server, this virtual method will be invoked.
537 Default implementation do nothing.
539 virtual void availabilityLost(Server *) const throw() {;}
542 When there is any bound client-session over the server, this virtual method will be invoked.
543 Default implementation do nothing.
545 virtual void availabilityRecovered(Server *) const throw() {;}
548 When a subyacent client session is going to be bound, this method is invoked before.
549 Default implementation do nothing.
551 virtual void bindingClientSession(const ClientSession *) const throw() {;}
554 * Class user should implement this method in order to define Disconnect-Peer-Answer for last received DPR.
555 * Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name).
556 * Default implementation imply DPA with DIAMETER_SUCCESS Result-Code, allowing remote disconnection.
557 * Any other implementation is responsible to build a valid DPA diameter message.
558 * DPR/DPA procedure is disabled with empty definition of this method: no DPA will be sent when DPR is received.
560 * @param dpa DPA datablock passed as reference
561 * @param dpr Corresponding DPR received (sequence values must be taken into account in order to build DPA)
563 virtual void readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) throw();
566 * Class user should implement this method in order to define Capabilities-Exchange-Answer for received CER over server socket.
567 * Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name).
568 * Default implementation imply CEA with DIAMETER_SUCCESS Result-Code, and own domain node parameters, but application should
569 * analyze the CER message in order to accept it or not (with apropiate non-success Result-Code).
570 * Any other implementation is responsible to build a valid CEA diameter message:
572 * If one peer sends a CER message to another Peer and receiver does not have support for
574 * 1) any common application then it must return the CEA with Result-Code Avp set to DIAMETER_NO_COMMON_APPLICATION
575 * and should disconnect the transport layer connection (automatically done by diameter::comm module).
576 * 2) no common security mechanism then it must return the CEA with Result-Code Avp set to DIAMETER_NO_COMMON_SECURITY
577 * and should disconnect the transport layer connection (automatically done by diameter::comm module).
578 * 3) if CER is received from any unknown peer then receiver should discard the message, or send the CEA with the
579 * Result-Code Avp set to DIAMETER_UNKNOWN_PEER.
581 * If the local implementation policy permits to receive CER from unknown hosts, a successful CEA MAY be returned,
582 * and the life time of the peer entry in PEER-Table is equal to the lifetime of the transport connection.
583 * If in any case transport connection fails then all the pending transactions destined to the unknown peer can be discarded.
585 * The CER and CEA messages MUST NOT be proxied, redirected or relayed. Since CER/CEA messages can not be proxied, but still
586 * it is possible that proxy will receive a CER message and proxy does not have any peer to handle the application requested
587 * in CER, in this case proxy set the E bit in CEA and set the Result-Code Avp to DIAMETER_UNABLE_TO_DELIVER, sends back to
588 * CER generator peer.
590 * @param cea CEA datablock passed as reference. Empty cea implies to discard CER received.
591 * @param cer Corresponding CER received (sequence values must be taken into account in order to build CEA)
593 virtual void readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) throw();
596 * Class user should implement this method in order to define Device-Watchdog-Answer for received DWR over server socket.
597 * Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name).
598 * Default implementation imply DWA with DIAMETER_SUCCESS Result-Code, and own domain node parameters.
599 * Any other implementation is responsible to build a valid DWA diameter message.
601 * @param dwa DWA datablock passed as reference
602 * @param dwr Corresponding DWR received (sequence values must be taken into account in order to build DWA)
604 virtual void readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) throw();
607 Reset engine statistics.
608 At the moment, only diameter servers processing time is observed.
610 void resetStatistics() throw();
616 @param className Component class name
618 Engine(const char *className);
621 // INTERNAL CREATORS AND CLOSE METHODS
622 Server *createServer(Entity*, const socket_t&) throw(anna::RuntimeException);
623 void closeServer(Server*, bool) throw(anna::RuntimeException);
624 ClientSession *createClientSession(Server*, int) throw(anna::RuntimeException);
625 void closeClientSession(ClientSession*, bool) throw(anna::RuntimeException);
627 // INTERNAL ALLOCATORS
628 Server* allocateServer() throw();
629 void releaseServer(Server*) throw();
630 ClientSession* allocateClientSession() throw();
631 void releaseClientSession(ClientSession*) throw();
635 Entity allocator method.
637 It is recommended to use anna::Recycler for entities creation/releasing.
641 virtual Entity* allocateEntity() throw() { return NULL; }
645 Invoked to free entities.
648 virtual void releaseEntity(Entity*) throw() {;}
652 Local server allocator method.
654 It is recommended to use anna::Recycler for entities creation/releasing.
658 virtual LocalServer* allocateLocalServer() throw() { return NULL; }
662 Invoked to free local servers.
665 virtual void releaseLocalServer(LocalServer*) throw() {;}
674 int a_numberOfClientSessionsPerServer;
677 // ClientSessions messages:
678 anna::DataBlock a_cer;
679 anna::DataBlock a_dwr;
680 anna::Millisecond a_watchdogPeriod;
682 // // ServerSessions messages:
683 // anna::DataBlock a_cea;
684 // anna::DataBlock a_dwa;
686 // Client connectivity
687 anna::Millisecond a_maxConnectionDelay;
691 bool a_availableForEntities; // any of the entities must be bound
692 void availabilityLostForEntities() throw();
693 void availabilityRecoveredForEntities() throw();
694 bool refreshAvailabilityForEntities() throw(); // return true if change
696 bool a_availableForLocalServers; // any of the local servers must be bound
697 void availabilityLostForLocalServers() throw();
698 void availabilityRecoveredForLocalServers() throw();
699 bool refreshAvailabilityForLocalServers() throw(); // return true if change
701 void eraseDeprecatedIdleEntities() throw();
704 void do_initialize() throw() {;}
705 void do_stop() throw();
708 void checkEntityCollision(const socket_v &) throw(anna::RuntimeException);
711 //////////////////////////
712 // CLIENT FUNCTIONALITY //
713 //////////////////////////
715 //typedef int clientSession_key; // exclusiveHash('ADDR:PORT|id')
716 typedef std::string clientSession_key; // 'ADDR:PORT|id'
717 typedef std::map <clientSession_key, ClientSession*> clientSession_container;
718 typedef clientSession_container::value_type clientSession_value_type;
719 typedef clientSession_container::iterator clientSession_iterator;
720 typedef clientSession_container::const_iterator const_clientSession_iterator;
721 clientSession_container a_clientSessions;
722 anna::Recycler<ClientSession> a_clientSessionsRecycler;
723 clientSession_iterator clientSession_find(const clientSession_key&) throw();
724 clientSession_iterator clientSession_begin() throw() { return a_clientSessions.begin(); }
725 clientSession_iterator clientSession_end() throw() { return a_clientSessions.end(); }
726 static ClientSession* clientSession(clientSession_iterator ii) throw() { return ii->second; }
727 const_clientSession_iterator clientSession_begin() const throw() { return a_clientSessions.begin(); }
728 const_clientSession_iterator clientSession_end() const throw() { return a_clientSessions.end(); }
729 static const ClientSession* clientSession(const_clientSession_iterator ii) throw() { return ii->second; }
731 typedef socket_t server_key;
732 server_key getServerKey(const std::string & addr, int port) const throw();
733 typedef std::map <server_key, Server*> server_container;
734 typedef server_container::value_type server_value_type;
735 typedef server_container::iterator server_iterator;
736 typedef server_container::const_iterator const_server_iterator;
737 server_container a_servers;
738 anna::Recycler<Server> a_serversRecycler;
739 server_iterator server_find(const server_key&) throw();
740 server_iterator server_begin() throw() { return a_servers.begin(); }
741 server_iterator server_end() throw() { return a_servers.end(); }
742 static Server* server(server_iterator ii) throw() { return ii->second; }
743 const_server_iterator server_begin() const throw() { return a_servers.begin(); }
744 const_server_iterator server_end() const throw() { return a_servers.end(); }
745 static const Server* server(const_server_iterator ii) throw() { return ii->second; }
747 //typedef int entity_key; // exclusiveHash('IP1:PORT1 IP2:PORT2 IP3:PORT3 ...')
748 typedef std::string entity_key; // 'ADDR1:PORT1 ADDR2:PORT2 ADDR3:PORT3 ...'
749 entity_key getEntityKey(const socket_v &) const throw();
750 entity_key getEntityKey(const std::string & addr1, int port1, const std::string & addr2, int port2) const throw();
751 typedef std::map <entity_key, Entity*> entity_container;
752 typedef entity_container::value_type entity_value_type;
753 typedef entity_container::iterator entity_iterator;
754 typedef entity_container::const_iterator const_entity_iterator;
755 entity_container a_entities;
756 entity_iterator entity_find(const entity_key&) throw();
757 entity_iterator entity_begin() throw() { return a_entities.begin(); }
758 entity_iterator entity_end() throw() { return a_entities.end(); }
759 static Entity* entity(entity_iterator ii) throw() { return ii->second; }
760 const_entity_iterator entity_begin() const throw() { return a_entities.begin(); }
761 const_entity_iterator entity_end() const throw() { return a_entities.end(); }
762 static const Entity* entity(const_entity_iterator ii) throw() { return ii->second; }
765 //////////////////////////
766 // SERVER FUNCTIONALITY //
767 //////////////////////////
770 typedef std::map <socket_t, LocalServer*> localServer_container;
771 typedef localServer_container::value_type localServer_value_type;
772 typedef localServer_container::iterator localServer_iterator;
773 typedef localServer_container::const_iterator const_localServer_iterator;
774 localServer_container a_localServers;
775 localServer_iterator localServer_find(const socket_t&) throw();
776 localServer_iterator localServer_begin() throw() { return a_localServers.begin(); }
777 localServer_iterator localServer_end() throw() { return a_localServers.end(); }
778 static LocalServer* localServer(localServer_iterator ii) throw() { return ii->second; }
779 const_localServer_iterator localServer_begin() const throw() { return a_localServers.begin(); }
780 const_localServer_iterator localServer_end() const throw() { return a_localServers.end(); }
781 static const LocalServer* localServer(const_localServer_iterator ii) throw() { return ii->second; }
783 // Server sessions are managed within LocalServer (not at engine) due to dynamic cration nature
786 friend class Session;
787 friend class ServerSession;
788 friend class ServerSocket;
791 friend class LocalServer;
792 //friend class Message;