docs/relay-selector.md
The relay selector's main purpose is to pick a configuration of one or more Mullvad relays taking into account certain user-configurable criteria. Relays can be filtered by their location (country, city, hostname), by the protocols and ports they support and by other constraints. The constraints are user specified and stored in the settings. The default value for location constraints restricts relay selection to relays from Sweden.
Generally, the filtering process consists of going through each relay in our relay list and removing relay and endpoint combinations that do not match the constraints outlined above. The filtering process produces a list of relays that only contain matching endpoints. Of all the relays that match the constraints, one is selected and a random matching endpoint is selected from that relay.
Endpoints may be filtered by:
Whilst all user selected constraints are always honored, when the user hasn't selected any specific constraints the following default ones will take effect
The iOS platform does not support connecting to a relay over IPv6. As such, the above algorithm is simplified to the following version:
QUIC will use port 443.
If no tunnel has been established after exhausting this list of attempts, the relay selector will loop back to the first default constraint and continue its search from there.
Any default constraint that is incompatible with user specified constraints will simply not be considered. Conversely, all default constraints which do not conflict with user specified constraints will be used in the search for a working tunnel endpoint on repeated connection failures.
To select a single relay from the set of filtered relays, the relay selector uses a roulette wheel selection algorithm using the weights that are assigned to each relay. The higher the weight is relatively to other relays, the higher the likelihood that a given relay will be picked. Once a relay is picked, then a random endpoint that matches the constraints from the relay is picked.
Since not all relays deploy DAITA, there are lots of tunnel endpoint constraints that are fundamentally incompatible with DAITA. As such, if DAITA is enabled the relay selector may select an alternative entry relay and implicitly use multihop in order to achieve a seamless user experience. The user's tunnel endpoint constraint is respected for the exit relay.
The user may opt out of this behaviour by toggling the "Direct only" option in the DAITA settings.
There are four types of obfuscators - udp2tcp, shadowsocks, quic, and lwo. Any of them may be used if the anti-censorship method mode is set Automatic.