]> git.rkrishnan.org Git - functorrent.git/blob - src/FuncTorrent/Peer.hs
Move things around
[functorrent.git] / src / FuncTorrent / Peer.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module FuncTorrent.Peer
3     (Peer(..),
4      handShakeMsg
5     ) where
6
7 import Prelude hiding (lookup, concat, replicate, splitAt)
8
9 import Data.ByteString.Char8 (ByteString, pack, concat, replicate)
10 import Data.ByteString.Lazy (toChunks)
11 import Data.Int (Int8)
12 import qualified Data.Binary as Bin (encode)
13
14 import FuncTorrent.Bencode (InfoDict)
15 import FuncTorrent.Metainfo (infoHash)
16
17 -- | Peer is a IP address, port tuple
18 data Peer = Peer String Integer
19             deriving (Show, Eq)
20
21 handShakeMsg :: InfoDict -> String -> ByteString
22 handShakeMsg m peer_id = concat [pstrlen, pstr, reserved, infoH, peerID]
23     where pstrlen = concat $ toChunks $ Bin.encode (19 :: Int8)
24           pstr = pack "BitTorrent protocol"
25           reserved = replicate 8 '\0'
26           infoH = infoHash m
27           peerID = pack peer_id