stun_shsp 0.5.1
stun_shsp: ^0.5.1 copied to clipboard
Combines STUN (RFC 5389) and SHSP protocols into a unified handler for NAT traversal and peer-to-peer UDP communication. Supports dual IPv4/IPv6 stacks, runtime socket migration, optional compression, [...]
0.5.0 #
Fixed #
- The
stun_shspbarrel no longer re-exportsstun's@internalmixins (StunHandlerMixin,DualStunHandlerMixin,NATDetectorMixin,StunLoggerMixin,StunMessageMixin,StunServerResolverMixin,HandlerFactoryMixin,HandlerSelectorMixin,DestroyableHandlerMixin,DualHandlerDelegationMixin,DualStunHandlerMigratableMixin,NATTestResult), which trippedinvalid_export_of_internal_elementunderdart analyze --fatal-infos. They were implementation details of thestunpackage that nothing here used.
0.4.0 #
Changed — breaking #
Ported the package to the current shsp, stun and singleton_manager 2.x APIs, adopting the same architecture as those packages (config sector, @dependencyInjectable classes with generated factories, a generated main_injection.dart, registry wiring helpers).
- The socket "wrapper" is gone, following
shsp:IShspSocketWrapper/ShspSocketWrapperbecomeIShspSocketMigratable/ShspSocketMigratable, andShspSocketWrapperDelegationMixinbecomesShspSocketMigratableDelegationMixin.IStunShspHandler.shspSocketis now anIShspSocketMigratable. - Dual-stack selection is by
InternetAddressTypeinstead of abool ipv6, followingstun:close({type}),setStunServer(address, port, {type}),getHandler/setHandler/clearHandler/replaceHandler({type}),getLastStunUpdated({type}),migrateSocket(socket, [type]),getSocket([type]). DualStunShspHandlernow extendsDualShspSocketAutoand implementsIDualShspSocketAutoonly. It is no longer anIDualStunHandler, becauseIDualStunHandler.getSocket({type})andIDualShspSocket.getSocket([type])cannot both be satisfied by one member; the dual STUN handler is exposed asdualStunHandler, and the rest of its surface is forwarded by the newDualStunHandlerDelegationMixin. Its per-family handlers areipv4StunShspHandler/ipv6StunShspHandler/getStunShspHandler([type])and are nullable, since a host without IPv6 binds one socket only.initializePointStunShsp()andinitializePointRegistryStunShsp(key)are replaced byinitializeStunShsp({key}),StunShspInjectorandconnectStunShspHandlerSubkeys({key}), onRegistryManager.instanceinstead ofSingletonDIAccess/RegistryAccess. Everything is keyed, so the two entry points collapse into one.StunShspInjectorwires all three graphs from its before hooks —DualShspInjector(which binds the ipv4/ipv6RawDatagramSockets) and thenregisterAllSingletonsStun— so the STUN graph of thestunpackage resolves onto the very same sockets as the SHSP one.DualStunInjectoris deliberately not used: it would bind sockets of its own and overwrite those connections.lib/generated/stun_shsp_handler_di.dartis replaced by the generatedlib/main_injection.dart(MainInjectionStunShspMixin.registerAllSingletonsStunShsp). Both handlers are now@dependencyInjectableand carry a generateddependencyInjectionFactory.- The mixins are renamed after the
shspconvention:IStunHandlerDelegationMixin→StunHandlerDelegationMixin,IDualStunHandlerDelegationMixin→DualStunHandlerDelegationMixin. They no longer forward the members that the new STUN API dropped (addOnSocketRefresh/removeOnSocketRefresh,initializeDI,setIpv4Handler/clearIpv4Handler,ipv4LastStunUpdatedand friends) and now forwardgetIpVersion(). - Neither interface implements
IValueForRegistryany more — it no longer exists insingleton_manager2.x. - Sources moved to
lib/src/implementations/(was the misspelledimlementations/), withlib/src/nat/andlib/src/registry/next to it, mirroring thestunpackage layout.
Added #
config_manager-based configuration, following the same architecture as thestunandshsppackages, but reading their sectors instead of duplicating them: thestun_shspsector owns only the bind ports (stunShspConfig.socket.port/ipv4Port/ipv6Port), while the address family comes fromipVersionof thestunsector, the STUN server and thenatsection from that same sector, and keep-alive/handshake/retry from theshspone — so configuringstun/shspconfigures this package too and no value exists twice. ShipsdefaultStunShspConfig,initStunShspConfig()/ensureStunShspConfig(),unwrapStunShspConfig()/mergeStunShspConfig(), theStunShspConfigExtensionmixin (typed getters for the ports and for the borrowed values:defaultIpv6Enabled,defaultNatPrimaryServer/Port/Timeout,defaultStunServerAddress/Port,defaultStunTimeout,defaultKeepAliveSeconds) and static-context helpers (defaultStunShspIpv6Enabled(),defaultStunShspPort(),defaultStunShspIpv4Port(),defaultStunShspIpv6Port(),defaultStunShspNatPrimaryServer(),defaultStunShspNatPrimaryPort(),defaultStunShspNatTimeout(),stunShspConfigValue()).initStunShspConfig()remains the single entry point: it loads the ports and forwardssocket.ipv6→stun.ipVersion,nat→ thestunsector and ashspsection → theshspsector, deep-merging so a configuration loaded earlier keeps what the call doesn't mention; with no arguments it resets every sector it reads.stunShspConfigValue()reads this sector only — usestunConfigValue()for thenat/serversections.- Test coverage for the configuration defaults, the deep-merge of overrides, the nested-document form, and the static-context helpers (
stun_shsp_config_test.dart), for the registry wiring (stun_shsp_registry_wiring_test.dart) and for the dual handler (dual_stun_shsp_handler_test.dart). StunShspHandler(socket, {address, port, timeout, onLog})takes the STUN server and timeout, so a handler no longer has to be built against the configured server and then reconfigured.DualStunShspHandler.fromSockets(Sockets), which wraps plain sockets into migratable ones.- Registry-level socket migration, the counterpart of
migrateShspSocket/migrateStunHandlerSocketin theshspandstunpackages and delegating to both:migrateStunShspSocket(socket, {key}),migrateStunShspSocketIpv4({key})/migrateStunShspSocketIpv6({key}),migrateDualStunShspSockets({ipv4Socket, ipv6Socket, key})andmigrateStunHandlerEntry(socket, {key}). The handlers and the migratable wrapper are never replaced — only theRawDatagramSocket/IShspSocketentries and the plainIStunHandlerof the STUN graph move — soIStunShspHandler,IDualStunShspHandlerand every peer holding them keep working across a swap. Covered bystun_shsp_socket_migration_test.dart. - Examples for the configuration (
config_example.dart), the registry wiring (registry_example.dart) and the socket migration (socket_migration_example.dart); the other examples were rewritten against the new API.
Changed #
StunShspHandler.createDefault()(ipv6,port),DualStunShspHandler.createDefault()(ipv4Port,ipv6Port) andNATDetectorShsp(primaryServer,primaryPort,timeout) take those parameters as optional and fall back to the configuration instead of hardcoded values.NATDetectorShsp.primaryServerandprimaryPortare no longer required.DualStunShspHandler.createDefault()binds IPv6 best-effort instead of failing on hosts without it.- The STUN handler is built on the migratable socket rather than on the socket behind it, so a
migrateSocketmoves both halves at once andgetSocket()reports the new port.
0.3.0 #
Added #
performStunRequest({bool ipv6 = true})now supports per-IP-family discovery. IPv6 is targeted by default, with graceful fallback to IPv4 when no IPv6 socket is available. Passipv6: falseto force IPv4.- STUN responses are now cached independently per IP family (
_cachedIpv4StunResponse,_cachedIpv6StunResponse). - IPv6 STUN test suite (
stun_shsp_handler_ipv6_test.dart); IPv6-only cases skip automatically when the host has no IPv6 connectivity.
Changed #
setStunServer()now invalidates both the IPv4 and IPv6 cached responses so the next request uses the new server.
0.2.2 #
Fixed #
initializePointStunShsp()now registersIShspSocketas an autonomous type in the DI container (initialize_point.dart:14). Previously, consumers resolvingSingletonDIAccess.get<IShspSocket>()would fail because onlyDualShspSocketWrapperDI.ipv4Socketwas accessible through the wrapper.
Added #
- Comprehensive test coverage for all 8 public DI registrations after
initializePointStunShsp(), including identity checks across the object graph (IShspSocket,IDualStunHandler,IDualCallbackHandler,DualShspSocketWrapperDI,StunHandlerBaseDI, etc.) - Consolidated integration test suite (socket migration, STUN requests) into the
stun_shsppackage.
0.2.0 #
Changed #
- Major refactor: STUN requests now run on the same SHSP socket instead of separate raw sockets. This guarantees that the public port discovered by STUN matches exactly the port that P2P peers must use to reach this node — eliminating port mismatch bugs.
- Bumped
stunto^1.5.1 - Bumped
shspto^1.8.0 - Updated SDK constraint to
>=3.5.0 <4.0.0
Added #
- Comprehensive test suite in
stun_shsp_handler_port_test.dartcovering:- STUN/SHSP port matching (core regression test)
- IPv4 and IPv6 socket sanity checks
- Explicit port binding and OS-assigned ports
- Double-initialize guard
- Dual socket structure validation
Fixed #
- STUN discoveries now reflect the exact SHSP socket port used for P2P communication
0.1.4 #
Fixed #
- Fixed
LateInitializationErrorinStunShspHandler.initialize(): now correctly createsStunHandlerSingletoninstance before attempting initialization. The manual initialization path (non-DI) was attempting to access_stunHandlerbefore assignment, violating Dart's late variable contract.
0.1.2 #
Changed #
- Bumped
stunto^1.4.2 - Bumped
shspto^1.6.1 - Bumped
singleton_managerto^0.6.1 - Removed deprecated lint rules (
avoid_returning_null_for_future,invariant_booleans,iterable_contains_unrelated_type,list_remove_unrelated_type) fromanalysis_options.yaml
0.1.0 #
Added #
IStunShspHandlerinterface combining STUN NAT traversal and SHSP socket operationsStunShspHandlerconcrete implementation with dual IPv4/IPv6 supportStunShspHandlerSingleton— Dart singleton wrapper aroundStunShspHandlerStunShspHandlerDI— auto-generated dependency injection class viasingleton_manager_generatorinitializePointStunShsp()— one-call bootstrap that wires SHSP sockets, STUN handlers, and DI registration- Socket migration at runtime via
migrateSocketIpv4()andmigrateSocketIpv6() - Graceful IPv6 fallback: IPv6 socket is created when available, skipped silently otherwise
- Optional compression codec support via
ICompressionCodecpassed toShspSocket - Public API:
performStunRequest(),performLocalRequest(),pingStunServer(),setStunServer(),close() isInitializedgetter onIStunShspHandler/StunShspHandler
Fixed #
initialize()now throwsStateErrorif called afterinjectDependencies(), preventing silent overwrite of DI-injected dependencies