Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): manual mediator pickup lifecycle management #989

Merged

Conversation

genaris
Copy link
Contributor

@genaris genaris commented Aug 23, 2022

Small update on Mediation Recipient module to allow stopping message pickup loop, and then restarting it anytime by calling initiateMessagePickup() manually.

An optional parameter has been added to initiateMessagePickup method in order to let start the agent with a None messagePickupStrategy (so it will not attempt to connect to mediator at the beginning) and be able to start the pickup afterwards (using any strategy we want).

So it can be used in the following way:

  1. Start agent normally (with whatever Mediation Strategy you already have). It will initiate Pickup loop (V1, V2 or Implicit)
  2. Call stopMessagePickup() to pause this process (e.g. when agent is offline)
  3. Call initiateMessagePickup() to restart the process (e.g. agent goes online)

In case that default pickup strategy is set to None, of course, initiateMessagePickup should be called after 1 using parameters defaultMediator and the desired strategy (and the same in 3)

And I'm not completely sure, but it might also help with some failures in test suites when shutting down agents.

Resolves #753

Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
@genaris genaris marked this pull request as ready for review August 23, 2022 22:37
@genaris genaris requested a review from a team as a code owner August 23, 2022 22:37
@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2022

Codecov Report

Merging #989 (d8f7f63) into main (c99f3c9) will decrease coverage by 0.06%.
The diff coverage is 46.66%.

@@            Coverage Diff             @@
##             main     #989      +/-   ##
==========================================
- Coverage   88.13%   88.06%   -0.07%     
==========================================
  Files         492      492              
  Lines       11613    11623      +10     
  Branches     1933     1936       +3     
==========================================
+ Hits        10235    10236       +1     
- Misses       1317     1326       +9     
  Partials       61       61              
