summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-29 08:18:36 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-29 08:18:36 +0400
commit2c30e11e4ed379afb7b3fc5c35de9913085f090e (patch)
tree2b4c4774050fab860a2f6c65efb5288f621ed751 /src/Network/BitTorrent/Core
parent1e1ab84ec903aac67b5d1f337cfb290975fc77e1 (diff)
Add hashable instances for all address types
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index 4905f910..d634716c 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -176,6 +176,17 @@ instance Pretty IP where
176 pretty = PP.text . show 176 pretty = PP.text . show
177 {-# INLINE pretty #-} 177 {-# INLINE pretty #-}
178 178
179instance Hashable IPv4 where
180 hashWithSalt = hashUsing toHostAddress
181 {-# INLINE hashWithSalt #-}
182
183instance Hashable IPv6 where
184 hashWithSalt s a = hashWithSalt s (toHostAddress6 a)
185
186instance Hashable IP where
187 hashWithSalt s (IPv4 h) = hashWithSalt s h
188 hashWithSalt s (IPv6 h) = hashWithSalt s h
189
179{----------------------------------------------------------------------- 190{-----------------------------------------------------------------------
180-- Peer addr 191-- Peer addr
181-----------------------------------------------------------------------} 192-----------------------------------------------------------------------}
@@ -267,6 +278,10 @@ instance Pretty a => Pretty (PeerAddr a) where
267 where 278 where
268 paddr = pretty peerHost <> ":" <> text (show peerPort) 279 paddr = pretty peerHost <> ":" <> text (show peerPort)
269 280
281instance Hashable a => Hashable (PeerAddr a) where
282 hashWithSalt s PeerAddr {..} =
283 s `hashWithSalt` peerId `hashWithSalt` peerHost `hashWithSalt` peerPort
284
270-- | Ports typically reserved for bittorrent P2P listener. 285-- | Ports typically reserved for bittorrent P2P listener.
271defaultPorts :: [PortNumber] 286defaultPorts :: [PortNumber]
272defaultPorts = [6881..6889] 287defaultPorts = [6881..6889]