mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
many tweaks
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
CFLAGS = -O2
|
||||
CFLAGS = -O2 -std=c++0x
|
||||
LDFLAGS =
|
||||
|
||||
CXX ?= c++
|
||||
@@ -7,10 +7,10 @@ SHARED ?= "1"
|
||||
ifeq ($(SHARED), 1)
|
||||
LDFLAGS := $(LDFLAGS) -lboost_system -lboost_date_time -lboost_program_options -lwebsocketpp
|
||||
else
|
||||
LDFLAGS := $(LDFLAGS) -lboost_system -lboost_date_time -lboost_regex -lboost_random -lboost_program_options ../../libwebsocketpp.a
|
||||
LDFLAGS := $(LDFLAGS) -lboost_system -lboost_date_time -lboost_regex -lcrypto -lssl ../../libwebsocketpp.a
|
||||
endif
|
||||
|
||||
echo_server: echo_server.o echo.o
|
||||
echo_server: echo_server.o
|
||||
$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
%.o: %.cpp
|
||||
|
||||
@@ -41,7 +41,7 @@ class echo_server_handler : public T::handler {
|
||||
public:
|
||||
typedef typename websocketpp::role::server<T>::handler handler_type;
|
||||
typedef typename websocketpp::role::server<T>::handler_ptr handler_ptr;
|
||||
typedef typename handler_type::connection_ptr connection_ptr;
|
||||
typedef typename handler_type::foo connection_ptr;
|
||||
|
||||
void validate(connection_ptr connection) {
|
||||
//std::cout << "state: " << connection->get_state() << std::endl;
|
||||
@@ -74,18 +74,18 @@ public:
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
short port = 9002;
|
||||
unsigned short port = 9002;
|
||||
bool ssl = false;
|
||||
|
||||
|
||||
if (argc == 2) {
|
||||
// TODO: input validation?
|
||||
port = atoi(argv[2]);
|
||||
port = atoi(argv[1]);
|
||||
}
|
||||
|
||||
if (argc == 3) {
|
||||
// TODO: input validation?
|
||||
port = atoi(argv[2]);
|
||||
ssl = (strcmp(argv[3],"-ssl"));
|
||||
port = atoi(argv[1]);
|
||||
ssl = !strcmp(argv[2],"-ssl");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -93,9 +93,14 @@ int main(int argc, char* argv[]) {
|
||||
plain_handler_ptr h(new echo_server_handler<plain_endpoint_type>());
|
||||
plain_endpoint_type e(h);
|
||||
|
||||
e.alog().set_level(websocketpp::log::alevel::CONNECT & websocketpp::log::alevel::DISCONNECT);
|
||||
e.alog().set_level(websocketpp::log::alevel::CONNECT);
|
||||
e.alog().set_level(websocketpp::log::alevel::DISCONNECT);
|
||||
|
||||
// TODO: fix
|
||||
//e.alog().set_level(websocketpp::log::alevel::CONNECT & websocketpp::log::alevel::DISCONNECT);
|
||||
e.elog().set_levels(websocketpp::log::elevel::ERROR,websocketpp::log::elevel::FATAL);
|
||||
|
||||
std::cout << "Starting WebSocket echo server on port " << port << std::endl;
|
||||
e.listen(port);
|
||||
} else {
|
||||
ssl_handler_ptr h(new echo_server_handler<ssl_endpoint_type>());
|
||||
@@ -104,6 +109,7 @@ int main(int argc, char* argv[]) {
|
||||
e.alog().set_level(websocketpp::log::alevel::CONNECT & websocketpp::log::alevel::DISCONNECT);
|
||||
e.elog().set_levels(websocketpp::log::elevel::ERROR,websocketpp::log::elevel::FATAL);
|
||||
|
||||
std::cout << "Starting Secure WebSocket echo server on port " << port << std::endl;
|
||||
e.listen(port);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "http/parser.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "logger/logger.hpp"
|
||||
|
||||
#include "roles/server.hpp"
|
||||
|
||||
@@ -72,12 +72,13 @@ public:
|
||||
|
||||
// friends (would require C++11) this would enable connection::start to be
|
||||
// protected instead of public.
|
||||
// friend typename endpoint_traits<endpoint_type>::role_type;
|
||||
friend typename endpoint_traits<endpoint_type>::role_type;
|
||||
friend typename endpoint_traits<endpoint_type>::socket_type;
|
||||
//friend class role<endpoint>;
|
||||
//friend class socket<endpoint>;
|
||||
|
||||
friend class role<endpoint>:: template connection<type>;
|
||||
friend class socket<endpoint>:: template connection<type>;
|
||||
friend class role<endpoint>::template connection<type>;
|
||||
friend class socket<endpoint>::template connection<type>;
|
||||
|
||||
enum write_state {
|
||||
IDLE = 0,
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace websocketpp {
|
||||
|
||||
#include "connection.hpp"
|
||||
#include "sockets/plain.hpp" // should this be here?
|
||||
#include "logger.hpp"
|
||||
#include "logger/logger.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,24 +53,51 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/*class application_client_handler : public client_handler {
|
||||
void on_action() {
|
||||
std::cout << "application_client_handler::on_action()" << std::endl;
|
||||
typedef websocketpp::endpoint<websocketpp::role::client,websocketpp::socket::plain> basic_client;
|
||||
typedef websocketpp::role::client<basic_client>::handler client_handler_type;
|
||||
typedef websocketpp::role::client<basic_client>::handler_ptr client_handler_ptr;
|
||||
|
||||
class application_client_handler : public client_handler_type {
|
||||
void validate(handler_type::connection_ptr connection) {
|
||||
std::cout << "state: " << connection->get_state() << std::endl;
|
||||
}
|
||||
};*/
|
||||
|
||||
void on_open(handler_type::connection_ptr connection) {
|
||||
std::cout << "connection opened" << std::endl;
|
||||
}
|
||||
|
||||
void on_close(handler_type::connection_ptr connection) {
|
||||
std::cout << "connection closed" << std::endl;
|
||||
}
|
||||
|
||||
void on_message(connection_ptr connection,websocketpp::utf8_string_ptr msg) {
|
||||
std::cout << "got message: " << *msg << std::endl;
|
||||
connection->send(*msg);
|
||||
}
|
||||
void on_message(connection_ptr connection,websocketpp::binary_string_ptr data) {
|
||||
std::cout << "got binary message of length: " << data->size() << std::endl;
|
||||
connection->send(*data);
|
||||
}
|
||||
|
||||
void http(handler_type::connection_ptr connection) {
|
||||
connection->set_body("HTTP Response!!");
|
||||
}
|
||||
|
||||
void on_fail(handler_type::connection_ptr connection) {
|
||||
std::cout << "connection failed" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main () {
|
||||
std::cout << "Endpoint 0" << std::endl;
|
||||
handler_ptr h(new application_server_handler());
|
||||
handler_ptr h(new application_client_handler());
|
||||
endpoint_type e(h);
|
||||
|
||||
e.alog().set_level(websocketpp::log::alevel::ALL);
|
||||
e.elog().set_level(websocketpp::log::elevel::ALL);
|
||||
|
||||
|
||||
e.listen(9002);
|
||||
std::cout << std::endl;
|
||||
e.connect("ws://localhost:9002");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -150,8 +150,6 @@ public:
|
||||
// TODO: check if get_uri is a full uri
|
||||
connection_uri.resource = request.uri();
|
||||
|
||||
std::cout << "parsed uri: " << connection_uri.str() << std::endl;
|
||||
|
||||
return connection_uri;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,30 @@ public:
|
||||
// continue as HTTP?
|
||||
m_endpoint.get_handler()->http(m_connection.shared_from_this());
|
||||
|
||||
// should there be a more encapsulated http processor here?
|
||||
m_origin = m_request.header("Origin");
|
||||
m_uri.secure = m_endpoint.is_secure();
|
||||
|
||||
std::string h = m_request.header("Host");
|
||||
|
||||
size_t found = h.find(":");
|
||||
if (found == std::string::npos) {
|
||||
m_uri.host = h;
|
||||
m_uri.port = (m_uri.secure ? DEFAULT_SECURE_PORT : DEFAULT_PORT);
|
||||
} else {
|
||||
uint16_t p = atoi(h.substr(found+1).c_str());
|
||||
|
||||
if (p == 0) {
|
||||
throw(http::exception("Could not determine request uri. Check host header.",http::status_code::BAD_REQUEST));
|
||||
} else {
|
||||
m_uri.host = h.substr(0,found);
|
||||
m_uri.port = p;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if get_uri is a full uri
|
||||
m_uri.resource = m_request.uri();
|
||||
|
||||
m_response.set_status(http::status_code::OK);
|
||||
}
|
||||
} catch (const http::exception& e) {
|
||||
@@ -337,21 +361,21 @@ public:
|
||||
// handler interface callback class
|
||||
class handler {
|
||||
public:
|
||||
typedef connection_ptr connection_ptr;
|
||||
typedef connection_ptr foo;
|
||||
|
||||
// Required
|
||||
virtual void validate(connection_ptr connection) = 0;
|
||||
virtual void on_open(connection_ptr connection) = 0;
|
||||
virtual void on_close(connection_ptr connection) = 0;
|
||||
virtual void validate(foo connection) = 0;
|
||||
virtual void on_open(foo connection) = 0;
|
||||
virtual void on_close(foo connection) = 0;
|
||||
|
||||
virtual void on_message(connection_ptr connection,utf8_string_ptr) = 0;
|
||||
virtual void on_message(connection_ptr connection,binary_string_ptr) = 0;
|
||||
virtual void on_message(foo connection,utf8_string_ptr) = 0;
|
||||
virtual void on_message(foo connection,binary_string_ptr) = 0;
|
||||
|
||||
// Optional
|
||||
virtual bool on_ping(connection_ptr connection,binary_string_ptr) {return true;}
|
||||
virtual void on_pong(connection_ptr connection,binary_string_ptr) {}
|
||||
virtual void http(connection_ptr connection) {}
|
||||
virtual void on_fail(connection_ptr connection) {}
|
||||
virtual bool on_ping(foo connection,binary_string_ptr) {return true;}
|
||||
virtual void on_pong(foo connection,binary_string_ptr) {}
|
||||
virtual void http(foo connection) {}
|
||||
virtual void on_fail(foo connection) {}
|
||||
};
|
||||
|
||||
server(boost::asio::io_service& m,handler_ptr h)
|
||||
|
||||
@@ -45,6 +45,10 @@ public:
|
||||
return m_io_service;
|
||||
}
|
||||
|
||||
bool is_secure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Connection specific details
|
||||
template <typename connection_type>
|
||||
class connection {
|
||||
|
||||
@@ -68,6 +68,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool is_secure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Connection specific details
|
||||
template <typename connection_type>
|
||||
class connection {
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace frame {
|
||||
} // namespace websocketpp
|
||||
|
||||
#include "network_utilities.hpp"
|
||||
#include "processor.hpp"
|
||||
#include "processors/processor.hpp"
|
||||
#include "utf8_validator/utf8_validator.hpp"
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
Reference in New Issue
Block a user