Impacted Files Coverage Δ
...ckages/core/src/modules/routing/RecipientModule.ts 62.01% <46.66%> (+0.40%) ⬆️
packages/core/src/logger/ConsoleLogger.ts 55.55% <0.00%> (-22.23%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

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

This is a great improvement. One thing I'd like to see but is probably much more work is that you can stopMessagePickup for a specific mediator. that is probably something we can add later on.

another thing we should do as a change to 0.3.0 (feel free to open a pr 😄) is to make the public api take mediator id's instead of the records.

@@ -47,6 +47,9 @@ export class RecipientModule {
private mediationRepository: MediationRepository
private routingService: RoutingService

// $stop is used for stop message pickup signal
private readonly stop$ = new Subject<boolean>()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we give this a more specific name? I'm already not a huge fan I named it stop$ for the generic agent shutdown subject

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've set it to stopMessagePickup$ to be more specific. Didn't want it to collide with stopMessagePickup() method but, as it is a private field, it should not be confusing I think.

})
const mediatorConfig = getBaseConfig('Mediation: Mediator', {
const mediatorConfig = getBaseConfig('Pickup: Mediator', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also ran into issues with this 😆

Comment on lines 40 to 43
Array.from(this.transportTable.values()).map((socket) => {
socket.removeEventListener('message', this.handleMessageEvent)
socket.close()
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there are any promises involved here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Was part of an experiment and left it by mistake 🙈

Comment on lines +344 to 346
await aliceAgent.mediationRecipient.stopMessagePickup()
await faberAgent.mediationRecipient.stopMessagePickup()
})
Copy link
Contributor

Choose a reason for hiding this comment

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

much better API

Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
@genaris
Copy link
Contributor Author

genaris commented Aug 29, 2022

This is a great improvement. One thing I'd like to see but is probably much more work is that you can stopMessagePickup for a specific mediator. that is probably something we can add later on.

another thing we should do as a change to 0.3.0 (feel free to open a pr 😄) is to make the public api take mediator id's instead of the records.

Thanks! I've been thinking about the management of individual message pickup loops but, as you said, requires some complexity and I think it will be better to develop it in a refactored MediationRecipient / MessagePickup module for 0.3.0.

I'll start working on these refactoring ideas (including the usage of mediatorId / connectionId) so we can discuss about it shortly.

@TimoGlastra TimoGlastra merged commit 69d4906 into openwallet-foundation:main Aug 30, 2022
@TimoGlastra
Copy link
Contributor

Awesome, merged! Thanks for all the contributions lately :)

genaris added a commit to 2060-io/aries-framework-javascript that referenced this pull request Sep 2, 2022
Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: expose oob domain (openwallet-foundation#990)

fix: some changes based on feedback

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

docs: a few clarifications and TODOs

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

feat: combine features

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

test(credentials): fix flaky tests with events (openwallet-foundation#966)

Signed-off-by: 2byrds <2byrds@gmail.com>

feat: OOB public did (openwallet-foundation#930)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

feat(routing): manual mediator pickup lifecycle management (openwallet-foundation#989)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

docs(demo): faber creates invitation (openwallet-foundation#995)

Signed-off-by: conanoc <conanoc@gmail.com>

chore(release): v0.2.3 (openwallet-foundation#999)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix: disclosures message fields and optional thid

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix(question-answer): question answer protocol state/role check (openwallet-foundation#1001)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

refactor: move feature registration to module

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: dependency manager test

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: feature registry instance

Signed-off-by: Ariel Gentile <gentilester@gmail.com>
@genaris genaris deleted the feat/manual-message-pickup branch September 5, 2022 19:12
genaris added a commit to 2060-io/aries-framework-javascript that referenced this pull request Sep 16, 2022
TimoGlastra added a commit that referenced this pull request Oct 11, 2022
* feat: OOB public did (#930)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

* feat(routing): manual mediator pickup lifecycle management (#989)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* docs(demo): faber creates invitation (#995)

Signed-off-by: conanoc <conanoc@gmail.com>

* chore(release): v0.2.3 (#999)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(question-answer): question answer protocol state/role check (#1001)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: Action Menu protocol (Aries RFC 0509) implementation (#974)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* fix(ledger): remove poolConnected on pool close (#1011)

Signed-off-by: Niall Shaw <niall.shaw@absa.africa>

* fix(ledger): check taa version instad of aml version (#1013)

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>

* chore: add @janrtvld to maintainers (#1016)

Signed-off-by: Timo Glastra <timo@animo.id>

* feat(routing): add settings to control back off strategy on mediator reconnection (#1017)

Signed-off-by: Sergi Garreta <sergi.garreta@entrust.com>

* fix: avoid crash when an unexpected message arrives (#1019)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

* chore(release): v0.2.4 (#1024)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* style: fix some lint errors

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: use did:key flag (#1029)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* ci: set default rust version (#1036)

Signed-off-by: Sai Ranjit Tummalapalli <sairanjit5@gmail.com>

* fix(oob): allow encoding in content type header (#1037)

Signed-off-by: Timo Glastra <timo@animo.id>

* feat: connection type (#994)

Signed-off-by: KolbyRKunz <KolbyKunz@yahoo.com>

* chore(module-tenants): match package versions

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: improve sending error handling (#1045)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: expose findAllByQuery method in modules and services (#1044)

Signed-off-by: Jim Ezesinachi <jim@animo.id>

* feat: possibility to set masterSecretId inside of WalletConfig (#1043)

Signed-off-by: Andrii Uhryn <an.ugryn@gmail.com>

* fix(oob): set connection alias when creating invitation (#1047)

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>

* build: fix missing parameter

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Signed-off-by: conanoc <conanoc@gmail.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Niall Shaw <niall.shaw@absa.africa>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Sergi Garreta <sergi.garreta@entrust.com>
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit5@gmail.com>
Signed-off-by: KolbyRKunz <KolbyKunz@yahoo.com>
Signed-off-by: Jim Ezesinachi <jim@animo.id>
Signed-off-by: Andrii Uhryn <an.ugryn@gmail.com>
Co-authored-by: Iskander508 <pavel.zarecky@seznam.cz>
Co-authored-by: conanoc <conanoc@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Niall Shaw <100220424+niallshaw-absa@users.noreply.github.com>
Co-authored-by: jakubkoci <jakub.koci@gmail.com>
Co-authored-by: Timo Glastra <timo@animo.id>
Co-authored-by: Sergi Garreta Serra <garretaserra@gmail.com>
Co-authored-by: Sai Ranjit Tummalapalli <34263716+sairanjit@users.noreply.github.com>
Co-authored-by: KolbyRKunz <KolbyKunz@yahoo.com>
Co-authored-by: Jim Ezesinachi <ezesinachijim@gmail.com>
Co-authored-by: an-uhryn <55444541+an-uhryn@users.noreply.github.com>
genaris added a commit to 2060-io/aries-framework-javascript that referenced this pull request Oct 13, 2022
* feat: OOB public did (openwallet-foundation#930)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

* feat(routing): manual mediator pickup lifecycle management (openwallet-foundation#989)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* docs(demo): faber creates invitation (openwallet-foundation#995)

Signed-off-by: conanoc <conanoc@gmail.com>

* chore(release): v0.2.3 (openwallet-foundation#999)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(question-answer): question answer protocol state/role check (openwallet-foundation#1001)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: Action Menu protocol (Aries RFC 0509) implementation (openwallet-foundation#974)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* fix(ledger): remove poolConnected on pool close (openwallet-foundation#1011)

Signed-off-by: Niall Shaw <niall.shaw@absa.africa>

* fix(ledger): check taa version instad of aml version (openwallet-foundation#1013)

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>

* chore: add @janrtvld to maintainers (openwallet-foundation#1016)

Signed-off-by: Timo Glastra <timo@animo.id>

* feat(routing): add settings to control back off strategy on mediator reconnection (openwallet-foundation#1017)

Signed-off-by: Sergi Garreta <sergi.garreta@entrust.com>

* fix: avoid crash when an unexpected message arrives (openwallet-foundation#1019)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

* chore(release): v0.2.4 (openwallet-foundation#1024)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* style: fix some lint errors

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: use did:key flag (openwallet-foundation#1029)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* ci: set default rust version (openwallet-foundation#1036)

Signed-off-by: Sai Ranjit Tummalapalli <sairanjit5@gmail.com>

* fix(oob): allow encoding in content type header (openwallet-foundation#1037)

Signed-off-by: Timo Glastra <timo@animo.id>

* feat: connection type (openwallet-foundation#994)

Signed-off-by: KolbyRKunz <KolbyKunz@yahoo.com>

* chore(module-tenants): match package versions

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: improve sending error handling (openwallet-foundation#1045)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

* feat: expose findAllByQuery method in modules and services (openwallet-foundation#1044)

Signed-off-by: Jim Ezesinachi <jim@animo.id>

* feat: possibility to set masterSecretId inside of WalletConfig (openwallet-foundation#1043)

Signed-off-by: Andrii Uhryn <an.ugryn@gmail.com>

* fix(oob): set connection alias when creating invitation (openwallet-foundation#1047)

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>

* build: fix missing parameter

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Signed-off-by: conanoc <conanoc@gmail.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Niall Shaw <niall.shaw@absa.africa>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Sergi Garreta <sergi.garreta@entrust.com>
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit5@gmail.com>
Signed-off-by: KolbyRKunz <KolbyKunz@yahoo.com>
Signed-off-by: Jim Ezesinachi <jim@animo.id>
Signed-off-by: Andrii Uhryn <an.ugryn@gmail.com>
Co-authored-by: Iskander508 <pavel.zarecky@seznam.cz>
Co-authored-by: conanoc <conanoc@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Niall Shaw <100220424+niallshaw-absa@users.noreply.github.com>
Co-authored-by: jakubkoci <jakub.koci@gmail.com>
Co-authored-by: Timo Glastra <timo@animo.id>
Co-authored-by: Sergi Garreta Serra <garretaserra@gmail.com>
Co-authored-by: Sai Ranjit Tummalapalli <34263716+sairanjit@users.noreply.github.com>
Co-authored-by: KolbyRKunz <KolbyKunz@yahoo.com>
Co-authored-by: Jim Ezesinachi <ezesinachijim@gmail.com>
Co-authored-by: an-uhryn <55444541+an-uhryn@users.noreply.github.com>
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.

Add ability to manage mediator pickup lifecycle manually
3 participants