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

Refactor/typestate connections #739

Merged
merged 66 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d1096bf
Added draft for typestate connection state machine
bobozaur Jan 19, 2023
d76bf5e
Added dummy, not functional tests, as a mere representation of the tr…
bobozaur Jan 24, 2023
598a7bc
Remove obsolete structs
bobozaur Jan 24, 2023
76f6c4f
Remove dummy tests. Will properly reimplement them later
bobozaur Jan 24, 2023
0295e46
Removed transport type from type state Connection
bobozaur Jan 25, 2023
63f7d46
Factored out build_con_request method
bobozaur Jan 25, 2023
ee571df
Moved all typestate connection related code to a different module
bobozaur Jan 25, 2023
8fff813
Refactored inner methods and simplified them
bobozaur Jan 25, 2023
ad9a6fe
Reverted changes on current code as the typestate_con is separated in…
bobozaur Jan 26, 2023
fb1260a
Added serde capabilities to typestate Connection
bobozaur Jan 26, 2023
f48c429
Added invitation processing to Invitee and moved some Connection meth…
bobozaur Jan 27, 2023
18b0f4c
Renamed SerdeCon to VagueConnection. This will be used for deserializ…
bobozaur Jan 27, 2023
6ea03e7
Added dedicated serialization types for borrowed serialization of Con…
bobozaur Jan 27, 2023
3b51586
Fixed Connection serialization trait bounds
bobozaur Jan 27, 2023
9280633
Reverted to using invitation ID as thread ID
bobozaur Jan 27, 2023
1927b5e
Added direct deserialization support to Connection through try_from i…
bobozaur Jan 27, 2023
ccbdb78
Set typestate_con states attributes pub(crate)
bobozaur Jan 27, 2023
792c4a6
Added typestate_con libvcx implementation draft
bobozaur Jan 27, 2023
0574540
Completed typestate_con implementation in libvcx
bobozaur Jan 29, 2023
6f65e34
Renamed remove_connection in libvcx to get_cloned_connection and impl…
bobozaur Jan 30, 2023
ebba648
Removed the lazy_static HTTPCLIENT in favor of using the ZST directly
bobozaur Jan 30, 2023
cf7b88b
Retro-fitted the process_request and send_response methods for backwa…
bobozaur Jan 30, 2023
ea14d58
Added ProblemReport generation and sending
bobozaur Jan 30, 2023
b81b2b6
Added test From implementations between SerializableConnection and Va…
bobozaur Jan 30, 2023
7595bbe
Added boilerplate macro for From impls for SerializationConnection
bobozaur Jan 30, 2023
ef29fbe
Modified aries-vcx-agent to use typestate connections
bobozaur Jan 31, 2023
f4e677e
Fixed method rename in libvcx
bobozaur Feb 1, 2023
6234370
Removed send_invitation method
bobozaur Feb 1, 2023
c060847
Typestate connection cosmetic changes, comments, and modules re-organ…
bobozaur Feb 1, 2023
1abda21
Removed previous non-mediated Connection in favor of newer typestate …
bobozaur Feb 1, 2023
7c932e5
Fixed state differences in Node.js wrapper
bobozaur Feb 1, 2023
695305a
Reuse request did_doc
bobozaur Feb 1, 2023
e88ce9e
Moved Transport trait and auto-implemented for references of types im…
bobozaur Feb 1, 2023
e30200d
Fix FFI wrapper to return a Promise for the async request handling
bobozaur Feb 1, 2023
b839c86
Reverting dependencies in vcxagent-core
bobozaur Feb 2, 2023
b2ce58e
Ignore dist dirs
bobozaur Feb 2, 2023
876a099
Reverted NAPI changes and mimicked old connection states more accurat…
bobozaur Feb 2, 2023
f2f8e5a
Fixed accept_invitation log comment and added more explicit logs to l…
bobozaur Feb 2, 2023
5cb9f83
processInvite is now a Promise
bobozaur Feb 2, 2023
43c8c95
Fixed thread_id handling when accepting invitation and sending reques…
bobozaur Feb 2, 2023
6e96c55
More state retro-fitting with previous implementation
bobozaur Feb 3, 2023
88e66f2
Fix thread_id usage in Request generation
bobozaur Feb 3, 2023
1324b59
Added comments
bobozaur Feb 3, 2023
ca3ddcc
Added concrete and generic connection serialization and deserializati…
bobozaur Feb 3, 2023
64fc633
Added whitespace in libcx
bobozaur Feb 3, 2023
05f0303
Ran cargo fmt
bobozaur Feb 3, 2023
2d5145a
Completely separated states between invitee and inviter
bobozaur Feb 7, 2023
1541771
Added BootstrapDidDoc trait
bobozaur Feb 7, 2023
079f742
Added non-mediated connection OOB handling
bobozaur Feb 7, 2023
2fdef4f
Improved OOB connection existence look-up and implemented libvcx non-…
bobozaur Feb 7, 2023
6ee9d09
Implemented necessary changes to node wrappers to expose non-mediated…
bobozaur Feb 7, 2023
98e4a50
Unexposed internal OOB method
bobozaur Feb 7, 2023
26a2441
Added re-export of PairwiseInfo to mediatedconnection to avoid struct…
bobozaur Feb 7, 2023
4675cb5
Ran cargo fmt
bobozaur Feb 7, 2023
ece4d8a
Fixed GenericConnection doc test and comment
bobozaur Feb 7, 2023
307ae05
Made processInvite in node wrapper async
bobozaur Feb 7, 2023
a34ff89
Fixed comments typos
bobozaur Feb 8, 2023
c960830
Added more comments to Connection::into_invited
bobozaur Feb 8, 2023
674015b
Added comments to Connection::get_invitation
bobozaur Feb 8, 2023
607b1dd
Accommodated previous send_message behavior
bobozaur Feb 8, 2023
8ff5041
Factored out read access to CONNECTION_MAP in libvcx into a closure a…
bobozaur Feb 8, 2023
3eba85b
Fixed wrapper send_message and added send_aries_message
bobozaur Feb 8, 2023
eacc08d
Fixed comment link
bobozaur Feb 8, 2023
735c302
Updated napi and napi-derive dependencies version
bobozaur Feb 8, 2023
afd198d
Made from_parts public and added into_parts method on Connection
bobozaur Feb 9, 2023
3cb83fb
Made node wrapper serialize a connection as a JSON object instead of …
bobozaur Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aries_vcx/src/handlers/connection/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl MediatedConnection {
}
}

