-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from chainbound/feat/connection-state
feat: `ConnectionState` abstraction
- Loading branch information
Showing
15 changed files
with
409 additions
and
209 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod state; | ||
pub use state::ConnectionState; | ||
|
||
pub mod backoff; | ||
pub use backoff::{Backoff, ExponentialBackoff}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::net::SocketAddr; | ||
|
||
use super::Backoff; | ||
|
||
/// Abstraction to represent the state of a connection. | ||
/// | ||
/// * `C` is the channel type, which is used to send and receive generic messages. | ||
/// * `B` is the backoff type, used to control the backoff state for inactive connections. | ||
pub enum ConnectionState<C, B> { | ||
Active { | ||
/// Channel to control the underlying connection. This is used to send | ||
/// and receive any kind of message in any direction. | ||
channel: C, | ||
}, | ||
Inactive { | ||
addr: SocketAddr, | ||
/// The current backoff state for inactive connections. | ||
backoff: B, | ||
}, | ||
} | ||
|
||
impl<C, B: Backoff> ConnectionState<C, B> { | ||
/// Returns `true` if the connection is active. | ||
#[allow(unused)] | ||
pub fn is_active(&self) -> bool { | ||
matches!(self, Self::Active { .. }) | ||
} | ||
|
||
/// Returns `true` if the connection is inactive. | ||
#[allow(unused)] | ||
pub fn is_inactive(&self) -> bool { | ||
matches!(self, Self::Inactive { .. }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.