summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/DHT/ContactInfo.hs13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs
index 172306a1..b7d7f2a2 100644
--- a/src/Network/BitTorrent/DHT/ContactInfo.hs
+++ b/src/Network/BitTorrent/DHT/ContactInfo.hs
@@ -149,20 +149,21 @@ instance Address a => Serialize (SerializeAddress a) where
149 | otherwise = return $ error "cannot serialize non-IP SerializeAddress" 149 | otherwise = return $ error "cannot serialize non-IP SerializeAddress"
150 150
151 151
152{- XXX: What happened to the ports?
153instance Serialize SwarmData where 152instance Serialize SwarmData where
154 get = flip SwarmData <$> get 153 get = flip SwarmData <$> get
155 <*> ( PSQ.fromList . L.map parseAddr <$> get ) 154 <*> ( PSQ.fromList . L.map parseAddr <$> get )
156 where 155 where
157 parseAddr addr = (unserializeAddress <$> addr) 156 parseAddr (pid,addr,port) = PeerAddr { peerId = pid
158 :-> 0 157 , peerHost = unserializeAddress addr
158 , peerPort = port
159 }
160 :-> 0
159 161
160 put SwarmData{..} = do 162 put SwarmData{..} = do
161 put name 163 put name
162 put $ L.map (\(addr :-> _) -> (SerializeAddress <$> addr)) 164 put $ L.map (\(addr :-> _) -> (peerId addr, SerializeAddress addr, peerPort addr))
163 -- XXX: should we serialize the timestamp? 165 -- XXX: should we serialize the timestamp?
164 $ PSQ.toList peers 166 $ PSQ.toList peers
165-}
166 167
167knownSwarms :: PeerStore -> [ (InfoHash, Int, Maybe ByteString) ] 168knownSwarms :: PeerStore -> [ (InfoHash, Int, Maybe ByteString) ]
168knownSwarms (PeerStore m) = L.map (\(ih,SwarmData q n) -> (ih,PSQ.size q,n)) $ HM.toList m 169knownSwarms (PeerStore m) = L.map (\(ih,SwarmData q n) -> (ih,PSQ.size q,n)) $ HM.toList m
@@ -194,13 +195,11 @@ instance Monoid PeerStore where
194 PeerStore (HM.unionWith swarmInsert a b) 195 PeerStore (HM.unionWith swarmInsert a b)
195 {-# INLINE mappend #-} 196 {-# INLINE mappend #-}
196 197
197{-
198-- | Can be used to store peers between invocations of the client 198-- | Can be used to store peers between invocations of the client
199-- software. 199-- software.
200instance Serialize PeerStore where 200instance Serialize PeerStore where
201 get = PeerStore . HM.fromList <$> get 201 get = PeerStore . HM.fromList <$> get
202 put (PeerStore m) = put (L.filter (isSwarmOccupied . snd) $ HM.toList m) 202 put (PeerStore m) = put (L.filter (isSwarmOccupied . snd) $ HM.toList m)
203-}
204 203
205-- | Returns all peers associated with a given info hash. 204-- | Returns all peers associated with a given info hash.
206lookup :: InfoHash -> PeerStore -> [PeerAddr] 205lookup :: InfoHash -> PeerStore -> [PeerAddr]