diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/PeerWire/Message.hs | 8 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker.hs | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/PeerWire/Message.hs b/src/Network/BitTorrent/PeerWire/Message.hs index 6515fdf2..3895ed5f 100644 --- a/src/Network/BitTorrent/PeerWire/Message.hs +++ b/src/Network/BitTorrent/PeerWire/Message.hs | |||
@@ -7,6 +7,7 @@ module Network.BitTorrent.PeerWire.Message | |||
7 | 7 | ||
8 | import Control.Applicative | 8 | import Control.Applicative |
9 | import qualified Data.ByteString as B | 9 | import qualified Data.ByteString as B |
10 | import qualified Data.ByteString.Lazy as Lazy | ||
10 | import Data.Serialize | 11 | import Data.Serialize |
11 | import Text.PrettyPrint | 12 | import Text.PrettyPrint |
12 | import Network | 13 | import Network |
@@ -91,7 +92,7 @@ instance Serialize Message where | |||
91 | 0x02 -> return Interested | 92 | 0x02 -> return Interested |
92 | 0x03 -> return NotInterested | 93 | 0x03 -> return NotInterested |
93 | 0x04 -> Have <$> getInt | 94 | 0x04 -> Have <$> getInt |
94 | 0x05 -> Bitfield <$> getBitfield (pred len) | 95 | 0x05 -> (Bitfield . fromBitmap) <$> getByteString (pred len) |
95 | 0x06 -> Request <$> get | 96 | 0x06 -> Request <$> get |
96 | 0x07 -> Piece <$> getBlock (len - 9) | 97 | 0x07 -> Piece <$> getBlock (len - 9) |
97 | 0x08 -> Cancel <$> get | 98 | 0x08 -> Cancel <$> get |
@@ -118,8 +119,9 @@ instance Serialize Message where | |||
118 | put Interested = putInt 1 >> putWord8 0x02 | 119 | put Interested = putInt 1 >> putWord8 0x02 |
119 | put NotInterested = putInt 1 >> putWord8 0x03 | 120 | put NotInterested = putInt 1 >> putWord8 0x03 |
120 | put (Have i) = putInt 5 >> putWord8 0x04 >> putInt i | 121 | put (Have i) = putInt 5 >> putWord8 0x04 >> putInt i |
121 | put (Bitfield b) = putInt l >> putWord8 0x05 >> putBitfield b | 122 | put (Bitfield bf) = putInt l >> putWord8 0x05 >> putLazyByteString b |
122 | where l = succ (bitfieldByteCount b) | 123 | where b = toBitmap bf |
124 | l = succ (fromIntegral (Lazy.length b)) | ||
123 | {-# INLINE l #-} | 125 | {-# INLINE l #-} |
124 | put (Request blk) = putInt 13 >> putWord8 0x06 >> put blk | 126 | put (Request blk) = putInt 13 >> putWord8 0x06 >> put blk |
125 | put (Piece blk) = putInt l >> putWord8 0x07 >> putBlock | 127 | put (Piece blk) = putInt l >> putWord8 0x07 >> putBlock |
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs index 2e599002..aaa08f3c 100644 --- a/src/Network/BitTorrent/Tracker.hs +++ b/src/Network/BitTorrent/Tracker.hs | |||
@@ -145,7 +145,7 @@ data TSession = TSession { | |||
145 | newSession :: Progress -> Int -> [PeerAddr] -> IO TSession | 145 | newSession :: Progress -> Int -> [PeerAddr] -> IO TSession |
146 | newSession pr i ps = TSession <$> newTVarIO pr | 146 | newSession pr i ps = TSession <$> newTVarIO pr |
147 | <*> newIORef i | 147 | <*> newIORef i |
148 | <*> newTVarIO psx | 148 | <*> newTVarIO ps |
149 | 149 | ||
150 | getPeerList :: TSession -> IO [PeerAddr] | 150 | getPeerList :: TSession -> IO [PeerAddr] |
151 | getPeerList = readTVarIO . sePeers | 151 | getPeerList = readTVarIO . sePeers |