summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-19 23:33:31 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-19 23:33:31 +0400
commit333347b468b33faf4a97a25be15de24fcf5d5601 (patch)
treebfd1609ac209f36bc2c2e9fde0ea5c8440471b12
parent67f96198ee63bb2faf08d0c6f6c89f11dc595f4a (diff)
Document DHT.Query module index
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs
index b9f12649..9c52220e 100644
--- a/src/Network/BitTorrent/DHT/Query.hs
+++ b/src/Network/BitTorrent/DHT/Query.hs
@@ -1,22 +1,40 @@
1-- |
2-- Copyright : (c) Sam Truzjan 2014
3-- License : BSD3
4-- Maintainer : pxqr.sta@gmail.com
5-- Stability : experimental
6-- Portability : portable
7--
8-- This module provides functions to interact with other nodes.
9-- Normally, you don't need to import this module, use
10-- "Network.BitTorrent.DHT" instead.
11--
1{-# LANGUAGE FlexibleContexts #-} 12{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE TemplateHaskell #-} 13{-# LANGUAGE TemplateHaskell #-}
3module Network.BitTorrent.DHT.Query 14module Network.BitTorrent.DHT.Query
4 ( -- * Handler 15 ( -- * Handler
16 -- | To bind specific set of handlers you need to pass
17 -- handler list to the 'startNode' function.
5 pingH 18 pingH
6 , findNodeH 19 , findNodeH
7 , getPeersH 20 , getPeersH
8 , announceH 21 , announceH
9 , defaultHandlers 22 , defaultHandlers
10 23
11 -- * Search 24 -- * Query
12 -- ** Step 25 -- ** Basic
26 -- | A basic query perform a single request expecting a
27 -- single response.
13 , Iteration 28 , Iteration
14 , pingQ 29 , pingQ
15 , findNodeQ 30 , findNodeQ
16 , getPeersQ 31 , getPeersQ
17 , announceQ 32 , announceQ
18 33
19 -- ** Traversal 34 -- ** Iterative
35 -- | An iterative query perform multiple basic queries,
36 -- concatenate its responses, optionally yielding result and
37 -- continue to the next iteration.
20 , Search 38 , Search
21 , search 39 , search
22 , publish 40 , publish
@@ -80,12 +98,12 @@ announceH = nodeHandler $ \ naddr @ NodeAddr {..} (Announce {..}) -> do
80 insertPeer topic peerAddr 98 insertPeer topic peerAddr
81 return Announced 99 return Announced
82 100
83-- | Includes all query handlers. 101-- | Includes all default query handlers.
84defaultHandlers :: Address ip => [NodeHandler ip] 102defaultHandlers :: Address ip => [NodeHandler ip]
85defaultHandlers = [pingH, findNodeH, getPeersH, announceH] 103defaultHandlers = [pingH, findNodeH, getPeersH, announceH]
86 104
87{----------------------------------------------------------------------- 105{-----------------------------------------------------------------------
88-- Search 106-- Basic queries
89-----------------------------------------------------------------------} 107-----------------------------------------------------------------------}
90 108
91type Iteration ip o = NodeInfo ip -> DHT ip (Either [NodeInfo ip] [o ip]) 109type Iteration ip o = NodeInfo ip -> DHT ip (Either [NodeInfo ip] [o ip])
@@ -127,6 +145,10 @@ announceQ ih p NodeInfo {..} = do
127 Announced <- Announce False ih p grantedToken <@> nodeAddr 145 Announced <- Announce False ih p grantedToken <@> nodeAddr
128 return (Right [nodeAddr]) 146 return (Right [nodeAddr])
129 147
148{-----------------------------------------------------------------------
149-- Iterative queries
150-----------------------------------------------------------------------}
151
130type Search ip o = Conduit [NodeInfo ip] (DHT ip) [o ip] 152type Search ip o = Conduit [NodeInfo ip] (DHT ip) [o ip]
131 153
132-- TODO: use reorder and filter (Traversal option) leftovers 154-- TODO: use reorder and filter (Traversal option) leftovers