diff options
Diffstat (limited to 'src/Network/BitTorrent/Core.hs')
-rw-r--r-- | src/Network/BitTorrent/Core.hs | 10 |
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 | -- |
10 | module Network.BitTorrent.Core | 10 | module 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 | ||
20 | import Control.Applicative | 23 | import Control.Applicative |
21 | import Data.IP | 24 | import Data.IP |
25 | import Data.Hashable | ||
22 | import Data.Serialize | 26 | import Data.Serialize |
23 | import Data.Time | 27 | import Data.Time |
24 | import Data.Typeable | 28 | import Data.Typeable |
@@ -35,10 +39,14 @@ import Network.BitTorrent.Core.PeerAddr as Core | |||
35 | instance Pretty UTCTime where | 39 | instance Pretty UTCTime where |
36 | pretty = PP.text . show | 40 | pretty = PP.text . show |
37 | 41 | ||
38 | class (Eq a, Serialize a, Typeable a, Pretty a) => Address a where | 42 | class (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 | ||
47 | fromAddr :: (Address a, Address b) => a -> Maybe b | ||
48 | fromAddr = fromSockAddr . toSockAddr | ||
49 | |||
42 | -- | Note that port is zeroed. | 50 | -- | Note that port is zeroed. |
43 | instance Address IPv4 where | 51 | instance Address IPv4 where |
44 | toSockAddr = SockAddrInet 0 . toHostAddress | 52 | toSockAddr = SockAddrInet 0 . toHostAddress |