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

Implement the Identity Agent #322

Merged
merged 270 commits into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 222 commits
Commits
Show all changes
270 commits
Select commit Hold shift + click to select a range
6708385
actor: Add builder for `Communicator`
PhilippGackstatter Jul 1, 2021
fb90837
identity: Re-export actor types
PhilippGackstatter Jul 2, 2021
0fb255f
actor: Specify `tokio` dep explicitly via git
PhilippGackstatter Jul 2, 2021
fea1cfd
actor: Specify `tokio` via crates.io
PhilippGackstatter Jul 5, 2021
85b2018
actor: Rename communicator module to actor
PhilippGackstatter Jul 5, 2021
4d493b9
actor: Rename communicator structs to actor
PhilippGackstatter Jul 5, 2021
8ff162a
actor: Rename `register_command` to `set_handler`
PhilippGackstatter Jul 5, 2021
d50633c
actor: Spawn handler loop internally
PhilippGackstatter Jul 7, 2021
94f743e
actor: Impl dispatch pattern for handler loop
PhilippGackstatter Jul 7, 2021
ac444fc
actor: Trait to determine `send_request` ret type
PhilippGackstatter Jul 7, 2021
5de923e
actor: Get request_name based on type parameter
PhilippGackstatter Jul 7, 2021
d64fa17
actor: Remove `Identity` prefixes in type names
PhilippGackstatter Jul 7, 2021
841c8f1
actor: Finer-grained handler impl for a nicer API
PhilippGackstatter Jul 9, 2021
15d0899
actor: Migrate to new stronghold comms version
PhilippGackstatter Jul 9, 2021
a103e82
actor: Fix account feature conditional guards
PhilippGackstatter Jul 9, 2021
b1c3f50
actor: Use type map to allow reusing receiver
PhilippGackstatter Jul 9, 2021
5286db7
actor: Update stronghold comms to new version
PhilippGackstatter Jul 9, 2021
6e9f22c
actor: Impl async handler functions
PhilippGackstatter Jul 13, 2021
4a335fa
actor: Separate storage handler & types
PhilippGackstatter Jul 14, 2021
d04c478
actor: Rename StorageHandler & impl resolution
PhilippGackstatter Jul 15, 2021
0ea1a07
actor: Reexport Keypair
PhilippGackstatter Jul 16, 2021
0444cce
actor: Expand Cargo package info
PhilippGackstatter Jul 16, 2021
5754455
actor: Only spawn listener if there are addresses
PhilippGackstatter Jul 16, 2021
d189efa
actor: Upgrade stronghold comms lib version
PhilippGackstatter Jul 19, 2021
c5af33b
actor: Add dummy comm handler
PhilippGackstatter Jul 20, 2021
c734593
actor: Expose executor builder API
PhilippGackstatter Jul 20, 2021
8d9983c
actor: Impl ffi-compatible handler registration
PhilippGackstatter Jul 21, 2021
b8765b5
actor: Use closures instead of function pointers
PhilippGackstatter Jul 21, 2021
d1e6caf
actor: Let request_name take &self for bindings
PhilippGackstatter Jul 29, 2021
ba78591
actor: Use `Cow` in trait for more flexibility
PhilippGackstatter Aug 3, 2021
4be9d93
actor: Use `log` instead of println
PhilippGackstatter Aug 3, 2021
3a40b20
actor: Implement `send_named_request` for bindings
PhilippGackstatter Aug 3, 2021
d47efc1
actor: Use `ClientMap` for working did resolution
PhilippGackstatter Aug 3, 2021
3c41ee6
actor: Upgrade to latest stronghold p2p
PhilippGackstatter Aug 4, 2021
56d8c8b
actor: Impl remote error and deserialization logic
PhilippGackstatter Aug 5, 2021
ef6afc1
actor: Restructure tests, add SendError test
PhilippGackstatter Aug 5, 2021
8a7a56b
actor: Use new `StorageError`
PhilippGackstatter Aug 5, 2021
bf4188a
actor: Handle all errors in handle invoker task
PhilippGackstatter Aug 6, 2021
9e6dcdd
actor: Define separate request & response types
PhilippGackstatter Aug 6, 2021
d5f8bdb
actor: Expand `StorageError` & impl `Category`
PhilippGackstatter Aug 6, 2021
806a0e1
Add licences to all files
PhilippGackstatter Sep 29, 2021
57cf41d
Apply cargo and toml formatting
PhilippGackstatter Sep 29, 2021
2c0891d
Address clippy lints
PhilippGackstatter Sep 29, 2021
7a47dbd
Define a type name for the more complex types
PhilippGackstatter Sep 29, 2021
a1ed930
Update to latest stronghold p2p version
PhilippGackstatter Sep 29, 2021
313f955
Let `add_method` take an `async fn` directly
PhilippGackstatter Sep 29, 2021
307a7fb
Use consistent names for the generics
PhilippGackstatter Sep 29, 2021
ede1ef0
Implement `Endpoint` and catch-all handler
PhilippGackstatter Oct 5, 2021
2ba7a26
Make `Actor` cloneable, inject it into handlers
PhilippGackstatter Oct 6, 2021
ab47c83
Inject `PeerId` into every handler
PhilippGackstatter Oct 6, 2021
1f6175d
Impl `RequestContext<T>` & dummy didcomm protocol
PhilippGackstatter Oct 7, 2021
7f69457
Add test for other presentation direction
PhilippGackstatter Oct 7, 2021
293e2ac
Rename handler registration methods
PhilippGackstatter Oct 7, 2021
8aab6b2
Refactor handler invocation in prep for hooks
PhilippGackstatter Oct 8, 2021
910abbe
Implement basic `call_hook` method
PhilippGackstatter Oct 11, 2021
7b746bc
Update account usages to latest dev
PhilippGackstatter Oct 19, 2021
17e42dd
Remove memory leak / circular reference
PhilippGackstatter Oct 19, 2021
844b9b2
Impl part of a hook test
PhilippGackstatter Oct 19, 2021
ed2869b
Fully impl hook invocation in send_request
PhilippGackstatter Oct 26, 2021
352c2fb
Apply new rustfmt granularity
PhilippGackstatter Oct 26, 2021
070a28b
Restructure actor crate
PhilippGackstatter Oct 26, 2021
a95c8cc
Restructure didcomm parts
PhilippGackstatter Oct 26, 2021
1951a83
Add error handling in `RequestHandler::invoke`
PhilippGackstatter Oct 26, 2021
93b773e
Fix response serialization
PhilippGackstatter Oct 26, 2021
81c7917
Impl hooks for `await_message`
PhilippGackstatter Oct 26, 2021
1e253e9
Add await_message hook error test
PhilippGackstatter Oct 26, 2021
4f037e5
Migrate to latest dev
PhilippGackstatter Jan 20, 2022
807e9f4
Reduce code duplication for handler invocation
PhilippGackstatter Jan 20, 2022
0ef1360
Replace `stronghold-p2p` with only `libp2p`
PhilippGackstatter Jan 28, 2022
bf0028e
Impl working serialization; add invocation test
PhilippGackstatter Feb 1, 2022
f2d0921
Return `RemoteSendError` in `Actor::send_request`
PhilippGackstatter Feb 1, 2022
454069e
Partially implement didcomm threads
PhilippGackstatter Feb 4, 2022
8f71d2c
Impl thread routing
PhilippGackstatter Feb 7, 2022
8f01558
Reimplement implicit hooks
PhilippGackstatter Feb 8, 2022
40c44c2
Add `StopListening` command
PhilippGackstatter Feb 8, 2022
a6d330c
Refactor handler invocation fns
PhilippGackstatter Feb 8, 2022
7b4ec79
Address clippy lints
PhilippGackstatter Feb 8, 2022
dd5e592
Shrink actor state to make cloning cheaper
PhilippGackstatter Feb 8, 2022
8e490d2
Improve type safety of `HandlerBuilder`
PhilippGackstatter Feb 8, 2022
60ea0ca
Store `peer_id` in `ActorState`
PhilippGackstatter Feb 16, 2022
8643565
Remove one superfluous tokio task and channel pair
PhilippGackstatter Feb 16, 2022
a159ce0
Map errors and document `ActorBuilder`
PhilippGackstatter Feb 17, 2022
c74e05f
Polish errors
PhilippGackstatter Feb 17, 2022
6a0a341
Update copyright to 2022
PhilippGackstatter Feb 17, 2022
e4d61d0
Replace `DidCommRequest` with `RequestMessage`
PhilippGackstatter Feb 20, 2022
5ed9de9
Move message types to p2p module
PhilippGackstatter Feb 20, 2022
6362dcb
Match more efficiently on swarm events
PhilippGackstatter Feb 20, 2022
7d9263a
Remove `SwarmCommand::GetPeerId`
PhilippGackstatter Feb 20, 2022
16b1572
Return inbound failure when sending response
PhilippGackstatter Feb 20, 2022
6e0a86e
Rename shutdown method
PhilippGackstatter Feb 20, 2022
432c110
Remove send_request functions for now
PhilippGackstatter Feb 20, 2022
4da9eef
Reorganize crate
PhilippGackstatter Feb 20, 2022
fe46e5b
Remove `DidCommActor`
PhilippGackstatter Feb 20, 2022
a5356f7
Factor out "default" `RequestHandler` impls
PhilippGackstatter Feb 20, 2022
65ac5e7
Spell out individual exports
PhilippGackstatter Feb 20, 2022
c174ee1
Rename `AsyncFn` -> `Handler`
PhilippGackstatter Feb 20, 2022
7522962
Rename `DidCommHook` -> `Hook`
PhilippGackstatter Feb 20, 2022
81e21fa
Move `ActorRequest` to its own module
PhilippGackstatter Feb 20, 2022
6cfb359
Reogranize dependencies
PhilippGackstatter Feb 20, 2022
9204942
Better test name
PhilippGackstatter Feb 21, 2022
f2c9782
Implement `RequestMode`, partially
PhilippGackstatter Feb 23, 2022
b94c921
Implement (a)sync `RequestMode` using strategies
PhilippGackstatter Feb 24, 2022
568f1b9
Make `InvocationStrategy` methods static
PhilippGackstatter Feb 24, 2022
b69d5b9
Add `Actor::send_request`
PhilippGackstatter Feb 24, 2022
5f74ac0
Do not send DCPM in sync mode
PhilippGackstatter Feb 25, 2022
48e665e
Make `ActorRequest` generic over `SyncMode`
PhilippGackstatter Feb 25, 2022
f834748
Redo the serialization errors (partial)
PhilippGackstatter Feb 25, 2022
d934149
Finish serialization error refactoring
PhilippGackstatter Mar 3, 2022
85ef809
Add timeout error
PhilippGackstatter Mar 3, 2022
9993015
Make downcasting & cloning objects fallible
PhilippGackstatter Mar 3, 2022
9663780
Introduce `HandlerObject` type for readability
PhilippGackstatter Mar 3, 2022
435a92b
Restrict `Endpoint`s to ascii alphabetic and `_`
PhilippGackstatter Mar 4, 2022
cc47f5a
Fix `Actor::start_listening`
PhilippGackstatter Mar 4, 2022
e8607b1
Drain open channels during shutdown
PhilippGackstatter Mar 4, 2022
c1da194
Add `ActorConfig` and timeout
PhilippGackstatter Mar 4, 2022
2533e28
Reorganize imports
PhilippGackstatter Mar 4, 2022
a426826
Be more specific for non-existent threads
PhilippGackstatter Mar 4, 2022
ddb9f45
Fix logger in tests and listening
PhilippGackstatter Mar 4, 2022
220b545
Add actor feature in identity crate
PhilippGackstatter Mar 4, 2022
c42741b
Impl working test remote account
PhilippGackstatter Mar 4, 2022
2bec251
Test thread not found error for async messages
PhilippGackstatter Mar 4, 2022
8a03293
Remove `RequestHandler::object_type_id` (unused)
PhilippGackstatter Mar 5, 2022
6b32a04
Inline `InvocationStrategy` methods
PhilippGackstatter Mar 5, 2022
f6a2d0c
Abort request handling on error in async strategy
PhilippGackstatter Mar 5, 2022
56f1327
Impl `FromStr` for `Endpoint`
PhilippGackstatter Mar 5, 2022
1f7ab7b
Only allow handler modification during build phase
PhilippGackstatter Mar 5, 2022
aaffb8b
Add remote account benchmark
PhilippGackstatter Mar 5, 2022
d17f06f
Document public types (partial)
PhilippGackstatter Mar 5, 2022
a2b5d12
Remove unused errors; remove `Category`
PhilippGackstatter Mar 6, 2022
f8e7201
Document the rest
PhilippGackstatter Mar 6, 2022
0b1e3da
Make p2p module exports explicit
PhilippGackstatter Mar 6, 2022
7fe43d8
Make remote_account exports explicit
PhilippGackstatter Mar 6, 2022
a8a51d2
Remove exports from remote_account
PhilippGackstatter Mar 6, 2022
ca8b1da
Remove commented code in didcomm presentation
PhilippGackstatter Mar 6, 2022
b662ea2
Rm unnecessary bounds on `ActorRequest` generics
PhilippGackstatter Mar 6, 2022
a3527a4
Test various error scenarios
PhilippGackstatter Mar 6, 2022
c2a7e3f
Remove start_listening test b/c non-deterministic
PhilippGackstatter Mar 6, 2022
477a945
Add handler finishes after shutdown test
PhilippGackstatter Mar 6, 2022
efe8cd2
Rename `ActorRequest::request_name` -> `endpoint`
PhilippGackstatter Mar 7, 2022
8c98360
Reduce p2p module visibility
PhilippGackstatter Mar 7, 2022
998d2f8
Make `Actor::peer_id` just `&self`
PhilippGackstatter Mar 7, 2022
5afe260
Impl `add_addresses` for improved test reliability
PhilippGackstatter Mar 9, 2022
95e466d
Increase timeout to increase test reliability
PhilippGackstatter Mar 9, 2022
74d409d
Specialize `add_handler` for synchronicity
PhilippGackstatter Mar 10, 2022
d507c4a
Fix documentation for `add_handler` functions
PhilippGackstatter Mar 10, 2022
a519665
Use minor version; use default-features = false
PhilippGackstatter Mar 10, 2022
a43e6ce
Return `Error::Shutdown` instead of panicking
PhilippGackstatter Mar 10, 2022
76c45ca
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Mar 10, 2022
9004e65
Document more on the `Actor` type
PhilippGackstatter Mar 10, 2022
a760fee
Move bounds onto `InvocationStrategy` trait
PhilippGackstatter Mar 11, 2022
6708434
Test subset of serialization errors
PhilippGackstatter Mar 11, 2022
a2faa55
Don't require absolute latest tokio version
PhilippGackstatter Mar 14, 2022
616d0ef
Bump `libp2p` to `0.43`
PhilippGackstatter Mar 14, 2022
2e2cd07
Feature gate `ActorBuilder::build`
PhilippGackstatter Mar 14, 2022
4abd401
Add Wasm integration features
PhilippGackstatter Mar 15, 2022
97eae18
Remove superfluous `pub(crate)` in `mod p2p`
PhilippGackstatter Mar 15, 2022
24213de
Use fn pointers instead of generic closures
PhilippGackstatter Mar 15, 2022
c41cf02
Update comment in shutdown test
PhilippGackstatter Mar 15, 2022
7c5a7ca
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Mar 16, 2022
37470f7
Address import issues caused by merge
PhilippGackstatter Mar 16, 2022
844e42c
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Apr 5, 2022
23872ed
Fix post-merge issues
PhilippGackstatter Apr 5, 2022
8dc6a88
Let `ActorRequest::endpoint` return `&'static str`
PhilippGackstatter Apr 5, 2022
309e67a
Remove explicit hook endpoint from `add_hook`
PhilippGackstatter Apr 5, 2022
9a53471
Remove TODO on actor protocol version
PhilippGackstatter Apr 5, 2022
2fae7e3
Factor out `DidComm` specifics into `DidCommActor`
PhilippGackstatter Apr 17, 2022
4fe4e7a
Split `ActorBuilder` into two
PhilippGackstatter Apr 18, 2022
2ee9901
Fix docs, remove superfluous functions
PhilippGackstatter Apr 18, 2022
4d6df63
Change how items are exported
PhilippGackstatter Apr 18, 2022
2d4751c
Refactor into `RawActor`
PhilippGackstatter Apr 19, 2022
6d2e030
Refactor actor state repr (partial)
PhilippGackstatter Apr 19, 2022
0fb39bf
Split `RequestHandler` in two
PhilippGackstatter Apr 20, 2022
4e8247e
Return `Endpoint` from `ActorRequest::endpoint`
PhilippGackstatter Apr 20, 2022
503a986
Remove `RawActor`
PhilippGackstatter Apr 21, 2022
7d698d5
Split `ActorRequest` in two
PhilippGackstatter Apr 21, 2022
1ca45c9
Fix `ActorRequest` docs
PhilippGackstatter Apr 21, 2022
17c6208
Merge pull request #840 from iotaledger/chore/merge-update-resolution…
eike-hass May 6, 2022
fe61a9f
Doc/resolve (#823)
May 6, 2022
f636bfe
Merge pull request #844 from iotaledger/docs/merge-resolve-docs
eike-hass May 6, 2022
0bfe13d
Upgrade to new `Stronghold` interface (#787)
PhilippGackstatter May 6, 2022
d810dbf
Fix Stronghold bindings build for musl (#845)
cycraig May 6, 2022
74eb6bd
Revert `IdentitySetup` modifications
PhilippGackstatter May 9, 2022
8e15d95
Refactor `Endpoint`
PhilippGackstatter May 9, 2022
e1bbd5b
Let `Endpoint` deserialization validate
PhilippGackstatter May 9, 2022
bdd4902
Document outstanding methods and types
PhilippGackstatter May 9, 2022
6f36d4b
Document and test `OneOrMany(Into)Iter(ator)`
PhilippGackstatter May 9, 2022
54e4985
Remove unstable error types from public API
PhilippGackstatter May 9, 2022
461f599
Remove duplicate test assertion
PhilippGackstatter May 9, 2022
9929b7c
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter May 9, 2022
f16da65
Test newer nightly in CI
PhilippGackstatter May 10, 2022
da52855
Refactor `Actor` to trait approach
PhilippGackstatter May 30, 2022
8ca19dc
Document types
PhilippGackstatter May 31, 2022
d16b6d0
Move poc modules behind test flag
PhilippGackstatter May 31, 2022
0acf6e5
Remove hooks
PhilippGackstatter May 31, 2022
f3dac5c
Rename modules
PhilippGackstatter May 31, 2022
dd7fd28
Remove `primitives` feature flag
PhilippGackstatter May 31, 2022
b77f7a8
Rename `actor` flag to `actor-unstable`
PhilippGackstatter May 31, 2022
18f4343
Derive Debug for `System`
PhilippGackstatter May 31, 2022
8c19d69
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter May 31, 2022
fdfeaca
Derive `Debug` for `DidCommSystem`
PhilippGackstatter May 31, 2022
b5608e5
More renaming actor to system
PhilippGackstatter Jun 1, 2022
805ceaa
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Jun 3, 2022
26ff921
Add missing `async` feature on `identity-iota`
PhilippGackstatter Jun 5, 2022
3c6c664
Remove `cfg-if` dep; use `tokio` unconditionally
PhilippGackstatter Jun 5, 2022
b06a65b
Bump `libp2p` to `0.45`
PhilippGackstatter Jun 5, 2022
4dd870f
Remove hooks from `Endpoint`s, simplify tests
PhilippGackstatter Jun 5, 2022
1d23d3f
Log warning instead of panicking
PhilippGackstatter Jun 5, 2022
ca40ea9
Improve log statements
PhilippGackstatter Jun 5, 2022
93b0e34
Document and rename `actor_not_found` method
PhilippGackstatter Jun 5, 2022
88edc88
Remove unnecessary tests, document tests more
PhilippGackstatter Jun 5, 2022
0b771f7
Add a `yield_now` to allow bg tasks to finish
PhilippGackstatter Jun 5, 2022
0a6460b
Remove `listen_on` due to unreliability
PhilippGackstatter Jun 5, 2022
b347905
Reorg imports to std/crates/internal hierarchy
PhilippGackstatter Jun 5, 2022
0b97d5e
Return error in base system on async requests
PhilippGackstatter Jun 7, 2022
14a18da
Rename actor to system
PhilippGackstatter Jun 7, 2022
3adcb3d
Remove unnecessary features and dependencies
PhilippGackstatter Jun 7, 2022
ad7e1b5
Improve `Endpoint` doc
PhilippGackstatter Jun 7, 2022
ebd76ae
Remove `HookInvocationError`
PhilippGackstatter Jun 7, 2022
257927b
Rename `add_address` -> `add_peer_address`
PhilippGackstatter Jun 7, 2022
cb5d1e5
Document more, make more things private
PhilippGackstatter Jun 7, 2022
1aa8a9d
Forbid unsafe code, add warning lints
PhilippGackstatter Jun 7, 2022
3966006
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Jun 20, 2022
9cda00a
Rename actor to agent
PhilippGackstatter Jun 20, 2022
9ba9485
Rename more types to agent, fix docs accordingly
PhilippGackstatter Jun 20, 2022
07c8d20
Add DIDComm benchmark
PhilippGackstatter Jun 20, 2022
19f6ef6
Add required features to run tests
PhilippGackstatter Jun 20, 2022
7f70a0b
Improve DIDComm test docs
PhilippGackstatter Jun 21, 2022
64402d4
Rename `PeerId` -> `AgentId`
PhilippGackstatter Jun 21, 2022
e43844f
Rename `ActorResult` -> `AgentResult`
PhilippGackstatter Jun 21, 2022
841f908
Rename mod `actor` to `agent`
PhilippGackstatter Jun 21, 2022
fe180ce
Rename `System` to `Agent`
PhilippGackstatter Jun 21, 2022
3a7235c
Rename `Actor` to `Handler`
PhilippGackstatter Jun 21, 2022
138d838
Revert unintended changes
PhilippGackstatter Jun 21, 2022
e2a3bdb
Use agent instead of actor in `identity_iota`
PhilippGackstatter Jun 21, 2022
2bb3dff
Revert another unintended change
PhilippGackstatter Jun 21, 2022
e47dbb3
Rename `ACT` generic type to `HND`
PhilippGackstatter Jun 22, 2022
ce1fa9e
Add keywords, remove wasm dependencies
PhilippGackstatter Jun 22, 2022
b03e559
Bump dashmap to `5.3`
PhilippGackstatter Jun 22, 2022
7702e73
Replace more occurences of peer with agent
PhilippGackstatter Jun 22, 2022
65f32ef
Use `DidCommRequest` terminology consistently
PhilippGackstatter Jun 22, 2022
c5a15f9
Annotate types in `AgentBuilder`
PhilippGackstatter Jun 22, 2022
c21e40a
Change agent exports
PhilippGackstatter Jun 22, 2022
1c7162e
Merge branch 'dev' into feat/identity-actor
PhilippGackstatter Jun 22, 2022
f85f667
Use only required features
PhilippGackstatter Jun 22, 2022
221a46f
Remove unused ITERATIONS param
PhilippGackstatter Jun 23, 2022
01721c2
Fix docs and implicit agent feature
PhilippGackstatter Jun 23, 2022
7cf621c
Use `AgentId` instead of peer id terminology
PhilippGackstatter Jun 23, 2022
4d3387b
Improve `DidCommAgent` doc description
PhilippGackstatter Jun 23, 2022
56d5423
Add README as crate description and in docs
PhilippGackstatter Jun 23, 2022
4e799b4
Ignore rust doctests
PhilippGackstatter Jun 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2022-01-08
toolchain: nightly-2022-04-08
override: true
components: llvm-tools-preview

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/coverage.sh
Expand Up @@ -5,7 +5,7 @@ set -e
rm -rf coverage
mkdir coverage

NIGHTLY="+nightly-2022-01-08"
NIGHTLY="+nightly-2022-04-08"

# Run tests with profiling instrumentation
echo "Running instrumented unit tests..."
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -5,13 +5,13 @@ members = [
# "identity-comm",
"identity-account",
"identity-account-storage",
"identity-actor",
"identity-core",
"identity-credential",
"identity-did",
"identity-diff",
"identity-iota",
"identity-iota-core",

"examples",
]

Expand Down
45 changes: 45 additions & 0 deletions identity-actor/Cargo.toml
@@ -0,0 +1,45 @@
[package]
name = "identity-actor"
version = "0.5.0"
authors = ["IOTA Stiftung"]
edition = "2021"
homepage = "https://www.iota.org"
keywords = ["iota", "tangle", "identity"]
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/iotaledger/identity.rs"
description = "A peer-to-peer identity communication framework"

[dependencies]
async-trait = { version = "0.1", default-features = false }
cfg-if = { version = "1.0", default-features = false }
dashmap = { version = "5.1", default-features = false }
futures = { version = "0.3", default-features = false }
identity-account = { path = "../identity-account", default-features = false, features = ["send-sync-storage"], optional = true }
identity-core = { path = "../identity-core", default-features = false }
identity-iota = { path = "../identity-iota", default-features = false }
identity-iota-core = { path = "../identity-iota-core", default-features = false }
libp2p = { version = "0.43", default-features = false, features = ["tcp-tokio", "dns-tokio", "websocket", "request-response", "noise", "yamux"] }
log = { version = "0.4", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
thiserror = { version = "1.0", default-features = false }
tokio = { version = "1.15", default-features = false, features = ["rt", "time"] }
uuid = { version = "0.8", default-features = false, features = ["v4", "serde"] }

[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies]
libp2p = { version = "*", features = ["wasm-bindgen", "wasm-ext", "wasm-ext-websocket"] }
uuid = { version = "*", features = ["wasm-bindgen"] }
wasm-bindgen-futures = { version = "0.4.29", default-features = false }
PhilippGackstatter marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
criterion = { version = "0.3", default-features = false, features = ["stable"] }
pretty_env_logger = { version = "0.4", default-features = false }

[[bench]]
name = "benchmark"
harness = false

[features]
account = ["identity-account/mem-client", "identity-account/async"]
default = []
151 changes: 151 additions & 0 deletions identity-actor/benches/benchmark.rs
@@ -0,0 +1,151 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use criterion::criterion_group;
use criterion::criterion_main;
use criterion::BenchmarkId;
use criterion::Criterion;
use identity_actor::actor::System;
use identity_actor::actor::SystemBuilder;
use identity_actor::Multiaddr;
use identity_actor::PeerId;

use actor::IdentityCreate;
use actor::RemoteAccount;

async fn setup() -> (System, PeerId, System) {
let addr: Multiaddr = "/ip4/0.0.0.0/tcp/0".parse().unwrap();
let mut builder = SystemBuilder::new();

let remote_account = RemoteAccount::new().unwrap();
builder.attach::<IdentityCreate, _>(remote_account);

let mut receiver: System = builder.build().await.unwrap();

let addr = receiver.start_listening(addr).await.unwrap();
let receiver_peer_id = receiver.peer_id();

let mut sender: System = SystemBuilder::new().build().await.unwrap();

sender.add_address(receiver_peer_id, addr).await.unwrap();

(receiver, receiver_peer_id, sender)
}

fn bench_create_remote_account(c: &mut Criterion) {
static ITERATIONS: &[usize] = &[100, 10_000, 100_000];

let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();

let (receiver, receiver_peer_id, sender) = runtime.block_on(setup());

let mut group = c.benchmark_group("create remote account");

for size in ITERATIONS.iter() {
group.bench_function(BenchmarkId::from_parameter(size), |bencher| {
bencher.to_async(&runtime).iter(|| {
let mut sender_clone: System = sender.clone();

async move {
sender_clone
.send_request(receiver_peer_id, IdentityCreate::default())
.await
.unwrap()
.unwrap();
}
});
});
}

group.finish();

runtime.block_on(async move {
sender.shutdown().await.unwrap();
receiver.shutdown().await.unwrap();
});
}

criterion_group!(benches, bench_create_remote_account);

criterion_main!(benches);

mod actor {
use dashmap::DashMap;
use identity_account::account::Account;
use identity_account::account::AccountBuilder;
use identity_account::types::IdentitySetup;
use identity_actor::actor::Actor;
use identity_actor::actor::ActorRequest;
use identity_actor::actor::Endpoint;
use identity_actor::actor::RequestContext;
use identity_iota_core::did::IotaDID;
use identity_iota_core::document::IotaDocument;
use serde::Deserialize;
use serde::Serialize;
use std::sync::Arc;
use tokio::sync::Mutex;

#[derive(Debug, Clone)]
pub struct RemoteAccount {
builder: Arc<Mutex<AccountBuilder>>,
accounts: Arc<DashMap<IotaDID, Account>>,
}

impl RemoteAccount {
pub fn new() -> identity_account::Result<Self> {
let builder: AccountBuilder = Account::builder().autopublish(false);

Ok(Self {
builder: Arc::new(Mutex::new(builder)),
accounts: Arc::new(DashMap::new()),
})
}
}

/// Can be sent to a `RemoteAccount` to instruct it to create an identity.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct IdentityCreate;

impl From<IdentityCreate> for IdentitySetup {
fn from(_: IdentityCreate) -> Self {
IdentitySetup::default()
}
}

impl ActorRequest for IdentityCreate {
type Response = Result<IotaDocument, RemoteAccountError>;

fn endpoint() -> Endpoint {
"remote_account/create".try_into().unwrap()
}
}

#[async_trait::async_trait]
impl Actor<IdentityCreate> for RemoteAccount {
async fn handle(&self, request: RequestContext<IdentityCreate>) -> Result<IotaDocument, RemoteAccountError> {
let account: Account = self.builder.lock().await.create_identity(request.input.into()).await?;
let doc = account.document().to_owned();
self.accounts.insert(account.did().to_owned(), account);
Ok(doc)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fairly expensive operation hence I am concerned the benchmark ends up primarily benchmarking account creation which is an operation implemented in another crate.

I do however agree with benching realistic use cases and it would be nice if we could find another such example, but where less time is spent inside the handler. Perhaps something like benchmarking sending a presentation request/offer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a second benchmark that purely tests DIDComm operations.

}
}

/// The error type for the [`RemoteAccount`].
#[derive(Debug, thiserror::Error, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub enum RemoteAccountError {
#[error("identity not found")]
IdentityNotFound,
#[error("{0}")]
AccountError(String),
}

impl From<identity_account::Error> for RemoteAccountError {
fn from(err: identity_account::Error) -> Self {
Self::AccountError(err.to_string())
}
}
}
106 changes: 106 additions & 0 deletions identity-actor/src/actor/actor.rs
@@ -0,0 +1,106 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::fmt::Debug;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;

use super::ActorRequest;
use super::RemoteSendError;
use super::RequestContext;
use crate::actor::ErrorLocation;

/// A boxed future that is `Send`.
pub(crate) type BoxFuture<'me, T> = Pin<Box<dyn Future<Output = T> + Send + 'me>>;

/// Actors are objects that encapsulate state and behavior.
///
/// Actors handle one or more requests by implementing this trait one or more times
/// for different `ActorRequest` types.
///
/// The requests for an actor are handled synchronously, meaning that the caller waits for
/// the actor to return its result before continuing.
#[async_trait::async_trait]
pub trait Actor<REQ: ActorRequest>: Debug + 'static {
/// Called when the system receives a request of type `REQ`.
/// The result will be returned to the calling peer.
async fn handle(&self, request: RequestContext<REQ>) -> REQ::Response;
}

/// A trait that wraps a synchronous actor implementation and erases its type.
/// This allows holding actors with different concrete types in the same collection.
pub(crate) trait AbstractActor: Debug + Send + Sync + 'static {
fn handle(&self, request: RequestContext<Vec<u8>>) -> BoxFuture<'_, Result<Vec<u8>, RemoteSendError>>;
}

/// A wrapper around synchronous actor implementations that is used for
/// type erasure together with [`AbstractSyncActor`].
#[derive(Debug)]
pub(crate) struct ActorWrapper<ACT, REQ>
where
REQ: ActorRequest + Send + Sync,
ACT: Actor<REQ> + Send + Sync,
{
actor: ACT,
_phantom_req: PhantomData<REQ>,
}

impl<ACT, REQ> ActorWrapper<ACT, REQ>
where
REQ: ActorRequest + Send + Sync,
ACT: Actor<REQ> + Send + Sync,
{
pub(crate) fn new(actor: ACT) -> Self {
Self {
actor,
_phantom_req: PhantomData,
}
}
}

impl<ACT, REQ> AbstractActor for ActorWrapper<ACT, REQ>
where
REQ: ActorRequest + Send + Sync,
REQ::Response: Send,
ACT: Actor<REQ> + Send + Sync,
{
fn handle(&self, request: RequestContext<Vec<u8>>) -> BoxFuture<'_, Result<Vec<u8>, RemoteSendError>> {
let future = async move {
let req: REQ =
serde_json::from_slice(&request.input).map_err(|error| RemoteSendError::DeserializationFailure {
location: ErrorLocation::Remote,
context: format!(
"deserializing the received bytes into the handler's expected type `{}`",
std::any::type_name::<REQ>()
),
error_message: error.to_string(),
})?;

let req: RequestContext<REQ> = request.convert(req);
let result: REQ::Response = self.actor.handle(req).await;
serialize_response::<REQ>(&result)
};

Box::pin(future)
}
}

#[inline(always)]
fn serialize_response<REQ: ActorRequest>(input: &REQ::Response) -> Result<Vec<u8>, RemoteSendError> {
log::debug!(
"Attempt serialization into {:?}",
std::any::type_name::<REQ::Response>()
);

let response: Vec<u8> = serde_json::to_vec(&input).map_err(|error| RemoteSendError::SerializationFailure {
location: ErrorLocation::Remote,
context: format!(
"serializing the handler's response into `{}`",
std::any::type_name::<REQ::Response>()
),
error_message: error.to_string(),
})?;

Ok(response)
}
18 changes: 18 additions & 0 deletions identity-actor/src/actor/config.rs
@@ -0,0 +1,18 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::time::Duration;

/// Configuration options for an `Actor`.
#[derive(Debug, Clone)]
pub(crate) struct ActorConfig {
pub(crate) timeout: Duration,
}

impl Default for ActorConfig {
fn default() -> Self {
Self {
timeout: Duration::from_secs(30),
}
}
}