Skip to content

New logic for establishing client connections#3131

Draft
lauckhart wants to merge 10 commits intomatter-js:mainfrom
lauckhart:peer-connection
Draft

New logic for establishing client connections#3131
lauckhart wants to merge 10 commits intomatter-js:mainfrom
lauckhart:peer-connection

Conversation

@lauckhart
Copy link
Collaborator

Most of this will be difficult to separate into separate commits so will likely need a "big bang" merge. And is maybe best considered "unreviewable" 🙄.

In addition to inevitable bugs this commit does not address legacy codepaths and thus leaves a large amount of deprecated code in place.

Overview:

  • Adds PeerConnection function that performs Peer (re-)connection. This implements new connection logic we've discussed and isolates relevant state to a single closure.

  • Other relevant bits include Peer.connect() and PeerExchangeProvider.

  • Numerous changes to existing @matter/protocol components in support of above. I tried to keep these changes minimal but the diffs end up pretty horrendous... Mostly this deals with new options

  • Adds additional information to PeerDescriptor, improves logic for reacting to descriptor changes, and now uses a partial descriptor to add/configure peers

  • Adds optional access to Interactable and NodeProtocol via Peer class. This makes generic access to Peer features (e.g. reading Basic Information attributes) from @node/protocol more straightforward

  • Improves ActionContext and constituent interfaces to make them more useful in a client context. For example you can now do e.g. toggle(undefined, { abort }) to make an invoke abortable

  • Adds NetworkProfiles to manage semaphores associated with network access, identified by a string name

  • Adds configurability to MRP handling to support new connection logic (namely, maximum backoff time and maximum number of retries)

  • Moves some logic generic logic from @matter/node to @matter/protocol

  • Changes lifecycle management of some dependencies of @matter/node to align them with the ServerNode instead of ServerNetworkRuntime

  • Various other updates to @matter/node involve movement to @matter/protocol code paths, but there are also various general improvements to issues I encountered along the way

  • Adds PeerTimingParameters to control new connection logic

  • Makes more operations abortable

  • Improves PeerAddress interning and ClientNode#peerAddress management

  • Considerable rework of network error handling to improve naming and consistency

@lauckhart lauckhart force-pushed the peer-connection branch 4 times, most recently from b58e583 to a91e492 Compare February 1, 2026 04:27
const session = await this.#peer.connect(options);

const network = this.#context.networks.select(this.#peer, options?.network);
const slot = await network.semaphore.obtainSlot(abort);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we get some kinda of network info somehow into the log also at least on level of exchange creation or logging ... would potentially be easier for debugging

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean specifically relating to semaphore slots held or something more general?

For semaphore specifically dedicated messages seem noisy but maybe we could log "slow acquisition" similar to how we handle transactions

Most of this will be difficult to separate into separate commits so will likely need a "big bang" merge.  And is maybe best considered "unreviewable" 🙄.

In addition to inevitable bugs this commit does not address legacy codepaths and thus leaves a large amount of deprecated code in place.

Overview:

* Adds `PeerConnection` function that performs Peer (re-)connection.  This implements new connection logic we've discussed and isolates relevant state to a single closure.

* Other relevant bits include `Peer.connect()` and `PeerExchangeProvider`.

* Numerous changes to existing `@matter/protocol` components in support of above.  I tried to keep these changes minimal but the diffs end up pretty horrendous...  Mostly this deals with new options

* Adds additional information to `PeerDescriptor`, improves logic for reacting to descriptor changes, and now uses a partial descriptor to add/configure peers

* Adds optional access to `Interactable` and `NodeProtocol` via `Peer` class.  This makes generic access to Peer features (e.g. reading Basic Information attributes) from @node/protocol more straightforward

* Improves `ActionContext` and constituent interfaces to make them more useful in a client context.  For example you can now do e.g. `toggle(undefined, { abort })` to make an invoke abortable

* Adds `NetworkProfiles` to manage semaphores associated with network access, identified by a string name

* Adds configurability to MRP handling to support new connection logic (namely, maximum backoff time and maximum number of retries)

* Moves some logic generic logic from `@matter/node` to `@matter/protocol`

* Changes lifecycle management of some dependencies of `@matter/node` to align them with the `ServerNode` instead of `ServerNetworkRuntime`

* Various other updates to `@matter/node` involve movement to `@matter/protocol` code paths, but there are also various general improvements to issues I encountered along the way

* Adds `PeerTimingParameters` to control new connection logic

* Makes more operations abortable

* Improves `PeerAddress` interning and `ClientNode#peerAddress` management

* Considerable rework of network error handling to improve naming and consistency
Fixes commissioning with CommissioningController
* Make mock IP address smaller ("abcd::1" vs "1111:2222:3333:4444:5555:6666:7777:8801")

* Fix "await abort" when `Abort` is already aborted

* Reduce mock time resolution interval in OtaTest and a ClientNode test to eliminate intermittent failures

* Reduce OtaTest mock firmware size

* Enable entropy for `MockSite` by default so we don't need to special-case everywhere that pairs (which requires entropy for ephemeral node ID generation)

* Add detailed logging for each connection attempt for each address

* Add the exchange's `via` to various log messages that had little context otherwise

* Fix a couple of errors from last merge

* Do not store resumption records when SessionManager closes; they're stored when changed and this allows storage to close before SessionManager (which otherwise caused errors in log)

* Log more CASE client errors caused by issues outside of our control without stack traces
Additional error handling to avoid crashing when generating diagnostics for an endpoint that is in a bad state.
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