diff options
author | joe <joe@jerkface.net> | 2017-07-27 07:12:56 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-27 07:12:56 -0400 |
commit | 994f36cc6e9e627de869ded4ac1058c2963a15e9 (patch) | |
tree | c80b7e42bc0f22008fb7089dbede07bcc4845941 /src/Network/BitTorrent/DHT/ContactInfo.hs | |
parent | 7d0a9f4e021dd15463659a115610df6d60f973a0 (diff) |
SwarmData Serialize instances.
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/ContactInfo.hs | 13 |
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? | ||
153 | instance Serialize SwarmData where | 152 | instance 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 | ||
167 | knownSwarms :: PeerStore -> [ (InfoHash, Int, Maybe ByteString) ] | 168 | knownSwarms :: PeerStore -> [ (InfoHash, Int, Maybe ByteString) ] |
168 | knownSwarms (PeerStore m) = L.map (\(ih,SwarmData q n) -> (ih,PSQ.size q,n)) $ HM.toList m | 169 | knownSwarms (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. |
200 | instance Serialize PeerStore where | 200 | instance 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. |
206 | lookup :: InfoHash -> PeerStore -> [PeerAddr] | 205 | lookup :: InfoHash -> PeerStore -> [PeerAddr] |