summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index ebc8b69e..fc2996a6 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -50,6 +50,7 @@ import qualified Data.Vector as V
50import qualified Data.Text as T 50import qualified Data.Text as T
51import qualified Data.Text.Encoding as T 51import qualified Data.Text.Encoding as T
52 52
53import Announcer
53import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) 54import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys)
54import Network.UPNP as UPNP 55import Network.UPNP as UPNP
55import Network.Address hiding (NodeId, NodeInfo(..)) 56import Network.Address hiding (NodeId, NodeInfo(..))
@@ -324,6 +325,7 @@ data Session = Session
324 , toxkeys :: TVar Tox.AnnouncedKeys 325 , toxkeys :: TVar Tox.AnnouncedKeys
325 , userkeys :: TVar [(SecretKey,PublicKey)] 326 , userkeys :: TVar [(SecretKey,PublicKey)]
326 , roster :: Roster 327 , roster :: Roster
328 , announcer :: Announcer
327 , signalQuit :: MVar () 329 , signalQuit :: MVar ()
328 } 330 }
329 331
@@ -528,6 +530,18 @@ clientSession s@Session{..} sock cnum h = do
528 maybe (hPutClient h ("Unsupported method: "++method)) 530 maybe (hPutClient h ("Unsupported method: "++method))
529 goTarget 531 goTarget
530 $ Map.lookup method dhtAnnouncables 532 $ Map.lookup method dhtAnnouncables
533
534 ("a", s) | Just DHT{..} <- Map.lookup netname dhts
535 , not (null s)
536 -> cmd0 $ do
537 let (op:method,xs) = break isSpace $ dropWhile isSpace s
538 (dtastr,ys) = break isSpace $ dropWhile isSpace xs
539 a = Map.lookup method dhtAnnouncables
540 q = Map.lookup method dhtQuery
541 doit '+' = schedule
542 doit '-' = cancel
543 doit _ = \_ _ _ -> hPutClient h "Starting(+) or canceling(-)?"
544 doit op announcer _announcemethod _what
531 ("s", s) | Just dht@DHT{..} <- Map.lookup netname dhts 545 ("s", s) | Just dht@DHT{..} <- Map.lookup netname dhts
532 -> cmd0 $ do 546 -> cmd0 $ do
533 let (method,xs) = break isSpace s 547 let (method,xs) = break isSpace s
@@ -667,6 +681,8 @@ main = do
667 (atomically . writeTVar (Mainline.contactInfo swarms)) 681 (atomically . writeTVar (Mainline.contactInfo swarms))
668 (peerdb >>= S.decodeLazy) 682 (peerdb >>= S.decodeLazy)
669 683
684 announcer <- forkAnnouncer
685
670 (quitBt,btdhts,btips,baddrs) <- case portbt opts of 686 (quitBt,btdhts,btips,baddrs) <- case portbt opts of
671 "" -> return (return (), Map.empty,return [],[]) 687 "" -> return (return (), Map.empty,return [],[])
672 p -> do 688 p -> do
@@ -871,6 +887,7 @@ main = do
871 , userkeys = toxids 887 , userkeys = toxids
872 , roster = rstr 888 , roster = rstr
873 , externalAddresses = liftM2 (++) btips toxips 889 , externalAddresses = liftM2 (++) btips toxips
890 , announcer = announcer
874 } 891 }
875 srv <- streamServer (withSession session) (SockAddrUnix "dht.sock") 892 srv <- streamServer (withSession session) (SockAddrUnix "dht.sock")
876 return $ do 893 return $ do
@@ -957,6 +974,7 @@ main = do
957 974
958 waitForSignal 975 waitForSignal
959 976
977 stopAnnouncer announcer
960 quitBt 978 quitBt
961 quitTox 979 quitTox
962 980