diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-12 21:33:06 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-12 21:33:06 +0400 |
commit | 0cd2099b36aa0382ec7363537ac9e2a8ca5831a9 (patch) | |
tree | 20a197cfd85951fa30f10c0974b74ed07b1f9227 /src/Network/BitTorrent | |
parent | cee8903392b263b938b7b4baaea6ef220ff03f21 (diff) |
Minor changes
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 56 |
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 () | |||
86 | deleteAll = undefined | 86 | deleteAll = undefined |
87 | 87 | ||
88 | {----------------------------------------------------------------------- | 88 | {----------------------------------------------------------------------- |
89 | -- Query | ||
90 | -----------------------------------------------------------------------} | ||
91 | |||
92 | getThisBitfield :: Wire Session Bitfield | ||
93 | getThisBitfield = undefined | ||
94 | |||
95 | {- | ||
96 | data PendingSet = PendingSet (Map (PeerAddr IP) [BlockIx]) | ||
97 | |||
98 | empty :: PendingSet | ||
99 | empty = undefined | ||
100 | |||
101 | member :: PeerAddr IP -> BlockIx -> PendingSet -> Bool | ||
102 | member addr bix = undefined | ||
103 | |||
104 | insert :: PeerAddr IP -> BlockIx -> PendingSet -> PendingSet | ||
105 | insert 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 | |||
107 | handleMessage :: Message -> Wire Session () | 127 | handleMessage :: Message -> Wire Session () |
108 | handleMessage KeepAlive = return () | 128 | handleMessage KeepAlive = return () |
109 | handleMessage (Status s) = undefined | 129 | handleMessage (Status s) = undefined |
110 | handleMessage (Available a) = undefined | 130 | handleMessage (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 | |||
111 | handleMessage (Transfer msg) = case msg of | 140 | handleMessage (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 | |||
121 | handleMessage (Port n) = undefined | 164 | handleMessage (Port n) = undefined |
122 | handleMessage (Fast _) = return () | 165 | handleMessage (Fast _) = undefined |
123 | handleMessage (Extended _) = return () | 166 | handleMessage (Extended _) = undefined |
167 | |||
168 | filterQueue :: (Message -> Bool) -> Wire s () | ||
169 | filterQueue = undefined | ||
124 | 170 | ||
125 | exchange :: Wire Session () | 171 | exchange :: Wire Session () |
126 | exchange = do | 172 | exchange = do |