summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebian Live user <user@localhost.localdomain>2017-10-30 00:42:10 +0000
committerDebian Live user <user@localhost.localdomain>2017-10-30 00:42:10 +0000
commit31bfaac79df26da3d356181c9c6af9c12034656d (patch)
tree1362c8c8b306aec490b03e552d6a06173d0a0e55
parentf0821a9484c3d65167a82e4d40fff72bc9b62312 (diff)
parent17baab3044b7984bf97f6e731272f7552d559ab6 (diff)
Merge branch 'dht-rewrite' of jerkface.net:/home/jim/repo/bittorrent into dht-rewrite
-rw-r--r--Announcer.hs23
-rw-r--r--dht-client.cabal1
-rw-r--r--examples/dhtd.hs18
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 #-}
2module Announcer where
3
4import Network.Kademlia.Search
5
6data Announcer = Announcer
7
8forkAnnouncer :: IO Announcer
9forkAnnouncer = return Announcer
10
11stopAnnouncer :: Announcer -> IO ()
12stopAnnouncer _ = return ()
13
14data 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
19schedule :: Announcer -> AnnounceMethod ni r info -> info -> IO ()
20schedule _ _ _ = return ()
21
22cancel :: Announcer -> AnnounceMethod ni r info -> info -> IO ()
23cancel _ _ _ = 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
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