using System; namespace Esiur.Resource; /// /// Runtime configuration owned by a Warehouse instance. /// public sealed class WarehouseConfiguration { public RateControlConfiguration RateControl { get; set; } = new RateControlConfiguration(); public ParserConfiguration Parser { get; set; } = new ParserConfiguration(); public ResourceAttachmentConfiguration ResourceAttachments { get; set; } = new ResourceAttachmentConfiguration(); public ConnectionConfiguration Connections { get; set; } = new ConnectionConfiguration(); public EncryptionConfiguration Encryption { get; set; } = new EncryptionConfiguration(); } /// /// Bounds encrypted transport records before any peer-controlled allocation occurs. /// A value of zero disables the limit. /// public sealed class EncryptionConfiguration { public uint MaximumRecordSize { get; set; } = 8 * 1024 * 1024 + 1024; } /// /// Limits memory and object amplification while parsing untrusted packets. /// A value of zero disables the corresponding limit. /// public sealed class ParserConfiguration { /// Default maximum nesting depth for TRU type metadata. public const int DefaultMaximumTypeMetadataDepth = 64; /// Maximum declared TDU payload retained for one packet. public uint MaximumPacketSize { get; set; } = 8 * 1024 * 1024; /// Maximum allocation produced by one decoded value. public uint MaximumAllocationSize { get; set; } = 4 * 1024 * 1024; /// Maximum number of values decoded into one collection. public int MaximumCollectionItems { get; set; } = 65_536; /// /// Maximum number of nested TRU type-metadata nodes, including the root node. /// A value of zero disables the limit. /// public int MaximumTypeMetadataDepth { get; set; } = DefaultMaximumTypeMetadataDepth; } /// /// Limits resources imported from, or attached by, one remote connection. /// A value of zero disables the corresponding limit. /// public sealed class ResourceAttachmentConfiguration { public int MaximumAttachedResourcesPerConnection { get; set; } = 4_096; public int MaximumPendingAttachmentsPerConnection { get; set; } = 128; public bool RejectDuplicateAttachments { get; set; } = true; } /// /// Configures network connection admission limits. /// A value of zero disables the corresponding limit. /// public sealed class ConnectionConfiguration { public int MaximumConnectionsPerIpAddress { get; set; } = 64; } /// /// Configures how repeated rate-control denials affect an EP connection. /// public sealed class RateControlConfiguration { /// /// Number of denials within that blocks the connection. /// Set to zero to disable connection blocking. /// public int DenialsBeforeConnectionBlock { get; set; } = 5; /// /// Window in which denials are accumulated for connection blocking. /// public TimeSpan DenialWindow { get; set; } = TimeSpan.FromMinutes(1); /// /// Delay before a blocked connection is closed, allowing its final error reply to flush. /// public TimeSpan ConnectionBlockDelay { get; set; } = TimeSpan.FromMilliseconds(100); }