11 #include <boost/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;
33 LifetimeActor(server->lifetime_manager()), server_(server) { }
38 server_->SessionShutdown();
49 :
SslServer(evm, boost::asio::ssl::context::tlsv12_server,
50 config.sandesh_ssl_enable),
51 sm_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kStateMachineTask)),
52 session_reader_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kSessionReaderTask)),
53 lifetime_mgr_task_id_(
TaskScheduler::GetInstance()->GetTaskId(kLifetimeMgrTask)),
60 TaskPolicy lm_task_policy = boost::assign::list_of
67 boost::asio::ssl::context *ctx =
context();
68 boost::system::error_code ec;
69 ctx->set_options(boost::asio::ssl::context::default_workarounds |
70 boost::asio::ssl::context::no_tlsv1 |
71 boost::asio::ssl::context::no_sslv3 |
72 boost::asio::ssl::context::no_sslv2 |
73 boost::asio::ssl::context::no_tlsv1_1, ec);
74 if (ec.value() != 0) {
75 SANDESH_LOG(ERROR,
"Error setting ssl options: " << ec.message());
81 ctx->set_verify_mode(boost::asio::ssl::verify_peer |
82 boost::asio::ssl::verify_fail_if_no_peer_cert,
84 if (ec.value() != 0) {
85 SANDESH_LOG(ERROR,
"Error setting verification mode: " <<
89 ctx->load_verify_file(config.
ca_cert, ec);
90 if (ec.value() != 0) {
91 SANDESH_LOG(ERROR,
"Error loading CA certificate: " <<
98 if (ec.value() != 0) {
99 SANDESH_LOG(ERROR,
"Error using server certificate: " <<
105 boost::asio::ssl::context::pem, ec);
106 if (ec.value() != 0) {
107 SANDESH_LOG(ERROR,
"Error using server private key file: " <<
129 boost::system::error_code ec;
132 SANDESH_LOG(ERROR, __func__ <<
": Invalid server address: " <<
133 ip <<
" Error: " << ec);
142 SANDESH_LOG(ERROR,
"Process EXITING: TCP Server initialization failed for port " << port);
149 tbb::mutex::scoped_lock lock(
mutex_);
160 tbb::mutex::scoped_lock lock(
mutex_);
163 for (
size_t i =
conn_bmap_.size(); i != 0; i--) {
176 SOL_SOCKET, SO_REUSEADDR> reuse_addr_t;
180 boost::system::error_code err;
181 socket->open(ip::tcp::v4(), err);
183 SANDESH_LOG(ERROR, __func__ <<
" Server Open Fail " << err.message());
186 socket->set_option(reuse_addr_t(
true), err);
188 SANDESH_LOG(ERROR, __func__ <<
" SetSockOpt Fail " << err.message());
194 SANDESH_LOG(ERROR, __func__ <<
" Server Bind Failure " << err.message());
207 return (peer_addr == p.second->endpoint() ?
false :
true);
211 tbb::mutex::scoped_lock lock(
mutex_);
212 SandeshConnectionMap::iterator loc = find_if(
connection_.begin(),
214 boost::ref(peer_addr), _1));
232 tbb::mutex::scoped_lock lock(
mutex_);
233 boost::asio::ip::tcp::endpoint endpoint = connection->
endpoint();
238 tbb::mutex::scoped_lock lock(
mutex_);
243 SandeshConnectionMap::iterator loc =
connection_.find(remote);
246 SANDESH_LOG(INFO,
"Server: " << __func__ <<
" " <<
"Create Connection");
254 connection = loc->second;
255 if (connection->
session() != NULL) {
265 const SandeshCtrlClientToServer *snh =
266 dynamic_cast<const SandeshCtrlClientToServer *
>(sandesh);
268 SANDESH_LOG(DEBUG,
"Received Ctrl Message with wrong type " << sandesh->
Name());
271 SANDESH_LOG(DEBUG,
"Received Ctrl Message from " << snh->get_module_name());
272 std::vector<UVETypeInfo> vu;
273 SandeshCtrlServerToClient::Request(vu,
true,
"ctrl", session->
connection());
virtual bool MayDelete() const
void RemoveConnection(SandeshConnection *connection)
static bool task_policy_set_
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
boost::asio::ip::tcp::socket Socket
boost::scoped_ptr< LifetimeManager > lifetime_manager_
virtual TcpSession * CreateSession()
void SetPolicy(int task_id, TaskPolicy &policy)
Sets the task exclusion policy. Adds policy entries for the task Examples:
SandeshServer(EventManager *evm, const SandeshConfig &config)
SandeshSession * session() const
virtual TcpSession * CreateSession()
SandeshConnectionMap connection_
std::string server_certfile
boost::asio::ssl::context * context()
int session_reader_task_id_
void AcceptSession(SandeshSession *session)
virtual int GetSessionInstance() const
virtual const char * Name() const
virtual bool ReceiveSandeshCtrlMsg(SandeshStateMachine *state_machine, SandeshSession *session, const Sandesh *sandesh)
int AllocConnectionIndex()
#define SANDESH_LOG(_Level, _Msg)
static const std::string kSessionReaderTask
Endpoint LocalEndpoint() const
virtual SslSession * AllocSession(SslSocket *socket)
static const int kMaxInitRetries
boost::dynamic_bitset conn_bmap_
virtual bool AcceptSession(TcpSession *session)
static TaskScheduler * GetInstance()
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
boost::scoped_ptr< DeleteActor > deleter_
SandeshConnection * FindConnection(const Endpoint &peer_addr)
boost::ptr_container_detail::ref_pair< boost::asio::ip::basic_endpoint< boost::asio::ip::tcp >, SandeshConnection *const > SandeshConnectionPair
int session_writer_task_id() const
LifetimeActor * deleter()
int lifetime_mgr_task_id()
static const std::string kLifetimeMgrTask
std::vector< TaskExclusion > TaskPolicy
std::string server_keyfile
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
Endpoint remote_endpoint() const
virtual bool Initialize(unsigned short port)
SandeshConnection * connection()
int lifetime_mgr_task_id_
virtual bool Initialize(short port, const std::string &ip="0.0.0.0")
bool Compare(const Endpoint &peer_addr, const SandeshConnectionPair &) const
LifetimeManager * lifetime_manager()
virtual void SessionShutdown()
DeleteActor(SandeshServer *server)
virtual Socket * socket() const
boost::asio::ip::tcp::endpoint Endpoint
void FreeConnectionIndex(int)
int session_reader_task_id() const
static const std::string kStateMachineTask