@@ -2,20 +2,20 @@ import Foundation
2
2
import Combine
3
3
4
4
final class NonControllerSessionStateMachine {
5
-
6
5
var onNamespacesUpdate : ( ( String , [ String : SessionNamespace ] ) -> Void ) ?
7
- var onExtend : ( ( String , Date ) -> Void ) ?
8
6
9
7
private let sessionStore : WCSessionStorage
10
8
private let networkingInteractor : NetworkInteracting
11
9
private let kms : KeyManagementServiceProtocol
12
10
private var publishers = [ AnyCancellable] ( )
13
11
private let logger : ConsoleLogging
14
12
15
- init ( networkingInteractor: NetworkInteracting ,
16
- kms: KeyManagementServiceProtocol ,
17
- sessionStore: WCSessionStorage ,
18
- logger: ConsoleLogging ) {
13
+ init (
14
+ networkingInteractor: NetworkInteracting ,
15
+ kms: KeyManagementServiceProtocol ,
16
+ sessionStore: WCSessionStorage ,
17
+ logger: ConsoleLogging
18
+ ) {
19
19
self . networkingInteractor = networkingInteractor
20
20
self . kms = kms
21
21
self . sessionStore = sessionStore
@@ -28,11 +28,6 @@ final class NonControllerSessionStateMachine {
28
28
. sink { [ unowned self] ( payload: RequestSubscriptionPayload < SessionType . UpdateParams > ) in
29
29
onSessionUpdateNamespacesRequest ( payload: payload, updateParams: payload. request)
30
30
} . store ( in: & publishers)
31
-
32
- networkingInteractor. requestSubscription ( on: SessionExtendProtocolMethod ( ) )
33
- . sink { [ unowned self] ( payload: RequestSubscriptionPayload < SessionType . UpdateExpiryParams > ) in
34
- onSessionUpdateExpiry ( payload: payload, updateExpiryParams: payload. request)
35
- } . store ( in: & publishers)
36
31
}
37
32
38
33
private func respondError( payload: SubscriptionPayload , reason: SignReasonCode , protocolMethod: ProtocolMethod ) {
@@ -72,27 +67,4 @@ final class NonControllerSessionStateMachine {
72
67
73
68
onNamespacesUpdate ? ( session. topic, updateParams. namespaces)
74
69
}
75
-
76
- private func onSessionUpdateExpiry( payload: SubscriptionPayload , updateExpiryParams: SessionType . UpdateExpiryParams ) {
77
- let protocolMethod = SessionExtendProtocolMethod ( )
78
- let topic = payload. topic
79
- guard var session = sessionStore. getSession ( forTopic: topic) else {
80
- return respondError ( payload: payload, reason: . noSessionForTopic, protocolMethod: protocolMethod)
81
- }
82
- guard session. peerIsController else {
83
- return respondError ( payload: payload, reason: . unauthorizedExtendRequest, protocolMethod: protocolMethod)
84
- }
85
- do {
86
- try session. updateExpiry ( to: updateExpiryParams. expiry)
87
- } catch {
88
- return respondError ( payload: payload, reason: . invalidExtendRequest, protocolMethod: protocolMethod)
89
- }
90
- sessionStore. setSession ( session)
91
-
92
- Task ( priority: . high) {
93
- try await networkingInteractor. respondSuccess ( topic: payload. topic, requestId: payload. id, protocolMethod: protocolMethod)
94
- }
95
-
96
- onExtend ? ( session. topic, session. expiryDate)
97
- }
98
70
}
0 commit comments