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
sendRequest :: UDPTrackerHandle -> ByteString -> IO ()
sendRequest h req = do
n <- sendTo (sock h) req (addr h)
+ print $ BC.length req
-- sanity check with n?
return ()
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
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