pub enum ResolverMessages {
DNSSECQuery(DNSSECQuery),
DNSSECProof(DNSSECProof),
- OfferRequest(OfferRequest),
- OfferResponse(OfferResponse),
}
#[derive(Debug)]
}
const DNSSEC_PROOF_TYPE: u64 = 65538;
-#[derive(Debug)]
-pub struct OfferRequest {
- pub user: String,
- pub domain: String,
-}
-const OFFER_REQUEST_TYPE: u64 = 44; // XXX
-
-#[derive(Debug)]
-pub struct OfferResponse {
- pub user: String,
- pub domain: String,
- pub offer: Offer,
-}
-const OFFER_RESPONSE_TYPE: u64 = 45; // XXX
-
impl Writeable for ResolverMessages {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), lightning::io::Error> {
match self {
w.write_all(&name.as_str().as_bytes())?;
proof.write(w)
},
- Self::OfferRequest(OfferRequest { user, domain }) => {
- (user.len() as u8).write(w)?;
- w.write_all(&user.as_bytes())?;
- (domain.len() as u8).write(w)?;
- w.write_all(&domain.as_bytes())
- },
- Self::OfferResponse(OfferResponse { user, domain, offer }) => {
- (user.len() as u8).write(w)?;
- w.write_all(&user.as_bytes())?;
- (domain.len() as u8).write(w)?;
- w.write_all(&domain.as_bytes())?;
- offer.to_string().write(w)
- },
}
}
}
let proof = Readable::read(buffer)?;
Ok(Some(ResolverMessages::DNSSECProof(DNSSECProof { name, proof })))
},
- OFFER_REQUEST_TYPE => {
- let user = read_byte_len_ascii_string(buffer)?;
- let domain = read_byte_len_ascii_string(buffer)?;
- Ok(Some(ResolverMessages::OfferRequest(OfferRequest { user, domain })))
- },
- OFFER_RESPONSE_TYPE => {
- let user = read_byte_len_ascii_string(buffer)?;
- let domain = read_byte_len_ascii_string(buffer)?;
- let offer_string: String = Readable::read(buffer)?;
- if !offer_string.is_ascii() { return Err(DecodeError::InvalidValue); }
- if let Ok(offer) = Offer::from_str(&offer_string) {
- Ok(Some(ResolverMessages::OfferResponse(OfferResponse { user, domain, offer })))
- } else {
- Err(DecodeError::InvalidValue)
- }
- },
_ => Ok(None),
}
}
match self {
ResolverMessages::DNSSECQuery(_) => DNSSEC_QUERY_TYPE,
ResolverMessages::DNSSECProof(_) => DNSSEC_PROOF_TYPE,
- ResolverMessages::OfferRequest(_) => OFFER_REQUEST_TYPE,
- ResolverMessages::OfferResponse(_) => OFFER_RESPONSE_TYPE,
}
}
}
fn handle_custom_message(&self, msg: ResolverMessages) -> Option<Self::CustomMessage> {
match msg {
ResolverMessages::DNSSECQuery(_) => {},
- ResolverMessages::OfferRequest(_) => {},
ResolverMessages::DNSSECProof(DNSSECProof { name: answer_name, proof }) => {
let parsed_rrs = parse_rr_stream(&proof);
let validated_rrs =
} else {
continue;
};
- if k.eq_ignore_ascii_case("b12") {
+ if k.eq_ignore_ascii_case("lno") {
if let Ok(offer) = Offer::from_str(v) {
resolution_callback(Some(offer));
} else {
resolution_callback(None);
}
return false;
- } else if k.eq_ignore_ascii_case("omlookup") {
- let data_hex = Vec::from_hex(v).map_err(|_| ());
- let request_path = data_hex
- .and_then(|data| BlindedPath::read(&mut &data[..])
- .map_err(|_| ()));
- let request_path = if let Ok(path) = request_path {
- path
- } else {
- resolution_callback(None);
- return false;
- };
- let contents = ResolverMessages::OfferRequest(OfferRequest {
- user: user.to_owned(),
- domain: domain.to_owned(),
- });
- let response = PendingOnionMessage {
- contents,
- destination: Destination::BlindedPath(request_path),
- reply_path: Some(self.reply_path.clone()),
- };
- self.pending_msgs.lock().unwrap().push(response);
- return true;
}
}
resolution_callback(None);
});
}
},
- ResolverMessages::OfferResponse(OfferResponse { user, domain, offer }) => {
- let mut pending_resolves = self.pending_resolves.lock().unwrap();
- pending_resolves.retain_mut(|(_height, query, resolution_callback)| {
- let (query_user, query_domain) = if let Some(r) = query.split_once("@") {
- r
- } else {
- debug_assert!(false, "This should be checked before insertion");
- return false;
- };
- if query_user != user || query_domain != domain { return true; }
- resolution_callback(Some(offer.clone()));
- false
- });
- },
}
None
}