fix up ResponseCode to be infalible parse

This commit is contained in:
Benjamin Fry 2019-12-21 21:35:14 -08:00
parent 9e13de8f8d
commit 71c8e0e0f2
13 changed files with 21 additions and 16 deletions

View File

@ -29,6 +29,7 @@ All notes should be prepended with the location of the change, e.g. `(proto)` or
- (proto) Removed deadlock from UDPSocket stream impl
- (named) made tests a little more resilient to port stealing
- (proto) Unknown ResponseCodes will no longer cause a panic
### Removed

View File

@ -20,7 +20,7 @@ fn bench_emit_header(b: &mut Bencher) {
})
}
// FIXME:
// TODO:
// This is a bit silly, because everywhere in the codebase, we reserve 512 bytes for the buffer.
// But what we want to measure here is the cost of reserving more space, which can happen for big
// messages exceeding 512 bytes. A better benchmark would be to emit such a big message.

View File

@ -792,7 +792,7 @@ impl<'r> BinDecodable<'r> for Message {
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
let header = Header::read(decoder)?;
// TODO/FIXME: return just header, and in the case of the rest of message getting an error.
// TODO: return just header, and in the case of the rest of message getting an error.
// this could improve error detection while decoding.
// get the questions

View File

@ -126,6 +126,8 @@ pub enum ResponseCode {
// 3841-4095 Reserved for Private Use [RFC6895]
// 4096-65534 Unassigned
// 65535 Reserved, can be allocated by Standards Action [RFC6895]
/// An unknown or unregisterd response code was received.
Unknown(u16),
}
impl ResponseCode {
@ -167,6 +169,7 @@ impl ResponseCode {
ResponseCode::BADALG => "Algorithm not supported", // 21 BADALG Algorithm not supported [RFC2930]
ResponseCode::BADTRUNC => "Bad truncation", // 22 BADTRUNC Bad Truncation [RFC4635]
ResponseCode::BADCOOKIE => "Bad server cookie", // 23 BADCOOKIE (TEMPORARY - registered 2015-07-26, expires 2016-07-26) Bad/missing server cookie [draft-ietf-dnsop-cookies]
ResponseCode::Unknown(_) => "Unknown response code",
}
}
}
@ -217,6 +220,7 @@ impl From<ResponseCode> for u16 {
ResponseCode::BADTRUNC => 22, // 22 BADTRUNC Bad Truncation [RFC4635]
// 23 BADCOOKIE (TEMPORARY - registered 2015-07-26, expires 2016-07-26) Bad/missing server cookie [draft-ietf-dnsop-cookies]
ResponseCode::BADCOOKIE => 23,
ResponseCode::Unknown(code) => code,
}
}
}
@ -234,7 +238,7 @@ impl From<ResponseCode> for u16 {
/// assert_eq!(0, var);
/// ```
impl From<u16> for ResponseCode {
#[allow(clippy::unimplemented)] // FIXME: this should be a TryFrom!
#[allow(clippy::unimplemented)]
fn from(value: u16) -> Self {
match value {
0 => ResponseCode::NoError, // 0 NoError No Error [RFC1035]
@ -259,7 +263,7 @@ impl From<u16> for ResponseCode {
21 => ResponseCode::BADALG, // 21 BADALG Algorithm not supported [RFC2930]
22 => ResponseCode::BADTRUNC, // 22 BADTRUNC Bad Truncation [RFC4635]
23 => ResponseCode::BADCOOKIE, // 23 BADCOOKIE (TEMPORARY - registered 2015-07-26, expires 2016-07-26) Bad/missing server cookie [draft-ietf-dnsop-cookies]
_ => unimplemented!(),
code => ResponseCode::Unknown(code),
}
}
}

View File

@ -798,7 +798,7 @@ pub fn read(decoder: &mut BinDecoder, rdata_length: Restrict<u16>) -> ProtoResul
return Err("extended flags currently not supported".into());
}
// FIXME: protocol my be infallible
// TODO: protocol my be infallible
let protocol = Protocol::from(decoder.read_u8()?.unverified(/*Protocol is verified as safe*/));
let algorithm: Algorithm = Algorithm::read(decoder)?;

View File

@ -223,7 +223,7 @@ impl<S: UdpSocket> Future for NextRandomUdpSocket<S> {
debug!("could not get next random port, delaying");
// FIXME: this replaced task::current().notify();
// TODO: because no interest is registered anywhere, we must awake.
cx.waker().wake_by_ref();
// returning NotReady here, perhaps the next poll there will be some more socket available.

View File

@ -113,7 +113,7 @@ where
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
DnsExchangeSend {
result: self.sender.send(request),
_sender: self.sender.clone(), // FIXME: HACK HACK HACK, this shouldn't be necessary, currently the presence of Senders is what allows the background to track current users, it generally is dropped right after send, this makes sure that there is at least one active after send
_sender: self.sender.clone(), // TODO: this shouldn't be necessary, currently the presence of Senders is what allows the background to track current users, it generally is dropped right after send, this makes sure that there is at least one active after send
}
}
}

