diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-11 09:40:25 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-11 09:40:25 +0400 |
commit | b083c7ea2e9b262ba23deb00cb063819978adb92 (patch) | |
tree | a4dcda1df040191c9179a9917cbd5c480aaab10f /src/Network/BitTorrent/Exchange | |
parent | 8e4d3bc8f70f10a45ef86a1a3ec3403d1a78d41c (diff) |
Add cost estimatator for WireFailure
Diffstat (limited to 'src/Network/BitTorrent/Exchange')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index 9b83590a..8eca5120 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs | |||
@@ -18,6 +18,7 @@ module Network.BitTorrent.Exchange.Wire | |||
18 | , ChannelSide (..) | 18 | , ChannelSide (..) |
19 | , ProtocolError (..) | 19 | , ProtocolError (..) |
20 | , WireFailure (..) | 20 | , WireFailure (..) |
21 | , peerPenalty | ||
21 | , isWireFailure | 22 | , isWireFailure |
22 | , disconnectPeer | 23 | , disconnectPeer |
23 | 24 | ||
@@ -158,6 +159,16 @@ data ProtocolError | |||
158 | instance Pretty ProtocolError where | 159 | instance Pretty ProtocolError where |
159 | pretty = PP.text . show | 160 | pretty = PP.text . show |
160 | 161 | ||
162 | errorPenalty :: ProtocolError -> Int | ||
163 | errorPenalty (InvalidProtocol _) = 1 | ||
164 | errorPenalty (UnexpectedProtocol _) = 1 | ||
165 | errorPenalty (UnexpectedTopic _) = 1 | ||
166 | errorPenalty (UnexpectedPeerId _) = 1 | ||
167 | errorPenalty (UnknownTopic _) = 0 | ||
168 | errorPenalty (HandshakeRefused ) = 1 | ||
169 | errorPenalty (BitfieldAlreadySent _) = 1 | ||
170 | errorPenalty (DisallowedMessage _ _) = 1 | ||
171 | |||
161 | -- | Exceptions used to interrupt the current P2P session. | 172 | -- | Exceptions used to interrupt the current P2P session. |
162 | data WireFailure | 173 | data WireFailure |
163 | -- | Force termination of wire connection. | 174 | -- | Force termination of wire connection. |
@@ -189,6 +200,16 @@ instance Exception WireFailure | |||
189 | instance Pretty WireFailure where | 200 | instance Pretty WireFailure where |
190 | pretty = PP.text . show | 201 | pretty = PP.text . show |
191 | 202 | ||
203 | -- TODO | ||
204 | -- data Penalty = Ban | Penalty Int | ||
205 | |||
206 | peerPenalty :: WireFailure -> Int | ||
207 | peerPenalty DisconnectPeer = 0 | ||
208 | peerPenalty PeerDisconnected = 0 | ||
209 | peerPenalty (DecodingError _) = 1 | ||
210 | peerPenalty (ProtocolError e) = errorPenalty e | ||
211 | peerPenalty (FloodDetected _) = 1 | ||
212 | |||
192 | -- | Do nothing with exception, used with 'handle' or 'try'. | 213 | -- | Do nothing with exception, used with 'handle' or 'try'. |
193 | isWireFailure :: Monad m => WireFailure -> m () | 214 | isWireFailure :: Monad m => WireFailure -> m () |
194 | isWireFailure _ = return () | 215 | isWireFailure _ = return () |