11 #include <boost/bind/bind.hpp>
12 #include <boost/assign.hpp>
15 #include <sandesh/protocol/TXMLProtocol.h>
16 #include <sandesh/sandesh_types.h>
17 #include <sandesh/sandesh.h>
18 #include <sandesh/sandesh_ctrl_types.h>
24 using namespace boost::asio;
25 using namespace boost::placeholders;
34 LifetimeActor(server->lifetime_manager()), server_(server) { }
39 server_->SessionShutdown();
51 config.sandesh_ssl_enable),
52 sm_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kStateMachineTask)),
53 session_reader_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kSessionReaderTask)),
54 lifetime_mgr_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kLifetimeMgrTask)),
61 TaskPolicy lm_task_policy = boost::assign::list_of
68 boost::asio::ssl::context *ctx =
context();
69 boost::system::error_code ec;
70 ctx->set_options(boost::asio::ssl::context::default_workarounds |
71 boost::asio::ssl::context::no_tlsv1 |
72 boost::asio::ssl::context::no_sslv3 |
73 boost::asio::ssl::context::no_sslv2 |
74 boost::asio::ssl::context::no_tlsv1_1, ec);
75 if (ec.value() != 0) {
76 SANDESH_LOG(ERROR,
"Error setting ssl options: " << ec.message());
82 ctx->set_verify_mode(boost::asio::ssl::verify_peer |
83 boost::asio::ssl::verify_fail_if_no_peer_cert,
85 if (ec.value() != 0) {
86 SANDESH_LOG(ERROR,
"Error setting verification mode: " <<
90 ctx->load_verify_file(config.
ca_cert, ec);
91 if (ec.value() != 0) {
92 SANDESH_LOG(ERROR,
"Error loading CA certificate: " <<
99 if (ec.value() != 0) {
100 SANDESH_LOG(ERROR,
"Error using server certificate: " <<
106 boost::asio::ssl::context::pem, ec);
107 if (ec.value() != 0) {
108 SANDESH_LOG(ERROR,
"Error using server private key file: " <<
130 boost::system::error_code ec;
133 SANDESH_LOG(ERROR, __func__ <<
": Invalid server address: " <<
134 ip <<
" Error: " << ec);
143 SANDESH_LOG(ERROR,
"Process EXITING: TCP Server initialization failed for port " << port);
150 std::scoped_lock lock(
mutex_);
161 std::scoped_lock lock(
mutex_);
164 for (
size_t i =
conn_bmap_.size(); i != 0; i--) {
177 SOL_SOCKET, SO_REUSEADDR> reuse_addr_t;
181 boost::system::error_code err;
182 socket->open(ip::tcp::v4(), err);
184 SANDESH_LOG(ERROR, __func__ <<
" Server Open Fail " << err.message());
187 socket->set_option(reuse_addr_t(
true), err);
189 SANDESH_LOG(ERROR, __func__ <<
" SetSockOpt Fail " << err.message());
195 SANDESH_LOG(ERROR, __func__ <<
" Server Bind Failure " << err.message());
208 return (peer_addr == p.second->endpoint() ?
false :
true);
212 std::scoped_lock lock(
mutex_);
213 SandeshConnectionMap::iterator loc = find_if(
connection_.begin(),
215 boost::ref(peer_addr), _1));
233 std::scoped_lock lock(
mutex_);
234 boost::asio::ip::tcp::endpoint endpoint = connection->
endpoint();
239 std::scoped_lock lock(
mutex_);
244 SandeshConnectionMap::iterator loc =
connection_.find(remote);
247 SANDESH_LOG(INFO,
"Server: " << __func__ <<
" " <<
"Create Connection");
255 connection = loc->second;
256 if (connection->
session() != NULL) {
266 const SandeshCtrlClientToServer *snh =
267 dynamic_cast<const SandeshCtrlClientToServer *
>(
sandesh);
272 SANDESH_LOG(DEBUG,
"Received Ctrl Message from " << snh->get_module_name());
273 std::vector<UVETypeInfo> vu;
274 SandeshCtrlServerToClient::Request(vu,
true,
"ctrl", session->
connection());
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
void AcceptSession(SandeshSession *session)
SandeshSession * session() const
DeleteActor(SandeshServer *server)
virtual bool MayDelete() const
static const std::string kLifetimeMgrTask
int AllocConnectionIndex()
virtual TcpSession * CreateSession()
int session_writer_task_id() const
virtual void SessionShutdown()
boost::scoped_ptr< LifetimeManager > lifetime_manager_
SandeshServer(EventManager *evm, const SandeshConfig &config)
int lifetime_mgr_task_id()
virtual SslSession * AllocSession(SslSocket *socket)
virtual bool Initialize(short port, const std::string &ip="0.0.0.0")
SandeshConnectionMap connection_
static const std::string kStateMachineTask
LifetimeActor * deleter()
bool Compare(const Endpoint &peer_addr, const SandeshConnectionPair &) const
static bool task_policy_set_
SandeshConnection * FindConnection(const Endpoint &peer_addr)
boost::dynamic_bitset conn_bmap_
void FreeConnectionIndex(int)
virtual bool ReceiveSandeshCtrlMsg(SandeshStateMachine *state_machine, SandeshSession *session, const Sandesh *sandesh)
LifetimeManager * lifetime_manager()
virtual bool AcceptSession(TcpSession *session)
boost::scoped_ptr< DeleteActor > deleter_
int session_reader_task_id() const
void RemoveConnection(SandeshConnection *connection)
int session_reader_task_id_
static const std::string kSessionReaderTask
boost::ptr_container_detail::ref_pair< boost::asio::ip::basic_endpoint< boost::asio::ip::tcp >, SandeshConnection *const > SandeshConnectionPair
int lifetime_mgr_task_id_
static const int kMaxInitRetries
SandeshConnection * connection()
virtual int GetSessionInstance() const
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
boost::asio::ssl::context * context()
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
void SetPolicy(int task_id, TaskPolicy &policy)
Sets the task exclusion policy. Adds policy entries for the task Examples:
static TaskScheduler * GetInstance()
boost::asio::ip::tcp::endpoint Endpoint
Endpoint LocalEndpoint() const
virtual bool Initialize(unsigned short port)
virtual TcpSession * CreateSession()
boost::asio::ip::tcp::socket Socket
virtual Socket * socket() const
Endpoint remote_endpoint() const
#define SANDESH_LOG(_Level, _Msg)
std::string server_keyfile
std::string server_certfile
The class is used to specify a Task label for formulating a task exclusion list (an execution policy)...
std::vector< TaskExclusion > TaskPolicy
Defines a type to store an execution policy (a list of task exclusions).