diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-15 19:50:51 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-15 19:50:51 +0400 |
commit | 110ca6eeeaf60c59992546614f31361ff058ae0f (patch) | |
tree | dc1b3eb23ece870e11c70668e8930907a3d59d55 /src/Network/BitTorrent/Core | |
parent | c1e3c9762eb5fea16188a0fb21ad01dd3240ab88 (diff) |
Rename PeerAddr(peerAddr) to PeerAddr(peerHost)
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index 3c3e98c5..6ef20f06 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs | |||
@@ -136,7 +136,7 @@ instance Serialize IPv6 where | |||
136 | -- compact list encoding. | 136 | -- compact list encoding. |
137 | data PeerAddr a = PeerAddr | 137 | data PeerAddr a = PeerAddr |
138 | { peerId :: !(Maybe PeerId) | 138 | { peerId :: !(Maybe PeerId) |
139 | , peerAddr :: a | 139 | , peerHost :: a |
140 | , peerPort :: {-# UNPACK #-} !PortNumber | 140 | , peerPort :: {-# UNPACK #-} !PortNumber |
141 | } deriving (Show, Eq, Typeable, Functor) | 141 | } deriving (Show, Eq, Typeable, Functor) |
142 | 142 | ||
@@ -148,7 +148,7 @@ peer_port_key = "port" | |||
148 | -- | The tracker's 'announce response' compatible encoding. | 148 | -- | The tracker's 'announce response' compatible encoding. |
149 | instance (Typeable a, BEncode a) => BEncode (PeerAddr a) where | 149 | instance (Typeable a, BEncode a) => BEncode (PeerAddr a) where |
150 | toBEncode PeerAddr {..} = toDict $ | 150 | toBEncode PeerAddr {..} = toDict $ |
151 | peer_ip_key .=! peerAddr | 151 | peer_ip_key .=! peerHost |
152 | .: peer_id_key .=? peerId | 152 | .: peer_id_key .=? peerId |
153 | .: peer_port_key .=! peerPort | 153 | .: peer_port_key .=! peerPort |
154 | .: endDict | 154 | .: endDict |
@@ -178,7 +178,7 @@ splitIPList xs = partitionEithers $ toEither <$> xs | |||
178 | -- | 178 | -- |
179 | -- TODO: test byte order | 179 | -- TODO: test byte order |
180 | instance (Serialize a) => Serialize (PeerAddr a) where | 180 | instance (Serialize a) => Serialize (PeerAddr a) where |
181 | put PeerAddr {..} = put peerAddr >> put peerPort | 181 | put PeerAddr {..} = put peerHost >> put peerPort |
182 | get = PeerAddr Nothing <$> get <*> get | 182 | get = PeerAddr Nothing <$> get <*> get |
183 | 183 | ||
184 | -- | @127.0.0.1:6881@ | 184 | -- | @127.0.0.1:6881@ |
@@ -217,12 +217,12 @@ instance IsString (PeerAddr IP) where | |||
217 | 217 | ||
218 | -- | fingerprint + "at" + dotted.host.inet.addr:port | 218 | -- | fingerprint + "at" + dotted.host.inet.addr:port |
219 | -- TODO: instances for IPv6, HostName | 219 | -- TODO: instances for IPv6, HostName |
220 | instance Pretty (PeerAddr IP) where | 220 | instance Pretty a => Pretty (PeerAddr a) where |
221 | pretty PeerAddr {..} | 221 | pretty PeerAddr {..} |
222 | | Just pid <- peerId = pretty (fingerprint pid) <+> "at" <+> paddr | 222 | | Just pid <- peerId = pretty (fingerprint pid) <+> "at" <+> paddr |
223 | | otherwise = paddr | 223 | | otherwise = paddr |
224 | where | 224 | where |
225 | paddr = text (show peerAddr ++ ":" ++ show peerPort) | 225 | paddr = pretty peerHost <> ":" <> text (show peerPort) |
226 | 226 | ||
227 | -- | Ports typically reserved for bittorrent P2P listener. | 227 | -- | Ports typically reserved for bittorrent P2P listener. |
228 | defaultPorts :: [PortNumber] | 228 | defaultPorts :: [PortNumber] |
@@ -236,6 +236,6 @@ _resolvePeerAddr = undefined | |||
236 | -- | 236 | -- |
237 | peerSockAddr :: PeerAddr IP -> SockAddr | 237 | peerSockAddr :: PeerAddr IP -> SockAddr |
238 | peerSockAddr PeerAddr {..} = | 238 | peerSockAddr PeerAddr {..} = |
239 | case peerAddr of | 239 | case peerHost of |
240 | IPv4 ipv4 -> SockAddrInet peerPort (toHostAddress ipv4) | 240 | IPv4 ipv4 -> SockAddrInet peerPort (toHostAddress ipv4) |
241 | IPv6 ipv6 -> SockAddrInet6 peerPort 0 (toHostAddress6 ipv6) 0 | 241 | IPv6 ipv6 -> SockAddrInet6 peerPort 0 (toHostAddress6 ipv6) 0 |