View File

@ -15,7 +15,7 @@ use smallvec::SmallVec;
use crate::op::Message;
// TODO: this needs to have the IP addr of the remote system...
// FIXME: see https://github.com/bluejekyll/trust-dns/issues/383 for removing vec of messages and instead returning a Stream
// TODO: see https://github.com/bluejekyll/trust-dns/issues/383 for removing vec of messages and instead returning a Stream
/// A DNS response object
///
/// For Most DNS requests, only one response is expected, the exception is a multicast request.

View File

@ -59,7 +59,7 @@ impl AuthLookup {
/// Returns true if either the associated Records are empty, or this is a NameExists or NxDomain
pub fn is_empty(&self) -> bool {
// FIXME: this needs to be cheap
// TODO: this needs to be cheap
self.was_empty()
}
@ -125,7 +125,7 @@ impl<'a> IntoIterator for &'a AuthLookup {
fn into_iter(self) -> Self::IntoIter {
match self {
AuthLookup::Empty => AuthLookupIter::Empty,
// FIXME: what about the additionals? is IntoIterator a bad idea?
// TODO: what about the additionals? is IntoIterator a bad idea?
AuthLookup::Records { answers: r, .. } | AuthLookup::SOA(r) => {
AuthLookupIter::Records(r.into_iter())
}

View File

@ -769,7 +769,7 @@ enum AuthorityLookupState {
},
}
// FIXME: turn this into a real future
// TODO: turn this into a real future
impl AuthorityLookupState {
#[allow(clippy::type_complexity)]
fn poll<R: ResponseHandler>(

View File

@ -181,7 +181,7 @@ impl<'q> BinDecodable<'q> for MessageRequest {
fn read(decoder: &mut BinDecoder<'q>) -> ProtoResult<Self> {
let header = Header::read(decoder)?;
// TODO/FIXME: return just header, and in the case of the rest of message getting an error.
// TODO: return just header, and in the case of the rest of message getting an error.
// this could improve error detection while decoding.
// get the questions

View File

@ -222,8 +222,8 @@ impl ZoneConfig {
/// this is ony used on first load, if dynamic update is enabled for the zone, then the journal
/// file is the actual source of truth for the zone.
pub fn get_file(&self) -> PathBuf {
// FIXME: Option on PathBuf
PathBuf::from(self.file.as_ref().unwrap())
// TODO: Option on PathBuf
PathBuf::from(self.file.as_ref().expect("file was none"))
}
/// enable dynamic updates for the zone (see SIG0 and the registered keys)

View File

@ -136,14 +136,14 @@ impl Authority for ForwardAuthority {
))
}
#[allow(clippy::unimplemented)] // FIXME: this should return an error
#[allow(clippy::unimplemented)]
fn get_nsec_records(
&self,
_name: &LowerName,
_is_secure: bool,
_supported_algorithms: SupportedAlgorithms,
) -> Pin<Box<dyn Future<Output = Result<Self::Lookup, LookupError>> + Send>> {
unimplemented!()
future::err(io::Error)
}
}