Skip to content

Commit 73bbeea

Browse files
committed
Update
1 parent 51d09ed commit 73bbeea

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

_do.cr

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ BUILD_DIR = Path[".build"]
6363
BACKUP_DIR = Path[".backup"]
6464
CACHE_DIR = BUILD_DIR.join(".cache")
6565
BANLISTS = CACHE_DIR.join("banlists.txt")
66+
RELAYS = Path["relays.json"]
6667
BROKEN_POST_URLS = CACHE_DIR.join("broken_post_urls.txt")
6768
COMMON_ROOT = Path["_ohmyvps/alpine/alpine-root"]
6869

@@ -73,6 +74,8 @@ MIRROR_FROM_TO = [
7374
{MEDIA_HOST, [{MIRROR_HOST, SERVER_MEDIA_DIR}]},
7475
]
7576

77+
RELAY_URI = "wss://nostr.codonaft.com"
78+
7679
USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
7780

7881
NAMESERVER = "1.1.1.1"
@@ -95,7 +98,7 @@ def main
9598
sync(hosts)
9699
elsif ARGV.size >= 1 && ARGV[0] == "sync-nostr"
97100
profiles = ARGV.size > 1 && ARGV[1] == "profiles"
98-
sync_nostr(config, profiles: profiles, output_relays: ["ws://localhost:7777", "wss://nostr.codonaft.com", "wss://purplepag.es", "wss://user.kindpag.es", "wss://nostr.oxtr.dev", "wss://nostr.girino.org"])
101+
sync_nostr(config, profiles: profiles, output_relays: ["ws://localhost:7777", RELAY_URI, "wss://purplepag.es", "wss://user.kindpag.es", "wss://nostr.oxtr.dev", "wss://nostr.girino.org"])
99102
elsif ARGV[0] == "follow"
100103
follow(config, ARGV[1..].to_set, ["wss://purplepag.es", "wss://user.kindpag.es", "wss://relay.vertexlab.io"])
101104
elsif ARGV.size >= 1 && ARGV[0] == "health"
@@ -253,6 +256,7 @@ def build
253256
)
254257

255258
generate_certbot_script(MEDIA_HOST)
259+
maybe_generate_relays
256260
end
257261

258262
def configure(config)
@@ -520,7 +524,7 @@ def health(config, hosts : Array(String))
520524
end
521525

522526
banlists =
523-
if nonempty_exists?(BANLISTS) && File.info(BANLISTS).modification_time + 1.days > Time.utc
527+
if updated_today?(BANLISTS)
524528
File.read_lines(BANLISTS).to_set
525529
else
526530
update_banlists
@@ -700,6 +704,48 @@ def generate_certbot_script(host)
700704
File.chmod(output, 0o755)
701705
end
702706

707+
def maybe_generate_relays
708+
return if updated_today?(RELAYS)
709+
710+
puts("generating relays list")
711+
online = JSON.parse(HTTP::Client.get("https://api.nostr.watch/v1/online").body).as_a.map { |i| i.as_s }
712+
old = JSON.parse(File.read(RELAYS)).as_a.map { |i| i.as_s }
713+
relays = (online + old).to_set - [RELAY_URI]
714+
resolvable_relays = select_resolvable(relays.map { |i| URI.parse(i) })
715+
File.write(RELAYS, resolvable_relays.map { |i| i.to_s }.sort.uniq.to_json)
716+
end
717+
718+
def select_resolvable(uris : Iterable(URI)) : Array(URI)
719+
ch = Channel(URI?).new
720+
721+
uris.reject { |i| i.host.nil? }.map do |uri|
722+
spawn do
723+
host = uri.host.not_nil!
724+
result =
725+
if host.includes?(".onion")
726+
uri
727+
elsif Socket::IPAddress.parse_v4_fields?(host).nil? && Socket::IPAddress.parse_v6_fields?(host).nil?
728+
begin
729+
Socket::Addrinfo.resolve(host, nil, :INET, :STREAM)
730+
uri
731+
rescue
732+
begin
733+
Socket::Addrinfo.resolve(host, nil, :INET6, :STREAM)
734+
uri
735+
rescue
736+
nil
737+
end
738+
end
739+
else
740+
nil
741+
end
742+
ch.send(result)
743+
end
744+
end
745+
746+
uris.size.times.compact_map { ch.receive }.to_a
747+
end
748+
703749
def check_icmp(host)
704750
output = `ping -c1 #{host} 2>&1 | grep --extended-regexp '(^ping:|100%|time=[0-9\\.]*)' | sed 's!.*time=!!;s!.*transmitted, !!'`.strip
705751
if output.starts_with?("ping:") || output.includes?("100%")
@@ -1903,6 +1949,10 @@ def nonempty_exists?(path : Path)
19031949
File.file?(path) && !File.empty?(path)
19041950
end
19051951

1952+
def updated_today?(path : Path)
1953+
nonempty_exists?(path) && File.info(path).modification_time + 1.days > Time.utc
1954+
end
1955+
19061956
def print_expiration(time)
19071957
if time.nil?
19081958
warn("unknown expiration")

_hosts/media.codonaft/etc/conf.d/broadcastr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ broadcastr_args="
33
--tor-proxy 127.0.0.1:9050
44
--allowed-pubkeys npub1alptdev5srcw2hxg03567p4k6xs3lgj7f6545suc0rzp0xw98svse7rg94,efd4d4a38bcd0004d31031a17972a6a6a3b32fe6f3953958c47d6325f2b8d106,e681745398e44c2ed67f116a02bc9e53d63d7de5eb26039224486801b0ac3c39
55
--allowed-kinds 0,1,3,5,6,7,8,9,11,16,17,20,21,22,24,30,31,32,33,40,41,42,43,44,62,818,1018,1021,1022,1063,1068,1111,1222,1244,1311,1337,1617,1618,1619,1621,1630,1631,1632,1633,1971,1984,1985,1987,2003,2004,2022,4550,9041,9321,9734,9735,9802,10000,10001,10002,10003,10004,10005,10006,10007,10009,10012,10013,10015,10020,10030,10050,10051,10063,10166,30000,30002,30003,30004,30005,30006,30007,30008,30009,30015,30017,30018,30019,30020,30023,30030,30040,30041,30267,30311,30312,30388,30402,30402,30617,30818,30819,31388,31922,31923,31924,31925,31989,31990,32267,32388,34550,38172,38173,39089,39092,39701
6-
--relays https://codonaft.com/relays.json,https://api.nostr.watch/v1/online,https://codonaft.com/relays_broadcasters.json,file:///etc/broadcastr/allowed.json
6+
--relays https://codonaft.com/relays.json,https://codonaft.com/relays_broadcasters.json,file:///etc/broadcastr/allowed.json
77
--blocked-relays file:///etc/broadcastr/blocked.json
88
--disable-spam-nostr-band
99
"

0 commit comments

Comments
 (0)