LCOV - code coverage report
Current view: top level - xmpp - xmpp_server.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 10 10 100.0 %
Date: 2026-11-09 02:10:49 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef __XMPP_SERVER_H__
       7             : #define __XMPP_SERVER_H__
       8             : 
       9             : #include <mutex>
      10             : #include <shared_mutex>
      11             : 
      12             : #include <boost/asio/ip/tcp.hpp>
      13             : #include <boost/scoped_ptr.hpp>
      14             : 
      15             : #include "base/lifetime.h"
      16             : #include "base/queue_task.h"
      17             : #include "base/address.h"
      18             : #include "bgp/bgp_config.h"
      19             : #include "io/ssl_server.h"
      20             : #include "xmpp/xmpp_session.h"
      21             : #include "xmpp/xmpp_config.h"
      22             : #include "xmpp/xmpp_connection_manager.h"
      23             : #include "xmpp/xmpp_channel_mux.h"
      24             : 
      25             : class LifetimeActor;
      26             : class LifetimeManager;
      27             : class ShowXmppConnection;
      28             : class ShowXmppServerResp;
      29             : class TcpSession;
      30             : class XmppConnectionEndpoint;
      31             : class XmppConfigUpdater;
      32             : class XmppServerConnection;
      33             : 
      34             : // Class to represent Xmpp Server
      35             : class XmppServer : public XmppConnectionManager {
      36             : public:
      37             :     typedef boost::asio::ip::tcp::endpoint Endpoint;
      38             :     typedef std::unique_lock<std::shared_mutex> WriteLock;
      39             :     typedef std::shared_lock<std::shared_mutex> ReadLock;
      40             : 
      41             :     XmppServer(EventManager *evm, const std::string &server_addr,
      42             :                const XmppChannelConfig *config);
      43             :     XmppServer(EventManager *evm, const std::string &server_addr);
      44             :     explicit XmppServer(EventManager *evm);
      45             :     virtual ~XmppServer();
      46             : 
      47             :     typedef boost::function<void(XmppChannelMux *, xmps::PeerState)> ConnectionEventCb;
      48             :     void RegisterConnectionEvent(xmps::PeerId, ConnectionEventCb);
      49             :     void UnRegisterConnectionEvent(xmps::PeerId);
      50             :     void NotifyConnectionEvent(XmppChannelMux *, xmps::PeerState);
      51             :     size_t ConnectionEventCount() const;
      52             : 
      53             :     LifetimeManager *lifetime_manager();
      54             :     virtual LifetimeActor *deleter();
      55             :     virtual LifetimeActor *deleter() const;
      56             : 
      57             :     virtual TcpSession *CreateSession();
      58             :     virtual bool Initialize(short port);
      59             :     virtual bool Initialize(short port, bool logUVE);
      60             :     virtual bool Initialize(short port, bool logUVE, const IpAddress &ip);
      61             :     void SessionShutdown();
      62             :     bool MayDelete() const;
      63             :     void Shutdown();
      64             :     void Terminate();
      65             : 
      66             :     virtual XmppServerConnection *CreateConnection(XmppSession *session);
      67             :     virtual XmppServerConnection *FindConnection(Endpoint remote_endpoint);
      68             :     virtual XmppServerConnection *FindConnection(const std::string &address);
      69             :     virtual void InsertConnection(XmppServerConnection *connection);
      70             :     virtual void RemoveConnection(XmppServerConnection *connection);
      71             :     void SwapXmppConnectionMapEntries(XmppConnection *connection1,
      72             :                                       XmppConnection *connection2);
      73             : 
      74             :     virtual void InsertDeletedConnection(XmppServerConnection *connection);
      75             :     virtual void RemoveDeletedConnection(XmppServerConnection *connection);
      76             : 
      77             :     bool ClearConnection(const std::string &hostname);
      78             :     void ClearAllConnections();
      79             :     void UpdateAllConnections(uint8_t time_out);
      80             : 
      81          24 :     const std::string &ServerAddr() const { return server_addr_; }
      82             :     size_t ConnectionCount() const;
      83             : 
      84             :     XmppConnectionEndpoint *FindConnectionEndpoint(
      85             :             const std::string &endpoint_name);
      86             :     XmppConnectionEndpoint *LocateConnectionEndpoint(
      87             :         XmppServerConnection *connection, bool &created);
      88             :     void ReleaseConnectionEndpoint(XmppServerConnection *connection);
      89             : 
      90             :     void FillShowConnections(
      91             :         std::vector<ShowXmppConnection> *show_connection_list) const;
      92             :     void FillShowServer(ShowXmppServerResp *resp) const;
      93             :     void CreateConfigUpdater(BgpConfigManager *config_manager);
      94             :     virtual bool IsPeerCloseGraceful() const;
      95             :     uint16_t GetGracefulRestartTime() const;
      96             :     uint32_t GetLongLivedGracefulRestartTime() const;
      97             :     uint32_t GetEndOfRibReceiveTime() const;
      98             :     uint32_t GetEndOfRibSendTime() const;
      99             :     bool IsGRHelperModeEnabled() const;
     100             :     bool gr_helper_disable() const { return gr_helper_disable_; }
     101         208 :     void set_gr_helper_disable(bool gr_helper_disable) {
     102         208 :         gr_helper_disable_ = gr_helper_disable;
     103         208 :     }
     104             :     void SetDscpValue(uint8_t value);
     105           4 :     uint8_t dscp_value() const { return dscp_value_; }
     106       10695 :     const std::string subcluster_name() const {
     107       10695 :         return subcluster_name_;
     108             :     }
     109           8 :     void set_subcluster_name(const std::string& subcluster_name) {
     110           8 :         subcluster_name_ = subcluster_name;
     111           8 :     }
     112             : 
     113             : protected:
     114             :     virtual SslSession *AllocSession(SslSocket *socket);
     115             :     virtual bool AcceptSession(TcpSession *session);
     116             : 
     117             :     mutable std::shared_mutex connection_map_mutex_;
     118             :     typedef std::map<Endpoint, XmppServerConnection *> ConnectionMap;
     119             :     ConnectionMap connection_map_;
     120             : 
     121             : private:
     122             :     class DeleteActor;
     123             :     friend class BgpXmppBasicTest;
     124             :     friend class DeleteActor;
     125             :     friend class XmppStateMachineTest;
     126             : 
     127             :     typedef std::set<XmppServerConnection *> ConnectionSet;
     128             :     typedef std::map<std::string, XmppConnectionEndpoint *> ConnectionEndpointMap;
     129             :     typedef std::map<xmps::PeerId, ConnectionEventCb> ConnectionEventCbMap;
     130             : 
     131             :     bool DequeueConnection(XmppServerConnection *connection);
     132             :     size_t GetConnectionQueueSize() const;
     133             :     void SetConnectionQueueDisable(bool disabled);
     134             :     void WorkQueueExitCallback(bool done);
     135             :     size_t ConnectionMapSize() const;
     136             : 
     137             :     ConnectionSet deleted_connection_set_;
     138             :     size_t max_connections_;
     139             : 
     140             :     std::mutex endpoint_map_mutex_;
     141             :     ConnectionEndpointMap connection_endpoint_map_;
     142             : 
     143             :     std::mutex deletion_mutex_;
     144             :     boost::scoped_ptr<LifetimeManager> lifetime_manager_;
     145             :     boost::scoped_ptr<DeleteActor> deleter_;
     146             : 
     147             :     ConnectionEventCbMap connection_event_map_;
     148             :     std::string server_addr_;
     149             :     bool log_uve_;
     150             :     bool auth_enabled_;
     151             :     int tcp_hold_time_;
     152             :     bool gr_helper_disable_;
     153             :     boost::scoped_ptr<XmppConfigUpdater> xmpp_config_updater_;
     154             :     uint8_t dscp_value_;
     155             :     std::string subcluster_name_;
     156             :     WorkQueue<XmppServerConnection *> connection_queue_;
     157             : 
     158             :     DISALLOW_COPY_AND_ASSIGN(XmppServer);
     159             : };
     160             : 
     161             : #endif

Generated by: LCOV version 1.14