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

WIP: manager: Improve address handling and refactor PeerState #248

Closed
wants to merge 66 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
22d6b48
manager/address: Fix typo
lexnv Sep 17, 2024
86e017f
manager/address: Store addresses using a HashMap
lexnv Sep 18, 2024
8ec9e54
manager: Keep dial addresses around even if the peer is connected
lexnv Sep 18, 2024
83b9361
manager: Update dial failure address scores
lexnv Sep 18, 2024
b28a234
manager: Clean up the disconnected dial record on failure
lexnv Sep 18, 2024
68e3328
manager: Bump addresses to 64
lexnv Sep 19, 2024
4ad526f
manager: Make add_known_address more robust to track multiple peer addrs
lexnv Sep 19, 2024
a924fa2
manager: Construct the store with dialing address present
lexnv Sep 19, 2024
445ca74
manager: Track dial failure addresses regardless of peer states
lexnv Sep 19, 2024
7220f7a
manager: Update addresses only in dedicated function
lexnv Sep 19, 2024
f56e8c0
manager: Remove unneeded methods
lexnv Sep 19, 2024
a0fb0c9
manager: Keep track of the latest connection ID
lexnv Sep 19, 2024
40e149b
manager: Better constants for scoring
lexnv Sep 19, 2024
7e15747
manager: Update addresses on connection established
lexnv Sep 19, 2024
9ce8a20
manager: Replace AddressRecord with DialRecord
lexnv Sep 19, 2024
47f97b5
manager: Remove AddressRecord from the Opening state
lexnv Sep 19, 2024
7f3147d
manager: Remove assert
lexnv Sep 19, 2024
d6e2d4d
manager: Rename DialRecord to ConnectionRecord
lexnv Sep 19, 2024
1eda8a7
manager/address: Remove connection ID from address store
lexnv Sep 19, 2024
526244b
manager/types: Add wrappers for consturcting connection records
lexnv Sep 19, 2024
dcac138
manager/address: Implement eviction algorithm
lexnv Sep 19, 2024
fc35762
manager: Rename recrod to address record
lexnv Sep 19, 2024
250c289
manager/handle: Keep WriteLock for a shorter time
lexnv Sep 19, 2024
6da7acf
manager/peer_state: Implement on_dial state advancing
lexnv Sep 19, 2024
b26dbd1
manager: Type safe state transition and trransports more modular
lexnv Sep 19, 2024
90e5b45
manager/peer_state: Implement on_dial_failure state advancing
lexnv Sep 19, 2024
5cd7949
manager/peer_state: Merge secondary connection with PeerState
lexnv Sep 20, 2024
3804db4
manager/peer_state: Handle connection closed transition
lexnv Sep 20, 2024
6912dda
manager/peer_state: Adjust connection established return
lexnv Sep 20, 2024
900ff49
manger: Use new peer state
lexnv Sep 20, 2024
e206588
manager/tests: Adjust tests to compile
lexnv Sep 20, 2024
d6dec2c
manager: Remove secondary connection from PeerContext
lexnv Sep 20, 2024
28aa178
manager/addresses: Configure address capacity from tests
lexnv Sep 20, 2024
4249410
manager/address: Move scores to the address from manager
lexnv Sep 20, 2024
42adc4a
manager/address: Evict entries with score below threshold
lexnv Sep 20, 2024
91d1e90
manager/addresses/tests: Evict on capacity
lexnv Sep 20, 2024
8248ba7
manager/tests: Test no longer panics on invalid peerIDs
lexnv Sep 20, 2024
a698a00
manager/tests: Persist dial addresses even if dial is not initiatied
lexnv Sep 20, 2024
a273531
manager/tests: Check dial attempt populated address
lexnv Sep 20, 2024
354f40a
manager/tests: Check track of addresses
lexnv Sep 20, 2024
1eea678
manager: Keep connection record on secondary upgrades
lexnv Sep 20, 2024
b684142
manager: Handle dial initiation result friendlier
lexnv Sep 20, 2024
461eb65
manager: Simplify dial on single and multiaddresses
lexnv Sep 20, 2024
a1dfe2e
manager/handle: Use state transitions
lexnv Sep 20, 2024
6d455d0
manager/peer_state: Add documentation
lexnv Sep 20, 2024
808793c
manager: Document possible race
lexnv Sep 20, 2024
dc6073d
manager/peer_state: Ensure disconnects are reported properly
lexnv Sep 20, 2024
0c36972
transport/tests: Connections are reported properly now
lexnv Sep 20, 2024
ecff792
transport/manager: Move error to score to the address store
lexnv Sep 23, 2024
8a95ba8
transport/maanager: Update address score on open failure
lexnv Sep 23, 2024
cd8ffb1
peer_state: Move open failure transitions to dedicated module
lexnv Sep 23, 2024
bda30df
transport/manager: Move to dedicated module
lexnv Sep 23, 2024
b2c51db
peer_state/tests: Check can dial states
lexnv Sep 23, 2024
a6d8684
peer_state/tests: Check disconnected -> dialing
lexnv Sep 23, 2024
5959e4e
peer_state/tests: Check Disconnected -> Opening
lexnv Sep 23, 2024
6a613d8
peer_state/tests: Check on dial failure
lexnv Sep 23, 2024
966cd18
peer_state/tests: Check connection established
lexnv Sep 24, 2024
6751581
peer_state/tests: Check connection established for Dialing
lexnv Sep 24, 2024
fc9a848
peer_state/tests: Check connection closed
lexnv Sep 24, 2024
fa03738
peer_state/tests: Check open failure state
lexnv Sep 24, 2024
dd3714f
peer_state/tests: Check full lifecycle of a connection
lexnv Sep 24, 2024
6050e96
manager: Remove pending connection state after success
lexnv Sep 24, 2024
1555437
peer_state: Handle connection opening
lexnv Sep 24, 2024
3c8058e
peer_state/tests: Check opening of connections
lexnv Sep 24, 2024
de5354b
manager: Better tracking of addresses for opening
lexnv Sep 24, 2024
9869283
peer_state: Return bool when dial failure was handled
lexnv Sep 24, 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
peer_state/tests: Check on dial failure
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Sep 23, 2024
commit 6a613d8835fb3a2d07387df13ba1f3bfc7e36f56
79 changes: 79 additions & 0 deletions src/transport/manager/peer_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,83 @@ mod tests {
}
);
}

#[test]
fn check_dial_failure() {
let record = ConnectionRecord::new(
PeerId::random(),
"/ip4/1.1.1.1/tcp/80".parse().unwrap(),
ConnectionId::from(0),
);

// Check from the dialing state.
{
let mut state = PeerState::Dialing {
dial_record: record.clone(),
};
let previous_state = state.clone();
// Check with different connection ID.
state.on_dial_failure(ConnectionId::from(1));
assert_eq!(state, previous_state);

// Check with the same connection ID.
state.on_dial_failure(ConnectionId::from(0));
assert_eq!(state, PeerState::Disconnected { dial_record: None });
}

// Check from the connected state without dialing state.
{
let mut state = PeerState::Connected {
record: record.clone(),
secondary: None,
};
let previous_state = state.clone();
// Check with different connection ID.
state.on_dial_failure(ConnectionId::from(1));
assert_eq!(state, previous_state);

// Check with the same connection ID.
// The connection ID is checked against dialing records, not established connections.
state.on_dial_failure(ConnectionId::from(0));
assert_eq!(state, previous_state);
}

// Check from the connected state with dialing state.
{
let mut state = PeerState::Connected {
record: record.clone(),
secondary: Some(SecondaryOrDialing::Dialing(record.clone())),
};
let previous_state = state.clone();
// Check with different connection ID.
state.on_dial_failure(ConnectionId::from(1));
assert_eq!(state, previous_state);

// Check with the same connection ID.
// Dial record is cleared.
state.on_dial_failure(ConnectionId::from(0));
assert_eq!(
state,
PeerState::Connected {
record: record.clone(),
secondary: None,
}
);
}

// Check from the disconnected state.
{
let mut state = PeerState::Disconnected {
dial_record: Some(record.clone()),
};
let previous_state = state.clone();
// Check with different connection ID.
state.on_dial_failure(ConnectionId::from(1));
assert_eq!(state, previous_state);

// Check with the same connection ID.
state.on_dial_failure(ConnectionId::from(0));
assert_eq!(state, PeerState::Disconnected { dial_record: None });
}
}
}
Loading