diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Tracker/UDP.hs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/Tracker/UDP.hs b/src/Network/BitTorrent/Tracker/UDP.hs index 8d43d7b8..645be359 100644 --- a/src/Network/BitTorrent/Tracker/UDP.hs +++ b/src/Network/BitTorrent/Tracker/UDP.hs | |||
@@ -107,7 +107,8 @@ data instance Transaction Response = TransactionR | |||
107 | } deriving Show | 107 | } deriving Show |
108 | 108 | ||
109 | -- TODO newtype | 109 | -- TODO newtype |
110 | type MessageId = Word32 | 110 | newtype MessageId = MessageId Word32 |
111 | deriving (Show, Eq, Num, Serialize) | ||
111 | 112 | ||
112 | connectId, announceId, scrapeId, errorId :: MessageId | 113 | connectId, announceId, scrapeId, errorId :: MessageId |
113 | connectId = 0 | 114 | connectId = 0 |
@@ -137,7 +138,7 @@ instance Serialize (Transaction Request) where | |||
137 | 138 | ||
138 | get = do | 139 | get = do |
139 | cid <- get | 140 | cid <- get |
140 | mid <- getWord32be | 141 | mid <- get |
141 | TransactionQ cid <$> get <*> getBody mid | 142 | TransactionQ cid <$> get <*> getBody mid |
142 | where | 143 | where |
143 | getBody :: MessageId -> Get Request | 144 | getBody :: MessageId -> Get Request |
@@ -147,7 +148,7 @@ instance Serialize (Transaction Request) where | |||
147 | | msgId == scrapeId = Scrape <$> many get | 148 | | msgId == scrapeId = Scrape <$> many get |
148 | | otherwise = fail errMsg | 149 | | otherwise = fail errMsg |
149 | where | 150 | where |
150 | errMsg = "unknown request message id: " ++ show msgId | 151 | errMsg = "unknown request: " ++ show msgId |
151 | 152 | ||
152 | instance Serialize (Transaction Response) where | 153 | instance Serialize (Transaction Response) where |
153 | put TransactionR {..} = do | 154 | put TransactionR {..} = do |
@@ -174,7 +175,7 @@ instance Serialize (Transaction Response) where | |||
174 | 175 | ||
175 | 176 | ||
176 | get = do | 177 | get = do |
177 | mid <- getWord32be | 178 | mid <- get |
178 | TransactionR <$> get <*> getBody mid | 179 | TransactionR <$> get <*> getBody mid |
179 | where | 180 | where |
180 | getBody :: MessageId -> Get Response | 181 | getBody :: MessageId -> Get Response |
@@ -185,7 +186,7 @@ instance Serialize (Transaction Response) where | |||
185 | | msgId == errorId = (Failed . decodeUtf8) <$> get | 186 | | msgId == errorId = (Failed . decodeUtf8) <$> get |
186 | | otherwise = fail msg | 187 | | otherwise = fail msg |
187 | where | 188 | where |
188 | msg = "unknown message response id: " ++ show msgId | 189 | msg = "unknown response: " ++ show msgId |
189 | 190 | ||
190 | {----------------------------------------------------------------------- | 191 | {----------------------------------------------------------------------- |
191 | Connection | 192 | Connection |