From b8f976b3df0af5d27f926022d7c7624609fc1072 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sat, 11 Jan 2014 08:49:40 +0400 Subject: Add documentation to peer store section --- src/Network/BitTorrent/DHT/Message.hs | 5 ++++- src/Network/BitTorrent/DHT/Session.hs | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Network') 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 , NodeFound (..) -- ** get_peers + , PeerList , GetPeers (..) , GotPeers (..) @@ -216,11 +217,13 @@ instance BEncode GetPeers where toBEncode (GetPeers ih) = toDict $ info_hash_key .=! ih .: endDict fromBEncode = fromDict $ GetPeers <$>! info_hash_key +type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] + data GotPeers ip = GotPeers { -- | If the queried node has no peers for the infohash, returned -- the K nodes in the queried nodes routing table closest to the -- infohash supplied in the query. - peers :: Either [NodeInfo ip] [PeerAddr ip] + peers :: PeerList ip -- | The token value is a required argument for a future -- 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 -----------------------------------------------------------------------} -- TODO limit dht peer store in size (probably by removing oldest peers) + +-- | Insert peer to peer store. Used to handle announce requests. insertPeer :: Eq ip => InfoHash -> PeerAddr ip -> DHT ip () insertPeer ih addr = do var <- asks contactInfo liftIO $ atomically $ modifyTVar' var (P.insert ih addr) +-- | Get peer set for specific swarm. lookupPeers :: InfoHash -> DHT ip [PeerAddr ip] lookupPeers ih = do var <- asks contactInfo liftIO $ P.lookup ih <$> readTVarIO var -type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] - --- | +-- | Prepare result for 'get_peers' query. -- --- This operation used 'getClosest' as failback. +-- This operation use 'getClosest' as failback so it may block. -- getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) getPeerList ih = do -- cgit v1.2.3