Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit fa50c16

Browse files
author
Tianyi Chen
committed
get rid of hacky ssl_able flag and refine Process Initial Packet
1 parent 0af039f commit fa50c16

File tree

6 files changed

+81
-98
lines changed

6 files changed

+81
-98
lines changed

src/include/network/connection_handle.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ConnectionHandle {
9191
* Flush out all the responses and do real SSL handshake
9292
*/
9393
Transition ProcessWrite_SSLHandshake();
94+
9495
private:
9596
/**
9697
* A state machine is defined to be a set of states, a set of symbols it
@@ -147,8 +148,8 @@ class ConnectionHandle {
147148
friend class ConnectionHandleFactory;
148149

149150
ConnectionHandle(int sock_fd, ConnectionHandlerTask *handler,
150-
std::shared_ptr<Buffer> rbuf, std::shared_ptr<Buffer> wbuf,
151-
bool ssl_able);
151+
std::shared_ptr<Buffer> rbuf,
152+
std::shared_ptr<Buffer> wbuf);
152153

153154
ProcessResult ProcessInitial();
154155

@@ -220,11 +221,8 @@ class ConnectionHandle {
220221
std::shared_ptr<Buffer> rbuf_; // Socket's read buffer
221222
std::shared_ptr<Buffer> wbuf_; // Socket's write buffer
222223
unsigned int next_response_ = 0; // The next response in the response buffer
223-
224-
StateMachine state_machine_;
225224

226-
// TODO(Tianyi) Can we encapsulate these flags?
227-
bool ssl_able_;
225+
StateMachine state_machine_;
228226

229227
short curr_event_flag_; // current libevent event flag
230228
};

src/include/network/connection_handle_factory.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,21 @@ class ConnectionHandleFactory {
4040
// (probably also to-do: beat up the person who wrote this)
4141
PelotonServer::recent_connfd = conn_fd;
4242
auto it = reusable_handles_.find(conn_fd);
43-
bool ssl_able = (PelotonServer::GetSSLLevel() != SSLLevel::SSL_DISABLE);
4443
if (it == reusable_handles_.end()) {
4544
// We are not using std::make_shared here because we want to keep
4645
// ConnectionHandle constructor
4746
// private to avoid unintentional use.
4847
auto handle = std::shared_ptr<ConnectionHandle>(
4948
new ConnectionHandle(conn_fd, handler, std::make_shared<Buffer>(),
50-
std::make_shared<Buffer>(), ssl_able));
49+
std::make_shared<Buffer>()));
5150
reusable_handles_[conn_fd] = handle;
5251
return handle;
5352
}
5453

5554
it->second->rbuf_->Reset();
5655
it->second->wbuf_->Reset();
5756
std::shared_ptr<ConnectionHandle> new_handle(new ConnectionHandle(
58-
conn_fd, handler, it->second->rbuf_, it->second->wbuf_, ssl_able));
57+
conn_fd, handler, it->second->rbuf_, it->second->wbuf_));
5958
reusable_handles_[conn_fd] = new_handle;
6059
return new_handle;
6160
}

src/include/network/postgres_protocol_handler.h

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,8 @@ class PostgresProtocolHandler : public ProtocolHandler {
4545
* thread_id is the thread of current running thread. This is used
4646
* to generate txn
4747
*/
48-
ProcessResult Process(Buffer &rbuf, const bool ssl_able, const size_t thread_id);
48+
ProcessResult Process(Buffer &rbuf, size_t thread_id);
4949

50-
/**
51-
*
52-
*/
53-
ProcessResult ProcessInitialPackets(
54-
55-
/**
56-
* Main switch case wrapper to process every general packet apart from the
57-
* initial packets. Avoid flushing the response for extended protocols.
58-
*/
59-
ProcessResult ProcessNormalPackets(InputPacket *pkt, const size_t thread_id);
60-
/* Manage the startup packet */
61-
// bool ManageStartupPacket();
62-
void SendInitialResponse();
6350
void Reset();
6451

6552
void GetResult();
@@ -96,17 +83,30 @@ class PostgresProtocolHandler : public ProtocolHandler {
9683
static bool ReadPacketHeader(Buffer &rbuf, InputPacket &rpkt,
9784
bool startup_format);
9885

99-
/* Routine to deal with the first packet from the client */
100-
bool ProcessInitialPackets(InputPacket *pkt, bool ssl_able);
101-
102-
/* Routine to deal with SSL request message */
103-
void ProcessSSLRequestPacket(bool ssl_able, bool &ssl_handshake);
104-
10586
//===--------------------------------------------------------------------===//
10687
// PROTOCOL HANDLING FUNCTIONS
10788
//===--------------------------------------------------------------------===//
108-
/* Manage the startup packet */
109-
virtual void SendInitialResponse();
89+
90+
/**
91+
* @brief Routine to deal with the first packet from the client
92+
*/
93+
ProcessResult ProcessInitialPackets(InputPacket *pkt);
94+
95+
/**
96+
* @brief Main Switch function to process general packets
97+
*/
98+
ProcessResult ProcessNormalPackets(InputPacket *pkt, const size_t thread_id);
99+
100+
/**
101+
* @brief Helper function to process startup packet
102+
* @param proto_version protocol version of the session
103+
*/
104+
ProcessResult ProcessStartupPacket(InputPacket *pkt, int32_t proto_version);
105+
106+
/**
107+
* Send hardcoded response
108+
*/
109+
void SendStartupResponse();
110110

111111
// Generic error protocol packet
112112
void SendErrorResponse(
@@ -202,6 +202,8 @@ class PostgresProtocolHandler : public ProtocolHandler {
202202
std::unordered_map<std::string, stats::QueryMetric::QueryParamBuf>
203203
statement_param_types_;
204204

205+
std::unordered_map<std::string, std::string> cmdline_options_;
206+
205207
//===--------------------------------------------------------------------===//
206208
// STATIC DATA
207209
//===--------------------------------------------------------------------===//

src/include/network/protocol_handler.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProtocolHandler {
3535
/**
3636
*
3737
*/
38-
virtual ProcessResult Process(Buffer &rbuf, const bool ssl_able, const size_t thread_id);
38+
virtual ProcessResult Process(Buffer &rbuf, const size_t thread_id);
3939

4040
virtual void Reset();
4141

@@ -49,14 +49,13 @@ class ProtocolHandler {
4949

5050
// TODO declare a response buffer pool so that we can reuse the responses
5151
// so that we don't have to new packet each time
52-
ResponseBuffer responses;
52+
ResponseBuffer responses_;
5353

54-
InputPacket request; // Used for reading a single request
54+
InputPacket request_; // Used for reading a single request
5555

5656
// The traffic cop used for this connection
5757
tcop::TrafficCop *traffic_cop_;
5858

59-
std::unordered_map<std::string, std::string> cmdline_options;
6059
};
6160

6261
} // namespace network

src/network/connection_handle.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ void ConnectionHandle::StateMachine::Accept(Transition action,
146146

147147
ConnectionHandle::ConnectionHandle(int sock_fd, ConnectionHandlerTask *handler,
148148
std::shared_ptr<Buffer> rbuf,
149-
std::shared_ptr<Buffer> wbuf, bool ssl_able)
149+
std::shared_ptr<Buffer> wbuf)
150150
: sock_fd_(sock_fd),
151151
handler_(handler),
152152
protocol_handler_(nullptr),
153153
rbuf_(std::move(rbuf)),
154-
wbuf_(std::move(wbuf)),
155-
ssl_able_(ssl_able) {
154+
wbuf_(std::move(wbuf)) {
156155
SetNonBlocking(sock_fd_);
157156
SetTCPNoDelay(sock_fd_);
158157

0 commit comments

Comments
 (0)