Refactor handling of CircTargets with unknown protocol capabilities
At present, we sometimes want to construct a CircTarget
when we don't know the Protocols
for the relay. This happens when we aren't building the CircTarget
from a Relay
object, or from a RouterDesc
, but instead from a set of information that we might have taken from (say) the onion service protocol.
When we do this, we currently proceed as follows:
- If there is a
Relay
in our latestNetDir
that matches the target Relay's ids, we use theProtocols
from thatRelay
. - Otherwise, we use the
required-relay-protocols
from the latest consensus directory, as the bare minimum.
There are two inconvenient aspects to this:
- The logic is duplicated. It appears in
circtarget_from_pieces
intor-hsclient
, and in establish_session intor-hsservice
. - The logic is, likely, at too high a level. It would be better if we could ensure that our CircTargets were always built with a reasonable set of protocols somehow, and it seems too easy to forget to follow this pattern.