From 3330135a2f0c400b45d4ef6bc30c76be40a4cb74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roman=20Smr=C5=BE?= <roman.smrz@seznam.cz>
Date: Mon, 21 Oct 2024 19:55:04 +0200
Subject: Try resolving multiple public servers

Changelog: Support multiple public peers
---
 main/Main.hs | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

(limited to 'main')

diff --git a/main/Main.hs b/main/Main.hs
index 94c0418..32c226f 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -540,8 +540,19 @@ cmdPeerAdd = void $ do
 cmdPeerAddPublic :: Command
 cmdPeerAddPublic = do
     server <- asks ciServer
-    addr:_ <- liftIO $ getAddrInfo (Just $ defaultHints { addrSocketType = Datagram }) (Just "discovery1.erebosprotocol.net") (Just (show discoveryPort))
-    void $ liftIO $ serverPeer server (addrAddress addr)
+    liftIO $ mapM_ (serverPeer server . addrAddress) =<< gather 'a'
+  where
+    gather c
+        | c <= 'z' = do
+            let hints = Just $ defaultHints { addrSocketType = Datagram }
+                hostname = Just $ c : ".discovery.erebosprotocol.net"
+                service = Just $ show discoveryPort
+            handle (\(_ :: IOException) -> return []) (getAddrInfo hints hostname service) >>= \case
+                addr : _ -> (addr :) <$> gather (succ c)
+                [] -> return []
+
+        | otherwise = do
+            return []
 
 cmdPeerDrop :: Command
 cmdPeerDrop = do
-- 
cgit v1.2.3