Enable dht relay for phone#328
Open
defnax wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
2. The Root Cause: Why DHT is "Not Working"
On a mobile client (such as Android/iOS), the device is almost always behind CGNAT (Carrier-Grade NAT) or restrictive firewalls. This means:
BITDHT_MODE_RELAYSERVERS_IGNORED(4096) is active, your client drops and refuses to contact any DHT relay servers.As a result, even though
bdboot.txtis loaded without issues, all direct UDP pings/queries sent to those bootstrap nodes time out because inbound replies are blocked by your network's NAT/firewall. Without relay support, the DHT is unable to bootstrap and remains offline.3. The
setRelayMode(01)Printing Bug in RetroShareIf you look at the definition of the custom stream insertion operator for enum flags in [
libretroshare/src/retroshare/rsflags.h]The bug lies in
std::bitset<sizeof(u_t)>:u_tisuint16_tforRsDhtRelayMode.sizeof(uint16_t)evaluates to2(the size in bytes, not bits).std::bitset<2>, displaying only the lowest 2 bits of the flag set.RsDhtRelayMode::OFFis0x0010(bit 4) andRsDhtRelayMode::ENABLEDis0x0001(bit 0). Their combined value is0x0011(17in decimal).0x0011to 2 bits yields01, hiding the fact thatOFF(bit 4) was also enabled.1. Forcing DHT Relays ON for Mobile
In p3bitdht_relay.cc
we added a preprocessor directive inside setRelayMode to override and force the relay mode to ON when compiling for Android (ANDROID) or iOS/macOS (APPLE):
cpp
This will bypass any OFF defaults or saved configuration presets, forcing the mobile client to use DHT relays so that it can bootstrap successfully behind NAT.
2. Fixing the stream output printing bug
In
rsflags.h we corrected the std::bitset size calculation so it multiplies bytes by 8 to convert them to bits, fixing the log formatting: