Electroneum
epee::net_utils::protocol_switcher Class Reference

#include <protocol_switcher.h>

Public Types

typedef protocl_switcher_config config_type
 

Public Member Functions

 protocol_switcher (net_utils::i_service_endpoint *psnd_hndlr, config_type &config, const net_utils::connection_context_base &conn_context)
 
virtual ~protocol_switcher ()
 
virtual bool handle_recv (const void *ptr, size_t cb)
 
bool after_init_connection ()
 

Detailed Description

Definition at line 69 of file protocol_switcher.h.

Member Typedef Documentation

◆ config_type

Constructor & Destructor Documentation

◆ protocol_switcher()

epee::net_utils::protocol_switcher::protocol_switcher ( net_utils::i_service_endpoint psnd_hndlr,
config_type config,
const net_utils::connection_context_base conn_context 
)

Definition at line 88 of file protocol_switcher.h.

88  :m_http_handler(psnd_hndlr, config.m_http_config, conn_context), m_levin_handler(psnd_hndlr, config.m_levin_config, conn_context), pcurrent_handler(NULL)
89  {}

◆ ~protocol_switcher()

virtual epee::net_utils::protocol_switcher::~protocol_switcher ( )
inlinevirtual

Definition at line 75 of file protocol_switcher.h.

75 {}

Member Function Documentation

◆ after_init_connection()

bool epee::net_utils::protocol_switcher::after_init_connection ( )
inline

Definition at line 79 of file protocol_switcher.h.

79 {return true;}

◆ handle_recv()

bool epee::net_utils::protocol_switcher::handle_recv ( const void *  ptr,
size_t  cb 
)
virtual

Definition at line 91 of file protocol_switcher.h.

92  {
93  if(pcurrent_handler)
94  return pcurrent_handler->handle_recv(ptr, cb);
95  else
96  {
97  m_cached_buff.append((const char*)ptr, cb);
98  if(m_cached_buff.size() < sizeof(uint64_t))
99  return true;
100 
101  if(*((uint64_t*)&m_cached_buff[0]) == LEVIN_SIGNATURE)
102  {
103  pcurrent_handler = &m_levin_handler;
104  return pcurrent_handler->handle_recv(m_cached_buff.data(), m_cached_buff.size());
105  }
106  if(m_cached_buff.substr(0, 4) == "GET " || m_cached_buff.substr(0, 4) == "POST")
107  {
108  pcurrent_handler = &m_http_handler;
109  return pcurrent_handler->handle_recv(m_cached_buff.data(), m_cached_buff.size());
110  }else
111  {
112  LOG_ERROR("Wrong protocol accepted on port...");
113  return false;
114  }
115  }
116 
117  return true;
118  }
#define LEVIN_SIGNATURE
Definition: levin_base.h:34
virtual bool handle_recv(const void *ptr, size_t cb)=0
unsigned __int64 uint64_t
Definition: stdint.h:136
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Here is the call graph for this function:

The documentation for this class was generated from the following file: