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
Connection Manager enhancements #371
Connection Manager enhancements #371
Conversation
RyanLassigBanks
commented
Dec 5, 2019
•
edited
edited
- Replace crossbeam with standard library channels
- Remove locks around connection state
- Move the heartbeat monitor into its own module
- Add remove connection to connection manager
2ab635e
to
6982c2a
Compare
libsplinter/src/network/connection_manager/heartbeat_monitor.rs
Outdated
Show resolved
Hide resolved
17937ca
to
1e891c3
Compare
1e891c3
to
3e06953
Compare
Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Heartbeat monitor and connection manager no longer share ConnectionState. Heartbeat messages are now sent from the connection manager thread and requested by the heartbeat monitor instead of the heartbeat monitor sending them directly. Signed-off-by: Ryan Banks <rbanks@bitwise.io>
3e06953
to
5ec97b4
Compare
ConnectionManagerError::HeartbeatError("cannot create NetworkHeartbeat message".to_string()) | ||
})?; | ||
fn create_heartbeat() -> Vec<u8> { | ||
let heartbeat = NetworkHeartbeat::new().write_to_bytes().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is panicking here desirable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe @peterschwarz mentioned this a few times, but write_to_bytes
only fails if the system completely runs out of memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deviates from the way we handle these errors everywhere else in splinter, so I'm not sure I 100% agree with this change from a consistency perspective, but I won't block the PR because of that. However, this should be changed to an expect
to provide an error message.
5ec97b4
to
e4783fd
Compare
e4783fd
to
db3afc5
Compare
Peter is OOO until Tuesday, and I'd like to try to get his merged before then.
@@ -62,7 +61,13 @@ impl ConnectionManager { | |||
|
|||
pub fn start(&mut self) -> Result<Connector, ConnectionManagerError> { | |||
let (sender, recv) = sync_channel(CHANNEL_CAPACITY); | |||
let mut state = self.connection_state.clone(); | |||
let mut state = if let Some(state) = self.connection_state.take() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if let ... else ...
could be simplified by using self.connection_state.take().ok_or_else(|| Err(...))?
ConnectionManagerError::HeartbeatError("cannot create NetworkHeartbeat message".to_string()) | ||
})?; | ||
fn create_heartbeat() -> Vec<u8> { | ||
let heartbeat = NetworkHeartbeat::new().write_to_bytes().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deviates from the way we handle these errors everywhere else in splinter, so I'm not sure I 100% agree with this change from a consistency perspective, but I won't block the PR because of that. However, this should be changed to an expect
to provide an error message.
db3afc5
to
5071d4e
Compare
46903d2
to
8f51057
Compare
ConnectionState needs to be passed to the connection_manager thread in `ConnectionManager::start`. ConnectionState can't be clonable because Transports aren't clonable, so in order to pass it to the thread it will be temporarily stored as an option. Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Fixing clippy errors that were introduced when the connection-manager feature was initially added Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Change test ports from 8080 to 3030 to avoid conflicts with other tests that use port 8080. Signed-off-by: Ryan Banks <rbanks@bitwise.io>
Signed-off-by: Ryan Banks <rbanks@bitwise.io>
f90530b
to
1bd5356
Compare