summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-05-08 09:45:59 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-05-08 09:45:59 +0200
commit5afb63aced2a6c5ec2fd3604f1b898d803686d8d (patch)
treec6ddd88716b8478241db9599419b3f23f88aefb5 /src/Main.hs
parentebe2292bc4bd19ec68935c2135160ca6aa0dbae3 (diff)
Command to manually add peer
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 4a2d910..cdaa9ae 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -232,6 +232,7 @@ commands :: [(String, Command)]
commands =
[ ("history", cmdHistory)
, ("peers", cmdPeers)
+ , ("peer-add", cmdPeerAdd)
, ("send", cmdSend)
, ("update-identity", cmdUpdateIdentity)
, ("attach", cmdAttach)
@@ -259,6 +260,16 @@ cmdPeers = do
forM_ (zip [1..] peers) $ \(i :: Int, (_, name)) -> do
liftIO $ putStrLn $ show i ++ ": " ++ name
+cmdPeerAdd :: Command
+cmdPeerAdd = void $ do
+ server <- asks ciServer
+ (hostname, port) <- (words <$> asks ciLine) >>= \case
+ hostname:p:_ -> return (hostname, p)
+ [hostname] -> return (hostname, show discoveryPort)
+ [] -> throwError "missing peer address"
+ addr:_ <- liftIO $ getAddrInfo (Just $ defaultHints { addrSocketType = Datagram }) (Just hostname) (Just port)
+ liftIO $ serverPeer server (addrAddress addr)
+
showPeer :: PeerIdentity -> PeerAddress -> String
showPeer pidentity paddr =
let name = case pidentity of