X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2FFuncTorrent%2FTracker%2FUdp.hs;fp=src%2FFuncTorrent%2FTracker%2FUdp.hs;h=7db020281403304f6e7cc92ea7dcefc673f1c481;hb=5d445371de19f2018b7f93ac8e87ac07b8848003;hp=2437003ec47692f5667e47dba970613823849a8b;hpb=46dc8fae54b98a586eb393c639716bbf3065255d;p=functorrent.git 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