macula_app_resolve (macula v14.0.0)
View SourceWhere an app runs, from its MRI (macula#75): the app record the org signed for it, then each of its services' procedures through the same provider lookup a call uses.
The app record is looked up under macula_record:app_key/3 of the MRI's realm, org and app, and is trusted only when macula_record:verify_app/3 passes against the realm key the pool pinned for that realm: the record carries the realm-signed org directory, so the check needs no second lookup. Of several records that pass, the newest is used. A procedure no provider serves right now is listed with no providers and the reason, so an app that serves nothing at the moment still resolves.
The DHT lookup, the pinned realm key and the provider lookup come from the resolve_io/0 seam (each entry defaults to the real function), so a test stubs them here rather than replacing a module other processes call.
Summary
Functions
Resolve the app AppMri (mri:app:<realm>/<org>/<app>) to its services and the providers serving each of their procedures, within TimeoutMs in all. {error, {invalid_app_mri, Reason}} for anything but a valid app MRI; {error, {unresolved, app_not_registered}} when no record is stored under it; {error, {unresolved, {no_trusted_app_record, Refusals}}} when none passes verify_app/3, naming each refusal.
As resolve/3, with the lookups taken from Io (see resolve_io/0).
Types
-type resolve_io() :: #{find_records => fun((pid(), <<_:256>>, pos_integer()) -> {ok, [macula_record:m_record()]} | {error, term()}), realm_key => fun((pid(), <<_:256>>) -> {ok, binary()} | none), providers => fun((pid(), <<_:256>>, binary(), pos_integer()) -> {ok, [map()]} | {error, term()})}.
Functions
-spec resolve(pid(), binary(), pos_integer()) -> {ok, resolved()} | {error, term()}.
Resolve the app AppMri (mri:app:<realm>/<org>/<app>) to its services and the providers serving each of their procedures, within TimeoutMs in all. {error, {invalid_app_mri, Reason}} for anything but a valid app MRI; {error, {unresolved, app_not_registered}} when no record is stored under it; {error, {unresolved, {no_trusted_app_record, Refusals}}} when none passes verify_app/3, naming each refusal.
-spec resolve(pid(), binary(), pos_integer(), resolve_io()) -> {ok, resolved()} | {error, term()}.
As resolve/3, with the lookups taken from Io (see resolve_io/0).