From: Ramakrishnan Muthukrishnan Date: Wed, 15 Jun 2016 05:26:07 +0000 (+0530) Subject: Tracker/Udp: send ip with annouce request X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/biz/readonly?a=commitdiff_plain;h=5d445371de19f2018b7f93ac8e87ac07b8848003;p=functorrent.git Tracker/Udp: send ip with annouce request --- diff --git a/src/FuncTorrent/Tracker/Udp.hs b/src/FuncTorrent/Tracker/Udp.hs index 2437003..7db0202 100644 --- a/src/FuncTorrent/Tracker/Udp.hs +++ b/src/FuncTorrent/Tracker/Udp.hs @@ -95,7 +95,7 @@ instance Binary UDPRequest where putWord64be (fromIntegral up) putWord32be $ fromIntegral (eventToInteger None) putWord32be 0 - -- key is optional, we will not send it for now + putWord32be 0 putWord32be $ fromIntegral (-1) putWord16be $ fromIntegral port put (ScrapeReq _ _ _) = undefined @@ -129,6 +129,7 @@ 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 () @@ -206,8 +207,8 @@ startSession host port = do addrinfos <- getAddrInfo Nothing (Just host) (Just (show port)) let (SockAddrInet p ip) = addrAddress $ head addrinfos putStrLn "connected to tracker" - return $ UDPTrackerHandle { sock = s - , addr = (SockAddrInet (fromIntegral port) ip) } + return UDPTrackerHandle { sock = s + , addr = (SockAddrInet (fromIntegral port) ip) } closeSession :: UDPTrackerHandle -> IO () closeSession (UDPTrackerHandle s _ _) = close s @@ -225,7 +226,10 @@ trackerLoop url sport peerId infohash fschan tstate = do flip runReaderT handle $ do t1 <- connectRequest cid <- connectResponse t1 + liftIO $ print "connect response" liftIO $ print cid t2 <- announceRequest cid infohash peerId (fromIntegral up) (fromIntegral down) (fromIntegral (left tstate)) (fromIntegral sport) + liftIO $ print "announce request" + liftIO $ print t2 stats <- announceResponse t2 liftIO $ print stats