From 65107192f9c5f8ff134362a7b9d37cb3f73dad7e Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Fri, 3 Jan 2014 00:59:48 +0400 Subject: Add skeleton for gettorrent example --- src/Network/BitTorrent/Core/Node.hs | 3 +++ src/Network/BitTorrent/Core/PeerAddr.hs | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'src') 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 $(deriveJSON omitRecordPrefix ''NodeAddr) +instance Read (NodeAddr IPv4) where + readsPrec i x = [ (fromPeerAddr a, s) | (a, s) <- readsPrec i x ] + -- | @127.0.0.1:6882@ instance Default (NodeAddr IPv4) where 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 = PeerAddr Nothing hostAddr portNum | otherwise = error $ "fromString: unable to parse (PeerAddr IPv4): " ++ str +instance Read (PeerAddr IPv4) where + readsPrec i = RP.readP_to_S $ do + ipv4 <- RP.readS_to_P (readsPrec i) + _ <- RP.char ':' + port <- toEnum <$> RP.readS_to_P (readsPrec i) + return $ PeerAddr Nothing ipv4 port + readsIPv6_port :: String -> [((IPv6, PortNumber), String)] readsIPv6_port = RP.readP_to_S $ do ip <- RP.char '[' *> (RP.readS_to_P reads) <* RP.char ']' -- cgit v1.2.3