summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Wire.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Wire.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs
index b04bd378..3ec01ca1 100644
--- a/src/Network/BitTorrent/Exchange/Wire.hs
+++ b/src/Network/BitTorrent/Exchange/Wire.hs
@@ -73,11 +73,15 @@ data ChannelSide
73 | RemotePeer 73 | RemotePeer
74 deriving (Show, Eq, Enum) 74 deriving (Show, Eq, Enum)
75 75
76-- TODO pretty instance 76instance Pretty ChannelSide where
77 pretty = PP.text . show
77 78
78-- | Errors occur when a remote peer violates protocol specification. 79-- | Errors occur when a remote peer violates protocol specification.
79data ProtocolError 80data ProtocolError
80 = UnexpectedTopic InfoHash -- ^ peer replied with unexpected infohash. 81 -- | Protocol string should be 'BitTorrent Protocol' but remote
82 -- peer send a different string.
83 = InvalidProtocol ProtocolString
84 | UnexpectedTopic InfoHash -- ^ peer replied with unexpected infohash.
81 | UnexpectedPeerId PeerId -- ^ peer replied with unexpected peer id. 85 | UnexpectedPeerId PeerId -- ^ peer replied with unexpected peer id.
82 | UnknownTopic InfoHash -- ^ peer requested unknown torrent. 86 | UnknownTopic InfoHash -- ^ peer requested unknown torrent.
83 | HandshakeRefused -- ^ peer do not send an extended handshake back. 87 | HandshakeRefused -- ^ peer do not send an extended handshake back.
@@ -270,6 +274,9 @@ connectWire hs addr extCaps wire =
270 bracket (connectToPeer addr) close $ \ sock -> do 274 bracket (connectToPeer addr) close $ \ sock -> do
271 hs' <- initiateHandshake sock hs 275 hs' <- initiateHandshake sock hs
272 276
277 unless (def == hsProtocol hs') $ do
278 throwIO $ ProtocolError $ InvalidProtocol (hsProtocol hs')
279
273 unless (hsInfoHash hs == hsInfoHash hs') $ do 280 unless (hsInfoHash hs == hsInfoHash hs') $ do
274 throwIO $ ProtocolError $ UnexpectedTopic (hsInfoHash hs') 281 throwIO $ ProtocolError $ UnexpectedTopic (hsInfoHash hs')
275 282