data UDPResponse = ConnectResp Integer Integer -- transaction_id connection_id
| AnnounceResp Integer Integer Integer Integer [(IP, Port)] -- transaction_id interval leechers seeders [(ip, port)]
| ScrapeResp Integer Integer Integer Integer
+ | ErrorResp Integer String
deriving (Show, Eq)
actionToInteger :: Action -> Integer
_ <- getWord32be
_ <- getWord32be
return $ ScrapeResp tid 0 0 0
+ 3 -> do -- error response
+ tid <- fromIntegral <$> getWord32be
+ bs <- getByteString 4
+ return $ ErrorResp tid $ unpack bs
_ -> error ("unknown response action type: " ++ show a)
getIPPortPairs :: Get [(IP, Port)]