pub fn get_remote_protocols(&self) -> Option<Vec<ProtocolDescriptor>> {
pub fn get_remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
match &self.connection_sm {
SmConnection::Inviter(sm_inviter) => sm_inviter.get_remote_protocols(),
SmConnection::Invitee(sm_invitee) => sm_invitee.get_remote_protocols(),
Expand Down Expand Up @@ -898,7 +898,7 @@ impl MediatedConnection {
recipient_keys: did_doc.recipient_keys()?,
routing_keys: did_doc.routing_keys(),
service_endpoint: did_doc.get_endpoint(),
protocols: self.get_remote_protocols(),
protocols: self.get_remote_protocols().map(ToOwned::to_owned),
}),
None => None,
};
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/protocols/connection/invitee/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod state_machine;
mod states;
pub mod states;
28 changes: 10 additions & 18 deletions aries_vcx/src/protocols/connection/invitee/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl SmConnectionInvitee {
SmConnectionInvitee {
source_id: source_id.to_string(),
thread_id: String::new(),
state: InviteeFullState::Initial(InitialState::new(None, Some(did_doc))),
state: InviteeFullState::Initial(InitialState::new(None, did_doc)),
pairwise_info,
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl SmConnectionInvitee {

pub fn their_did_doc(&self) -> Option<AriesDidDoc> {
match self.state {
InviteeFullState::Initial(ref state) => state.did_doc.clone(),
InviteeFullState::Initial(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Invited(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Requested(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Responded(ref state) => Some(state.did_doc.clone()),
Expand All @@ -122,7 +122,7 @@ impl SmConnectionInvitee {

pub async fn bootstrap_did_doc(&self) -> Option<AriesDidDoc> {
match self.state {
InviteeFullState::Initial(ref state) => state.did_doc.clone(),
InviteeFullState::Initial(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Invited(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Requested(ref state) => Some(state.did_doc.clone()),
InviteeFullState::Responded(ref state) => Some(state.did_doc.clone()),
Expand Down Expand Up @@ -150,9 +150,9 @@ impl SmConnectionInvitee {
ProtocolRegistry::init().protocols()
}

pub fn get_remote_protocols(&self) -> Option<Vec<ProtocolDescriptor>> {
pub fn get_remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
match self.state {
InviteeFullState::Completed(ref state) => state.protocols.clone(),
InviteeFullState::Completed(ref state) => state.remote_protocols(),
_ => None,
}
}
Expand Down Expand Up @@ -242,17 +242,9 @@ impl SmConnectionInvitee {
let Self { state, .. } = self;
let thread_id = invitation.get_id()?;
let state = match state {
InviteeFullState::Initial(state) => InviteeFullState::Invited(
(
state.clone(),
invitation,
state.did_doc.ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
"Expected none None state.did_doc result given current state",
))?,
)
.into(),
),
InviteeFullState::Initial(state) => {
bobozaur marked this conversation as resolved.
Show resolved Hide resolved
InviteeFullState::Invited((state.clone(), invitation, state.did_doc).into())
}
s => {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
Expand Down Expand Up @@ -373,8 +365,8 @@ impl SmConnectionInvitee {

pub fn handle_problem_report(self, _problem_report: ProblemReport) -> VcxResult<Self> {
let state = match self.state {
InviteeFullState::Requested(_state) => InviteeFullState::Initial(InitialState::new(None, None)),
InviteeFullState::Invited(_state) => InviteeFullState::Initial(InitialState::new(None, None)),
InviteeFullState::Requested(_state) => InviteeFullState::Initial(InitialState::new(None, _state.did_doc)),
InviteeFullState::Invited(_state) => InviteeFullState::Initial(InitialState::new(None, _state.did_doc)),
_ => self.state.clone(),
};
Ok(Self { state, ..self })
Expand Down
12 changes: 11 additions & 1 deletion aries_vcx/src/protocols/connection/invitee/states/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::protocols::connection::invitee::states::requested::RequestedState;
use crate::protocols::connection::invitee::states::responded::RespondedState;
use messages::diddoc::aries::diddoc::AriesDidDoc;
use messages::protocols::connection::response::Response;
use messages::protocols::discovery::disclose::ProtocolDescriptor;
use messages::protocols::discovery::disclose::{ProtocolDescriptor, Disclose};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CompleteState {
Expand All @@ -13,6 +13,16 @@ pub struct CompleteState {
pub protocols: Option<Vec<ProtocolDescriptor>>,
}

impl CompleteState {
pub fn remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
self.protocols.as_deref()
}

pub fn handle_disclose(&mut self, disclose: Disclose) {
self.protocols = Some(disclose.protocols)
}
}

impl From<(CompleteState, Vec<ProtocolDescriptor>)> for CompleteState {
fn from((state, protocols): (CompleteState, Vec<ProtocolDescriptor>)) -> CompleteState {
trace!("ConnectionInvitee: transit state from CompleteState to CompleteState");
Expand Down
6 changes: 3 additions & 3 deletions aries_vcx/src/protocols/connection/invitee/states/initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use messages::protocols::connection::problem_report::ProblemReport;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct InitialState {
problem_report: Option<ProblemReport>,
pub did_doc: Option<AriesDidDoc>,
pub problem_report: Option<ProblemReport>,
pub did_doc: AriesDidDoc,
}

impl From<(InitialState, Invitation, AriesDidDoc)> for InvitedState {
Expand All @@ -17,7 +17,7 @@ impl From<(InitialState, Invitation, AriesDidDoc)> for InvitedState {
}

impl InitialState {
pub fn new(problem_report: Option<ProblemReport>, did_doc: Option<AriesDidDoc>) -> Self {
pub fn new(problem_report: Option<ProblemReport>, did_doc: AriesDidDoc) -> Self {
InitialState {
problem_report,
did_doc,
Expand Down
10 changes: 5 additions & 5 deletions aries_vcx/src/protocols/connection/invitee/states/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(super) mod complete;
pub(super) mod initial;
pub(super) mod invited;
pub(super) mod requested;
pub(super) mod responded;
pub mod complete;
pub mod initial;
pub mod invited;
pub mod requested;
pub mod responded;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl From<(RequestedState, ProblemReport)> for InitialState {
"ConnectionInvitee: transit state from RequestedState to InitialState, problem_report: {:?}",
problem_report
);
InitialState::new(Some(problem_report), None)
InitialState::new(Some(problem_report), _state.did_doc)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ impl From<(RespondedState, ProblemReport)> for InitialState {
"ConnectionInvitee: transit state from RespondedState to InitialState, problem_report: {:?}",
problem_report
);
InitialState::new(Some(problem_report), None)
InitialState::new(Some(problem_report), _state.did_doc)
}
}
4 changes: 2 additions & 2 deletions aries_vcx/src/protocols/connection/inviter/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ impl SmConnectionInviter {
ProtocolRegistry::init().protocols()
}

pub fn get_remote_protocols(&self) -> Option<Vec<ProtocolDescriptor>> {
pub fn get_remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
match self.state {
InviterFullState::Completed(ref state) => state.protocols.clone(),
InviterFullState::Completed(ref state) => state.remote_protocols(),
_ => None,
}
}
Expand Down
12 changes: 11 additions & 1 deletion aries_vcx/src/protocols/connection/inviter/states/complete.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::clone::Clone;

use messages::diddoc::aries::diddoc::AriesDidDoc;
use messages::protocols::discovery::disclose::ProtocolDescriptor;
use messages::protocols::discovery::disclose::{Disclose, ProtocolDescriptor};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CompleteState {
Expand All @@ -10,6 +10,16 @@ pub struct CompleteState {
pub thread_id: Option<String>,
}

impl CompleteState {
pub fn remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
self.protocols.as_deref()
}

pub fn handle_disclose(&mut self, disclose: Disclose) {
self.protocols = Some(disclose.protocols)
}
}

impl From<(CompleteState, Vec<ProtocolDescriptor>)> for CompleteState {
fn from((state, protocols): (CompleteState, Vec<ProtocolDescriptor>)) -> CompleteState {
trace!("ConnectionInviter: transit state from CompleteState to CompleteState");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ impl From<(Request, SignedResponse)> for RequestedState {
thread_id: request.id.0,
}
}
}
}
1 change: 1 addition & 0 deletions aries_vcx/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod oob;
pub mod proof_presentation;
pub mod revocation_notification;
pub mod trustping;
pub mod typestate_con;

pub type SendClosure = Box<dyn FnOnce(A2AMessage) -> BoxFuture<'static, VcxResult<()>> + Send + Sync>;
pub type SendClosureConnection =
Expand Down
1 change: 1 addition & 0 deletions aries_vcx/src/protocols/typestate_con/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod states;
37 changes: 37 additions & 0 deletions aries_vcx/src/protocols/typestate_con/common/states/complete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::clone::Clone;

use messages::diddoc::aries::diddoc::AriesDidDoc;
use messages::protocols::discovery::disclose::{Disclose, ProtocolDescriptor};

use crate::protocols::typestate_con::trait_bounds::TheirDidDoc;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CompleteState {
pub did_doc: AriesDidDoc,
pub thread_id: String,
pub protocols: Option<Vec<ProtocolDescriptor>>,
}

impl CompleteState {
pub fn new(did_doc: AriesDidDoc, thread_id: String, protocols: Option<Vec<ProtocolDescriptor>>) -> Self {
Self {
did_doc,
thread_id,
protocols,
}
}

pub fn remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
self.protocols.as_deref()
}

pub fn handle_disclose(&mut self, disclose: Disclose) {
self.protocols = Some(disclose.protocols)
}
}

impl TheirDidDoc for CompleteState {
fn their_did_doc(&self) -> &AriesDidDoc {
&self.did_doc
}
}
2 changes: 2 additions & 0 deletions aries_vcx/src/protocols/typestate_con/common/states/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod complete;
pub mod responded;
21 changes: 21 additions & 0 deletions aries_vcx/src/protocols/typestate_con/common/states/responded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use messages::diddoc::aries::diddoc::AriesDidDoc;

use crate::protocols::typestate_con::trait_bounds::TheirDidDoc;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RespondedState {
pub did_doc: AriesDidDoc,
pub thread_id: String
}

impl RespondedState {
pub fn new(did_doc: AriesDidDoc, thread_id: String) -> Self {
Self { did_doc, thread_id }
}
}

impl TheirDidDoc for RespondedState {
fn their_did_doc(&self) -> &AriesDidDoc {
&self.did_doc
}
}
6 changes: 6 additions & 0 deletions aries_vcx/src/protocols/typestate_con/initiation_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/// Unit struct illustrating that the connection was initiated by an inviter.
pub struct Inviter;

/// Unit struct illustrating that the connection was initiated by an invitee.
pub struct Invitee;
Loading