X-Git-Url: https://git.rkrishnan.org/?p=functorrent.git;a=blobdiff_plain;f=src%2FFuncTorrent%2FPeerMsgs.hs;fp=src%2FFuncTorrent%2FPeerMsgs.hs;h=467ac8d6f72e94a41bc9233643e731ded0a4e802;hp=d6bbdcfadefac6d3f7672f090a952492d7299fa2;hb=d80bf91010f9f2f8653c55bb902ec83bf1f034a2;hpb=5180138e2fb80cf8b236784e0be981671506001d diff --git a/src/FuncTorrent/PeerMsgs.hs b/src/FuncTorrent/PeerMsgs.hs index d6bbdcf..467ac8d 100644 --- a/src/FuncTorrent/PeerMsgs.hs +++ b/src/FuncTorrent/PeerMsgs.hs @@ -64,7 +64,12 @@ data PeerMsg = KeepAliveMsg | CancelMsg Integer Integer Integer | PortMsg Port | ExtendedMsg Integer ByteString - deriving (Show) + deriving (Show) + +data ExtMetadataMsg = Request Integer + | Data Integer Integer + | Reject Integer + deriving (Eq, Show) instance Binary PeerMsg where put msg = case msg of @@ -101,14 +106,13 @@ instance Binary PeerMsg where PortMsg p -> do putWord32be 3 putWord8 9 putWord16be (fromIntegral p) - ExtendedHandshakeMsg t b-> do putWord32be msgLen - putWord8 20 - putWord8 t -- 0 => handshake msg - -- actual extension msg follows - mapM_ putWord8 blockList - where blockList = unpack b - blockLen = length blockList - + ExtendedMsg t b-> do putWord32be (fromIntegral blockLen) + putWord8 20 + putWord8 (fromIntegral t) -- 0 => handshake msg + -- actual extension msg follows + mapM_ putWord8 blockList + where blockList = unpack b + blockLen = length blockList where putIndexOffsetLength i o l = do putWord32be (fromIntegral i) @@ -152,9 +156,9 @@ genHandshakeMsg :: ByteString -> String -> ByteString genHandshakeMsg infoHash peer_id = concat [pstrlen, pstr, reserved1, reserved2, reserved3, infoHash, peerID] where pstrlen = singleton 19 pstr = BC.pack "BitTorrent protocol" - reserved1 = BC.replicate 4 '\0' + reserved1 = BC.replicate 5 '\0' reserved2 = singleton 0x10 -- support extension protocol - reserved3 = BC.replicate 3 '\0' + reserved3 = BC.replicate 2 '\0' peerID = BC.pack peer_id bsToInt :: ByteString -> Int