+ return handle
+
+instance Binary PeerMsg where
+ put msg = case msg of
+ KeepAliveMsg -> putWord32be 0
+ ChokeMsg -> do putWord32be 1
+ putWord8 0
+ UnChokeMsg -> do putWord32be 1
+ putWord8 1
+ InterestedMsg -> do putWord32be 1
+ putWord8 2
+ NotInterestedMsg -> do putWord32be 1
+ putWord8 3
+ HaveMsg index -> do putWord32be 5
+ putWord8 4
+ putWord32be (fromIntegral index)
+ BitFieldMsg bf -> do putWord32be $ fromIntegral (1 + bfListLen)
+ putWord8 5
+ mapM_ putWord8 bfList
+ where bfList = unpack bf
+ bfListLen = length bfList
+ RequestMsg i o l -> do putWord32be 13
+ putWord8 6
+ putWord32be (fromIntegral i)
+ putWord32be (fromIntegral o)
+ putWord32be (fromIntegral l)
+ PieceMsg i o b -> do putWord32be $ fromIntegral (9 + blocklen)
+ putWord8 7
+ putWord32be (fromIntegral i)
+ putWord32be (fromIntegral o)
+ mapM_ putWord8 blockList
+ where blockList = unpack b
+ blocklen = length blockList
+ CancelMsg i o l -> undefined
+ PortMsg p -> undefined
+ get = undefined