encode (Blist xs) = "l" ++ encodeList xs ++ "e"
where encodeList = foldr ((++) . encode) ""
encode (Bdict d) = "d" ++ encodeDict d ++ "e"
- where encodeDict m = concat [encode k ++ encode ((!) m k) | k <- keys m]
+ where encodeDict m = concat [encode k ++ encode (m ! k) | k <- keys m]
} deriving (Eq, Show)
mkInfo :: BVal -> Maybe Info
-mkInfo (Bdict m) = let (Bint pieceLength') = m M.! Bstr (pack "piece length")
- (Bstr pieces') = m M.! Bstr (pack "pieces")
+mkInfo (Bdict m) = let (Bint pieceLength') = m ! Bstr (pack "piece length")
+ (Bstr pieces') = m ! Bstr (pack "pieces")
private' = Nothing
- (Bstr name') = m M.! Bstr (pack "name")
- (Bint length') = m M.! Bstr (pack "length")
+ (Bstr name') = m ! Bstr (pack "name")
+ (Bint length') = m ! Bstr (pack "length")
md5sum' = Nothing
in Just Info { pieceLength = pieceLength'
, pieces = pieces'
in Just (unpack bs)
mkMetaInfo :: BVal -> Maybe Metainfo
-mkMetaInfo (Bdict m) = let (Just info') = mkInfo (m M.! Bstr (pack "info"))
- (Bstr announce') = m M.! Bstr (pack "announce")
+mkMetaInfo (Bdict m) = let (Just info') = mkInfo (m ! Bstr (pack "info"))
+ (Bstr announce') = m ! Bstr (pack "announce")
-- announceList = lookup (Bstr (pack "announce list"))
announceList' = Nothing
-- creationDate = lookup (Bstr (pack "creation date")) m
getPeerResponse body = case decode body of
Right (Bdict peerM) ->
let (Just (Bint i)) = lookup (Bstr (pack "lookup")) peerM
- (Bstr peersBS) = peerM M.! Bstr (pack "peers")
+ (Bstr peersBS) = peerM ! Bstr (pack "peers")
pl = map (\peer -> let (ip', port') = splitAt 4 peer
in Peer (toIPNum ip') (toPortNum port'))
(splitN 6 peersBS)
nonSpecialChars = ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "-_.~"
infoHash :: Map BVal BVal -> ByteString
-infoHash m = let info = m M.! Bstr (pack "info")
+infoHash m = let info = m ! Bstr (pack "info")
in (hash . pack . encode) info
prepareRequest :: InfoDict -> String -> Integer -> String