hypercore_protocol/
builder.rs1use crate::Protocol;
2use crate::{duplex::Duplex, protocol::Options};
3use futures_lite::io::{AsyncRead, AsyncWrite};
4
5#[derive(Debug)]
7pub struct Builder(Options);
8
9impl Builder {
10 pub fn new(initiator: bool) -> Self {
12 Self(Options::new(initiator))
13 }
14
15 pub fn encrypted(mut self, encrypted: bool) -> Self {
17 self.0.encrypted = encrypted;
18 self
19 }
20
21 pub fn handshake(mut self, handshake: bool) -> Self {
23 self.0.noise = handshake;
24 self
25 }
26
27 pub fn connect<IO>(self, io: IO) -> Protocol<IO>
29 where
30 IO: AsyncRead + AsyncWrite + Send + Unpin + 'static,
31 {
32 Protocol::new(io, self.0)
33 }
34
35 pub fn connect_rw<R, W>(self, reader: R, writer: W) -> Protocol<Duplex<R, W>>
37 where
38 R: AsyncRead + Send + Unpin + 'static,
39 W: AsyncWrite + Send + Unpin + 'static,
40 {
41 let io = Duplex::new(reader, writer);
42 Protocol::new(io, self.0)
43 }
44}