diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:40:05 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:40:05 +0400 |
commit | bc1c976e9175b4ac13430ba9c23ea8b099401e9e (patch) | |
tree | 67a0d7064d1c0f843e8efbdaa1e2b32e35f1955b /src/Network | |
parent | 412919e88e1d60303f7a14134e37f27becf5f959 (diff) |
~ Fix some long standing warnings.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/DHT/Protocol.hs | 9 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Protocol.hs | 20 | ||||
-rw-r--r-- | src/Network/BitTorrent/Sessions.hs | 9 |
3 files changed, 13 insertions, 25 deletions
diff --git a/src/Network/BitTorrent/DHT/Protocol.hs b/src/Network/BitTorrent/DHT/Protocol.hs index 5267a916..5cc1722d 100644 --- a/src/Network/BitTorrent/DHT/Protocol.hs +++ b/src/Network/BitTorrent/DHT/Protocol.hs | |||
@@ -36,6 +36,7 @@ import Remote.KRPC.Protocol | |||
36 | import Data.BEncode | 36 | import Data.BEncode |
37 | import Data.Torrent | 37 | import Data.Torrent |
38 | import Network.BitTorrent.Peer | 38 | import Network.BitTorrent.Peer |
39 | import Network.BitTorrent.Exchange.Protocol () | ||
39 | 40 | ||
40 | {----------------------------------------------------------------------- | 41 | {----------------------------------------------------------------------- |
41 | Node | 42 | Node |
@@ -50,11 +51,6 @@ type NodeId = ByteString | |||
50 | genNodeId :: IO NodeId | 51 | genNodeId :: IO NodeId |
51 | genNodeId = getEntropy 20 | 52 | genNodeId = getEntropy 20 |
52 | 53 | ||
53 | instance Serialize PortNumber where | ||
54 | get = fromIntegral <$> getWord16be | ||
55 | put = putWord16be . fromIntegral | ||
56 | |||
57 | |||
58 | data NodeAddr = NodeAddr { | 54 | data NodeAddr = NodeAddr { |
59 | nodeIP :: {-# UNPACK #-} !HostAddress | 55 | nodeIP :: {-# UNPACK #-} !HostAddress |
60 | , nodePort :: {-# UNPACK #-} !PortNumber | 56 | , nodePort :: {-# UNPACK #-} !PortNumber |
@@ -66,7 +62,6 @@ instance Serialize NodeAddr where | |||
66 | putWord32be nodeIP | 62 | putWord32be nodeIP |
67 | put nodePort | 63 | put nodePort |
68 | 64 | ||
69 | |||
70 | data NodeInfo = NodeInfo { | 65 | data NodeInfo = NodeInfo { |
71 | nodeID :: !NodeId | 66 | nodeID :: !NodeId |
72 | , nodeAddr :: !NodeAddr | 67 | , nodeAddr :: !NodeAddr |
@@ -175,7 +170,7 @@ assignToken _ _ = return "" | |||
175 | 170 | ||
176 | -- TODO | 171 | -- TODO |
177 | checkToken :: NodeId -> Token -> NodeSession -> IO Bool | 172 | checkToken :: NodeId -> Token -> NodeSession -> IO Bool |
178 | checkToken nid token _ = return True | 173 | checkToken _ _ _ = return True |
179 | 174 | ||
180 | updateTimestamp :: NodeSession -> NodeId -> IO () | 175 | updateTimestamp :: NodeSession -> NodeId -> IO () |
181 | updateTimestamp = error "updateTimestamp" | 176 | updateTimestamp = error "updateTimestamp" |
diff --git a/src/Network/BitTorrent/Exchange/Protocol.hs b/src/Network/BitTorrent/Exchange/Protocol.hs index c4128032..6dce2b4a 100644 --- a/src/Network/BitTorrent/Exchange/Protocol.hs +++ b/src/Network/BitTorrent/Exchange/Protocol.hs | |||
@@ -28,6 +28,7 @@ | |||
28 | {-# LANGUAGE OverloadedStrings #-} | 28 | {-# LANGUAGE OverloadedStrings #-} |
29 | {-# LANGUAGE RecordWildCards #-} | 29 | {-# LANGUAGE RecordWildCards #-} |
30 | {-# LANGUAGE TemplateHaskell #-} | 30 | {-# LANGUAGE TemplateHaskell #-} |
31 | {-# OPTIONS -fno-warn-orphans #-} | ||
31 | module Network.BitTorrent.Exchange.Protocol | 32 | module Network.BitTorrent.Exchange.Protocol |
32 | ( -- * Initial handshake | 33 | ( -- * Initial handshake |
33 | Handshake(..), ppHandshake | 34 | Handshake(..), ppHandshake |
@@ -76,7 +77,6 @@ import qualified Data.ByteString.Char8 as BC | |||
76 | import qualified Data.ByteString.Lazy as Lazy | 77 | import qualified Data.ByteString.Lazy as Lazy |
77 | import Data.Char | 78 | import Data.Char |
78 | import Data.Default | 79 | import Data.Default |
79 | import Data.Int | ||
80 | import Data.List as L | 80 | import Data.List as L |
81 | import Data.Word | 81 | import Data.Word |
82 | 82 | ||
@@ -309,7 +309,6 @@ blockRange pieceSize blk = (offset, offset + len) | |||
309 | + fromIntegral (blkOffset blk) | 309 | + fromIntegral (blkOffset blk) |
310 | len = fromIntegral (Lazy.length (blkData blk)) | 310 | len = fromIntegral (Lazy.length (blkData blk)) |
311 | {-# INLINE blockRange #-} | 311 | {-# INLINE blockRange #-} |
312 | {-# SPECIALIZE blockRange :: Int -> Block -> (Int64, Int64) #-} | ||
313 | 312 | ||
314 | ixRange :: (Num a, Integral a) => Int -> BlockIx -> (a, a) | 313 | ixRange :: (Num a, Integral a) => Int -> BlockIx -> (a, a) |
315 | ixRange pieceSize i = (offset, offset + len) | 314 | ixRange pieceSize i = (offset, offset + len) |
@@ -318,8 +317,6 @@ ixRange pieceSize i = (offset, offset + len) | |||
318 | + fromIntegral (ixOffset i) | 317 | + fromIntegral (ixOffset i) |
319 | len = fromIntegral (ixLength i) | 318 | len = fromIntegral (ixLength i) |
320 | {-# INLINE ixRange #-} | 319 | {-# INLINE ixRange #-} |
321 | {-# SPECIALIZE ixRange :: Int -> BlockIx -> (Int64, Int64) #-} | ||
322 | |||
323 | 320 | ||
324 | {----------------------------------------------------------------------- | 321 | {----------------------------------------------------------------------- |
325 | Regular messages | 322 | Regular messages |
@@ -386,6 +383,11 @@ data Message = KeepAlive | |||
386 | | AllowedFast !PieceIx | 383 | | AllowedFast !PieceIx |
387 | deriving (Show, Eq) | 384 | deriving (Show, Eq) |
388 | 385 | ||
386 | instance Serialize PortNumber where | ||
387 | get = fromIntegral <$> S.getWord16be | ||
388 | {-# INLINE get #-} | ||
389 | put = S.putWord16be . fromIntegral | ||
390 | {-# INLINE put #-} | ||
389 | 391 | ||
390 | instance Serialize Message where | 392 | instance Serialize Message where |
391 | get = do | 393 | get = do |
@@ -404,7 +406,7 @@ instance Serialize Message where | |||
404 | 0x06 -> Request <$> S.get | 406 | 0x06 -> Request <$> S.get |
405 | 0x07 -> Piece <$> getBlock (len - 9) | 407 | 0x07 -> Piece <$> getBlock (len - 9) |
406 | 0x08 -> Cancel <$> S.get | 408 | 0x08 -> Cancel <$> S.get |
407 | 0x09 -> (Port . fromIntegral) <$> S.getWord16be | 409 | 0x09 -> Port <$> S.get |
408 | 0x0E -> return HaveAll | 410 | 0x0E -> return HaveAll |
409 | 0x0F -> return HaveNone | 411 | 0x0F -> return HaveNone |
410 | 0x0D -> SuggestPiece <$> getInt | 412 | 0x0D -> SuggestPiece <$> getInt |
@@ -441,7 +443,7 @@ instance Serialize Message where | |||
441 | {-# INLINE putBlock #-} | 443 | {-# INLINE putBlock #-} |
442 | 444 | ||
443 | put (Cancel blk) = putInt 13 >> S.putWord8 0x08 >> S.put blk | 445 | put (Cancel blk) = putInt 13 >> S.putWord8 0x08 >> S.put blk |
444 | put (Port p ) = putInt 3 >> S.putWord8 0x09 >> S.putWord16be (fromIntegral p) | 446 | put (Port p ) = putInt 3 >> S.putWord8 0x09 >> S.put p |
445 | put HaveAll = putInt 1 >> S.putWord8 0x0E | 447 | put HaveAll = putInt 1 >> S.putWord8 0x0E |
446 | put HaveNone = putInt 1 >> S.putWord8 0x0F | 448 | put HaveNone = putInt 1 >> S.putWord8 0x0F |
447 | put (SuggestPiece pix) = putInt 5 >> S.putWord8 0x0D >> putInt pix | 449 | put (SuggestPiece pix) = putInt 5 >> S.putWord8 0x0D >> putInt pix |
@@ -471,11 +473,7 @@ instance Binary Message where | |||
471 | 0x0D -> SuggestPiece <$> getIntB | 473 | 0x0D -> SuggestPiece <$> getIntB |
472 | 0x10 -> RejectRequest <$> B.get | 474 | 0x10 -> RejectRequest <$> B.get |
473 | 0x11 -> AllowedFast <$> getIntB | 475 | 0x11 -> AllowedFast <$> getIntB |
474 | _ -> do | 476 | _ -> fail $ "unknown message ID: " ++ show mid |
475 | rm <- B.remaining >>= B.getBytes . fromIntegral | ||
476 | fail $ "unknown message ID: " ++ show mid ++ "\n" | ||
477 | ++ "remaining available bytes: " ++ show rm | ||
478 | |||
479 | where | 477 | where |
480 | getBlock :: Int -> B.Get Block | 478 | getBlock :: Int -> B.Get Block |
481 | getBlock len = Block <$> getIntB <*> getIntB | 479 | getBlock len = Block <$> getIntB <*> getIntB |
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs index 2118ccf0..5047f06c 100644 --- a/src/Network/BitTorrent/Sessions.hs +++ b/src/Network/BitTorrent/Sessions.hs | |||
@@ -51,7 +51,7 @@ import Control.Applicative | |||
51 | import Control.Concurrent | 51 | import Control.Concurrent |
52 | import Control.Concurrent.STM | 52 | import Control.Concurrent.STM |
53 | import Control.Concurrent.MSem as MSem | 53 | import Control.Concurrent.MSem as MSem |
54 | import Control.Monad (when, forever, (>=>)) | 54 | import Control.Monad (forever, (>=>)) |
55 | import Control.Exception | 55 | import Control.Exception |
56 | import Control.Monad.Trans | 56 | import Control.Monad.Trans |
57 | 57 | ||
@@ -61,12 +61,9 @@ import Data.HashMap.Strict as HM | |||
61 | import Data.Foldable as F | 61 | import Data.Foldable as F |
62 | import Data.Set as S | 62 | import Data.Set as S |
63 | 63 | ||
64 | import Data.Serialize hiding (get) | ||
65 | |||
66 | import Network hiding (accept) | 64 | import Network hiding (accept) |
67 | import Network.BSD | 65 | import Network.BSD |
68 | import Network.Socket | 66 | import Network.Socket |
69 | import Network.Socket.ByteString | ||
70 | 67 | ||
71 | import Data.Bitfield as BF | 68 | import Data.Bitfield as BF |
72 | import Data.Torrent | 69 | import Data.Torrent |
@@ -120,9 +117,7 @@ torrentPresence ClientSession {..} ih = do | |||
120 | 117 | ||
121 | startListener :: ClientSession -> PortNumber -> IO () | 118 | startListener :: ClientSession -> PortNumber -> IO () |
122 | startListener cs @ ClientSession {..} port = | 119 | startListener cs @ ClientSession {..} port = |
123 | startService peerListener port $ listener cs $ \conn @ (sock, PeerSession{..}) -> do | 120 | startService peerListener port $ listener cs $ \conn @ (_, PeerSession{..}) -> do |
124 | print "accepted" | ||
125 | let storage = error "storage" | ||
126 | runP2P conn p2p | 121 | runP2P conn p2p |
127 | 122 | ||
128 | -- | Create a new client session. The data passed to this function are | 123 | -- | Create a new client session. The data passed to this function are |