Transition into ready state.
This commit is contained in:
22
crypto.cc
22
crypto.cc
@@ -182,7 +182,16 @@ void CryptoPubServerConnection::OnReadable_(struct bufferevent* bev, void* this_
|
||||
void CryptoPubServerConnection::OnReadable() {
|
||||
char buf[UINT16_MAX];
|
||||
int bytes = bufferevent_read(bev_, buf, UINT16_MAX);
|
||||
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(std::string(buf, bytes)));
|
||||
const std::string input(buf, bytes);
|
||||
|
||||
if (state_ == AWAITING_HANDSHAKE) {
|
||||
OnHandshake(input);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CryptoPubServerConnection::OnHandshake(const std::string& input) {
|
||||
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(input));
|
||||
if (!decoded.get()) {
|
||||
// TODO: re-buffer?
|
||||
return;
|
||||
@@ -288,7 +297,16 @@ void CryptoPubClient::OnReadable_(struct bufferevent* bev, void* this__) {
|
||||
void CryptoPubClient::OnReadable() {
|
||||
char buf[UINT16_MAX];
|
||||
int bytes = bufferevent_read(bev_, buf, UINT16_MAX);
|
||||
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(std::string(buf, bytes)));
|
||||
const std::string input(buf, bytes);
|
||||
|
||||
if (state_ == AWAITING_HANDSHAKE) {
|
||||
OnHandshake(input);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CryptoPubClient::OnHandshake(const std::string& input) {
|
||||
std::unique_ptr<TLVNode> decoded(TLVNode::Decode(input));
|
||||
if (!decoded.get()) {
|
||||
// TODO: re-buffer?
|
||||
return;
|
||||
|
||||
2
crypto.h
2
crypto.h
@@ -49,6 +49,7 @@ class CryptoPubServerConnection : public CryptoBase {
|
||||
private:
|
||||
static void OnReadable_(struct bufferevent* bev, void* this__);
|
||||
void OnReadable();
|
||||
void OnHandshake(const std::string& input);
|
||||
static void OnError_(struct bufferevent* bev, const short what, void* this__);
|
||||
void OnError(const short what);
|
||||
|
||||
@@ -79,6 +80,7 @@ class CryptoPubClient : public CryptoBase {
|
||||
private:
|
||||
static void OnReadable_(struct bufferevent* bev, void* this__);
|
||||
void OnReadable();
|
||||
void OnHandshake(const std::string& input);
|
||||
static void OnConnectOrError_(struct bufferevent* bev, const short what, void* this__);
|
||||
void OnConnect();
|
||||
void OnError();
|
||||
|
||||
Reference in New Issue
Block a user