Commit d48e230
committed
Replace Sender
This commit updates the v2 Sender state transition methods to
return state transition objects. Each state transition produces
different outcomes based on the current state. When persisted, a state
transition object returns the next valid state.
Changes to `v2::receiver`
`persist.rs`
This file now contains the core logic for the session history manager,
receiver session events, and associated error types.
`send/v2/mod.rs`
Introduced a sum type that wraps all possible sender session states.
This type processes session events by checking if the event is valid for
the current state. If valid, it uses the state’s `apply` method to move
to the next state. The `apply` method acts as a shorthand for handling
state transitions based on session events.
Updated all state transition methods to return a transition object.
Removed the `sender_ser_de_roundtrip` test since session events no
longer store the data needed to reconstruct this typestate.
Removed `V2PostContext` as a sender session typestate because it broke
the typestate pattern and introduces risk of OHTTP key reuse.
Other typestates follow a clear structure: construct a request, process
a response, and transition only after learning new information.
Information that we log as a session event. `V2PostContext` deviated
from this by not representing any new session information. Re-generating
the POST request (`extract_v2`) simply produces the same request. The
only variation comes from the ephemeral OHTTP keys that are created per
request. Supporting `V2PostContext` as its own typestate would require
storing the request in the session event. That approach would allow
applications to reuse the same ephemeral OHTTP keys, linking requests
and undermining privacy. Instead, this commit updates the flow to let
applications resume a session by re-extracting the v2 payload. The state
only advances after successfully processing the response.
Multiparty changes:
Removed the `Persister` trait support from the sender’s multiparty
module. Calls to the wrapped v2 typestate now use a noop persister and
forward API errors. Storage-related errors are unwrapped with `expect()`
since they're currently infallible. Future work will add proper session
persistence to both sender and receiver multiparty modules.
Changes to Payjoin-CLI
`app/v2/mod.rs`
Updated app logic to handle resumed sender sessions that may be in any
of the typestates. Renamed `long_poll_post` to `post_original_proposal`,
which now tries to advance the state machine after receiving a proposal.
Database
Removed the old `Persister` implementation in favor of
`SessionPersister`. Also dropped the `close` and `get_session` methods
since the current flow no longer uses them.
FFI changes
This commit monomorphizes each state transition object to be specific to
its corresponding state transition, removing generic parameters to
enable UniFFI exposure. Each state transition object is wrapped in an
`Arc<RwLock<Option<Object>>>` to allow FFI bindings to reference self
safely. UniFFI does not enforce Rust’s strong borrowing guarantees and
operates more predictabily with `&self`.
To prevent a replay error naming comflict this commit prefixes the
receiver's error with "Reciver_".
Additionally, this commit introduces `JsonSenderSessionPersister`,
enabling applications to persist and load session events using exposed
to_json and from_json methods on `SenderSessionEvent`.Persister trait with SessionPersister
1 parent e7c6786 commit d48e230
File tree
17 files changed
+940
-600
lines changed- payjoin-cli/src
- app/v2
- db
- payjoin-ffi
- python/test
- src
- receive
- send
- tests
- payjoin
- src
- send
- multiparty
- v2
- tests
17 files changed
+940
-600
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
63 | 77 | | |
| 78 | + | |
64 | 79 | | |
65 | | - | |
66 | | - | |
| 80 | + | |
67 | 81 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
74 | 85 | | |
75 | 86 | | |
76 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
77 | 95 | | |
78 | 96 | | |
79 | 97 | | |
| |||
104 | 122 | | |
105 | 123 | | |
106 | 124 | | |
107 | | - | |
| 125 | + | |
108 | 126 | | |
109 | | - | |
| 127 | + | |
110 | 128 | | |
111 | 129 | | |
112 | 130 | | |
| |||
124 | 142 | | |
125 | 143 | | |
126 | 144 | | |
127 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
128 | 150 | | |
129 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
130 | 154 | | |
131 | 155 | | |
132 | 156 | | |
| |||
147 | 171 | | |
148 | 172 | | |
149 | 173 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
157 | 194 | | |
158 | | - | |
159 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
160 | 200 | | |
| 201 | + | |
161 | 202 | | |
162 | 203 | | |
163 | 204 | | |
164 | 205 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
188 | 237 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
202 | 247 | | |
203 | 248 | | |
204 | 249 | | |
| |||
0 commit comments