Skip to content

Implement turns#1434

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

Implement turns#1434
paulomorgado wants to merge 1 commit into
sipsorcery-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 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

Related PRs:

@paulomorgado paulomorgado force-pushed the turns branch 8 times, most recently from 9bd9c56 to fa28ad3 Compare April 11, 2026 17:27
@paulomorgado paulomorgado force-pushed the turns branch 2 times, most recently from 9e02eef to 91c559c Compare April 15, 2026 18:14
@paulomorgado paulomorgado force-pushed the turns branch 3 times, most recently from 371e431 to a881b38 Compare April 29, 2026 11:19
@paulomorgado paulomorgado force-pushed the turns branch 5 times, most recently from 0d3588b to b0f66b9 Compare May 7, 2026 09:41
@paulomorgado
Copy link
Copy Markdown
Contributor Author

Hi @sipsorcery, @ispysoftware, @jimm98y, @ha-ves and see how it goes?

I hope it improves memory and CPU performance and, thus, latency.

@ispysoftware
Copy link
Copy Markdown
Contributor

It would be good to get this merged...

@paulomorgado
Copy link
Copy Markdown
Contributor Author

It would be good to get this merged...

This doesn't need to be a all or nothing.

We can do that in phases.

@sipsorcery
Copy link
Copy Markdown
Member

We can do that in phases.

Definitely needs to be in phases. There doesn't seem to be much this PR doesn't touch including a lot of foundation classes.

Ideally some smaller PRs for less critical classes could be split off. That would help build the confidence for the more critical ones.

@ispysoftware
Copy link
Copy Markdown
Contributor

ispysoftware commented May 23, 2026

I added it to my fork a while back - it's been working fine I dunno how it compares to this one with other changes in master. It wasn't very complicated and only touched a few files at the time.

ispysoftware@35712ef

@paulomorgado
Copy link
Copy Markdown
Contributor Author

paulomorgado commented May 25, 2026

I added it to my fork a while back - it's been working fine I dunno how it compares to this one with other changes in master. It wasn't very complicated and only touched a few files at the time.

ispysoftware@35712ef

@ispysoftware, I opted by having a pipeline dedicated to TLS alongside UDP and TCP. Maybe we can simplify that.

@ispysoftware
Copy link
Copy Markdown
Contributor

@paulomorgado I pushed a few changes including turns support
#1635

@paulomorgado
Copy link
Copy Markdown
Contributor Author

@paulomorgado I pushed a few changes including turns support
#1635

@ispysoftware, I saw it, but didn't look at it in detail, yet.

…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.

3 participants