diff options
-rw-r--r-- | Announcer.hs | 23 | ||||
-rw-r--r-- | dht-client.cabal | 1 | ||||
-rw-r--r-- | examples/dhtd.hs | 18 |
3 files changed, 42 insertions, 0 deletions
diff --git a/Announcer.hs b/Announcer.hs new file mode 100644 index 00000000..2d2c2197 --- /dev/null +++ b/Announcer.hs | |||
@@ -0,0 +1,23 @@ | |||
1 | {-# LANGUAGE ExistentialQuantification #-} | ||
2 | module Announcer where | ||
3 | |||
4 | import Network.Kademlia.Search | ||
5 | |||
6 | data Announcer = Announcer | ||
7 | |||
8 | forkAnnouncer :: IO Announcer | ||
9 | forkAnnouncer = return Announcer | ||
10 | |||
11 | stopAnnouncer :: Announcer -> IO () | ||
12 | stopAnnouncer _ = return () | ||
13 | |||
14 | data AnnounceMethod ni r info = forall nid addr tok. AnnounceMethod | ||
15 | { aSearch :: Search nid addr tok ni r | ||
16 | , aPublish :: info -> Maybe ni -> IO (Maybe r) | ||
17 | } | ||
18 | |||
19 | schedule :: Announcer -> AnnounceMethod ni r info -> info -> IO () | ||
20 | schedule _ _ _ = return () | ||
21 | |||
22 | cancel :: Announcer -> AnnounceMethod ni r info -> info -> IO () | ||
23 | cancel _ _ _ = return () | ||
diff --git a/dht-client.cabal b/dht-client.cabal index 6bd680cc..c5985a41 100644 --- a/dht-client.cabal +++ b/dht-client.cabal | |||
@@ -92,6 +92,7 @@ library | |||
92 | Crypto.Tox | 92 | Crypto.Tox |
93 | Text.XXD | 93 | Text.XXD |
94 | Roster | 94 | Roster |
95 | Announcer | ||
95 | 96 | ||
96 | build-depends: base | 97 | build-depends: base |
97 | , containers | 98 | , containers |
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 | |||
50 | import qualified Data.Text as T | 50 | import qualified Data.Text as T |
51 | import qualified Data.Text.Encoding as T | 51 | import qualified Data.Text.Encoding as T |
52 | 52 | ||
53 | import Announcer | ||
53 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) | 54 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) |
54 | import Network.UPNP as UPNP | 55 | import Network.UPNP as UPNP |
55 | import Network.Address hiding (NodeId, NodeInfo(..)) | 56 | import 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 | ||