@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.
- package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/cjs/action/client/ClientInteraction.js +11 -0
- package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
- package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Icac.js +7 -1
- package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/operational.d.ts +1 -1
- package/dist/cjs/certificate/kinds/definitions/operational.js +1 -1
- package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
- package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
- package/dist/cjs/dcl/DclCertificateService.js +18 -2
- package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
- package/dist/cjs/dcl/DclOtaUpdateService.d.ts +9 -4
- package/dist/cjs/dcl/DclOtaUpdateService.d.ts.map +1 -1
- package/dist/cjs/dcl/DclOtaUpdateService.js +126 -51
- package/dist/cjs/dcl/DclOtaUpdateService.js.map +2 -2
- package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
- package/dist/cjs/fabric/Fabric.js +0 -11
- package/dist/cjs/fabric/Fabric.js.map +1 -1
- package/dist/cjs/mdns/MdnsClient.d.ts.map +1 -1
- package/dist/cjs/mdns/MdnsClient.js +1 -3
- package/dist/cjs/mdns/MdnsClient.js.map +1 -1
- package/dist/cjs/peer/PeerSet.d.ts.map +1 -1
- package/dist/cjs/peer/PeerSet.js +32 -23
- package/dist/cjs/peer/PeerSet.js.map +1 -1
- package/dist/cjs/protocol/MRP.d.ts +14 -1
- package/dist/cjs/protocol/MRP.d.ts.map +1 -1
- package/dist/cjs/protocol/MRP.js +16 -9
- package/dist/cjs/protocol/MRP.js.map +1 -1
- package/dist/cjs/protocol/MessageChannel.d.ts +3 -1
- package/dist/cjs/protocol/MessageChannel.d.ts.map +1 -1
- package/dist/cjs/protocol/MessageChannel.js +11 -6
- package/dist/cjs/protocol/MessageChannel.js.map +1 -1
- package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
- package/dist/cjs/protocol/MessageExchange.js +7 -5
- package/dist/cjs/protocol/MessageExchange.js.map +1 -1
- package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/esm/action/client/ClientInteraction.js +11 -0
- package/dist/esm/action/client/ClientInteraction.js.map +1 -1
- package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Icac.js +7 -1
- package/dist/esm/certificate/kinds/Icac.js.map +1 -1
- package/dist/esm/certificate/kinds/definitions/operational.d.ts +1 -1
- package/dist/esm/certificate/kinds/definitions/operational.js +1 -1
- package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
- package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
- package/dist/esm/dcl/DclCertificateService.js +18 -2
- package/dist/esm/dcl/DclCertificateService.js.map +1 -1
- package/dist/esm/dcl/DclOtaUpdateService.d.ts +9 -4
- package/dist/esm/dcl/DclOtaUpdateService.d.ts.map +1 -1
- package/dist/esm/dcl/DclOtaUpdateService.js +126 -51
- package/dist/esm/dcl/DclOtaUpdateService.js.map +2 -2
- package/dist/esm/fabric/Fabric.d.ts.map +1 -1
- package/dist/esm/fabric/Fabric.js +0 -11
- package/dist/esm/fabric/Fabric.js.map +1 -1
- package/dist/esm/mdns/MdnsClient.d.ts.map +1 -1
- package/dist/esm/mdns/MdnsClient.js +1 -3
- package/dist/esm/mdns/MdnsClient.js.map +1 -1
- package/dist/esm/peer/PeerSet.d.ts.map +1 -1
- package/dist/esm/peer/PeerSet.js +32 -23
- package/dist/esm/peer/PeerSet.js.map +1 -1
- package/dist/esm/protocol/MRP.d.ts +14 -1
- package/dist/esm/protocol/MRP.d.ts.map +1 -1
- package/dist/esm/protocol/MRP.js +16 -9
- package/dist/esm/protocol/MRP.js.map +1 -1
- package/dist/esm/protocol/MessageChannel.d.ts +3 -1
- package/dist/esm/protocol/MessageChannel.d.ts.map +1 -1
- package/dist/esm/protocol/MessageChannel.js +11 -6
- package/dist/esm/protocol/MessageChannel.js.map +1 -1
- package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
- package/dist/esm/protocol/MessageExchange.js +7 -5
- package/dist/esm/protocol/MessageExchange.js.map +1 -1
- package/package.json +6 -6
- package/src/action/client/ClientInteraction.ts +13 -0
- package/src/certificate/kinds/Icac.ts +1 -4
- package/src/certificate/kinds/definitions/operational.ts +1 -1
- package/src/dcl/DclCertificateService.ts +21 -3
- package/src/dcl/DclOtaUpdateService.ts +171 -62
- package/src/fabric/Fabric.ts +0 -18
- package/src/mdns/MdnsClient.ts +1 -4
- package/src/peer/PeerSet.ts +38 -25
- package/src/protocol/MRP.ts +32 -8
- package/src/protocol/MessageChannel.ts +15 -6
- package/src/protocol/MessageExchange.ts +7 -5
package/src/peer/PeerSet.ts
CHANGED
|
@@ -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
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
|
package/src/protocol/MRP.ts
CHANGED
|
@@ -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
|
|
106
|
-
transmissionNumber,
|
|
107
|
-
|
|
108
|
-
|
|
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 && (
|
|
115
|
-
|
|
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 + (
|
|
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(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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(
|
|
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`,
|