summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Core.hs')
-rw-r--r--src/Network/BitTorrent/Core.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Core.hs b/src/Network/BitTorrent/Core.hs
index 2ddee517..5717e4de 100644
--- a/src/Network/BitTorrent/Core.hs
+++ b/src/Network/BitTorrent/Core.hs
@@ -9,7 +9,10 @@
9-- 9--
10module Network.BitTorrent.Core 10module Network.BitTorrent.Core
11 ( module Core 11 ( module Core
12
13 -- * Address class
12 , Address (..) 14 , Address (..)
15 , fromAddr
13 16
14 -- * Re-exports from Data.IP 17 -- * Re-exports from Data.IP
15 , IPv4 18 , IPv4
@@ -19,6 +22,7 @@ module Network.BitTorrent.Core
19 22
20import Control.Applicative 23import Control.Applicative
21import Data.IP 24import Data.IP
25import Data.Hashable
22import Data.Serialize 26import Data.Serialize
23import Data.Time 27import Data.Time
24import Data.Typeable 28import Data.Typeable
@@ -35,10 +39,14 @@ import Network.BitTorrent.Core.PeerAddr as Core
35instance Pretty UTCTime where 39instance Pretty UTCTime where
36 pretty = PP.text . show 40 pretty = PP.text . show
37 41
38class (Eq a, Serialize a, Typeable a, Pretty a) => Address a where 42class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a)
43 => Address a where
39 toSockAddr :: a -> SockAddr 44 toSockAddr :: a -> SockAddr
40 fromSockAddr :: SockAddr -> Maybe a 45 fromSockAddr :: SockAddr -> Maybe a
41 46
47fromAddr :: (Address a, Address b) => a -> Maybe b
48fromAddr = fromSockAddr . toSockAddr
49
42-- | Note that port is zeroed. 50-- | Note that port is zeroed.
43instance Address IPv4 where 51instance Address IPv4 where
44 toSockAddr = SockAddrInet 0 . toHostAddress 52 toSockAddr = SockAddrInet 0 . toHostAddress