1
2
3
4
5
6
7
8
9
10
11
12
13
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![deny(missing_docs)]
#![doc(html_root_url = "https://docs.rs/lapin-futures-rustls/0.16.4/")]
extern crate futures;
extern crate lapin_futures_tls_internal;
extern crate tokio_rustls;
extern crate webpki_roots;
pub mod lapin;
pub mod uri;
pub type AMQPStream = lapin_futures_tls_internal::AMQPStream<TlsStream<TcpStream, ClientSession>>;
use tokio_rustls::{rustls, webpki};
use std::io;
use std::sync::Arc;
use futures::future::Future;
use lapin_futures_tls_internal::{AMQPConnectionTlsExt, TcpStream};
use rustls::{ClientConfig, ClientSession};
use tokio_rustls::{TlsConnector, TlsStream};
use uri::AMQPUri;
fn connector(host: String, stream: TcpStream) -> Box<Future<Item = Box<TlsStream<TcpStream, ClientSession>>, Error = io::Error> + Send + 'static> {
let mut config = ClientConfig::new();
config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
let config = TlsConnector::from(Arc::new(config));
Box::new(futures::future::result(webpki::DNSNameRef::try_from_ascii_str(&host).map(move |domain| domain.to_owned()).map_err(|()| io::Error::new(io::ErrorKind::Other, "Invalid domain name"))).and_then(move |domain| {
config.connect(domain.as_ref(), stream).map_err(From::from).map(Box::new)
}))
}
pub trait AMQPConnectionRustlsExt<F: FnOnce(io::Error) + Send + 'static> : AMQPConnectionTlsExt<TlsStream<TcpStream, ClientSession>, F> where Self: Sized {
fn connect(self, heartbeat_error_handler: F) -> Box<Future<Item = lapin::client::Client<AMQPStream>, Error = io::Error> + Send + 'static> {
AMQPConnectionTlsExt::connect(self, heartbeat_error_handler, connector)
}
fn connect_cancellable(self, heartbeat_error_handler: F) -> Box<Future<Item = (lapin::client::Client<AMQPStream>, lapin::client::HeartbeatHandle), Error = io::Error> + Send + 'static> {
AMQPConnectionTlsExt::connect_cancellable(self, heartbeat_error_handler, connector)
}
}
impl<F: FnOnce(io::Error) + Send + 'static> AMQPConnectionRustlsExt<F> for AMQPUri {}
impl<'a, F: FnOnce(io::Error) + Send + 'static> AMQPConnectionRustlsExt<F> for &'a str {}