Fix reverse dns lookups on static binds #120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Turmoil supports the creation of clients/hosts bound to any address that
impl ToIpAddr
.This allows for then creation of nodes, bound to static IP addresses. Such nodes
will not appear in the internal mappings of
Dns
, since they have no hostname.Dns::reverse
however expects that all nodes (all inputs would be more correct) are containedin the dns mapping. If this assumption is broken,
Dns::reverse
panics. This means that any use ofDns::reverse
in combination with a statically bound address will panic.The problem: If a tracing subscriber is active, internal traces will attempt to use
Dns::reverse
oncewhen the node is initialized, thus crashing the simulation (world.rs:107).
Solutions
I See three solutions:
A (currently implemented)
If a reverse lookup does not find any entry in the dns mapping, it returns the input address as a
String
.This would keep API changes small (
&str
toString
). However all input addresses that have not appearedin the mapping would be handled this way, not just statically bound addresses.
B
Add static binds to dns mapping. We could implement node creation in a way, that a dns entry
mapping the stringified static address to the real static address is created. This would not
change the
Dns::reverse
, but major changes in address resolution / node creation would be nessecary.C
Change the API of
Dns::reverse
to reflect the failable nature of such lookups. By changing the return type to eitherOption<&str>
orResult<&str>
we could deal with failing lookups without panicking. This would be the most expressivoption, but it would change the public API of
Dns::reverse
andSim::reverse_lookup_pair
.