diff options
author | joe <joe@jerkface.net> | 2017-07-01 11:18:04 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-01 11:18:04 -0400 |
commit | e22ca7f163b6b771a570013d506f5d5f6576c2aa (patch) | |
tree | fd4b59f3302cd352a745db1659383643fb2166ab /examples | |
parent | ac8bced8dafa1a52bd02bdec8c1959af67442ed7 (diff) |
Simplified Kademlia class.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dhtd.hs | 40 |
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 | ||
14 | import Control.Arrow | 15 | import Control.Arrow |
15 | import Control.Monad | 16 | import Control.Monad |
@@ -223,6 +224,8 @@ ipType :: f dht ip -> DHT raw dht u ip () | |||
223 | ipType _ = return () | 224 | ipType _ = return () |
224 | 225 | ||
225 | instance Kademlia Tox.Message where | 226 | instance Kademlia Tox.Message where |
227 | data DHTData Tox.Message ip = ToxData | ||
228 | initializeDHTData = return ToxData | ||
226 | instance Pretty (NodeId Tox.Message) where | 229 | instance Pretty (NodeId Tox.Message) where |
227 | instance Pretty (NodeInfo Tox.Message IPv4 ()) where | 230 | instance Pretty (NodeInfo Tox.Message IPv4 ()) where |
228 | instance Pretty (NodeInfo Tox.Message IPv4 Bool) where -- TODO | 231 | instance 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 |
231 | instance Read (NodeId Tox.Message) where -- TODO | 234 | instance Read (NodeId Tox.Message) where -- TODO |
232 | instance Serialize (FindNode Tox.Message IPv4) where | 235 | instance 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" |
235 | instance Serialize (NodeFound Tox.Message IPv4) where | 238 | instance 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" |
238 | instance Serialize (Ping Tox.Message) where | 241 | instance 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" |
241 | instance Serialize (Query Tox.Message (FindNode Tox.Message IPv4)) where | 244 | instance 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" |
244 | instance Serialize (Query Tox.Message (Ping Tox.Message)) where -- TODO | 247 | instance 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" |
247 | instance Serialize (Response Tox.Message (NodeFound Tox.Message IPv4)) where | 250 | instance 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" |
250 | instance Serialize (Response Tox.Message (Ping Tox.Message)) where -- TODO | 253 | instance 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" |
253 | instance KRPC Tox.Message (Query Tox.Message (FindNode Tox.Message IPv4)) | 256 | instance 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" |
256 | instance KRPC Tox.Message (Query Tox.Message (Ping Tox.Message )) | 259 | instance 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" |
259 | instance DataHandlers ByteString Tox.Message where | 262 | instance 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 |