Skip to content

Add Network discovery metadata - #28

Closed
rchatham wants to merge 2 commits into
feature/network-migration-transport-adaptersfrom
feature/network-migration-discovery-metadata
Closed

rchatham wants to merge 2 commits into
feature/network-migration-transport-adaptersfrom
feature/network-migration-discovery-metadata

Conversation

@rchatham

Copy link
Copy Markdown
Owner

Summary

Adds Bonjour discovery identity metadata for the Network transport stack so discovered Network browser results can map to framework-neutral PeerIdentity values and endpoints.

Changes

  • Add PeerNetworkDiscoveryInfo for TXT record encode/decode.
  • Validate discovery metadata:
    • required identifier/display name/protocol version
    • supported protocol version only
    • non-empty values
    • bounded TXT-record-safe advertised lengths
  • Advertise local peer discovery metadata from NetworkPeerListener.
  • Parse NWBrowser.Result Bonjour metadata in NetworkPeerBrowserTransport.
  • Store PeerIdentity -> NWEndpoint mappings for later invitePeer connection attempts.
  • Ignore self-discovery in the browser adapter.
  • Keep malformed/missing metadata ignored.

Non-goals

  • No public backend selector yet.
  • No default backend change.
  • No trust/auth claim for TXT metadata; it is discovery routing data only.
  • No local simulator loopback integration yet.

Verification

  • swift test — 88 tests passed
  • xcodebuild test -project PeerConnectivity.xcodeproj -scheme PeerConnectivity -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' -configuration Debug — 88 tests passed

Stack context

Stacked on PR #27 (feature/network-migration-transport-adapters). This is the discovery metadata slice in the Network migration stack.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Bonjour TXT-record discovery metadata to the internal Network transport so NWBrowser results can be mapped to stable, framework-neutral PeerIdentity values and later resolved back to NWEndpoint for connection attempts.

Changes:

  • Introduces PeerNetworkDiscoveryInfo to encode/decode identity + protocol version into Bonjour TXT records.
  • Advertises local discovery metadata from NetworkPeerListener and parses it in NetworkPeerBrowserTransport.
  • Adds/updates XCTest coverage for discovery TXT record behavior and browser adapter behavior (including self-discovery ignore).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Sources/PeerNetworkProtocol.swift Adds PeerNetworkDiscoveryInfo TXT record encode/decode and validation logic.
Sources/NetworkPeerTransportAdapters.swift Parses Bonjour metadata from NWBrowser.Result, ignores self results, and maps PeerIdentity to NWEndpoint for invitePeer.
Sources/NetworkPeerTransport.swift Advertises discovery TXT record via NWListener.Service(..., txtRecord:) when identity is provided.
PeerConnectivityTests/PeerNetworkProtocolTests.swift Adds round-trip / validation tests for discovery TXT records.
PeerConnectivityTests/NetworkPeerTransportAdapterTests.swift Updates browser transport tests to use explicit identities and adds self-ignore coverage.
Suppressed comments (1)

Sources/PeerNetworkProtocol.swift:65

  • Discovery TXT record validation currently checks String.count for identifier/displayName length. Since the advertised values are constrained in UTF-8 bytes, the validation should also use utf8.count to avoid accepting values that will exceed DNS-SD TXT byte limits (especially for non-ASCII display names).
            protocolVersion == PeerNetworkHandshake.currentProtocolVersion,
            !identifier.isEmpty,
            !displayName.isEmpty,
            identifier.count <= PeerNetworkDiscoveryInfo.maxIdentifierLength,
            displayName.count <= PeerNetworkDiscoveryInfo.maxDisplayNameLength else { return nil }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/PeerNetworkProtocol.swift
Comment thread Sources/NetworkPeerTransportAdapters.swift
Comment thread PeerConnectivityTests/PeerNetworkProtocolTests.swift
@rchatham

Copy link
Copy Markdown
Owner Author

Superseded by consolidated PR #29. No commits were discarded; this branch is preserved as a recovery and reference point. Addressed review findings were replied to and resolved before consolidation.

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.

2 participants