From: Ramakrishnan Muthukrishnan Date: Thu, 16 Jun 2016 04:03:59 +0000 (+0530) Subject: Tracker/Udp: bug fix, IP is 4 bytes, not 6. Doh! X-Git-Url: https://git.rkrishnan.org/frontends/specifications//%22news.html/%22?a=commitdiff_plain;h=386df507252c466f486f3b1570a885d597487469;p=functorrent.git Tracker/Udp: bug fix, IP is 4 bytes, not 6. Doh! --- diff --git a/src/FuncTorrent/Tracker/Udp.hs b/src/FuncTorrent/Tracker/Udp.hs index 2060454..aedc4a7 100644 --- a/src/FuncTorrent/Tracker/Udp.hs +++ b/src/FuncTorrent/Tracker/Udp.hs @@ -96,7 +96,7 @@ instance Binary UDPRequest where putWord32be $ fromIntegral (eventToInteger event) putWord32be 0 putWord32be 0 - putWord32be 20 + putWord32be 10 putWord16be $ fromIntegral port put (ScrapeReq _ _ _) = undefined get = undefined @@ -129,7 +129,6 @@ instance Binary UDPResponse where sendRequest :: UDPTrackerHandle -> ByteString -> IO () sendRequest h req = do n <- sendTo (sock h) req (addr h) - print $ BC.length req -- sanity check with n? return () @@ -150,7 +149,6 @@ connectResponse :: Word32 -> ReaderT UDPTrackerHandle IO Word64 connectResponse tid = do h <- ask resp <- liftIO $ recvResponse h - liftIO $ print resp -- check if nbytes is at least 16 bytes long case resp of (ConnectResp tidr cid) -> @@ -195,7 +193,7 @@ getIPPortPairs = do if empty then return [] else do - ip <- toIP <$> getByteString 6 + ip <- toIP <$> getByteString 4 port <- toPort <$> getByteString 2 ipportpairs <- getIPPortPairs return $ (ip, port) : ipportpairs @@ -226,10 +224,7 @@ trackerLoop url sport peerId infohash fschan tstate = do t1 <- connectRequest cid <- connectResponse t1 liftIO $ print "connected: connect id" - liftIO $ print cid t2 <- announceRequest cid infohash peerId (fromIntegral up) (fromIntegral down) (fromIntegral (left tstate)) (fromIntegral sport) - liftIO $ print "announce request" - liftIO $ print t2 liftIO $ print "waiting for announce response" stats <- announceResponse t2 liftIO $ print stats