Skip to content

Commit d4fd1ae

Browse files
authored
feat(routing): add reconnection parameters to RecipientModuleConfig (openwallet-foundation#1070)
Signed-off-by: Ariel Gentile <[email protected]>
1 parent 28f54e2 commit d4fd1ae

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Diff for: packages/core/src/agent/AgentConfig.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,16 @@ export class AgentConfig {
104104
public get maximumMessagePickup() {
105105
return this.initConfig.maximumMessagePickup ?? 10
106106
}
107-
107+
/**
108+
* @deprecated use baseMediatorReconnectionIntervalMs from the `RecipientModuleConfig` class
109+
*/
108110
public get baseMediatorReconnectionIntervalMs() {
109111
return this.initConfig.baseMediatorReconnectionIntervalMs ?? 100
110112
}
111113

114+
/**
115+
* @deprecated use maximumMediatorReconnectionIntervalMs from the `RecipientModuleConfig` class
116+
*/
112117
public get maximumMediatorReconnectionIntervalMs() {
113118
return this.initConfig.maximumMediatorReconnectionIntervalMs ?? Number.POSITIVE_INFINITY
114119
}

Diff for: packages/core/src/agent/AgentModules.ts

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ function getDefaultAgentModules(agentConfig: AgentConfig) {
113113
maximumMessagePickup: agentConfig.maximumMessagePickup,
114114
mediatorInvitationUrl: agentConfig.mediatorConnectionsInvite,
115115
mediatorPickupStrategy: agentConfig.mediatorPickupStrategy,
116+
baseMediatorReconnectionIntervalMs: agentConfig.baseMediatorReconnectionIntervalMs,
117+
maximumMediatorReconnectionIntervalMs: agentConfig.maximumMediatorReconnectionIntervalMs,
116118
mediatorPollingInterval: agentConfig.mediatorPollingInterval,
117119
}),
118120
basicMessages: () => new BasicMessagesModule(),

Diff for: packages/core/src/modules/routing/RecipientApi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class RecipientApi {
151151
}
152152

153153
private async openWebSocketAndPickUp(mediator: MediationRecord, pickupStrategy: MediatorPickupStrategy) {
154-
const { baseMediatorReconnectionIntervalMs, maximumMediatorReconnectionIntervalMs } = this.agentContext.config
154+
const { baseMediatorReconnectionIntervalMs, maximumMediatorReconnectionIntervalMs } = this.config
155155
let interval = baseMediatorReconnectionIntervalMs
156156

157157
const stopConditions$ = merge(this.stop$, this.stopMessagePickup$).pipe()

Diff for: packages/core/src/modules/routing/RecipientModuleConfig.ts

+33
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ export interface RecipientModuleConfigOptions {
3636
*/
3737
maximumMessagePickup?: number
3838

39+
/**
40+
* Initial interval in milliseconds between reconnection attempts when losing connection with the mediator. This value is doubled after
41+
* each retry, resulting in an exponential backoff strategy.
42+
*
43+
* For instance, if maximumMediatorReconnectionIntervalMs is b, the agent will attempt to reconnect after b, 2*b, 4*b, 8*b, 16*b, ... ms.
44+
*
45+
* This is only applicable when pickup protocol v2 or implicit pickup is used.
46+
*
47+
* @default 100
48+
*/
49+
baseMediatorReconnectionIntervalMs?: number
50+
51+
/**
52+
* Maximum interval in milliseconds between reconnection attempts when losing connection with the mediator.
53+
*
54+
* For instance, if maximumMediatorReconnectionIntervalMs is set to 1000 and maximumMediatorReconnectionIntervalMs is set to 10000,
55+
* the agent will attempt to reconnect after 1000, 2000, 4000, 8000, 10000, ..., 10000 ms.
56+
*
57+
* This is only applicable when pickup protocol v2 or implicit pickup is used.
58+
* @default Number.POSITIVE_INFINITY
59+
*/
60+
maximumMediatorReconnectionIntervalMs?: number
61+
3962
/**
4063
* Invitation url for connection to a mediator. If provided, a connection to the mediator will be made, and the mediator will be set as default.
4164
* This is meant as the simplest form of connecting to a mediator, if more control is desired the api should be used.
@@ -67,6 +90,16 @@ export class RecipientModuleConfig {
6790
return this.options.maximumMessagePickup ?? 10
6891
}
6992

93+
/** See {@link RecipientModuleConfigOptions.baseMediatorReconnectionIntervalMs} */
94+
public get baseMediatorReconnectionIntervalMs() {
95+
return this.options.baseMediatorReconnectionIntervalMs ?? 100
96+
}
97+
98+
/** See {@link RecipientModuleConfigOptions.maximumMediatorReconnectionIntervalMs} */
99+
public get maximumMediatorReconnectionIntervalMs() {
100+
return this.options.maximumMediatorReconnectionIntervalMs ?? Number.POSITIVE_INFINITY
101+
}
102+
70103
/** See {@link RecipientModuleConfigOptions.mediatorInvitationUrl} */
71104
public get mediatorInvitationUrl() {
72105
return this.options.mediatorInvitationUrl

0 commit comments

Comments
 (0)