diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-26 02:06:05 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-26 02:06:05 +0400 |
commit | ea5c29d7f91397f7979b6f73052ef30a5cdf030f (patch) | |
tree | b2ca2c858f814f45658cfe95fbe6aa305635a2f7 /src/Network/BitTorrent/Core/PeerAddr.hs | |
parent | 62253eb04e3ad1225d2a87a3c9647c6c092114df (diff) | |
parent | 5d545a58787bc1beadc13fa5838a4ad2472c5e88 (diff) |
Merge branch 'dev' of https://github.com/DanielG/bittorrent
Diffstat (limited to 'src/Network/BitTorrent/Core/PeerAddr.hs')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 14 |
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 | ||
136 | instance 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 | |||
136 | instance Serialize IPv4 where | 150 | instance Serialize IPv4 where |
137 | put = putWord32host . toHostAddress | 151 | put = putWord32host . toHostAddress |
138 | get = fromHostAddress <$> getWord32host | 152 | get = fromHostAddress <$> getWord32host |