summaryrefslogtreecommitdiff
path: root/dht/examples
diff options
context:
space:
mode:
Diffstat (limited to 'dht/examples')
-rw-r--r--dht/examples/dhtd.hs34
1 files changed, 30 insertions, 4 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs
index 2772416b..e0b58539 100644
--- a/dht/examples/dhtd.hs
+++ b/dht/examples/dhtd.hs
@@ -47,6 +47,7 @@ import GHC.Conc (threadStatus,ThreadStatus(..))
47import GHC.Stats 47import GHC.Stats
48import Network.Socket 48import Network.Socket
49import System.Environment 49import System.Environment
50import System.Exit
50import System.IO 51import System.IO
51import System.Mem 52import System.Mem
52import System.Posix.Process 53import System.Posix.Process
@@ -121,6 +122,7 @@ import DebugTag
121import LocalChat 122import LocalChat
122import ToxChat 123import ToxChat
123import MUC 124import MUC
125import Data.Either
124 126
125 127
126pshow :: Show a => a -> B.ByteString 128pshow :: Show a => a -> B.ByteString
@@ -1135,10 +1137,33 @@ sensibleDefaults = Options
1135 , verboseTags = [XUnexpected, XUnused] 1137 , verboseTags = [XUnexpected, XUnused]
1136 } 1138 }
1137 1139
1140data ShowHelp = ShowHelp
1141 deriving (Eq,Show)
1142
1143usage ShowHelp
1144 = let { cs = [ ([["--help"]] ,["display this help"])
1145 , ([["--dhtkey ",dhtkey]
1146 ,["--dht-key ",dhtkey]],["use ",dhtkey," as the dht key"])
1147 , ([["-4"]] ,["Use IPv4 only"])
1148 , ([["-v ",tags]] ,["Enable or disable specified DebugTags.\n DebugTags = ", listDebugTags])
1149 ] ;
1150 dhtkey ="<dhtkey>" ;
1151 tags = "[-]Tag1,[-]Tag2,... " ;
1152 -- TODO: word-wrap listDebugTags for terminal width
1153 listDebugTags = intercalate ", " $ map ((drop 1) . show) ([minBound .. maxBound]::[DebugTag]) ;
1154 } in do
1155 putStrLn "dhtd OPTIONS\n"
1156 forM cs $ \(how,what) -> do
1157 forM how $ putStrLn . (" "++) . concat
1158 putStr "\t"
1159 putStrLn . concat $ what
1160 exitFailure
1161
1138-- bt=<port>,tox=<port> 1162-- bt=<port>,tox=<port>
1139-- -4 1163-- -4
1140parseArgs :: [String] -> Options -> Options 1164parseArgs :: [String] -> Options -> Either ShowHelp Options
1141parseArgs [] opts = opts 1165parseArgs [] opts = Right opts
1166parseArgs ("--help":args) opts = Left ShowHelp
1142parseArgs ("--dhtkey":k:args) opts = parseArgs args opts 1167parseArgs ("--dhtkey":k:args) opts = parseArgs args opts
1143 { dhtkey = decodeSecret $ B.pack k } 1168 { dhtkey = decodeSecret $ B.pack k }
1144parseArgs ("--dht-key":k:args) opts = parseArgs args opts 1169parseArgs ("--dht-key":k:args) opts = parseArgs args opts
@@ -1619,8 +1644,9 @@ initJabber opts ssvar announcer mbtox toxdhts toxchat = case portxmpp opts of
1619main :: IO () 1644main :: IO ()
1620main = do 1645main = do
1621 args <- getArgs 1646 args <- getArgs
1622 let opts = parseArgs args sensibleDefaults 1647 let eopts = parseArgs args sensibleDefaults
1623 print opts 1648 either usage print eopts -- quits on left
1649 let Right opts = eopts
1624 1650
1625 swarms <- Mainline.newSwarmsDatabase 1651 swarms <- Mainline.newSwarmsDatabase
1626 -- Restore peer database before forking the listener thread. 1652 -- Restore peer database before forking the listener thread.