From: Ramakrishnan Muthukrishnan Date: Sat, 21 Feb 2015 03:55:15 +0000 (+0530) Subject: more refactoring: type synonym for info dictionary X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/flags/%22doc.html//%22?a=commitdiff_plain;h=281159d486afec2a54383db397a94410f14a39e6;p=functorrent.git more refactoring: type synonym for info dictionary --- diff --git a/src/Bencode.hs b/src/Bencode.hs index 1fe6aea..717170e 100644 --- a/src/Bencode.hs +++ b/src/Bencode.hs @@ -12,9 +12,11 @@ data BVal = Bint Integer | Bstr BC.ByteString | Blist [BVal] - | Bdict (M.Map BVal BVal) + | Bdict InfoDict deriving (Ord, Eq) +type InfoDict = M.Map BVal BVal + instance Show BVal where show (Bint i) = show i show (Bstr s) = "\"" ++ BC.unpack s ++ "\"" diff --git a/src/Peer.hs b/src/Peer.hs index 0f33961..f647c61 100644 --- a/src/Peer.hs +++ b/src/Peer.hs @@ -53,7 +53,7 @@ getPeerResponse body = case Benc.decode body of } -handShakeMsg :: M.Map Benc.BVal Benc.BVal -> String -> BC.ByteString +handShakeMsg :: Benc.InfoDict -> String -> BC.ByteString handShakeMsg m peer_id = let pstrlen = BC.concat $ BL.toChunks $ Bin.encode (19 :: DI.Int8) pstr = BC.pack "BitTorrent protocol" reserved = BC.replicate 8 '\0' diff --git a/src/Tracker.hs b/src/Tracker.hs index 5afc26f..dad05e6 100644 --- a/src/Tracker.hs +++ b/src/Tracker.hs @@ -12,7 +12,6 @@ import qualified Utils as U import Data.Char type Url = String -type InfoDict = M.Map Benc.BVal Benc.BVal -- | urlEncodeHash -- @@ -35,7 +34,7 @@ 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 -prepareRequest :: InfoDict -> String -> Integer -> String +prepareRequest :: Benc.InfoDict -> String -> Integer -> String prepareRequest d peer_id len = let p = [("info_hash", urlEncodeHash ((B16.encode . infoHash) d)), ("peer_id", HB.urlEncode peer_id),