+infoHash :: (M.Map Benc.BVal Benc.BVal) -> BC.ByteString
+infoHash m = let info = m M.! (Benc.Bstr (BC.pack "info"))
+ in SHA1.hash $ BC.pack $ Benc.encode info
+
+peerHash :: String -> BC.ByteString
+peerHash peer_id = SHA1.hash (BC.pack peer_id)
+
+prepareRequest :: Benc.BVal -> String -> String
+prepareRequest (Benc.Bdict d) peer_id = let p = [("info_hash", urlEncode (infoHash d)),
+ ("peer_id", urlEncode (peerHash peer_id)),
+ ("port", "6881"),
+ ("uploaded", "0"),
+ ("downloaded", "0"),
+ ("left", "0"),
+ ("compact", "1"),
+ ("event", "started")]
+ in
+ List.intercalate "&" [f ++ "=" ++ s | (f,s) <- p]
+