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

Generated by: LCOV version 1.14