diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Core/Node.hs | 3 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Core/Node.hs b/src/Network/BitTorrent/Core/Node.hs index da96ca43..116333c5 100644 --- a/src/Network/BitTorrent/Core/Node.hs +++ b/src/Network/BitTorrent/Core/Node.hs | |||
@@ -122,6 +122,9 @@ data NodeAddr a = NodeAddr | |||
122 | 122 | ||
123 | $(deriveJSON omitRecordPrefix ''NodeAddr) | 123 | $(deriveJSON omitRecordPrefix ''NodeAddr) |
124 | 124 | ||
125 | instance Read (NodeAddr IPv4) where | ||
126 | readsPrec i x = [ (fromPeerAddr a, s) | (a, s) <- readsPrec i x ] | ||
127 | |||
125 | -- | @127.0.0.1:6882@ | 128 | -- | @127.0.0.1:6882@ |
126 | instance Default (NodeAddr IPv4) where | 129 | instance Default (NodeAddr IPv4) where |
127 | def = "127.0.0.1:6882" | 130 | def = "127.0.0.1:6882" |
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index d634716c..e3e09fd6 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs | |||
@@ -251,6 +251,13 @@ instance IsString (PeerAddr IPv4) where | |||
251 | = PeerAddr Nothing hostAddr portNum | 251 | = PeerAddr Nothing hostAddr portNum |
252 | | otherwise = error $ "fromString: unable to parse (PeerAddr IPv4): " ++ str | 252 | | otherwise = error $ "fromString: unable to parse (PeerAddr IPv4): " ++ str |
253 | 253 | ||
254 | instance Read (PeerAddr IPv4) where | ||
255 | readsPrec i = RP.readP_to_S $ do | ||
256 | ipv4 <- RP.readS_to_P (readsPrec i) | ||
257 | _ <- RP.char ':' | ||
258 | port <- toEnum <$> RP.readS_to_P (readsPrec i) | ||
259 | return $ PeerAddr Nothing ipv4 port | ||
260 | |||
254 | readsIPv6_port :: String -> [((IPv6, PortNumber), String)] | 261 | readsIPv6_port :: String -> [((IPv6, PortNumber), String)] |
255 | readsIPv6_port = RP.readP_to_S $ do | 262 | readsIPv6_port = RP.readP_to_S $ do |
256 | ip <- RP.char '[' *> (RP.readS_to_P reads) <* RP.char ']' | 263 | ip <- RP.char '[' *> (RP.readS_to_P reads) <* RP.char ']' |