diff --git a/chronos/apps/http/httpserver.nim b/chronos/apps/http/httpserver.nim index 92ed3567..c1e52793 100644 --- a/chronos/apps/http/httpserver.nim +++ b/chronos/apps/http/httpserver.nim @@ -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, `$`, `==` @@ -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, @@ -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, diff --git a/chronos/apps/http/multipart.nim b/chronos/apps/http/multipart.nim index 302d6efd..5c50e461 100644 --- a/chronos/apps/http/multipart.nim +++ b/chronos/apps/http/multipart.nim @@ -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 @@ -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. diff --git a/chronos/apps/http/shttpserver.nim b/chronos/apps/http/shttpserver.nim index 6272bb2b..532839d2 100644 --- a/chronos/apps/http/shttpserver.nim +++ b/chronos/apps/http/shttpserver.nim @@ -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 @@ -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, @@ -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, diff --git a/chronos/config.nim b/chronos/config.nim index cf500dba..26d110f1 100644 --- a/chronos/config.nim +++ b/chronos/config.nim @@ -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 @@ -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 diff --git a/chronos/streams/boundstream.nim b/chronos/streams/boundstream.nim index ce695719..8d2e52c5 100644 --- a/chronos/streams/boundstream.nim +++ b/chronos/streams/boundstream.nim @@ -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 @@ -44,7 +44,7 @@ type BoundedStreamRW* = BoundedStreamReader | BoundedStreamWriter const - BoundedBufferSize* = 4096 + BoundedBufferSize* = chronosStreamDefaultBufferSize BoundarySizeDefectMessage = "Boundary must not be empty array" template newBoundedStreamIncompleteError(): ref BoundedStreamError = diff --git a/chronos/streams/chunkstream.nim b/chronos/streams/chunkstream.nim index 77392076..f3e73e0c 100644 --- a/chronos/streams/chunkstream.nim +++ b/chronos/streams/chunkstream.nim @@ -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 diff --git a/chronos/streams/tlsstream.nim b/chronos/streams/tlsstream.nim index 12ea6d3c..6c019f11 100644 --- a/chronos/streams/tlsstream.nim +++ b/chronos/streams/tlsstream.nim @@ -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 @@ -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