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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use std::fmt::Debug;
use std::marker::PhantomData;
use std::net::SocketAddr;
use error::*;
use futures::sync::mpsc::{SendError, UnboundedSender};
use op::Message;
pub mod dns_future;
pub mod dns_handle;
pub mod dns_request;
pub mod dns_response;
pub mod retry_dns_handle;
#[cfg(feature = "dnssec")]
pub mod secure_dns_handle;
pub use self::dns_future::DnsFuture;
pub use self::dns_handle::{BasicDnsHandle, DnsHandle, DnsStreamHandle, StreamHandle};
pub use self::dns_request::{DnsRequest, DnsRequestOptions};
pub use self::dns_response::DnsResponse;
pub use self::retry_dns_handle::RetryDnsHandle;
#[cfg(feature = "dnssec")]
pub use self::secure_dns_handle::SecureDnsHandle;
fn ignore_send<M, E: Debug>(result: Result<M, E>) {
if let Err(error) = result {
warn!("error notifying wait, possible future leak: {:?}", error);
}
}
#[derive(Clone)]
pub struct BufStreamHandle<E>
where
E: FromProtoError,
{
sender: UnboundedSender<(Vec<u8>, SocketAddr)>,
phantom: PhantomData<E>,
}
impl<E> BufStreamHandle<E>
where
E: FromProtoError,
{
pub fn new(sender: UnboundedSender<(Vec<u8>, SocketAddr)>) -> Self {
BufStreamHandle {
sender,
phantom: PhantomData::<E>,
}
}
pub fn unbounded_send(
&self,
msg: (Vec<u8>, SocketAddr),
) -> Result<(), SendError<(Vec<u8>, SocketAddr)>> {
self.sender.unbounded_send(msg)
}
}
pub type MessageStreamHandle = UnboundedSender<Message>;
pub struct BufDnsStreamHandle<E>
where
E: FromProtoError,
{
name_server: SocketAddr,
sender: BufStreamHandle<E>,
}
impl<E> BufDnsStreamHandle<E>
where
E: FromProtoError,
{
pub fn new(name_server: SocketAddr, sender: BufStreamHandle<E>) -> Self {
BufDnsStreamHandle {
name_server: name_server,
sender: sender,
}
}
}
impl<E> DnsStreamHandle for BufDnsStreamHandle<E>
where
E: FromProtoError,
{
type Error = E;
fn send(&mut self, buffer: Vec<u8>) -> Result<(), E> {
let name_server: SocketAddr = self.name_server;
let sender: &mut _ = &mut self.sender;
sender
.sender
.unbounded_send((buffer, name_server))
.map_err(|e| E::from(ProtoErrorKind::Msg(format!("mpsc::SendError {}", e)).into()))
}
}