@matter/protocol 0.16.9 → 0.16.10-alpha.0-20260219-28569004a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
  2. package/dist/cjs/action/client/ClientInteraction.js +11 -0
  3. package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
  4. package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
  5. package/dist/cjs/certificate/kinds/Icac.js +7 -1
  6. package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
  7. package/dist/cjs/certificate/kinds/definitions/operational.d.ts +1 -1
  8. package/dist/cjs/certificate/kinds/definitions/operational.js +1 -1
  9. package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
  10. package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
  11. package/dist/cjs/dcl/DclCertificateService.js +18 -2
  12. package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
  13. package/dist/cjs/dcl/DclOtaUpdateService.d.ts +9 -4
  14. package/dist/cjs/dcl/DclOtaUpdateService.d.ts.map +1 -1
  15. package/dist/cjs/dcl/DclOtaUpdateService.js +126 -51
  16. package/dist/cjs/dcl/DclOtaUpdateService.js.map +2 -2
  17. package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
  18. package/dist/cjs/fabric/Fabric.js +0 -11
  19. package/dist/cjs/fabric/Fabric.js.map +1 -1
  20. package/dist/cjs/mdns/MdnsClient.d.ts.map +1 -1
  21. package/dist/cjs/mdns/MdnsClient.js +1 -3
  22. package/dist/cjs/mdns/MdnsClient.js.map +1 -1
  23. package/dist/cjs/peer/PeerSet.d.ts.map +1 -1
  24. package/dist/cjs/peer/PeerSet.js +32 -23
  25. package/dist/cjs/peer/PeerSet.js.map +1 -1
  26. package/dist/cjs/protocol/MRP.d.ts +14 -1
  27. package/dist/cjs/protocol/MRP.d.ts.map +1 -1
  28. package/dist/cjs/protocol/MRP.js +16 -9
  29. package/dist/cjs/protocol/MRP.js.map +1 -1
  30. package/dist/cjs/protocol/MessageChannel.d.ts +3 -1
  31. package/dist/cjs/protocol/MessageChannel.d.ts.map +1 -1
  32. package/dist/cjs/protocol/MessageChannel.js +11 -6
  33. package/dist/cjs/protocol/MessageChannel.js.map +1 -1
  34. package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
  35. package/dist/cjs/protocol/MessageExchange.js +7 -5
  36. package/dist/cjs/protocol/MessageExchange.js.map +1 -1
  37. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  38. package/dist/esm/action/client/ClientInteraction.js +11 -0
  39. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  40. package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
  41. package/dist/esm/certificate/kinds/Icac.js +7 -1
  42. package/dist/esm/certificate/kinds/Icac.js.map +1 -1
  43. package/dist/esm/certificate/kinds/definitions/operational.d.ts +1 -1
  44. package/dist/esm/certificate/kinds/definitions/operational.js +1 -1
  45. package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
  46. package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
  47. package/dist/esm/dcl/DclCertificateService.js +18 -2
  48. package/dist/esm/dcl/DclCertificateService.js.map +1 -1
  49. package/dist/esm/dcl/DclOtaUpdateService.d.ts +9 -4
  50. package/dist/esm/dcl/DclOtaUpdateService.d.ts.map +1 -1
  51. package/dist/esm/dcl/DclOtaUpdateService.js +126 -51
  52. package/dist/esm/dcl/DclOtaUpdateService.js.map +2 -2
  53. package/dist/esm/fabric/Fabric.d.ts.map +1 -1
  54. package/dist/esm/fabric/Fabric.js +0 -11
  55. package/dist/esm/fabric/Fabric.js.map +1 -1
  56. package/dist/esm/mdns/MdnsClient.d.ts.map +1 -1
  57. package/dist/esm/mdns/MdnsClient.js +1 -3
  58. package/dist/esm/mdns/MdnsClient.js.map +1 -1
  59. package/dist/esm/peer/PeerSet.d.ts.map +1 -1
  60. package/dist/esm/peer/PeerSet.js +32 -23
  61. package/dist/esm/peer/PeerSet.js.map +1 -1
  62. package/dist/esm/protocol/MRP.d.ts +14 -1
  63. package/dist/esm/protocol/MRP.d.ts.map +1 -1
  64. package/dist/esm/protocol/MRP.js +16 -9
  65. package/dist/esm/protocol/MRP.js.map +1 -1
  66. package/dist/esm/protocol/MessageChannel.d.ts +3 -1
  67. package/dist/esm/protocol/MessageChannel.d.ts.map +1 -1
  68. package/dist/esm/protocol/MessageChannel.js +11 -6
  69. package/dist/esm/protocol/MessageChannel.js.map +1 -1
  70. package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
  71. package/dist/esm/protocol/MessageExchange.js +7 -5
  72. package/dist/esm/protocol/MessageExchange.js.map +1 -1
  73. package/package.json +6 -6
  74. package/src/action/client/ClientInteraction.ts +13 -0
  75. package/src/certificate/kinds/Icac.ts +1 -4
  76. package/src/certificate/kinds/definitions/operational.ts +1 -1
  77. package/src/dcl/DclCertificateService.ts +21 -3
  78. package/src/dcl/DclOtaUpdateService.ts +171 -62
  79. package/src/fabric/Fabric.ts +0 -18
  80. package/src/mdns/MdnsClient.ts +1 -4
  81. package/src/peer/PeerSet.ts +38 -25
  82. package/src/protocol/MRP.ts +32 -8
  83. package/src/protocol/MessageChannel.ts +15 -6
  84. package/src/protocol/MessageExchange.ts +7 -5
