summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:33:06 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:33:06 +0400
commit0cd2099b36aa0382ec7363537ac9e2a8ca5831a9 (patch)
tree20a197cfd85951fa30f10c0974b74ed07b1f9227 /src/Network/BitTorrent
parentcee8903392b263b938b7b4baaea6ef220ff03f21 (diff)
Minor changes
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index d798a8c6..dfb0355b 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -86,6 +86,25 @@ deleteAll :: Session -> IO ()
86deleteAll = undefined 86deleteAll = undefined
87 87
88{----------------------------------------------------------------------- 88{-----------------------------------------------------------------------
89-- Query
90-----------------------------------------------------------------------}
91
92getThisBitfield :: Wire Session Bitfield
93getThisBitfield = undefined
94
95{-
96data PendingSet = PendingSet (Map (PeerAddr IP) [BlockIx])
97
98empty :: PendingSet
99empty = undefined
100
101member :: PeerAddr IP -> BlockIx -> PendingSet -> Bool
102member addr bix = undefined
103
104insert :: PeerAddr IP -> BlockIx -> PendingSet -> PendingSet
105insert addr bix = undefined
106-}
107{-----------------------------------------------------------------------
89-- Event loop 108-- Event loop
90-----------------------------------------------------------------------} 109-----------------------------------------------------------------------}
91{- 110{-
@@ -104,10 +123,20 @@ readBlock bix @ BlockIx {..} s = do
104 then return chunk 123 then return chunk
105 else throwIO $ InvalidRequest bix (InvalidSize ixLength) 124 else throwIO $ InvalidRequest bix (InvalidSize ixLength)
106-} 125-}
126
107handleMessage :: Message -> Wire Session () 127handleMessage :: Message -> Wire Session ()
108handleMessage KeepAlive = return () 128handleMessage KeepAlive = return ()
109handleMessage (Status s) = undefined 129handleMessage (Status s) = undefined
110handleMessage (Available a) = undefined 130handleMessage (Available msg) = do
131 thisBf <- getThisBitfield
132 case msg of
133 Have ix
134 | ix `BF.member` thisBf -> return ()
135 | otherwise -> undefined
136 Bitfield bf
137 | bf `BF.isSubsetOf` thisBf -> return ()
138 | otherwise -> undefined
139
111handleMessage (Transfer msg) = case msg of 140handleMessage (Transfer msg) = case msg of
112 Request bix -> do 141 Request bix -> do
113-- Session {..} <- getSession 142-- Session {..} <- getSession
@@ -116,11 +145,28 @@ handleMessage (Transfer msg) = case msg of
116-- blk <- liftIO $ readBlock bix storage 145-- blk <- liftIO $ readBlock bix storage
117-- sendMsg (Piece blk) 146-- sendMsg (Piece blk)
118 return () 147 return ()
119 Piece blk -> return () 148
120 Cancel bix -> return () 149 Piece blk -> do
150{-
151 Session {..} <- getSession
152 when (blockIx blk `PS.member` pendingSet) $ do
153 insert blk stalledSet
154 sendBroadcast have
155 maybe send not interested
156-}
157 return ()
158
159 Cancel bix -> filterQueue (not . (transferResponse bix))
160 where
161 transferResponse bix (Transfer (Piece blk)) = blockIx blk == bix
162 transferResponse _ _ = False
163
121handleMessage (Port n) = undefined 164handleMessage (Port n) = undefined
122handleMessage (Fast _) = return () 165handleMessage (Fast _) = undefined
123handleMessage (Extended _) = return () 166handleMessage (Extended _) = undefined
167
168filterQueue :: (Message -> Bool) -> Wire s ()
169filterQueue = undefined
124 170
125exchange :: Wire Session () 171exchange :: Wire Session ()
126exchange = do 172exchange = do