summaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 9f6cade72232420b7f44863193bc0c7964990338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 PubKey
import Storage


main :: IO ()
main = do
    [bhost] <- getArgs
    st <- openStorage "test"
    idhead <- catchJust (guard . isDoesNotExistError) (loadHead st "identity") $ \_ -> do
        putStr "Name: "
        hFlush stdout
        name <- T.getLine
        (secret, public) <- generateKeys st

        base <- sign secret =<< wrappedStore st (Identity name Nothing public)
        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 ()