@@ -511,34 +511,47 @@ export class PeerSet implements ImmutableSet<Peer>, ObservableSet<Peer> {
511
511
  operationalAddress !== undefined &&
512
512
  (runningDiscoveryType === NodeDiscoveryType.None || requestedDiscoveryType === NodeDiscoveryType.None)
513
513
  ) {
514
- const session = this.#sessions.maybeSessionFor(address);
515
- const queueSlot = await queue?.obtainSlot();
516
-
517
- if (queueSlot !== undefined) {
518
- // If we got a new session while waiting for the queue slot, we assume we are done here
519
- const currentSession = this.#sessions.maybeSessionFor(address);
520
- if (currentSession?.isSecure && session !== currentSession) {
521
- queueSlot.close();
522
- return currentSession;
514
+ const knownDiscoveredDevice = mdnsScanner.getDiscoveredOperationalDevice(
515
+ this.#sessions.fabricFor(address),
516
+ address.nodeId,
517
+ );
518
+ if (
519
+ knownDiscoveredDevice === undefined ||
520
+ knownDiscoveredDevice.addresses.some(addr => ServerAddress.isEqual(addr, operationalAddress!))
521
+ ) {
522
+ const session = this.#sessions.maybeSessionFor(address);
523
+ const queueSlot = await queue?.obtainSlot();
524
+
525
+ if (queueSlot !== undefined) {
526
+ // If we got a new session while waiting for the queue slot, we assume we are done here
527
+ const currentSession = this.#sessions.maybeSessionFor(address);
528
+ if (currentSession?.isSecure && session !== currentSession) {
529
+ queueSlot.close();
530
+ return currentSession;
531
+ }
523
532
  }
524
- }
525
533
 
526
- try {
527
- const directReconnection = await this.#reconnectKnownAddress(
528
- address,
529
- operationalAddress,
530
- discoveryData,
531
- // When we use a timeout for discovery also use this for reconnecting to the node
532
- { expectedProcessingTime: timeout, caseAuthenticatedTags },
533
- );
534
- if (directReconnection !== undefined) {
535
- return directReconnection;
534
+ try {
535
+ const directReconnection = await this.#reconnectKnownAddress(
536
+ address,
537
+ operationalAddress,
538
+ discoveryData,
539
+ // Attempt to reconnect using the last known operational address and current discovery context
540
+ { caseAuthenticatedTags },
541
+ );
542
+ if (directReconnection !== undefined) {
543
+ return directReconnection;
544
+ }
545
+ } finally {
546
+ queueSlot?.close();
536
547
  }
537
- } finally {
538
- queueSlot?.close();
539
- }
540
- if (requestedDiscoveryType === NodeDiscoveryType.None) {
541
- throw new DiscoveryError(`${address} is not reachable right now.`);
548
+
549
+ if (requestedDiscoveryType === NodeDiscoveryType.None) {
550
+ throw new DiscoveryError(`${address} is not reachable right now.`);
551
+ }
552
+ } else {
553
+ logger.info(address, "Formerly known address is no longer in the MDNS results, discard ...");
554
+ operationalAddress = undefined;
542
555
  }
543
556
  }
544
557
 
@@ -36,6 +36,12 @@ export namespace MRP {
36
36
  */
37
37
  export const DEFAULT_EXPECTED_PROCESSING_TIME = Seconds(2);
38
38
 
39
+ /**
40
+ * To better handle network congestion, we add a delay to the MRP base timings.
41
+ * TODO Make this value dynamic depending on network type and maybe network behavior
42
+ */
43
+ export const ADDITIONAL_MRP_DELAY = Seconds(1.5);
44
+
39
45
  /**
40
46
  * The buffer time in milliseconds to add to the peer response time to also consider network delays and other factors.
41
47
  * TODO: This is a pure guess and should be adjusted in the future.
@@ -94,31 +100,44 @@ export namespace MRP {
94
100
  isPeerActive: boolean;
95
101
  }
96
102
 
103
+ /**
104
+ * Calculates the maximum backoff time for a resubmission based on the current retransmission count.
105
+ * Maximum means we calculate the maximum time without any randomness.
106
+ */
107
+ export function maxRetransmissionIntervalOf(inputs: RetryDelayInputs) {
108
+ return retransmissionIntervalOf(inputs, true);
109
+ }
110
+
97
111
  /**
98
112
  * Calculates the backoff time for a resubmission based on the current retransmission count.
99
113
  * If no session parameters are provided, the parameters of the current session are used.
100
114
  * If session parameters are provided, the method can be used to calculate the maximum backoff time for the other
101
115
  * side of the exchange.
102
116
  *
117
+ * When `calculateMaximum` is set to true, we calculate the maximum time without any randomness.
118
+ * Otherwise, we add a network overhead to the timings.
119
+ *
103
120
  * @see {@link MatterSpecification.v10.Core}, section 4.11.2.1
104
121
  */
105
- export function maxRetransmissionIntervalOf({
106
- transmissionNumber,
107
- sessionParameters,
108
- isPeerActive,
109
- }: RetryDelayInputs) {
122
+ export function retransmissionIntervalOf(
123
+ { transmissionNumber, sessionParameters, isPeerActive }: RetryDelayInputs,
124
+ calculateMaximum = false,
125
+ ) {
110
126
  const { activeInterval, idleInterval } = sessionParameters;
111
127
 
112
128
  // For the first message of a new exchange ... SHALL be set according to the idle state of the peer node.
113
129
  // For all subsequent messages of the exchange, ... SHOULD be set according to the active state of the peer node
114
- const peerActive = transmissionNumber > 0 && (sessionParameters !== undefined || isPeerActive);
115
- const baseInterval = peerActive ? activeInterval : idleInterval;
130
+ const peerActive = transmissionNumber > 0 && (!calculateMaximum || isPeerActive);
131
+ let baseInterval = peerActive ? activeInterval : idleInterval;
132
+ if (!calculateMaximum) {
133
+ baseInterval += ADDITIONAL_MRP_DELAY;
134
+ }
116
135
  return Millis.floor(
117
136
  Millis(
118
137
  baseInterval *
119
138
  MRP.BACKOFF_MARGIN *
120
139
  Math.pow(MRP.BACKOFF_BASE, Math.max(0, transmissionNumber - MRP.BACKOFF_THRESHOLD)) *
121
- (1 + (sessionParameters !== undefined ? 1 : Math.random()) * MRP.BACKOFF_JITTER),
140
+ (1 + (calculateMaximum ? 1 : Math.random()) * MRP.BACKOFF_JITTER),
122
141
  ),
123
142
  );
124
143
  }
@@ -132,6 +151,11 @@ function maxResponseTimeOf(sessionParameters: SessionParameters, isPeerActive: b
132
151
 
133
152
  // and then add the time the other side needs for a full resubmission cycle under the assumption we are active
134
153
  for (let i = 0; i < MRP.MAX_TRANSMISSIONS; i++) {
154
+ if (isPeerActive && finalWaitTime > sessionParameters.activeThreshold) {
155
+ // If we considered the device active initially but the wait time goes beyond the active threshold,
156
+ // we consider the device as inactive for further calculations
157
+ isPeerActive = false;
158
+ }
135
159
  finalWaitTime = Millis(
136
160
  finalWaitTime +
137
161
  MRP.maxRetransmissionIntervalOf({
@@ -170,13 +170,22 @@ export class MessageChannel implements Channel<Message> {
170
170
  * If session parameters are provided, the method can be used to calculate the maximum backoff time for the other
171
171
  * side of the exchange.
172
172
  *
173
+ * When `calculateMaximum` is set to true, we calculate the maximum time without any randomness.
174
+ *
173
175
  * @see {@link MatterSpecification.v10.Core}, section 4.11.2.1
174
176
  */
175
- getMrpResubmissionBackOffTime(retransmissionCount: number, sessionParameters?: SessionParameters) {
176
- return MRP.maxRetransmissionIntervalOf({
177
- transmissionNumber: retransmissionCount,
178
- sessionParameters: sessionParameters ?? this.session.parameters,
179
- isPeerActive: this.session.isPeerActive,
180
- });
177
+ getMrpResubmissionBackOffTime(
178
+ retransmissionCount: number,
179
+ sessionParameters?: SessionParameters,
180
+ calculateMaximum = false,
181
+ ) {
182
+ return MRP.retransmissionIntervalOf(
183
+ {
184
+ transmissionNumber: retransmissionCount,
185
+ sessionParameters: sessionParameters ?? this.session.parameters,
186
+ isPeerActive: this.session.isPeerActive,
187
+ },
188
+ calculateMaximum,
189
+ );
181
190
  }
182
191
  }
@@ -565,13 +565,13 @@ export class MessageExchange {
565
565
 
566
566
  this.context.retry(this.#retransmissionCounter);
567
567
  const resubmissionBackoffTime = this.channel.getMrpResubmissionBackOffTime(this.#retransmissionCounter);
568
- logger.debug(
569
- `Resubmitting ${Message.via(this, message)} (retransmission attempt ${this.#retransmissionCounter}, backoff time ${Duration.format(resubmissionBackoffTime)}))`,
570
- );
571
568
 
572
569
  // TODO await
573
570
  this.channel
574
- .send(message, this)
571
+ .send(message, this, {
572
+ "retrans#": this.#retransmissionCounter,
573
+ backoff: Duration.format(resubmissionBackoffTime),
574
+ })
575
575
  .then(() => this.#initializeResubmission(message, resubmissionBackoffTime, expectedProcessingTime))
576
576
  .catch(error => {
577
577
  logger.error(`Error retransmitting ${Message.via(this, message)}:`, error);
@@ -709,7 +709,9 @@ export class MessageExchange {
709
709
  // in normal case this timer is cancelled before it triggers when all retries are done.
710
710
  let maxResubmissionTime = Instant;
711
711
  for (let i = this.#retransmissionCounter; i <= MRP.MAX_TRANSMISSIONS; i++) {
712
- maxResubmissionTime = Millis(maxResubmissionTime + this.channel.getMrpResubmissionBackOffTime(i));
712
+ maxResubmissionTime = Millis(
713
+ maxResubmissionTime + this.channel.getMrpResubmissionBackOffTime(i, undefined, true),
714
+ );
713
715
  }
714
716
  this.#closeTimer = Time.getTimer(
715
717
  `Exchange ${this.via} close`,