Path: redb-route/redb.Route.As2/As2EndpointOptions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As2/As2EndpointOptions.cs ---- using redb.Route.Abstractions; using redb.Route.Http; using redb.Route.Core; namespace redb.Route.As2; /// /// Strongly-typed options for an AS2 endpoint, bound from URI query parameters by /// . Secrets are marked [Sensitive] so they are /// redacted in logs. A partner profile (certificates, IDs, algorithms) usually comes from a named /// in the registry via connectionFactory=name. The agreement has one /// source: with a factory named, the inline agreement options below are refused on the URI; without one, they are the /// whole agreement (no certificates, so only for an agreement that neither signs nor encrypts). /// public sealed class As2EndpointOptions : EndpointOptions { // ── Transport ──────────────────────────────────────────────────────────── /// Bind address for the AS2 receive server (consumer). Default 0.0.0.0. public string Host { get; set; } = "0.0.0.0"; /// Listen port for the AS2 receive server (consumer). Default 4080. public int Port { get; set; } = 4080; /// Partner endpoint URL the producer POSTs to. Reconstructed from the URI when absent. public string? PartnerUrl { get; set; } /// /// A registry reference (#name) to an that /// decides which headers this endpoint carries between the exchange and the HTTP headers of an AS2 message, in /// place of . /// [RegistryReference(typeof(IHeaderFilterStrategy))] public string? HeaderFilterStrategy { get; set; } /// Use HTTPS/TLS. Set automatically when the URI scheme is as2s. public bool UseTls { get; set; } // ── Admission limit (HTTP_CONCURRENCY_LIMITS_PLAN) ── /// Default of . public const int DefaultMaxConcurrentRequests = 32; /// Default of while limits. public const int DefaultRequestQueueLimit = 32; private int? _requestQueueLimit; /// /// Maximum concurrent executions of this receiver's pipeline. Default 32; 0 = unlimited. /// Overflow beyond the limit and is shed with /// before any MIME/crypto work; AS2 partners retry on their /// own MDN timeouts, which makes early shedding cheaper than a saturated receiver. /// public int MaxConcurrentRequests { get; set; } = DefaultMaxConcurrentRequests; /// /// Requests over the limit that WAIT for a permit (FIFO); 0 = reject immediately. When not set: 32 while /// limits, 0 when it is 0 (unlimited, nothing to wait for). /// public int RequestQueueLimit { get => _requestQueueLimit ?? (MaxConcurrentRequests > 0 ? DefaultRequestQueueLimit : 0); set => _requestQueueLimit = value; } /// /// Status code of a refused request: shed by the admission limit, or finding every asynchronous MDN slot taken /// (). Default 503 Service Unavailable: the receiver is busy, the partner resends. /// public int RejectStatusCode { get; set; } = 503; /// /// Value of the Retry-After header on a refused request; 0 = do not send it. Default 30: an AS2 resend /// carries the whole message again, so the partner is told to wait long enough for the load to pass. /// public int RetryAfterSeconds { get; set; } = 30; /// /// Receive side: how many asynchronous MDNs the receiver handles at once. A message that asks for one takes a slot /// when it is admitted, before any work, and keeps it until its receipt is posted (retries included); with every /// slot taken it is refused with and . Default 20. /// public int AsyncMdnPoolSize { get; set; } = 20; /// /// Receive side: how many times an asynchronous MDN is posted before the receiver gives up on it (1 = no retry). /// A post is tried again after a connection failure, a timeout, 408, 429 or a 5xx answer, not after another 4xx. /// Default 3. /// public int AsyncMdnAttempts { get; set; } = 3; /// /// Receive side: milliseconds before the first retry of an asynchronous MDN, doubled for each one after it. /// Default 5000. /// public int AsyncMdnRetryDelay { get; set; } = 5000; /// /// PFX certificate the receive server presents to the trading partner. This is the TLS server /// certificate, a different thing from , which /// signs and decrypts the S/MIME payload. May be left unset when the host carries a default /// (AddRedbRouteHttpHosting(o => o.Tls.DefaultCertificatePath = ...)); a receive /// endpoint with TLS and no certificate in either place refuses to bind. /// public string? SslCertPath { get; set; } /// Password for . [Sensitive] public string? SslCertPassword { get; set; } /// /// Timeout in milliseconds of an outgoing POST: the message on a send, the asynchronous MDN on a receive. /// Default 30000. /// public int Timeout { get; set; } = 30000; /// Default of : 100 MB, as the AS4 receiver. public const long DefaultMaxRequestBodySize = 100L * 1024 * 1024; /// Default of : 4 MB, ample for an MDN. public const long DefaultMaxResponseBodySize = 4L * 1024 * 1024; /// /// Receive side (messages and MDNs): the largest request body accepted, in bytes; a larger one is answered 413 /// before it is read. The received message is processed in memory (body, decrypted content and payload), so this /// also bounds the memory one request takes. Default . /// public long MaxRequestBodySize { get; set; } = DefaultMaxRequestBodySize; /// /// Receive side: the most bytes a compressed message (RFC 3274) may inflate to. A few kilobytes of compressed data /// can inflate to gigabytes, and the inflated payload is spooled and, without , held in /// memory; past this limit the inflating stops and the message is refused with decompression-failed. Unset /// (default): , so the payload a request hands over is bounded as its body is. /// public long? MaxDecompressedSize { get; set; } /// The bound of a decompressed payload: , else . internal long DecompressedLimit => MaxDecompressedSize ?? MaxRequestBodySize; /// /// Send side: the largest response body read, in bytes (the synchronous MDN). A larger one (a proxy's error page, /// say) fails the send without being read. Default . /// public long MaxResponseBodySize { get; set; } = DefaultMaxResponseBodySize; // ── Partner binding ────────────────────────────────────────────────────── /// Name of an registered in the route context. [RegistryReference(typeof(As2ConnectionFactory))] public string? ConnectionFactory { get; set; } /// /// Receive side: name of an IIdempotentRepository registered with context.AddIdempotentRepository(name, repo) /// (the contract of the IdempotentConsumer EIP and of the AS4 and S3 receivers). It remembers received /// Message-IDs: a message received again is answered with a positive MDN carrying /// processed/warning: duplicate-document and not delivered twice. The id is claimed after the message /// authenticated and released when the route fails, so the partner's resend is then delivered. Unset (default): /// every copy is delivered. Which store it is (memory, redb, SQL) decides whether it survives a restart and works /// across nodes; give the endpoint one of its own. /// [RegistryReference(typeof(IIdempotentRepository))] public string? IdempotentRepository { get; set; } /// /// Receive side, with : milliseconds after which a claim of a Message-ID that /// was never confirmed is taken to be left by a stopped node and taken over, so its message is processed. A younger /// one means the message is still in a route: a copy that arrives meanwhile is refused with /// and , not answered as a duplicate. Takes effect with a /// repository that keeps the confirmed state (the redb, SQL and in-memory ones do). Default 600000 (10 minutes). /// public int InFlightClaimTimeout { get; set; } = 600_000; /// /// Receive side: if true, the exchange body is a Stream (the spooled payload) instead of a byte array, as /// streamBody does for the AS4, File, SFTP and S3 consumers; Exchange.DisposeAsync() closes it. Either way /// the connector spools the request and each decrypted and decompressed stage to a temporary file past the core /// stream-cache threshold, instead of holding them in memory, and hands the payload over only after it is decrypted, /// verified and decompressed. Default false. /// public bool StreamBody { get; set; } /// What a receive endpoint accepts: business messages (default) or async MDN receipts. public As2ReceiveMode Mode { get; set; } = As2ReceiveMode.Message; // ── Agreement (inline; refused when a connection factory is named) ─────── /// Sign outgoing / expect signed incoming (S/MIME). Default true. public bool Sign { get; set; } = true; /// Encrypt outgoing / expect encrypted incoming (S/MIME). Default true. public bool Encrypt { get; set; } = true; /// Compress the payload (RFC 3274). Default false. public bool Compress { get; set; } /// Signature digest algorithm (sha-256, sha-384, ...). Default sha-256. public string SignAlg { get; set; } = "sha-256"; /// Encryption algorithm (aes-128-cbc, aes-256-cbc, ...). Default aes-128-cbc. public string EncryptAlg { get; set; } = "aes-128-cbc"; /// MDN mode: , or . public As2MdnMode MdnMode { get; set; } = As2MdnMode.Sync; /// Request/produce a signed MDN. Default true. public bool SignedMdn { get; set; } = true; /// Hard-fail a send on an unacceptable MDN (negative / MIC mismatch / missing required signature). public bool RequireValidMdn { get; set; } /// URL the partner posts asynchronous MDNs to (our receiver). Required for async MDN. public string? AsyncMdnUrl { get; set; } /// /// Receive side: comma-separated hosts an asynchronous MDN may be posted to (see /// ). Required for a receive endpoint whose MDN mode is async. /// public string? AsyncMdnAllowedHosts { get; set; } // ── Identity ───────────────────────────────────────────────────────────── /// Our AS2 identifier (AS2-From on send, expected AS2-To on receive). public string? As2From { get; set; } /// Partner AS2 identifier (AS2-To on send, expected AS2-From on receive). public string? As2To { get; set; } /// Permits the legacy algorithms sha-1 and 3des (see ). public bool AllowLegacyAlgorithms { get; set; } /// public override void Validate() { if (Port is < 1 or > 65535) throw new ArgumentOutOfRangeException(nameof(Port), Port, "AS2 port must be between 1 and 65535."); if (Timeout < 0) throw new ArgumentOutOfRangeException(nameof(Timeout), Timeout, "AS2 timeout must be non-negative."); if (MaxRequestBodySize <= 0) throw new ArgumentOutOfRangeException(nameof(MaxRequestBodySize), MaxRequestBodySize, "AS2 maxRequestBodySize must be positive."); if (InFlightClaimTimeout < 1) throw new ArgumentOutOfRangeException(nameof(InFlightClaimTimeout), InFlightClaimTimeout, "AS2 inFlightClaimTimeout must be positive."); if (AsyncMdnPoolSize < 1) throw new ArgumentOutOfRangeException(nameof(AsyncMdnPoolSize), AsyncMdnPoolSize, "AS2 asyncMdnPoolSize must be at least 1."); if (AsyncMdnAttempts < 1) throw new ArgumentOutOfRangeException(nameof(AsyncMdnAttempts), AsyncMdnAttempts, "AS2 asyncMdnAttempts must be at least 1."); if (AsyncMdnRetryDelay < 0) throw new ArgumentOutOfRangeException(nameof(AsyncMdnRetryDelay), AsyncMdnRetryDelay, "AS2 asyncMdnRetryDelay must be non-negative."); if (MaxDecompressedSize is <= 0) throw new ArgumentOutOfRangeException(nameof(MaxDecompressedSize), MaxDecompressedSize, "AS2 maxDecompressedSize must be positive."); if (MaxResponseBodySize <= 0) throw new ArgumentOutOfRangeException(nameof(MaxResponseBodySize), MaxResponseBodySize, "AS2 maxResponseBodySize must be positive."); ConcurrencyLimitOptions.ValidateShape(MaxConcurrentRequests, RequestQueueLimit, RejectStatusCode, RetryAfterSeconds); if (MdnMode == As2MdnMode.Async && string.IsNullOrEmpty(AsyncMdnUrl) && string.IsNullOrEmpty(ConnectionFactory)) throw new ArgumentException("Async MDN requires 'asyncMdnUrl' or a 'connectionFactory' that provides it."); if (Sign && !Crypto.As2CryptoEngine.IsSupportedDigest(SignAlg)) throw new ArgumentException($"Unsupported AS2 signature algorithm '{SignAlg}'. Supported: sha-1, sha-256, sha-384, sha-512."); if (Encrypt && !Crypto.As2CryptoEngine.IsSupportedEncryption(EncryptAlg)) throw new ArgumentException($"Unsupported AS2 encryption algorithm '{EncryptAlg}'. Supported: aes-128-cbc, aes-192-cbc, aes-256-cbc, 3des."); if (!AllowLegacyAlgorithms && (As2Profile.IsLegacy(SignAlg) || (Encrypt && As2Profile.IsLegacy(EncryptAlg)))) throw new ArgumentException( $"AS2 algorithm '{(As2Profile.IsLegacy(SignAlg) ? SignAlg : EncryptAlg)}' is legacy (sha-1, 3des); set allowLegacyAlgorithms=true only if the partner requires it."); } /// protected override string? UnknownParameterHint(string name) => string.Equals(name, "certPassword", StringComparison.OrdinalIgnoreCase) ? "The S/MIME certificates and their passwords belong on the As2ConnectionFactory the endpoint names (connectionFactory=...), not in the URI; the TLS certificate is sslCertPath/sslCertPassword." : null; }