p2p/connection/incoming_effectful/
p2p_connection_incoming_effectful_effects.rs1use redux::ActionMeta;
2
3use super::P2pConnectionIncomingEffectfulAction;
4use crate::connection::{
5 incoming::{P2pConnectionIncomingAction, P2pConnectionIncomingError},
6 P2pConnectionService,
7};
8
9impl P2pConnectionIncomingEffectfulAction {
10 pub fn effects<Store, S>(self, _meta: &ActionMeta, store: &mut Store)
11 where
12 Store: crate::P2pStore<S>,
13 Store::Service: P2pConnectionService,
14 {
15 match self {
16 P2pConnectionIncomingEffectfulAction::Init { opts } => {
17 let peer_id = opts.peer_id;
18 store.service().incoming_init(peer_id, *opts.offer);
19 store.dispatch(P2pConnectionIncomingAction::AnswerSdpCreatePending { peer_id });
20 }
21 P2pConnectionIncomingEffectfulAction::ConnectionAuthorizationEncryptAndSend {
22 peer_id,
23 other_pub_key,
24 auth,
25 } => {
26 store
27 .service()
28 .auth_encrypt_and_send(peer_id, &other_pub_key, auth);
29 }
30 P2pConnectionIncomingEffectfulAction::ConnectionAuthorizationDecryptAndCheck {
31 peer_id,
32 other_pub_key,
33 expected_auth,
34 auth,
35 } => {
36 if store
37 .service()
38 .auth_decrypt(&other_pub_key, auth)
39 .is_some_and(|remote_auth| remote_auth == expected_auth)
40 {
41 store.dispatch(P2pConnectionIncomingAction::Success { peer_id });
42 } else {
43 store.dispatch(P2pConnectionIncomingAction::Error {
44 peer_id,
45 error: P2pConnectionIncomingError::ConnectionAuthError,
46 });
47 }
48 }
49 }
50 }
51}