10 #include "noise/protocol.h" 67 virtual bool can_write_without_blocking() = 0;
68 virtual APIError write_packet(uint16_t
type,
const uint8_t *data,
size_t len) = 0;
69 virtual std::string getpeername() = 0;
72 virtual APIError shutdown(
int how) = 0;
74 virtual void set_log_info(std::string info) = 0;
81 : socket_(
std::move(socket)), ctx_(
std::move(
std::move(ctx))) {}
86 bool can_write_without_blocking()
override;
87 APIError write_packet(uint16_t
type,
const uint8_t *payload,
size_t len)
override;
88 std::string
getpeername()
override {
return this->socket_->getpeername(); }
90 return this->socket_->getpeername(addr, addrlen);
95 void set_log_info(std::string info)
override { info_ = std::move(info); }
99 std::vector<uint8_t>
msg;
105 APIError write_frame_(
const uint8_t *data,
size_t len);
108 APIError check_handshake_finished_();
109 void send_explicit_handshake_reject_(
const std::string &reason);
114 uint8_t rx_header_buf_[3];
115 size_t rx_header_buf_len_ = 0;
117 size_t rx_buf_len_ = 0;
122 std::shared_ptr<APINoiseContext>
ctx_;
123 NoiseHandshakeState *handshake_{
nullptr};
124 NoiseCipherState *send_cipher_{
nullptr};
125 NoiseCipherState *recv_cipher_{
nullptr};
137 } state_ = State::INITIALIZE;
139 #endif // USE_API_NOISE 141 #ifdef USE_API_PLAINTEXT 149 bool can_write_without_blocking()
override;
150 APIError write_packet(uint16_t
type,
const uint8_t *payload,
size_t len)
override;
151 std::string
getpeername()
override {
return this->socket_->getpeername(); }
153 return this->socket_->getpeername(addr, addrlen);
156 APIError shutdown(
int how)
override;
158 void set_log_info(std::string info)
override { info_ = std::move(info); }
173 bool rx_header_parsed_ =
false;
174 uint32_t rx_header_parsed_type_ = 0;
175 uint32_t rx_header_parsed_len_ = 0;
178 size_t rx_buf_len_ = 0;
187 } state_ = State::INITIALIZE;
std::shared_ptr< APINoiseContext > ctx_
std::vector< uint8_t > msg
std::string getpeername() override
const char * api_error_to_str(APIError err)
std::vector< uint8_t > tx_buf_
std::vector< uint8_t > rx_header_buf_
std::unique_ptr< socket::Socket > socket_
std::string getpeername() override
std::vector< uint8_t > prologue_
void set_log_info(std::string info) override
void set_log_info(std::string info) override
std::vector< uint8_t > msg
int getpeername(struct sockaddr *addr, socklen_t *addrlen) override
std::vector< uint8_t > rx_buf_
std::unique_ptr< socket::Socket > socket_
Implementation of SPI Controller mode.
std::vector< uint8_t > tx_buf_
std::vector< uint8_t > rx_buf_
std::vector< uint8_t > container
int getpeername(struct sockaddr *addr, socklen_t *addrlen) override
APIPlaintextFrameHelper(std::unique_ptr< socket::Socket > socket)
APINoiseFrameHelper(std::unique_ptr< socket::Socket > socket, std::shared_ptr< APINoiseContext > ctx)
const std::vector< uint8_t > container
std::unique_ptr< Socket > socket(int domain, int type, int protocol)
Create a socket of the given domain, type and protocol.