21#include <seastar/core/seastar.hh>
22#include <seastar/core/iostream.hh>
24namespace seastar::experimental::websocket {
43 static constexpr uint8_t FIN = 7;
44 static constexpr uint8_t RSV1 = 6;
45 static constexpr uint8_t RSV2 = 5;
46 static constexpr uint8_t RSV3 = 4;
47 static constexpr uint8_t MASKED = 7;
57 this->fin = (input[0] >> FIN) & 1;
58 this->rsv1 = (input[0] >> RSV1) & 1;
59 this->rsv2 = (input[0] >> RSV2) & 1;
60 this->rsv3 = (input[0] >> RSV3) & 1;
61 this->opcode = input[0] & 0b1111;
62 this->masked = (input[1] >> MASKED) & 1;
63 this->length = (input[1] & 0b1111111);
66 uint64_t get_rest_of_header_length() {
67 size_t next_read_length =
sizeof(uint32_t);
69 next_read_length +=
sizeof(uint16_t);
70 }
else if (length == 127) {
71 next_read_length +=
sizeof(uint64_t);
73 return next_read_length;
75 uint8_t get_fin() {
return fin;}
76 uint8_t get_rsv1() {
return rsv1;}
77 uint8_t get_rsv2() {
return rsv2;}
78 uint8_t get_rsv3() {
return rsv3;}
79 uint8_t get_opcode() {
return opcode;}
80 uint8_t get_masked() {
return masked;}
81 uint8_t get_length() {
return length;}
83 bool is_opcode_known() {
85 return opcode < 0xA && !(opcode < 0x8 && opcode > 0x2);
90 enum class parsing_state : uint8_t {
91 flags_and_payload_data,
92 payload_length_and_mask,
95 enum class connection_state : uint8_t {
103 parsing_state _state;
106 connection_state _cstate;
108 std::unique_ptr<frame_header> _header;
109 uint64_t _payload_length = 0;
110 uint64_t _consumed_payload_length = 0;
111 uint32_t _masking_key;
118 return make_ready_future<consumption_result_t>(
stop_consuming(std::move(data)));
120 uint64_t remaining_payload_length()
const {
121 return _payload_length - _consumed_payload_length;
125 void remove_mask(
buff_t& p,
size_t n) {
127 for (uint64_t i = 0, j = 0; i < n; ++i, j = (j + 1) % 4) {
128 payload[i] ^=
static_cast<char>(((_masking_key << (j * 8)) >> 24));
133 _cstate(connection_state::valid),
136 bool is_valid() {
return _cstate == connection_state::valid; }
137 bool eof() {
return _cstate == connection_state::closed; }
Definition: iostream.hh:238
A representation of a possibly not-yet-computed value.
Definition: future.hh:1197
Definition: iostream.hh:218
CharType * get_write() noexcept
Definition: temporary_buffer.hh:128
opcodes
Possible type of a websocket frame.
Definition: parser.hh:32
Definition: iostream.hh:215