From fdb47f1503a234491a59997dc052dda3cec79c73 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Sun, 28 Feb 2016 17:32:05 +0530
Subject: [PATCH] Tracker: add UDP tracker error response parsing

---
 src/FuncTorrent/Tracker.hs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/FuncTorrent/Tracker.hs b/src/FuncTorrent/Tracker.hs
index 224a30e..dd66c12 100644
--- a/src/FuncTorrent/Tracker.hs
+++ b/src/FuncTorrent/Tracker.hs
@@ -78,6 +78,7 @@ data UDPRequest = ConnectReq Integer
 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
@@ -137,6 +138,10 @@ instance Binary UDPResponse where
         _ <- 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)]
-- 
2.45.2