Skip to content

Commit

Permalink
Add missing parts of defaults buffer size increase. (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatfate authored Mar 5, 2024
1 parent 4ed0cd6 commit f6c7ecf
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
6 changes: 3 additions & 3 deletions chronos/apps/http/httpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import std/[tables, uri, strutils]
import stew/[base10], httputils, results
import ../../[asyncloop, asyncsync]
import ../../[asyncloop, asyncsync, config]
import ../../streams/[asyncstream, boundstream, chunkstream]
import "."/[httptable, httpcommon, multipart]
from ../../transports/common import TransportAddress, ServerFlags, `$`, `==`
Expand Down Expand Up @@ -244,7 +244,7 @@ proc new*(
serverUri = Uri(),
serverIdent = "",
maxConnections: int = -1,
bufferSize: int = 4096,
bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192,
Expand Down Expand Up @@ -304,7 +304,7 @@ proc new*(
serverUri = Uri(),
serverIdent = "",
maxConnections: int = -1,
bufferSize: int = 4096,
bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192,
Expand Down
10 changes: 6 additions & 4 deletions chronos/apps/http/multipart.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export asyncloop, httptable, httpcommon, httpbodyrw, asyncstream, httputils
const
UnableToReadMultipartBody = "Unable to read multipart message body, reason: "
UnableToSendMultipartMessage = "Unable to send multipart message, reason: "
MaxMultipartHeaderSize = 4096

type
MultiPartSource* {.pure.} = enum
Expand Down Expand Up @@ -142,10 +143,11 @@ proc init*[A: BChar, B: BChar](mpt: typedesc[MultiPartReader],
MultiPartReader(kind: MultiPartSource.Buffer,
buffer: buf, offset: 0, boundary: fboundary)

proc new*[B: BChar](mpt: typedesc[MultiPartReaderRef],
stream: HttpBodyReader,
boundary: openArray[B],
partHeadersMaxSize = 4096): MultiPartReaderRef =
proc new*[B: BChar](
mpt: typedesc[MultiPartReaderRef],
stream: HttpBodyReader,
boundary: openArray[B],
partHeadersMaxSize = MaxMultipartHeaderSize): MultiPartReaderRef =
## Create new MultiPartReader instance with `stream` interface.
##
## ``stream`` is stream used to read data.
Expand Down
6 changes: 3 additions & 3 deletions chronos/apps/http/shttpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{.push raises: [].}

import httpserver
import ../../asyncloop, ../../asyncsync
import ../../[asyncloop, asyncsync, config]
import ../../streams/[asyncstream, tlsstream]
export asyncloop, asyncsync, httpserver, asyncstream, tlsstream

Expand Down Expand Up @@ -91,7 +91,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
serverIdent = "",
secureFlags: set[TLSFlags] = {},
maxConnections: int = -1,
bufferSize: int = 4096,
bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192,
Expand Down Expand Up @@ -157,7 +157,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
serverIdent = "",
secureFlags: set[TLSFlags] = {},
maxConnections: int = -1,
bufferSize: int = 4096,
bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192,
Expand Down
5 changes: 5 additions & 0 deletions chronos/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const
chronosStreamDefaultBufferSize* {.intdefine.} = 16384
## Default size of chronos async stream internal buffer.

chronosTLSSessionCacheBufferSize* {.intdefine.} = 4096
## Default size of chronos TLS Session cache's internal buffer.

when defined(chronosStrictException):
{.warning: "-d:chronosStrictException has been deprecated in favor of handleException".}
# In chronos v3, this setting was used as the opposite of
Expand All @@ -123,6 +126,8 @@ when defined(debug) or defined(chronosConfig):
chronosTransportDefaultBufferSize)
printOption("chronosStreamDefaultBufferSize",
chronosStreamDefaultBufferSize)
printOption("chronosTLSSessionCacheBufferSize",
chronosTLSSessionCacheBufferSize)

# In nim 1.6, `sink` + local variable + `move` generates the best code for
# moving a proc parameter into a closure - this only works for closure
Expand Down
6 changes: 3 additions & 3 deletions chronos/streams/boundstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
{.push raises: [].}

import results
import ../asyncloop, ../timer
import asyncstream, ../transports/stream, ../transports/common
import ../[asyncloop, timer, config]
import asyncstream, ../transports/[stream, common]
export asyncloop, asyncstream, stream, timer, common

type
Expand All @@ -44,7 +44,7 @@ type
BoundedStreamRW* = BoundedStreamReader | BoundedStreamWriter

const
BoundedBufferSize* = 4096
BoundedBufferSize* = chronosStreamDefaultBufferSize
BoundarySizeDefectMessage = "Boundary must not be empty array"

template newBoundedStreamIncompleteError(): ref BoundedStreamError =
Expand Down
6 changes: 3 additions & 3 deletions chronos/streams/chunkstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

{.push raises: [].}

import ../asyncloop, ../timer
import asyncstream, ../transports/stream, ../transports/common
import ../[asyncloop, timer, config]
import asyncstream, ../transports/[stream, common]
import results
export asyncloop, asyncstream, stream, timer, common, results

const
ChunkBufferSize = 4096
ChunkBufferSize = chronosStreamDefaultBufferSize
MaxChunkHeaderSize = 1024
ChunkHeaderValueSize = 8
# This is limit for chunk size to 8 hexadecimal digits, so maximum
Expand Down
10 changes: 7 additions & 3 deletions chronos/streams/tlsstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import
bearssl/[brssl, ec, errors, pem, rsa, ssl, x509],
bearssl/certs/cacert
import ".."/[asyncloop, asyncsync, config, timer]
import asyncstream, ../transports/stream, ../transports/common
import asyncstream, ../transports/[stream, common]
export asyncloop, asyncsync, timer, asyncstream

const
TLSSessionCacheBufferSize* = chronosTLSSessionCacheBufferSize

type
TLSStreamKind {.pure.} = enum
Client, Server
Expand Down Expand Up @@ -777,11 +780,12 @@ proc init*(tt: typedesc[TLSCertificate],
raiseTLSStreamProtocolError("Could not find any certificates")
res

proc init*(tt: typedesc[TLSSessionCache], size: int = 4096): TLSSessionCache =
proc init*(tt: typedesc[TLSSessionCache],
size: int = TLSSessionCacheBufferSize): TLSSessionCache =
## Create new TLS session cache with size ``size``.
##
## One cached item is near 100 bytes size.
var rsize = min(size, 4096)
let rsize = min(size, 4096)
var res = TLSSessionCache(storage: newSeq[byte](rsize))
sslSessionCacheLruInit(addr res.context, addr res.storage[0], rsize)
res
Expand Down

0 comments on commit f6c7ecf

Please sign in to comment.