Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions proxy/http2/HTTP2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,6 @@ http2_write_frame_header(const Http2FrameHeader &hdr, IOVec iov)
return true;
}

bool
http2_write_data(const uint8_t *src, size_t length, const IOVec &iov)
{
byte_pointer ptr(iov.iov_base);
write_and_advance(ptr, src, length);

return true;
}

bool
http2_write_headers(const uint8_t *src, size_t length, const IOVec &iov)
{
byte_pointer ptr(iov.iov_base);
write_and_advance(ptr, src, length);

return true;
}

bool
http2_write_rst_stream(uint32_t error_code, IOVec iov)
{
Expand Down
7 changes: 3 additions & 4 deletions proxy/http2/HTTP2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class HTTPHdr;

typedef unsigned Http2StreamId;

constexpr Http2StreamId HTTP2_CONNECTION_CONTROL_STRTEAM = 0;
constexpr uint8_t HTTP2_FRAME_NO_FLAG = 0;

// [RFC 7540] 6.9.2. Initial Flow Control Window Size
// the flow control window can be come negative so we need to track it with a signed type.
typedef int32_t Http2WindowSize;
Expand Down Expand Up @@ -320,10 +323,6 @@ bool http2_parse_frame_header(IOVec, Http2FrameHeader &);

bool http2_write_frame_header(const Http2FrameHeader &, IOVec);

bool http2_write_data(const uint8_t *, size_t, const IOVec &);

bool http2_write_headers(const uint8_t *, size_t, const IOVec &);

bool http2_write_rst_stream(uint32_t, IOVec);

bool http2_write_settings(const Http2SettingsParameter &, const IOVec &);
Expand Down
27 changes: 16 additions & 11 deletions proxy/http2/Http2ClientSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB
this->read_buffer->water_mark = connection_state.server_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE);
this->_reader = reader ? reader : this->read_buffer->alloc_reader();

this->write_buffer = new_MIOBuffer(HTTP2_HEADER_BUFFER_SIZE_INDEX);
// Set write buffer size to max size of TLS record (16KB)
this->write_buffer = new_MIOBuffer(BUFFER_SIZE_INDEX_16K);
this->sm_writer = this->write_buffer->alloc_reader();

this->_handle_if_ssl(new_vc);
Expand Down Expand Up @@ -332,6 +333,19 @@ Http2ClientSession::set_half_close_local_flag(bool flag)
half_close_local = flag;
}

int64_t
Http2ClientSession::xmit(const Http2TxFrame &frame)
{
int64_t len = frame.write_to(this->write_buffer);

if (len > 0) {
total_write_len += len;
write_reenable();
}

return len;
}

int
Http2ClientSession::main_event_handler(int event, void *edata)
{
Expand All @@ -356,16 +370,6 @@ Http2ClientSession::main_event_handler(int event, void *edata)
break;
}

case HTTP2_SESSION_EVENT_XMIT: {
Http2Frame *frame = static_cast<Http2Frame *>(edata);
total_write_len += frame->size();
write_vio->nbytes = total_write_len;
frame->xmit(this->write_buffer);
write_reenable();
retval = 0;
break;
}

case HTTP2_SESSION_EVENT_REENABLE:
// VIO will be reenableed in this handler
retval = (this->*session_handler)(VC_EVENT_READ_READY, static_cast<VIO *>(e->cookie));
Expand All @@ -391,6 +395,7 @@ Http2ClientSession::main_event_handler(int event, void *edata)
retval = 0;
break;

case HTTP2_SESSION_EVENT_XMIT:
default:
Http2SsnDebug("unexpected event=%d edata=%p", event, edata);
ink_release_assert(0);
Expand Down
92 changes: 2 additions & 90 deletions proxy/http2/Http2ClientSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Plugin.h"
#include "ProxySession.h"
#include "Http2ConnectionState.h"
#include "Http2Frame.h"
#include <string_view>
#include "tscore/ink_inet.h"
#include "tscore/History.h"
Expand Down Expand Up @@ -77,96 +78,6 @@ struct Http2UpgradeContext {
Http2ConnectionSettings client_settings;
};

class Http2Frame
{
public:
Http2Frame(const Http2FrameHeader &h, IOBufferReader *r, bool e = false) : hdr(h), ioreader(r), from_early_data(e) {}
Http2Frame(Http2FrameType type, Http2StreamId streamid, uint8_t flags, bool e = false)
: hdr({0, (uint8_t)type, flags, streamid}), from_early_data(e)
{
}

IOBufferReader *
reader() const
{
return ioreader;
}

const Http2FrameHeader &
header() const
{
return this->hdr;
}

// Allocate an IOBufferBlock for payload of this frame.
void
alloc(int index)
{
this->ioblock = new_IOBufferBlock();
this->ioblock->alloc(index);
}

// Return the writeable buffer space for frame payload
IOVec
write()
{
return make_iovec(this->ioblock->end(), this->ioblock->write_avail());
}

// Once the frame has been serialized, update the payload length of frame header.
void
finalize(size_t nbytes)
{
if (this->ioblock) {
ink_assert((int64_t)nbytes <= this->ioblock->write_avail());
this->ioblock->fill(nbytes);

this->hdr.length = this->ioblock->size();
}
}

void
xmit(MIOBuffer *iobuffer)
{
// Write frame header
uint8_t buf[HTTP2_FRAME_HEADER_LEN];
http2_write_frame_header(hdr, make_iovec(buf));
iobuffer->write(buf, sizeof(buf));

// Write frame payload
// It could be empty (e.g. SETTINGS frame with ACK flag)
if (ioblock && ioblock->read_avail() > 0) {
iobuffer->append_block(this->ioblock.get());
}
}

int64_t
size()
{
if (ioblock) {
return HTTP2_FRAME_HEADER_LEN + ioblock->size();
} else {
return HTTP2_FRAME_HEADER_LEN;
}
}

bool
is_from_early_data() const
{
return this->from_early_data;
}

// noncopyable
Http2Frame(Http2Frame &) = delete;
Http2Frame &operator=(const Http2Frame &) = delete;

private:
Http2FrameHeader hdr; // frame header
Ptr<IOBufferBlock> ioblock; // frame payload
IOBufferReader *ioreader = nullptr;
bool from_early_data = false;
};

class Http2ClientSession : public ProxySession
{
public:
Expand Down Expand Up @@ -194,6 +105,7 @@ class Http2ClientSession : public ProxySession

// more methods
void write_reenable();
int64_t xmit(const Http2TxFrame &frame);

////////////////////
// Accessors
Expand Down
Loading