Skip to content

Implement turns#1434

Draft
paulomorgado wants to merge 1 commit intosipsorcery-org:masterfrom
paulomorgado:turns
Draft

Implement turns#1434
paulomorgado wants to merge 1 commit intosipsorcery-org:masterfrom
paulomorgado:turns

Conversation

@paulomorgado
Copy link
Copy Markdown
Contributor

@paulomorgado paulomorgado commented Jun 30, 2025

NEW FEATURES:

  • turns implementation

PERFORMANCE OPTIMIZATIONS:

Memory Management:

  • Add PooledSegmentedBuffer<T> for efficient buffer pooling with ArrayPool<T> integration
  • Implement MemoryOperations helper for optimized memory operations
  • Add ValueStringBuilder for stack-allocated string building to reduce heap allocations
  • Introduce SearchValues for optimized span-based searching
  • Use NetEscapades.EnumGenerators to optimize enum usage.

Socket and Network Layer:

  • Refactor NetServices with connection pooling and reduced allocations
  • Add SocketConnection abstraction with concrete implementations (SocketTcpConnection,
    SocketUdpConnection, SocketTlsConnection) for better resource management
  • Optimize IPSocket with span-based parsing and reduced string allocations
  • Enhance PortRange with improved allocation patterns

System Utilities:

  • Add BinaryOperations for bit manipulation optimizations
  • Implement EncodingExtensions for efficient encoding/decoding operations
  • Add HashExtensions for streamlined hash computations

Crypto and Security:

  • Refactor Crypto class with reduced allocations
  • Add SslClientAuthenticationOptions and SslStreamExtensions for down-level targets
  • Optimize CRC32 implementation

Data Serialization:

  • Add SipSorceryJsonSerializerContext for AOT-friendly JSON serialization
  • Remove legacy JSONWriter and JsonParser in favor of System.Text.Json

Protocol Implementations:

  • Optimize RTP/RTCP packet handling with span-based operations
  • Refactor SCTP chunks for reduced allocations
  • Improve SDP parsing with ValueStringBuilder
  • Optimize STUN attribute handling

Codec Optimizations:

  • Extensive refactoring of codes to optimize memory usage
  • Update AudioEncoder with more efficient buffer handling

HIGH-PERFORMANCE LOGGING:

Structured Logging Infrastructure:

  • Introduce LoggerMessageAttribute source generator pattern across all modules
  • Add domain-specific logging extensions for compile-time log message generation

Benefits:

  • Zero-cost logging when log level is disabled
  • Compile-time string formatting
  • Reduced memory allocations in hot paths
  • Type-safe structured logging
  • Improved debuggability with consistent log patterns

MODERNIZATION:

  • Standardize on .NET 10.0 and C# 14.0
    • Used Meziantou.Polyfill for down-level targets
      • Added other polyfills to keep the source code clean of conditional compilation symbols.
    • Introduce BouncyCastleExtensions for down-level targets

RETARGETING:

  • Removed .NET Framework targets from libraries
  • Keep dependencies on the lowest supported LTS version for non-.NET targets
  • Target the same channel for supported .NET targets

SUPPORTING CHANGES:

Type System:

  • Refactor TypeExtensions
  • Add IByteSerializable interface for consistent serialization
  • Add ProtocolTypeExtensions for protocol type handling

Testing:

Supersedes #1335, #1338, #1407, #1414, #1423

…g, polyfills

Enable nullable reference types across the solution and set C# language
version to 14.0. Replace TinyJson with System.Text.Json source-generated
serialization (SipSorceryJsonSerializerContext) and add a single-pass
sanitizer in RTCSessionDescriptionInit.TryParse that escapes raw CR/LF
inside JSON string values without allocating when no escaping is needed.

Introduce compile-time logging extensions (LoggerMessage) for every
subsystem (Media, DTLS-SRTP, ICE, RTCP, RTP, SCTP, SDP, STUN, WebRTC,
sys/Net) to eliminate boxing and string formatting on hot paths.

Add Meziantou.Polyfill and CommunityToolkit.HighPerformance packages to
back-fill modern APIs (Span, FrozenDictionary, SearchValues, etc.) on
older target frameworks. Add System.Text.Json, System.IO.Pipelines, and
Microsoft.Bcl.Cryptography conditional references per TFM.

Extract reusable low-level helpers into sys/: ValueStringBuilder,
MemoryOperations, BinaryOperations, EncodingExtensions, HashExtensions,
BouncyCastleExtensions, PolyfillExtensions, SocketConnection hierarchy,
IPAddressExtension, and more.

Move UdpReceiver from net/RTP to sys/Net. Convert file-scoped namespaces
throughout. Update all projects and test infrastructure accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant