-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.hs
61 lines (58 loc) · 1.79 KB
/
main.hs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Monad
import Data.Aeson
import Network.DHT.Kademlia
import Network.DHT.Kademlia.Def (Config(..))
import System.Environment (getArgs)
import System.Exit
import qualified Data.ByteString.Lazy as BL
main :: IO ()
main = do
args <- getArgs
case args of
["--help"] -> usage
["--gen-conf"] -> do
putStrLn $ unlines [
"{"
, " \"routingTablePath\": \"routes.json\","
, " \"datastore\": {"
, " \"type\": \"hashtables\""
, " },"
, " \"seedNode\": {"
, " \"nodeId\": 2.1111456317203406E+38,"
, " \"location\": {"
, " \"port\": 1234,"
, " \"host\": 16777343"
, " }"
, " },"
, " \"thisNode\": {"
, " \"nodeId\": 2.3931456317203406E+38,"
, " \"location\": {"
, " \"port\": 41487,"
, " \"host\": 16777343"
, " }"
, " }"
, "}"
]
[cfgFile] -> do
(ecfg :: Either String Config) <- liftM eitherDecode $ BL.readFile cfgFile
case ecfg of
Left err -> putStrLn err >> exitFailure
Right cfg -> runKademlia cfg
otherwise -> usage
usage :: IO ()
usage = do
putStrLn "KADEMLIA(1) Kademlia Manual KADEMLIA(1)"
putStrLn ""
putStrLn "NAME"
putStrLn " kademlia -- distributed hashtable"
putStrLn ""
putStrLn "SYNOPSIS"
putStrLn " kademlia [--help] [--gen-conf] [config file ...]"
putStrLn ""
putStrLn "DESCRIPTION"
putStrLn " Kademila is an implementation of the Kademlia Distributed Hash Table (DHT) in Haskell"
putStrLn ""
exitFailure