summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-03 00:59:48 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-03 00:59:48 +0400
commit65107192f9c5f8ff134362a7b9d37cb3f73dad7e (patch)
treec04f56cf4ec079a47f9bdb5d9cc73cbcfa2ca6d3 /src/Network/BitTorrent/Core
parent8815a137d8300d62a897154ec4fd02917d22bcb3 (diff)
Add skeleton for gettorrent example
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/Node.hs3
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs7
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
125instance 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@
126instance Default (NodeAddr IPv4) where 129instance 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
254instance 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
254readsIPv6_port :: String -> [((IPv6, PortNumber), String)] 261readsIPv6_port :: String -> [((IPv6, PortNumber), String)]
255readsIPv6_port = RP.readP_to_S $ do 262readsIPv6_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 ']'