11#include "noise/protocol.h"
21class ProtoWriteBuffer;
93 if (how == SHUT_RDWR) {
168 template<
typename StateEnum>
170 const std::string &info, StateEnum &
state, StateEnum failed_state);
224 std::shared_ptr<APINoiseContext>
ctx_;
232#ifdef USE_API_PLAINTEXT
virtual uint8_t frame_footer_size()=0
std::vector< uint8_t > rx_buf_
APIError write_raw_(const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector< uint8_t > &tx_buf, const std::string &info, StateEnum &state, StateEnum failed_state)
virtual APIError read_packet(ReadPacketBuffer *buffer)=0
std::unique_ptr< socket::Socket > socket_owned_
bool is_socket_ready() const
void set_log_info(std::string info)
int getpeername(struct sockaddr *addr, socklen_t *addrlen)
virtual APIError loop()=0
APIError shutdown(int how)
std::vector< struct iovec > reusable_iovs_
std::string getpeername()
uint8_t frame_header_padding_
virtual APIError init()=0
virtual APIError write_protobuf_packets(ProtoWriteBuffer buffer, const std::vector< PacketInfo > &packets)=0
void buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len)
APIFrameHelper(std::unique_ptr< socket::Socket > socket)
APIError try_send_tx_buf_()
uint8_t frame_footer_size_
APIError write_raw_(const struct iovec *iov, int iovcnt)
virtual uint8_t frame_header_padding()=0
bool can_write_without_blocking()
virtual APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer)=0
std::deque< SendBuffer > tx_buf_
virtual ~APIFrameHelper()=default
uint8_t rx_header_buf_len_
APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer) override
NoiseCipherState * send_cipher_
APIError read_packet(ReadPacketBuffer *buffer) override
NoiseCipherState * recv_cipher_
APIError try_read_frame_(ParsedFrame *frame)
Read a packet into the rx_buf_.
~APINoiseFrameHelper() override
std::vector< uint8_t > prologue_
APIError write_protobuf_packets(ProtoWriteBuffer buffer, const std::vector< PacketInfo > &packets) override
APIError state_action_()
To be called from read/write methods.
APIError loop() override
Run through handshake messages (if in that phase)
NoiseHandshakeState * handshake_
uint8_t rx_header_buf_[3]
uint8_t frame_header_padding() override
APIError write_frame_(const uint8_t *data, uint16_t len)
std::shared_ptr< APINoiseContext > ctx_
uint8_t frame_footer_size() override
APIError init() override
Initialize the frame helper, returns OK if successful.
APIError check_handshake_finished_()
void send_explicit_handshake_reject_(const std::string &reason)
APIError init_handshake_()
Initiate the data structures for the handshake.
APINoiseFrameHelper(std::unique_ptr< socket::Socket > socket, std::shared_ptr< APINoiseContext > ctx)
APIPlaintextFrameHelper(std::unique_ptr< socket::Socket > socket)
uint8_t rx_header_buf_[6]
uint16_t rx_header_parsed_type_
APIError write_protobuf_packets(ProtoWriteBuffer buffer, const std::vector< PacketInfo > &packets) override
APIError init() override
Initialize the frame helper, returns OK if successful.
uint16_t rx_header_parsed_len_
APIError loop() override
Not used for plaintext.
~APIPlaintextFrameHelper() override=default
uint8_t frame_header_padding() override
APIError read_packet(ReadPacketBuffer *buffer) override
APIError write_protobuf_packet(uint16_t type, ProtoWriteBuffer buffer) override
uint8_t frame_footer_size() override
uint8_t rx_header_buf_pos_
APIError try_read_frame_(ParsedFrame *frame)
Read a packet into the rx_buf_.
bool ready() const
Check if socket has data ready to read For loop-monitored sockets, checks with the Application's sele...
virtual int shutdown(int how)=0
virtual int getpeername(struct sockaddr *addr, socklen_t *addrlen)=0
@ HANDSHAKESTATE_READ_FAILED
@ HANDSHAKESTATE_BAD_STATE
@ HANDSHAKESTATE_SPLIT_FAILED
@ BAD_HANDSHAKE_PACKET_LEN
@ BAD_HANDSHAKE_ERROR_BYTE
@ HANDSHAKESTATE_SETUP_FAILED
@ CIPHERSTATE_ENCRYPT_FAILED
@ CIPHERSTATE_DECRYPT_FAILED
@ HANDSHAKESTATE_WRITE_FAILED
const char * api_error_to_str(APIError err)
Providing packet encoding functions for exchanging data with a remote host.
std::vector< uint8_t > msg
uint16_t remaining() const
std::vector< uint8_t > data
const uint8_t * current_data() const
PacketInfo(uint16_t type, uint16_t off, uint16_t size)
std::vector< uint8_t > container