summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-11 08:49:40 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-11 08:49:40 +0400
commitb8f976b3df0af5d27f926022d7c7624609fc1072 (patch)
tree0d6b4d23d9ae87aacb4991dac0f7e4607738f551 /src/Network/BitTorrent/DHT
parent353c25a17d4100afd23127fc32d96995a9c70388 (diff)
Add documentation to peer store section
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r--src/Network/BitTorrent/DHT/Message.hs5
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs9
2 files changed, 9 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/DHT/Message.hs b/src/Network/BitTorrent/DHT/Message.hs
index acecf8b1..7bcd00f0 100644
--- a/src/Network/BitTorrent/DHT/Message.hs
+++ b/src/Network/BitTorrent/DHT/Message.hs
@@ -73,6 +73,7 @@ module Network.BitTorrent.DHT.Message
73 , NodeFound (..) 73 , NodeFound (..)
74 74
75 -- ** get_peers 75 -- ** get_peers
76 , PeerList
76 , GetPeers (..) 77 , GetPeers (..)
77 , GotPeers (..) 78 , GotPeers (..)
78 79
@@ -216,11 +217,13 @@ instance BEncode GetPeers where
216 toBEncode (GetPeers ih) = toDict $ info_hash_key .=! ih .: endDict 217 toBEncode (GetPeers ih) = toDict $ info_hash_key .=! ih .: endDict
217 fromBEncode = fromDict $ GetPeers <$>! info_hash_key 218 fromBEncode = fromDict $ GetPeers <$>! info_hash_key
218 219
220type PeerList ip = Either [NodeInfo ip] [PeerAddr ip]
221
219data GotPeers ip = GotPeers 222data GotPeers ip = GotPeers
220 { -- | If the queried node has no peers for the infohash, returned 223 { -- | If the queried node has no peers for the infohash, returned
221 -- the K nodes in the queried nodes routing table closest to the 224 -- the K nodes in the queried nodes routing table closest to the
222 -- infohash supplied in the query. 225 -- infohash supplied in the query.
223 peers :: Either [NodeInfo ip] [PeerAddr ip] 226 peers :: PeerList ip
224 227
225 -- | The token value is a required argument for a future 228 -- | The token value is a required argument for a future
226 -- announce_peer query. 229 -- announce_peer query.
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 5ceca4a3..f08d85c6 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -354,21 +354,22 @@ insertNode info = fork $ do
354-----------------------------------------------------------------------} 354-----------------------------------------------------------------------}
355 355
356-- TODO limit dht peer store in size (probably by removing oldest peers) 356-- TODO limit dht peer store in size (probably by removing oldest peers)
357
358-- | Insert peer to peer store. Used to handle announce requests.
357insertPeer :: Eq ip => InfoHash -> PeerAddr ip -> DHT ip () 359insertPeer :: Eq ip => InfoHash -> PeerAddr ip -> DHT ip ()
358insertPeer ih addr = do 360insertPeer ih addr = do
359 var <- asks contactInfo 361 var <- asks contactInfo
360 liftIO $ atomically $ modifyTVar' var (P.insert ih addr) 362 liftIO $ atomically $ modifyTVar' var (P.insert ih addr)
361 363
364-- | Get peer set for specific swarm.
362lookupPeers :: InfoHash -> DHT ip [PeerAddr ip] 365lookupPeers :: InfoHash -> DHT ip [PeerAddr ip]
363lookupPeers ih = do 366lookupPeers ih = do
364 var <- asks contactInfo 367 var <- asks contactInfo
365 liftIO $ P.lookup ih <$> readTVarIO var 368 liftIO $ P.lookup ih <$> readTVarIO var
366 369
367type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] 370-- | Prepare result for 'get_peers' query.
368
369-- |
370-- 371--
371-- This operation used 'getClosest' as failback. 372-- This operation use 'getClosest' as failback so it may block.
372-- 373--
373getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) 374getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip)
374getPeerList ih = do 375getPeerList ih = do