diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-11 08:49:40 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-11 08:49:40 +0400 |
commit | b8f976b3df0af5d27f926022d7c7624609fc1072 (patch) | |
tree | 0d6b4d23d9ae87aacb4991dac0f7e4607738f551 /src | |
parent | 353c25a17d4100afd23127fc32d96995a9c70388 (diff) |
Add documentation to peer store section
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/DHT/Message.hs | 5 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 9 |
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 | ||
220 | type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] | ||
221 | |||
219 | data GotPeers ip = GotPeers | 222 | data 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. | ||
357 | insertPeer :: Eq ip => InfoHash -> PeerAddr ip -> DHT ip () | 359 | insertPeer :: Eq ip => InfoHash -> PeerAddr ip -> DHT ip () |
358 | insertPeer ih addr = do | 360 | insertPeer 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. | ||
362 | lookupPeers :: InfoHash -> DHT ip [PeerAddr ip] | 365 | lookupPeers :: InfoHash -> DHT ip [PeerAddr ip] |
363 | lookupPeers ih = do | 366 | lookupPeers 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 | ||
367 | type 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 | -- |
373 | getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) | 374 | getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) |
374 | getPeerList ih = do | 375 | getPeerList ih = do |