General Upgrade, NEW: WebServers, Better Docs
Some checks failed
CI / checks (push) Failing after 2m23s
Some checks failed
CI / checks (push) Failing after 2m23s
This commit is contained in:
parent
5f11d476b6
commit
3afc75b45d
120 changed files with 10032 additions and 4886 deletions
|
|
@ -362,7 +362,7 @@ impl WasmTransport {
|
|||
}
|
||||
|
||||
/// Try to pull one complete frame out of the buffer without reading more.
|
||||
fn parse_buffer(&self) -> Result<Option<FrameOutcome>, JsValue> {
|
||||
fn parse_buffer(&self, max_message_size: u32) -> Result<Option<FrameOutcome>, JsValue> {
|
||||
let buf = self.buffer.borrow();
|
||||
if buf.len() < 4 {
|
||||
return Ok(None);
|
||||
|
|
@ -371,7 +371,7 @@ impl WasmTransport {
|
|||
if frame_len == CLOSE_FRAME_LEN {
|
||||
return Ok(Some(FrameOutcome::Closed));
|
||||
}
|
||||
if frame_len > self.max_message_size {
|
||||
if frame_len > max_message_size {
|
||||
return Err(js_error("message too large"));
|
||||
}
|
||||
let frame_len = frame_len as usize;
|
||||
|
|
@ -393,9 +393,9 @@ impl WasmTransport {
|
|||
* persistent uni stream) or one-per-stream; both are handled by buffering
|
||||
* across reads and advancing to the next stream when the current one ends.
|
||||
*/
|
||||
async fn next_frame(&self) -> Result<FrameOutcome, JsValue> {
|
||||
async fn next_frame(&self, max_message_size: u32) -> Result<FrameOutcome, JsValue> {
|
||||
loop {
|
||||
if let Some(outcome) = self.parse_buffer()? {
|
||||
if let Some(outcome) = self.parse_buffer(max_message_size)? {
|
||||
return Ok(outcome);
|
||||
}
|
||||
|
||||
|
|
@ -407,7 +407,15 @@ impl WasmTransport {
|
|||
match self.read_chunk().await? {
|
||||
Some(chunk) => {
|
||||
if !chunk.is_empty() {
|
||||
self.buffer.borrow_mut().extend_from_slice(&chunk);
|
||||
let mut buffer = self.buffer.borrow_mut();
|
||||
let maximum_buffer = max_message_size as usize + 4;
|
||||
if buffer.len().saturating_add(chunk.len()) > maximum_buffer {
|
||||
return Err(js_error("message too large"));
|
||||
}
|
||||
buffer
|
||||
.try_reserve(chunk.len())
|
||||
.map_err(|_| js_error("message allocation failed"))?;
|
||||
buffer.extend_from_slice(&chunk);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
|
@ -430,7 +438,10 @@ impl WasmTransport {
|
|||
|
||||
/// Read exactly one application frame (used during the auth handshake).
|
||||
pub async fn read_one_frame(&self) -> Result<Vec<u8>, JsValue> {
|
||||
match self.next_frame().await? {
|
||||
match self
|
||||
.next_frame(self.max_message_size.min(64 * 1024))
|
||||
.await?
|
||||
{
|
||||
FrameOutcome::Frame(frame) => Ok(frame),
|
||||
FrameOutcome::Closed => Err(js_error("connection closed before frame")),
|
||||
FrameOutcome::Ended => Err(js_error("stream ended before frame")),
|
||||
|
|
@ -445,7 +456,7 @@ impl WasmTransport {
|
|||
F: FnMut(JsValue),
|
||||
{
|
||||
loop {
|
||||
match self.next_frame().await {
|
||||
match self.next_frame(self.max_message_size).await {
|
||||
Ok(FrameOutcome::Frame(frame)) => match parse_frame_value(&frame) {
|
||||
Ok(parsed) => {
|
||||
on_message(parsed);
|
||||
|
|
@ -477,16 +488,16 @@ impl WasmTransport {
|
|||
G: FnMut(crate::pipe::PipeReader),
|
||||
{
|
||||
let pipe_request_type =
|
||||
mtp_codec::CommunicationType::PipeRequest.to_id(&mtp_codec::TypeMap::latest());
|
||||
mtp_codec::CommunicationType::PipeRequest.try_to_id(&mtp_codec::TypeMap::latest());
|
||||
|
||||
loop {
|
||||
match self.next_frame().await {
|
||||
match self.next_frame(self.max_message_size).await {
|
||||
Ok(FrameOutcome::Frame(frame)) => {
|
||||
let is_first = self.new_stream_frame.get();
|
||||
if is_first {
|
||||
self.new_stream_frame.set(false);
|
||||
if let Ok(comm) = mtp_codec::CommunicationValue::from_bytes(&frame)
|
||||
&& comm.get_type() == pipe_request_type
|
||||
&& Some(comm.get_type()) == pipe_request_type
|
||||
{
|
||||
let pipe_id = comm.get_id();
|
||||
let description = comm
|
||||
|
|
|
|||
Loading…
Reference in a new issue