summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-05-29 22:30:40 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-05-31 17:09:53 +0200
commit847b60ae7eb2d98576ed7e8775a690041fed8081 (patch)
treec81f208c53e0151d8be2869f32629cf36f09e6e3 /main
parentd9800045d572358526bf18688f06a4cfa4f99772 (diff)
Use weak refs in discovery service
Diffstat (limited to 'main')
-rw-r--r--main/Main.hs9
-rw-r--r--main/Test.hs5
2 files changed, 6 insertions, 8 deletions
diff --git a/main/Main.hs b/main/Main.hs
index a0c28f7..e9c0ae4 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -924,13 +924,12 @@ cmdDiscoveryInit = void $ do
cmdDiscovery :: Command
cmdDiscovery = void $ do
Just peer <- gets csIcePeer
- st <- getStorage
sref <- asks ciLine
eprint <- asks ciPrint
- liftIO $ readRef st (BC.pack sref) >>= \case
- Nothing -> error "ref does not exist"
- Just ref -> do
- res <- runExceptT $ sendToPeer peer $ DiscoverySearch ref
+ case readRefDigest (BC.pack sref) of
+ Nothing -> throwOtherError "failed to parse ref"
+ Just dgst -> liftIO $ do
+ res <- runExceptT $ sendToPeer peer $ DiscoverySearch $ Right dgst
case res of
Right _ -> return ()
Left err -> eprint err
diff --git a/main/Test.hs b/main/Test.hs
index 44818fd..a119b0f 100644
--- a/main/Test.hs
+++ b/main/Test.hs
@@ -957,11 +957,10 @@ cmdChatroomMessageSend = do
cmdDiscoveryConnect :: Command
cmdDiscoveryConnect = do
- st <- asks tiStorage
[ tref ] <- asks tiParams
- Just ref <- liftIO $ readRef st $ encodeUtf8 tref
+ Just dgst <- return $ readRefDigest $ encodeUtf8 tref
Just RunningServer {..} <- gets tsServer
peers <- liftIO $ getCurrentPeerList rsServer
forM_ peers $ \peer -> do
- sendToPeer peer $ DiscoverySearch ref
+ sendToPeer peer $ DiscoverySearch $ Right dgst