summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs12
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.
137data PeerAddr a = PeerAddr 137data 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.
149instance (Typeable a, BEncode a) => BEncode (PeerAddr a) where 149instance (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
180instance (Serialize a) => Serialize (PeerAddr a) where 180instance (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
220instance Pretty (PeerAddr IP) where 220instance 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.
228defaultPorts :: [PortNumber] 228defaultPorts :: [PortNumber]
@@ -236,6 +236,6 @@ _resolvePeerAddr = undefined
236-- 236--
237peerSockAddr :: PeerAddr IP -> SockAddr 237peerSockAddr :: PeerAddr IP -> SockAddr
238peerSockAddr PeerAddr {..} = 238peerSockAddr 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