Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection-manager: cleanup of hardcoded connection types. #17

Open
wants to merge 2 commits into
base: verity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/builtin/connection-manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ namespace bassl = ::boost::asio::ssl;

static Vlog_module lg("connection_manager");

static const std::string conn_t_str[] = { "tcp", "ssl", "ptcp", "pssl" };
const std::string Connection_manager::Connection_type_string[NR_CONNECTION_TYPES] =
{
"tcp",
"ssl",
"ptcp",
"pssl",
"unknown"
};

Connection_manager::Connection_manager(const Component_context* ctxt,
const std::list<std::string>& interfaces)
Expand Down Expand Up @@ -85,7 +92,7 @@ Connection_manager::install()
/* Bind/listen to interfaces */
BOOST_FOREACH(const std::string& interface, interfaces)
{
Conn_t type;
Connection_type type;
std::string host, key, cert, cafile;
uint16_t port;

Expand All @@ -112,21 +119,21 @@ Connection_manager::install()
if (type == TCP || type == SSL)
{
VLOG_DBG(lg, "connecting to %s:%s:%d:%s:%s:%s",
conn_t_str[type].c_str(), host.c_str(), port,
Connection_type_string[type].c_str(), host.c_str(), port,
key.c_str(), cert.c_str(), cafile.c_str());
connect(type, host, port, key, cert, cafile);
}
else if (type == PTCP || type == PSSL)
{
VLOG_DBG(lg, "listening on %s:%s:%d:%s:%s:%s",
conn_t_str[type].c_str(), host.c_str(), port,
Connection_type_string[type].c_str(), host.c_str(), port,
key.c_str(), cert.c_str(), cafile.c_str());
listen(type, host, port, key, cert, cafile);
}
else
{
throw std::runtime_error("Unsupported connection type \""
+ conn_t_str[type] + "\"");
+ Connection_type_string[type] + "\"");
}
}

Expand All @@ -137,7 +144,7 @@ Connection_manager::install()

void
Connection_manager::parse(const std::string& interface,
Conn_t& type,
Connection_type& type,
std::string& host,
uint16_t& port,
std::string& key,
Expand All @@ -159,13 +166,13 @@ Connection_manager::parse(const std::string& interface,
size_t ntokens = tokens.size();
if (ntokens >= 1)
{
if (tokens[0] == "tcp")
if (tokens[0] == Connection_type_string[TCP])
type = TCP;
else if (tokens[0] == "ssl")
else if (tokens[0] == Connection_type_string[SSL])
type = SSL;
else if (tokens[0] == "ptcp")
else if (tokens[0] == Connection_type_string[PTCP])
type = PTCP;
else if (tokens[0] == "pssl")
else if (tokens[0] == Connection_type_string[PSSL])
type = PSSL;

if (ntokens == 2)
Expand Down Expand Up @@ -245,7 +252,7 @@ Connection_manager::handle_handshake(bassl::stream_base::handshake_type type,
}

void
Connection_manager::connect(Conn_t type,
Connection_manager::connect(Connection_type type,
const std::string& host, const uint16_t& port,
const std::string& key,
const std::string& cert,
Expand Down Expand Up @@ -329,7 +336,7 @@ Connection_manager::listen(boost::shared_ptr<boost::asio::ip::tcp::acceptor> acc
}

void
Connection_manager::listen(Conn_t type,
Connection_manager::listen(Connection_type type,
const std::string& bind_ip, const uint16_t& port,
const std::string& key,
const std::string& cert,
Expand Down
20 changes: 16 additions & 4 deletions src/include/connection-manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ public:
void install();

private:
enum Conn_t { TCP, SSL, PTCP, PSSL, UNKNOWN };

enum Connection_type
{
TCP = 0,
SSL = 1,
PTCP = 2,
PSSL = 3,
UNKNOWN = 4,
// should be last
NR_CONNECTION_TYPES = UNKNOWN+1
};

static const std::string Connection_type_string[NR_CONNECTION_TYPES];

typedef boost::function<void()> Listen_callback;
//typedef std::string Protocol_name;
Expand All @@ -72,7 +84,7 @@ private:
const std::list<std::string>& interfaces);

void parse(const std::string& interface,
Conn_t& type,
Connection_type& type,
std::string& ip,
uint16_t& port,
std::string& key,
Expand All @@ -88,7 +100,7 @@ private:
boost::shared_ptr<ssl_socket>,
Listen_callback, const boost::system::error_code&);

void connect(Conn_t type, const std::string& host, const uint16_t& port,
void connect(Connection_type type, const std::string& host, const uint16_t& port,
const std::string& key,
const std::string& cert,
const std::string& cafile);
Expand All @@ -98,7 +110,7 @@ private:
const std::string& key,
const std::string& cert,
const std::string& cafile);
void listen(Conn_t type, const std::string& bind_ip, const uint16_t& port,
void listen(Connection_type type, const std::string& bind_ip, const uint16_t& port,
const std::string& key,
const std::string& cert,
const std::string& cafile);
Expand Down