Skip to content

Commit

Permalink
relays: automatically load extra regional bootstrap relays
Browse files Browse the repository at this point in the history
Depending on user's locale. currently only supported for Japanese users.

This change allows Japanese users to automatically connect with popular
Japanese regional relays during account creation, thus allowing Japanese
users to better connect with the Japanese Nostr community.

More specifically, 3 Japanese regional relays will be automatically
added to the user's relay list (on top of the usual relays) under the
following conditions:

1. User's region (As configured in iOS settings) is Japan, AND
2. The user is creating a new Nostr account through Damus.

In the case the Nostr account is not new, Damus will not add any
regional relays (It will respect the user's relay list).

Testing
-------

PASS

Device: iPhone 15 Pro (Simulator)
iOS: 17.0.1
Damus: This commit
Test steps:

1. With the US region set, install Damus
2. Go through onboarding and create a new account.
3. Once the onboarding is complete, look at the connected relays. Should only be connected with popular international relays. PASS
4. Uninstall Damus
5. On iOS settings, go to Location & Region settings and change the region to Japan.
6. Install Damus
7. Go through onboarding and create a new account.
8. Once the onboarding is complete, look at the connected relays. User should be connected with intl relays as well as Japanese relays. PASS
9. Quit Damus and restart
10. Ensure the Japanese relays are still on the list. PASS
11. Quit Damus
12. Change region back to US
13. Restart Damus and check the relay list. Relay list should not be affected. PASS
14. Reinstall Damus
15. Check relay list. Only intl relays should be shown. PASS
16. Change region to Japan (JP)
17. Restart Damus and check the relay list. Relay list should not be affected. PASS
18. Reinstall Damus
19. This time, login with a pre-existing account (One that is not connected to Japanese relays).
20. After onboarding, check relay list. The relay list should be unaffected (i.e. Japanese relays should not have been added since this account is pre-existing). PASS

Note: The actual network connection with some of the Japanese relays
failed, but that is likely due to the Geo-based IP restrictions imposed
by some of those Japanese relays. The relay list has been copied
verbatim from @mattn's suggestions.

Reference ticket: #1447

Changelog-Changed: Automatically load extra regional Japanese relays during account creation if user's region is set to Japan.
Signed-off-by: Daniel D’Aquino <[email protected]>
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
danieldaquino authored and jb55 committed Oct 31, 2023
1 parent c437a05 commit d2bb013
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions damus/Util/Relays/RelayBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ let BOOTSTRAP_RELAYS = [
"wss:https://nos.lol",
]

let REGION_SPECIFIC_BOOTSTRAP_RELAYS: [Locale.Region: [String]] = [
Locale.Region.japan: [
"wss:https://relay-jp.nostr.wirednet.jp",
"wss:https://yabu.me",
"wss:https://r.kojira.io",
]
]

func bootstrap_relays_setting_key(pubkey: Pubkey) -> String {
return pk_setting_key(pubkey, key: "bootstrap_relays")
}
Expand All @@ -29,16 +37,25 @@ func load_bootstrap_relays(pubkey: Pubkey) -> [String] {

guard let relays = UserDefaults.standard.stringArray(forKey: key) else {
print("loading default bootstrap relays")
return BOOTSTRAP_RELAYS.map { $0 }
return get_default_bootstrap_relays().map { $0 }
}

if relays.count == 0 {
print("loading default bootstrap relays")
return BOOTSTRAP_RELAYS.map { $0 }
return get_default_bootstrap_relays().map { $0 }
}

let loaded_relays = Array(Set(relays + BOOTSTRAP_RELAYS))
let loaded_relays = Array(Set(relays + get_default_bootstrap_relays()))
print("Loading custom bootstrap relays: \(loaded_relays)")
return loaded_relays
}

func get_default_bootstrap_relays() -> [String] {
var default_bootstrap_relays = BOOTSTRAP_RELAYS

if let user_region = Locale.current.region, let regional_bootstrap_relays = REGION_SPECIFIC_BOOTSTRAP_RELAYS[user_region] {
default_bootstrap_relays.append(contentsOf: regional_bootstrap_relays)
}

return default_bootstrap_relays
}

0 comments on commit d2bb013

Please sign in to comment.