summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-26 02:06:05 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-26 02:06:05 +0400
commitea5c29d7f91397f7979b6f73052ef30a5cdf030f (patch)
treeb2ca2c858f814f45658cfe95fbe6aa305635a2f7 /src/Network/BitTorrent/Core
parent62253eb04e3ad1225d2a87a3c9647c6c092114df (diff)
parent5d545a58787bc1beadc13fa5838a4ad2472c5e88 (diff)
Merge branch 'dev' of https://github.com/DanielG/bittorrent
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index 63ae04b9..b9d4878e 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -133,6 +133,20 @@ instance BEncode IPv6 where
133 fromBEncode = ipFromBEncode 133 fromBEncode = ipFromBEncode
134 {-# INLINE fromBEncode #-} 134 {-# INLINE fromBEncode #-}
135 135
136instance Serialize IP where
137 put (IPv4 ip) = put ip
138 put (IPv6 ip) = put ip
139
140 -- | When 'get'ing an IP it must be 'isolate'd to the appropriate number of
141 -- bytes since we have no other way of telling which address type we are
142 -- trying to parse
143 get = do
144 n <- remaining
145 case n of
146 4 -> IPv4 <$> get
147 16 -> IPv6 <$> get
148 _ -> fail "Wrong number of bytes remaining to parse IP"
149
136instance Serialize IPv4 where 150instance Serialize IPv4 where
137 put = putWord32host . toHostAddress 151 put = putWord32host . toHostAddress
138 get = fromHostAddress <$> getWord32host 152 get = fromHostAddress <$> getWord32host