From 5727e7f6f9022cc40a07e17398c8bf619e0a690f Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 9 Dec 2013 06:45:55 +0400 Subject: Rename ProtocolString newtype to ProtocolName --- src/Network/BitTorrent/Exchange/Message.hs | 38 +++++++++++++++--------------- src/Network/BitTorrent/Exchange/Wire.hs | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index b3100269..070a0e42 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs @@ -40,7 +40,7 @@ module Network.BitTorrent.Exchange.Message , Caps -- * Handshake - , ProtocolString + , ProtocolName , Handshake(..) , defaultHandshake , handshakeSize @@ -208,48 +208,48 @@ instance Capabilities Caps where Handshake -----------------------------------------------------------------------} -maxProtocolStringSize :: Word8 -maxProtocolStringSize = maxBound +maxProtocolNameSize :: Word8 +maxProtocolNameSize = maxBound -- | The protocol name is used to identify to the local peer which -- version of BTP the remote peer uses. -newtype ProtocolString = ProtocolString BS.ByteString +newtype ProtocolName = ProtocolName BS.ByteString deriving (Eq, Ord, Typeable) -- | In BTP/1.0 the name is 'BitTorrent protocol'. If this string is -- different from the local peers own protocol name, then the -- connection is to be dropped. -instance Default ProtocolString where - def = ProtocolString "BitTorrent protocol" +instance Default ProtocolName where + def = ProtocolName "BitTorrent protocol" -instance Show ProtocolString where - show (ProtocolString bs) = show bs +instance Show ProtocolName where + show (ProtocolName bs) = show bs -instance Pretty ProtocolString where - pretty (ProtocolString bs) = PP.text $ BC.unpack bs +instance Pretty ProtocolName where + pretty (ProtocolName bs) = PP.text $ BC.unpack bs -instance IsString ProtocolString where +instance IsString ProtocolName where fromString str - | L.length str <= fromIntegral maxProtocolStringSize - = ProtocolString (fromString str) - | otherwise = error $ "fromString: ProtocolString too long: " ++ str + | L.length str <= fromIntegral maxProtocolNameSize + = ProtocolName (fromString str) + | otherwise = error $ "fromString: ProtocolName too long: " ++ str -instance Serialize ProtocolString where - put (ProtocolString bs) = do +instance Serialize ProtocolName where + put (ProtocolName bs) = do putWord8 $ fromIntegral $ BS.length bs putByteString bs get = do len <- getWord8 bs <- getByteString $ fromIntegral len - return (ProtocolString bs) + return (ProtocolName bs) -- | Handshake message is used to exchange all information necessary -- to establish connection between peers. -- data Handshake = Handshake { -- | Identifier of the protocol. This is usually equal to 'def'. - hsProtocol :: ProtocolString + hsProtocol :: ProtocolName -- | Reserved bytes used to specify supported BEP's. , hsReserved :: Caps @@ -290,7 +290,7 @@ handshakeSize n = 1 + fromIntegral n + 8 + 20 + 20 -- | Maximum size of handshake message in bytes. handshakeMaxSize :: Int -handshakeMaxSize = handshakeSize maxProtocolStringSize +handshakeMaxSize = handshakeSize maxProtocolNameSize -- | Handshake with default protocol string and reserved bitmask. defaultHandshake :: InfoHash -> PeerId -> Handshake diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index fe4086bc..e0e652ec 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs @@ -102,7 +102,7 @@ instance Pretty ChannelSide where data ProtocolError -- | Protocol string should be 'BitTorrent Protocol' but remote -- peer send a different string. - = InvalidProtocol ProtocolString + = InvalidProtocol ProtocolName | UnexpectedTopic InfoHash -- ^ peer replied with unexpected infohash. | UnexpectedPeerId PeerId -- ^ peer replied with unexpected peer id. | UnknownTopic InfoHash -- ^ peer requested unknown torrent. -- cgit v1.2.3