pub struct EntropyReceiver { /* private fields */ }Expand description
Entropy receiver driver.
§Examples
use std::path::PathBuf;
use std::sync::Arc;
use dynomite::entropy::{
receive::RedisReplaySink, EntropyConfig, EntropyReceiver,
};
let cfg = EntropyConfig {
key_file: PathBuf::from("conf/recon_key.pem"),
iv_file: PathBuf::from("conf/recon_iv.pem"),
listen_addr: "127.0.0.1:8105".parse().unwrap(),
send_addr: None,
peer_endpoint: "127.0.0.1:8105".parse().unwrap(),
buffer_size: 16 * 1024,
header_size: 1024,
encrypt: true,
};
let sink = Arc::new(RedisReplaySink::default());
let handle = EntropyReceiver::run(cfg, sink).await.unwrap();
handle.abort();Implementations§
Source§impl EntropyReceiver
impl EntropyReceiver
Sourcepub async fn run(
cfg: EntropyConfig,
sink: BoxedSnapshotSink,
) -> EntropyResult<JoinHandle<EntropyResult<()>>>
pub async fn run( cfg: EntropyConfig, sink: BoxedSnapshotSink, ) -> EntropyResult<JoinHandle<EntropyResult<()>>>
Bind a receiver to cfg.listen_addr and spawn the accept
loop on a tokio task.
Each accepted connection is handled in line on the same
task, mirroring the reference engine’s single-threaded
entropy loop. The returned handle resolves to Ok(()) only
after the listener is shut down (e.g. by aborting the task)
or to an error if the bind fails.
§Errors
Forwards anything from key loading or socket bind.
Sourcepub async fn bind(
cfg: EntropyConfig,
sink: BoxedSnapshotSink,
) -> EntropyResult<Self>
pub async fn bind( cfg: EntropyConfig, sink: BoxedSnapshotSink, ) -> EntropyResult<Self>
Bind without spawning. Used by tests that want to drive the accept loop on the caller’s task.
§Errors
Forwards anything from key loading or socket bind.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Local address the receiver is bound to. Useful for tests
that bind to :0 and then dial the kernel-assigned port.
§Errors
Forwarded from the underlying socket call.
Sourcepub async fn accept_one(self) -> EntropyResult<usize>
pub async fn accept_one(self) -> EntropyResult<usize>
Accept exactly one connection, process it, and return.
§Errors
Forwards I/O, protocol, and crypto errors from the worker.
Sourcepub async fn accept_loop(self) -> EntropyResult<()>
pub async fn accept_loop(self) -> EntropyResult<()>
Accept connections until the task is aborted.