@@ -41,16 +41,19 @@ fn cleans_after_delay() {
41
41
let first = fake_entry ( 1 ) ;
42
42
let second = fake_entry ( 1 ) ;
43
43
let third = fake_entry ( 1 ) ;
44
- map. insert ( first. clone ( ) ) ;
45
- map. insert ( second. clone ( ) ) ;
44
+ map. on_new_path_secrets ( first. clone ( ) ) ;
45
+ map. on_handshake_complete ( first. clone ( ) ) ;
46
+ map. on_new_path_secrets ( second. clone ( ) ) ;
47
+ map. on_handshake_complete ( second. clone ( ) ) ;
46
48
47
49
assert ! ( map. state. ids. contains_key( first. secret. id( ) ) ) ;
48
50
assert ! ( map. state. ids. contains_key( second. secret. id( ) ) ) ;
49
51
50
52
map. state . cleaner . clean ( & map. state , 1 ) ;
51
53
map. state . cleaner . clean ( & map. state , 1 ) ;
52
54
53
- map. insert ( third. clone ( ) ) ;
55
+ map. on_new_path_secrets ( third. clone ( ) ) ;
56
+ map. on_handshake_complete ( third. clone ( ) ) ;
54
57
55
58
assert ! ( !map. state. ids. contains_key( first. secret. id( ) ) ) ;
56
59
assert ! ( map. state. ids. contains_key( second. secret. id( ) ) ) ;
@@ -86,9 +89,10 @@ struct Model {
86
89
87
90
#[ derive( bolero:: TypeGenerator , Debug , Copy , Clone ) ]
88
91
enum Operation {
89
- Insert { ip : u8 , path_secret_id : TestId } ,
92
+ NewPathSecret { ip : u8 , path_secret_id : TestId } ,
90
93
AdvanceTime ,
91
94
ReceiveUnknown { path_secret_id : TestId } ,
95
+ HandshakeComplete { path_secret_id : TestId } ,
92
96
}
93
97
94
98
#[ derive( bolero:: TypeGenerator , PartialEq , Eq , Hash , Copy , Clone ) ]
@@ -130,13 +134,13 @@ enum Invariant {
130
134
impl Model {
131
135
fn perform ( & mut self , operation : Operation , state : & Map ) {
132
136
match operation {
133
- Operation :: Insert { ip, path_secret_id } => {
137
+ Operation :: NewPathSecret { ip, path_secret_id } => {
134
138
let ip = SocketAddr :: V4 ( SocketAddrV4 :: new ( Ipv4Addr :: from ( [ 0 , 0 , 0 , ip] ) , 0 ) ) ;
135
139
let secret = path_secret_id. secret ( ) ;
136
140
let id = * secret. id ( ) ;
137
141
138
142
let stateless_reset = state. state . signer . sign ( & id) ;
139
- state. insert ( Arc :: new ( Entry :: new (
143
+ state. on_new_path_secrets ( Arc :: new ( Entry :: new (
140
144
ip,
141
145
secret,
142
146
sender:: State :: new ( stateless_reset) ,
@@ -145,9 +149,16 @@ impl Model {
145
149
dc:: testing:: TEST_REHANDSHAKE_PERIOD ,
146
150
) ) ) ;
147
151
148
- self . invariants . insert ( Invariant :: ContainsIp ( ip) ) ;
149
152
self . invariants . insert ( Invariant :: ContainsId ( id) ) ;
150
153
}
154
+ Operation :: HandshakeComplete { path_secret_id } => {
155
+ if let Some ( entry) = state. state . ids . get_by_key ( & path_secret_id. id ( ) ) {
156
+ if !state. state . peers . contains_key ( & entry. peer ) {
157
+ state. on_handshake_complete ( entry. clone ( ) ) ;
158
+ }
159
+ self . invariants . insert ( Invariant :: ContainsIp ( entry. peer ) ) ;
160
+ }
161
+ }
151
162
Operation :: AdvanceTime => {
152
163
let mut invalidated = Vec :: new ( ) ;
153
164
self . invariants . retain ( |invariant| {
@@ -232,7 +243,7 @@ fn has_duplicate_pids(ops: &[Operation]) -> bool {
232
243
let mut ids = HashSet :: new ( ) ;
233
244
for op in ops. iter ( ) {
234
245
match op {
235
- Operation :: Insert {
246
+ Operation :: NewPathSecret {
236
247
ip : _,
237
248
path_secret_id,
238
249
} => {
@@ -244,6 +255,10 @@ fn has_duplicate_pids(ops: &[Operation]) -> bool {
244
255
Operation :: ReceiveUnknown { path_secret_id : _ } => {
245
256
// no-op, we're fine receiving unknown pids.
246
257
}
258
+ Operation :: HandshakeComplete { .. } => {
259
+ // no-op, a handshake complete for the same pid as a
260
+ // new path secret is expected
261
+ }
247
262
}
248
263
}
249
264
@@ -320,7 +335,9 @@ fn no_memory_growth() {
320
335
map. state . cleaner . stop ( ) ;
321
336
for idx in 0 ..500_000 {
322
337
// FIXME: this ends up 2**16 peers in the `peers` map
323
- map. insert ( fake_entry ( idx as u16 ) ) ;
338
+ let entry = fake_entry ( idx as u16 ) ;
339
+ map. on_new_path_secrets ( entry. clone ( ) ) ;
340
+ map. on_handshake_complete ( entry)
324
341
}
325
342
}
326
343
0 commit comments