summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-16 20:40:05 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-16 20:40:05 +0400
commitbc1c976e9175b4ac13430ba9c23ea8b099401e9e (patch)
tree67a0d7064d1c0f843e8efbdaa1e2b32e35f1955b /src/Network
parent412919e88e1d60303f7a14134e37f27becf5f959 (diff)
~ Fix some long standing warnings.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/DHT/Protocol.hs9
-rw-r--r--src/Network/BitTorrent/Exchange/Protocol.hs20
-rw-r--r--src/Network/BitTorrent/Sessions.hs9
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
36import Data.BEncode 36import Data.BEncode
37import Data.Torrent 37import Data.Torrent
38import Network.BitTorrent.Peer 38import Network.BitTorrent.Peer
39import Network.BitTorrent.Exchange.Protocol ()
39 40
40{----------------------------------------------------------------------- 41{-----------------------------------------------------------------------
41 Node 42 Node
@@ -50,11 +51,6 @@ type NodeId = ByteString
50genNodeId :: IO NodeId 51genNodeId :: IO NodeId
51genNodeId = getEntropy 20 52genNodeId = getEntropy 20
52 53
53instance Serialize PortNumber where
54 get = fromIntegral <$> getWord16be
55 put = putWord16be . fromIntegral
56
57
58data NodeAddr = NodeAddr { 54data 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
70data NodeInfo = NodeInfo { 65data 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
177checkToken :: NodeId -> Token -> NodeSession -> IO Bool 172checkToken :: NodeId -> Token -> NodeSession -> IO Bool
178checkToken nid token _ = return True 173checkToken _ _ _ = return True
179 174
180updateTimestamp :: NodeSession -> NodeId -> IO () 175updateTimestamp :: NodeSession -> NodeId -> IO ()
181updateTimestamp = error "updateTimestamp" 176updateTimestamp = 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 #-}
31module Network.BitTorrent.Exchange.Protocol 32module 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
76import qualified Data.ByteString.Lazy as Lazy 77import qualified Data.ByteString.Lazy as Lazy
77import Data.Char 78import Data.Char
78import Data.Default 79import Data.Default
79import Data.Int
80import Data.List as L 80import Data.List as L
81import Data.Word 81import 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
314ixRange :: (Num a, Integral a) => Int -> BlockIx -> (a, a) 313ixRange :: (Num a, Integral a) => Int -> BlockIx -> (a, a)
315ixRange pieceSize i = (offset, offset + len) 314ixRange 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
386instance Serialize PortNumber where
387 get = fromIntegral <$> S.getWord16be
388 {-# INLINE get #-}
389 put = S.putWord16be . fromIntegral
390 {-# INLINE put #-}
389 391
390instance Serialize Message where 392instance 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
51import Control.Concurrent 51import Control.Concurrent
52import Control.Concurrent.STM 52import Control.Concurrent.STM
53import Control.Concurrent.MSem as MSem 53import Control.Concurrent.MSem as MSem
54import Control.Monad (when, forever, (>=>)) 54import Control.Monad (forever, (>=>))
55import Control.Exception 55import Control.Exception
56import Control.Monad.Trans 56import Control.Monad.Trans
57 57
@@ -61,12 +61,9 @@ import Data.HashMap.Strict as HM
61import Data.Foldable as F 61import Data.Foldable as F
62import Data.Set as S 62import Data.Set as S
63 63
64import Data.Serialize hiding (get)
65
66import Network hiding (accept) 64import Network hiding (accept)
67import Network.BSD 65import Network.BSD
68import Network.Socket 66import Network.Socket
69import Network.Socket.ByteString
70 67
71import Data.Bitfield as BF 68import Data.Bitfield as BF
72import Data.Torrent 69import Data.Torrent
@@ -120,9 +117,7 @@ torrentPresence ClientSession {..} ih = do
120 117
121startListener :: ClientSession -> PortNumber -> IO () 118startListener :: ClientSession -> PortNumber -> IO ()
122startListener cs @ ClientSession {..} port = 119startListener 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