summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-01 11:18:04 -0400
committerjoe <joe@jerkface.net>2017-07-01 11:18:04 -0400
commite22ca7f163b6b771a570013d506f5d5f6576c2aa (patch)
treefd4b59f3302cd352a745db1659383643fb2166ab /examples
parentac8bced8dafa1a52bd02bdec8c1959af67442ed7 (diff)
Simplified Kademlia class.
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs40
1 files changed, 23 insertions, 17 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 68f91446..e4716d1a 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -10,6 +10,7 @@
10{-# LANGUAGE PartialTypeSignatures #-} 10{-# LANGUAGE PartialTypeSignatures #-}
11{-# LANGUAGE CPP #-} 11{-# LANGUAGE CPP #-}
12{-# LANGUAGE RankNTypes #-} 12{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE TypeFamilies #-}
13 14
14import Control.Arrow 15import Control.Arrow
15import Control.Monad 16import Control.Monad
@@ -223,6 +224,8 @@ ipType :: f dht ip -> DHT raw dht u ip ()
223ipType _ = return () 224ipType _ = return ()
224 225
225instance Kademlia Tox.Message where 226instance Kademlia Tox.Message where
227 data DHTData Tox.Message ip = ToxData
228 initializeDHTData = return ToxData
226instance Pretty (NodeId Tox.Message) where 229instance Pretty (NodeId Tox.Message) where
227instance Pretty (NodeInfo Tox.Message IPv4 ()) where 230instance Pretty (NodeInfo Tox.Message IPv4 ()) where
228instance Pretty (NodeInfo Tox.Message IPv4 Bool) where -- TODO 231instance Pretty (NodeInfo Tox.Message IPv4 Bool) where -- TODO
@@ -230,32 +233,32 @@ instance Read (NodeId KMessageOf) where
230 readsPrec d s = map (\(ih,s) -> (toNodeId (ih::InfoHash),s)) $ readsPrec d s 233 readsPrec d s = map (\(ih,s) -> (toNodeId (ih::InfoHash),s)) $ readsPrec d s
231instance Read (NodeId Tox.Message) where -- TODO 234instance Read (NodeId Tox.Message) where -- TODO
232instance Serialize (FindNode Tox.Message IPv4) where 235instance Serialize (FindNode Tox.Message IPv4) where
233 get = error "TODO get" 236 get = error "TODO get 1"
234 put = error "TODO put" 237 put = error "TODO put 2"
235instance Serialize (NodeFound Tox.Message IPv4) where 238instance Serialize (NodeFound Tox.Message IPv4) where
236 get = error "TODO get" 239 get = error "TODO get 3"
237 put = error "TODO put" 240 put = error "TODO put 4"
238instance Serialize (Ping Tox.Message) where 241instance Serialize (Ping Tox.Message) where
239 get = error "TODO get" 242 get = error "TODO get 5"
240 put = error "TODO put" 243 put = error "TODO put 6"
241instance Serialize (Query Tox.Message (FindNode Tox.Message IPv4)) where 244instance Serialize (Query Tox.Message (FindNode Tox.Message IPv4)) where
242 get = error "TODO get" 245 get = error "TODO get 7"
243 put = error "TODO put" 246 put = error "TODO put 8"
244instance Serialize (Query Tox.Message (Ping Tox.Message)) where -- TODO 247instance Serialize (Query Tox.Message (Ping Tox.Message)) where -- TODO
245 get = error "TODO get" 248 get = error "TODO get 9"
246 put = error "TODO put" 249 put = error "TODO put 10"
247instance Serialize (Response Tox.Message (NodeFound Tox.Message IPv4)) where 250instance Serialize (Response Tox.Message (NodeFound Tox.Message IPv4)) where
248 get = error "TODO get" 251 get = error "TODO get 11"
249 put = error "TODO put" 252 put = error "TODO put 12"
250instance Serialize (Response Tox.Message (Ping Tox.Message)) where -- TODO 253instance Serialize (Response Tox.Message (Ping Tox.Message)) where -- TODO
251 get = error "TODO get" 254 get = error "TODO get 13"
252 put = error "TODO put" 255 put = error "TODO put 14"
253instance KRPC Tox.Message (Query Tox.Message (FindNode Tox.Message IPv4)) 256instance KRPC Tox.Message (Query Tox.Message (FindNode Tox.Message IPv4))
254 (Response Tox.Message (NodeFound Tox.Message IPv4)) where 257 (Response Tox.Message (NodeFound Tox.Message IPv4)) where
255 method = error "TODO method" 258 method = error "TODO method 15"
256instance KRPC Tox.Message (Query Tox.Message (Ping Tox.Message )) 259instance KRPC Tox.Message (Query Tox.Message (Ping Tox.Message ))
257 (Response Tox.Message (Ping Tox.Message )) where 260 (Response Tox.Message (Ping Tox.Message )) where
258 method = error "TODO method" 261 method = error "TODO method 16"
259instance DataHandlers ByteString Tox.Message where 262instance DataHandlers ByteString Tox.Message where
260 263
261 264
@@ -490,6 +493,9 @@ main = do
490 ["-p",port] | not ("-" `isPrefixOf` port) -> return port 493 ["-p",port] | not ("-" `isPrefixOf` port) -> return port
491 ("-p":_) -> error "Port not specified! (-p PORT)" 494 ("-p":_) -> error "Port not specified! (-p PORT)"
492 _ -> defaultPort 495 _ -> defaultPort
496
497 tox_state <- godht (show (succ (read p::Int))) $ \a me0 -> ask
498
493 godht p $ \a me0 -> do 499 godht p $ \a me0 -> do
494 printTable 500 printTable
495 bs <- liftIO bootstrapNodes 501 bs <- liftIO bootstrapNodes
@@ -525,7 +531,7 @@ main = do
525 st <- ask 531 st <- ask
526 waitForSignal <- liftIO $ do 532 waitForSignal <- liftIO $ do
527 signalQuit <- newEmptyMVar 533 signalQuit <- newEmptyMVar
528 srv <- streamServer (withSession $ clientSession st (error "todo: tox state") signalQuit True) (SockAddrUnix "dht.sock") 534 srv <- streamServer (withSession $ clientSession st tox_state signalQuit True) (SockAddrUnix "dht.sock")
529 return $ liftIO $ do 535 return $ liftIO $ do
530 () <- takeMVar signalQuit 536 () <- takeMVar signalQuit
531 quitListening srv 537 quitListening srv