pub struct Config {
pub cert_filename: Option<String>,
pub key_filename: Option<String>,
pub reset_seed: Option<[u8; 16]>,
}
Expand description
Configuration used by Context
to setup Picoquic.
Fields§
§cert_filename: Option<String>
The path to the certificate.
key_filename: Option<String>
The path to the private key.
reset_seed: Option<[u8; 16]>
The reset seed is used to create the stateless resets per Connection
.
Implementations§
Source§impl Config
impl Config
Sourcepub fn server(cert_filename: &str, key_filename: &str) -> Config
pub fn server(cert_filename: &str, key_filename: &str) -> Config
Creates a Config
that makes a Context
usable as server. A server is also able to act as
client. So, if you want to support P2P connections, you should use this Config
.
Examples found in repository?
examples/server.rs (lines 19-22)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
fn main() {
let mut evt_loop = Core::new().unwrap();
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let config = Config::server(
&format!("{}/examples/cert.pem", manifest_dir),
&format!("{}/examples/key.pem", manifest_dir),
);
let server = Context::new(&([0, 0, 0, 0], 22222).into(), &evt_loop.handle(), config).unwrap();
println!("Server listening on: {}", server.local_addr());
let handle = evt_loop.handle();
evt_loop
.run(server.for_each(|c| {
println!("New connection from: {}", c.peer_addr());
let handle = handle.clone();
handle.clone().spawn(c.for_each(move |s| {
// Let's see what we got
let s = match s {
CMessage::NewStream(s) => s,
_ => return Ok(()),
};
// We print the received message and sent a new one, after that we collect all
// remaining messages. The collect is a "hack" that prevents that the `Stream` is
// dropped to early.
handle.spawn(
s.into_future()
.map_err(|_| ())
.and_then(|(m, s)| {
println!("Got: {:?}", m);
s.send(SMessage::Data(Bytes::from("hello client")))
.map_err(|_| ())
})
.and_then(|s| s.collect().map_err(|_| ()))
.map(|_| ()),
);
Ok(())
}).map_err(|_| ()));
Ok(())
}))
.unwrap();
}
Sourcepub fn client() -> Config
pub fn client() -> Config
Creates a Config
that makes a Context
usable as client.
Examples found in repository?
examples/client.rs (line 17)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut evt_loop = Core::new().unwrap();
let config = Config::client();
let mut client = Context::new(&([0, 0, 0, 0], 0).into(), &evt_loop.handle(), config).unwrap();
let mut con = evt_loop
.run(client.new_connection(([127, 0, 0, 1], 22222).into()))
.unwrap();
let stream = evt_loop.run(con.new_bidirectional_stream()).unwrap();
let stream = evt_loop
.run(stream.send(SMessage::Data(Bytes::from("hello server"))))
.unwrap();
let answer = evt_loop
.run(
stream
.into_future()
.map(|(m, _)| m.unwrap())
.map_err(|(e, _)| e),
)
.unwrap();
println!("Got: {:?}", answer);
}
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more