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

peer_state: Robust state machine transitions #251

Merged
merged 46 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
59dbbf8
address: Add score constants to the address store
lexnv Sep 24, 2024
ae7799a
address: Convert DialError to appropriate score
lexnv Sep 24, 2024
ac5d731
address: Implement eviction algorithm for the AddressStore
lexnv Sep 24, 2024
a2356ec
manager: Keep track of the address for future dials
lexnv Sep 24, 2024
5355e85
manager: Make add_known_address more robust to track multiple peer addrs
lexnv Sep 24, 2024
ecb436b
manager: Track addresses better for dial and open failure
lexnv Sep 24, 2024
bf066d1
manager: Update addresses on connection established
lexnv Sep 24, 2024
b052c5d
manager/handle: Keep lock for shorter time
lexnv Sep 24, 2024
da52056
address/tests: Adjust testing
lexnv Sep 24, 2024
6c7f399
address/tests: Add tests for eviction and insertion
lexnv Sep 24, 2024
5b88ea4
manager/tests: Adjust testing to new address store interface
lexnv Sep 24, 2024
d575812
peer_state: Introduce connection record without address score
lexnv Sep 24, 2024
6494256
peer_state: Refactor peerstate for minimal state machine
lexnv Sep 24, 2024
7029015
peer_state: Implement peer state transitions isolated from manager
lexnv Sep 24, 2024
3f4cdc9
peer_state/tests: Add tests for peerstate transitions
lexnv Sep 24, 2024
6bf358b
address_store: Remove connection ID from the store
lexnv Sep 24, 2024
c9205df
types: Remove secondary connection ID and use new peerstate
lexnv Sep 24, 2024
25a5c5e
manager: Handle opening addresses generically
lexnv Sep 24, 2024
a792d0e
manager: Refactor dialing on multiple addresses
lexnv Sep 24, 2024
c7c5ed4
manager: Refactor dial addresses
lexnv Sep 24, 2024
b137d0a
manager: Refactor on dial failure
lexnv Sep 24, 2024
f4d46a9
manager: Refacotr on connection closed
lexnv Sep 24, 2024
a795fd4
manager: Refactor on connection established
lexnv Sep 24, 2024
7c8242b
manager: Refactor on connection opened
lexnv Sep 24, 2024
f7e6d88
manager: Refactor on open failure
lexnv Sep 24, 2024
10cb1ed
manager/tests: Adjust testing to the new interface
lexnv Sep 24, 2024
728c563
manager/handle: Use new peerstate interface
lexnv Sep 24, 2024
450c109
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
16e1294
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
ebe8853
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
2a33ab5
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
caaa3f1
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
f2b4285
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
4614c7d
Update src/transport/manager/peer_state.rs
lexnv Oct 25, 2024
c8180ab
Update src/transport/manager/mod.rs
lexnv Oct 25, 2024
2105dd2
peer_state: Fix clippy
lexnv Oct 25, 2024
896c47b
peer_state: Address other possible states
lexnv Oct 25, 2024
4a09f3f
peer_state: Warn if connection opened from other sources
lexnv Oct 25, 2024
8fa12bb
peerstate: Add warns when opening -> connected
lexnv Oct 25, 2024
22406c6
peer_state: Warn about peerId mismatch
lexnv Oct 25, 2024
764b769
manager: Replace assert with warn
lexnv Oct 25, 2024
14d7f0f
Merge remote-tracking branch 'origin/master' into lexnv/improve-peer-…
lexnv Oct 25, 2024
b7ba361
peerstate: Downgrade warn to trace
lexnv Oct 25, 2024
6e5868e
manager: Rename `Self::open_addresses` to
lexnv Oct 28, 2024
c2ee9b8
manager: Link todo issue
lexnv Oct 28, 2024
fc7dea1
peer_state: Use peer as state to ensure peerID
lexnv Oct 28, 2024
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
Prev Previous commit
Next Next commit
address/tests: Add tests for eviction and insertion
Signed-off-by: Alexandru Vasile <[email protected]>
lexnv committed Sep 24, 2024

Verified

This commit was signed with the committer’s verified signature.
lexnv Alexandru Vasile
commit 6c7f399ee20254d99dd1ff0e2d2b6f7f46501ab9
73 changes: 73 additions & 0 deletions src/transport/manager/address.rs
Original file line number Diff line number Diff line change
@@ -497,4 +497,77 @@ mod tests {
assert_eq!(stored.address(), record.address());
}
}

#[test]
fn insert_record() {
let mut store = AddressStore::new();
let mut rng = rand::thread_rng();

let mut record = tcp_address_record(&mut rng);
record.score = 10;

store.insert(record.clone());

assert_eq!(store.addresses.len(), 1);
assert_eq!(store.addresses.get(record.address()).unwrap(), &record);

// This time the record is updated.
store.insert(record.clone());

assert_eq!(store.addresses.len(), 1);
let store_record = store.addresses.get(record.address()).unwrap();
assert_eq!(store_record.score, record.score * 2);
}

#[test]
fn evict_below_threshold() {
let mut store = AddressStore::new();
let mut rng = rand::thread_rng();

let mut record = tcp_address_record(&mut rng);
record.score = scores::CONNECTION_FAILURE;
store.insert(record.clone());

assert_eq!(store.addresses.len(), 1);

store.insert(record.clone());

assert_eq!(store.addresses.len(), 0);
}

#[test]
fn evict_on_capacity() {
let mut store = AddressStore {
addresses: HashMap::new(),
max_capacity: 2,
};

let mut rng = rand::thread_rng();
let mut first_record = tcp_address_record(&mut rng);
first_record.score = scores::CONNECTION_ESTABLISHED;
let mut second_record = ws_address_record(&mut rng);
second_record.score = 0;

store.insert(first_record.clone());
store.insert(second_record.clone());

assert_eq!(store.addresses.len(), 2);

// We have better addresses, ignore this one.
let mut third_record = quic_address_record(&mut rng);
third_record.score = scores::CONNECTION_FAILURE;
store.insert(third_record.clone());
assert_eq!(store.addresses.len(), 2);
assert!(store.addresses.contains_key(first_record.address()));
assert!(store.addresses.contains_key(second_record.address()));

// Evict the address with the lowest score.
let mut fourth_record = quic_address_record(&mut rng);
fourth_record.score = scores::DIFFERENT_PEER_ID;
store.insert(fourth_record.clone());

assert_eq!(store.addresses.len(), 2);
assert!(store.addresses.contains_key(first_record.address()));
assert!(store.addresses.contains_key(fourth_record.address()));
}
}