mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-02 08:17:13 +00:00
cleaned up session, added better protocol version identification
This commit is contained in:
Binary file not shown.
@@ -72,7 +72,6 @@ Build tested on
|
||||
|
||||
Outstanding issues
|
||||
- Acknowledgement details
|
||||
- Add license information to each file
|
||||
- Subprotocol negotiation interface
|
||||
- check draft 14 issues
|
||||
- session.cpp - add_header. Decide what should happen with multiple calls to
|
||||
|
||||
@@ -83,6 +83,13 @@ void session::remove_host(std::string host) {
|
||||
m_hosts.erase(host);
|
||||
}
|
||||
|
||||
void session::set_max_message_size(uint64_t val) {
|
||||
if (val > frame::PAYLOAD_64BIT_LIMIT) {
|
||||
throw "illegal maximum message size";
|
||||
}
|
||||
m_max_message_size = val;
|
||||
}
|
||||
|
||||
std::string session::get_header(const std::string& key) const {
|
||||
std::map<std::string,std::string>::const_iterator h = m_headers.find(key);
|
||||
|
||||
@@ -289,10 +296,15 @@ void session::handle_read_handshake(const boost::system::error_code& e,
|
||||
this->set_http_error(400);
|
||||
}
|
||||
|
||||
if (get_header("Sec-WebSocket-Version") != "8" &&
|
||||
get_header("Sec-WebSocket-Version") != "7") {
|
||||
std::cerr << "Invalid or missing Sec-Websocket-Version header." << std::endl;
|
||||
if (get_header("Sec-WebSocket-Version") == "" ) {
|
||||
std::cerr << "Missing Sec-Websocket-Version header." << std::endl;
|
||||
this->set_http_error(400);
|
||||
} else {
|
||||
m_version = strtoul(get_header("Sec-WebSocket-Version").c_str(),NULL,10);
|
||||
|
||||
if (m_version != 7 && m_version != 8 && m_version != 13) {
|
||||
this->set_http_error(400);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_http_error_code != 0) {
|
||||
|
||||
@@ -99,6 +99,10 @@ public:
|
||||
void add_host(std::string host);
|
||||
void remove_host(std::string host);
|
||||
|
||||
// Sets the maximum allowed message size. Higher values will require larger
|
||||
// memory buffers. Maximum value is 2^63, default value is ??
|
||||
void set_max_message_size(uint64_t);
|
||||
|
||||
// By default a failed handshake validation will return an HTTP 400 Bad
|
||||
// Request error. If your application wants to reject the connection for
|
||||
// another reason it can be set here. Example: 404 if the resource request
|
||||
@@ -199,28 +203,37 @@ private:
|
||||
|
||||
std::string lookup_http_error_string(int code);
|
||||
private:
|
||||
std::set<std::string> m_hosts;
|
||||
std::string m_host;
|
||||
tcp::socket m_socket;
|
||||
status_code m_status;
|
||||
int m_http_error_code;
|
||||
std::string m_http_error_string;
|
||||
// Connection specific constants (defaults to values from server, can be
|
||||
// changed on a per connection basis if needed.)
|
||||
std::set<std::string> m_hosts;
|
||||
uint64_t m_max_message_size;
|
||||
|
||||
// Immutable state about the current connection from the handshake
|
||||
std::string m_request;
|
||||
std::map<std::string,std::string> m_headers;
|
||||
unsigned int m_version;
|
||||
std::string m_subprotocol;
|
||||
|
||||
// Mutable connection state;
|
||||
status_code m_status;
|
||||
|
||||
// Connection Resources
|
||||
tcp::socket m_socket;
|
||||
connection_handler_ptr m_local_interface;
|
||||
|
||||
// Buffers
|
||||
boost::asio::streambuf m_buf;
|
||||
|
||||
// unorganized
|
||||
int m_http_error_code;
|
||||
std::string m_http_error_string;
|
||||
std::string m_handshake;
|
||||
|
||||
std::string m_request;
|
||||
std::map<std::string,std::string> m_headers;
|
||||
|
||||
frame m_read_frame;
|
||||
frame m_write_frame;
|
||||
std::vector<unsigned char> m_current_message;
|
||||
|
||||
bool m_error;
|
||||
bool m_fragmented;
|
||||
frame::opcode m_current_opcode;
|
||||
|
||||
connection_handler_ptr m_local_interface;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user