summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2019-05-02 22:55:09 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2019-05-02 22:55:09 +0200
commit8a03527dba479b520ebda47cdf00080d82d4e933 (patch)
treea6b8d4c0f962fa30b2812402456b6ead8a7b1673 /src/Main.hs
parent4b722b1ca195e70e2ac6518d88f79eb40a1095b2 (diff)
Basic local network peer discovery
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 65ae4a0..017d70d 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,4 +1,34 @@
-module Main where
+module Main (main) where
+
+import Control.Concurrent.Chan
+import Control.Exception
+import Control.Monad
+
+import qualified Data.Text.IO as T
+
+import System.Environment
+import System.IO
+import System.IO.Error
+
+import Identity
+import Network
+import Storage
+
main :: IO ()
-main = putStrLn "Hello, Haskell!"
+main = do
+ [bhost] <- getArgs
+ st <- openStorage "test"
+ idhead <- catchJust (guard . isDoesNotExistError) (loadHead st "identity") $ \_ -> do
+ putStr "Name: "
+ hFlush stdout
+ name <- T.getLine
+ let base = Identity name Nothing
+ Right h <- replaceHead base (Left (st, "identity"))
+ return h
+ let sidentity = wrappedLoad (headRef idhead) :: Stored Identity
+ print $ fromStored sidentity
+
+ chan <- peerDiscovery bhost sidentity
+ void $ forever $ print =<< readChan chan
+ return ()