summaryrefslogtreecommitdiff
path: root/examples/dhtd.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-01 03:03:51 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-01 03:03:51 +0000
commite76aa076a366d020bdda61f7477d30c4957ed6a1 (patch)
treeb28e62c880eab29f12d494756798550fbe00ec87 /examples/dhtd.hs
parent03d30d155a9f932a2b282d126ffcecd394be46f9 (diff)
c command...
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r--examples/dhtd.hs38
1 files changed, 35 insertions, 3 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index df36f5d8..ede203bf 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -131,9 +131,17 @@ data DHTAnnouncable = forall dta tok ni r.
131 , announceSendData :: dta -> tok -> Maybe ni -> IO (Maybe r) 131 , announceSendData :: dta -> tok -> Maybe ni -> IO (Maybe r)
132 } 132 }
133 133
134data DHTLink = forall status linkid. (Show status, Typeable status, Show linkid, Typeable linkid) => DHTLink 134data DHTLink = forall status linkid params.
135 { linkInit :: String -> IO (Either String status) 135 ( Show status
136 , Show linkid
137 , Typeable status
138 , Typeable linkid
139 , Typeable params
140 ) => DHTLink
141 { linkInit :: params -> IO (Either String status)
142 , linkParamParser :: [String] -> Either String params
136 , linkStatus :: IO (Either String status) 143 , linkStatus :: IO (Either String status)
144 , showLinkStatus :: status -> String
137 , linkNewPipe :: String -> linkid -> IO (Either String status) 145 , linkNewPipe :: String -> linkid -> IO (Either String status)
138 , linkUnPipe :: linkid -> IO (Either String status) 146 , linkUnPipe :: linkid -> IO (Either String status)
139 } 147 }
@@ -667,7 +675,31 @@ clientSession s@Session{..} sock cnum h = do
667 mkentry (k :-> Down tm) = [ show cnt, show k, show (now - tm) ] 675 mkentry (k :-> Down tm) = [ show cnt, show k, show (now - tm) ]
668 where Just (_,(cnt,_)) = MM.lookup' k (Tox.keyAssoc keydb) 676 where Just (_,(cnt,_)) = MM.lookup' k (Tox.keyAssoc keydb)
669 hPutClient h $ showColumns entries 677 hPutClient h $ showColumns entries
670 678 ("c", s) | "" <- strp s -> cmd0 $ do
679 let combinedLinkMap = Map.unions $map (dhtLinks . snd) (Map.toList dhts)
680 -- TODO: list all connections
681 let connections = [[{-TODO-}]]
682 hPutClient h $ showColumns connections
683 ("c", s) -> cmd0 $ do
684 let combinedLinkMap = Map.unions $map (dhtLinks . snd) (Map.toList dhts)
685 -- form new connection according of type corresponding to parameter
686 let ws = words s
687 result
688 <- case ws of
689 (linktype:rest)
690 -> case (Map.lookup (head ws) combinedLinkMap) of
691 Nothing -> return . Left $ "I don't know a '" ++ head ws ++ "' link type."
692 Just l@(DHTLink
693 { linkInit {- :: params -> IO (Either String status) -}
694 , linkParamParser {- :: [String] -> Either String params -}
695 , showLinkStatus {- :: status -> String -}
696 }) -> case linkParamParser rest of
697 Left er -> return $ Left er
698 Right params -> fmap showLinkStatus <$> linkInit params
699 _ -> return $ Left "parse error"
700 case result of
701 Left er -> hPutClient h er
702 Right statusstr -> hPutClient h statusstr
671 (n, _) | n `elem` Map.keys dhts -> switchNetwork n 703 (n, _) | n `elem` Map.keys dhts -> switchNetwork n
672 704
673 _ -> cmd0 $ hPutClient h "error." 705 _ -> cmd0 $ hPutClient h "error."