From 100f8d432b550e3538941ab675d3ec0b3a082d77 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Fri, 6 Dec 2013 04:47:47 +0400 Subject: Add documentation to extended handshake --- src/Network/BitTorrent/Exchange/Message.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/Network/BitTorrent') diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index c614b1ae..8f6e1a5a 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs @@ -68,6 +68,7 @@ module Network.BitTorrent.Exchange.Message -- *** Handshake , ExtendedHandshake (..) + , defaultQueueLength , nullExtendedHandshake -- *** Metadata @@ -549,8 +550,13 @@ data ExtendedHandshake = ExtendedHandshake extendedHandshakeId :: ExtendedMessageId extendedHandshakeId = 0 +-- | Default 'Request' queue size. +defaultQueueLength :: Int +defaultQueueLength = 0 + +-- | All fields are empty. instance Default ExtendedHandshake where - def = nullExtendedHandshake def + def = ExtendedHandshake def def def def def def instance BEncode ExtendedHandshake where toBEncode ExtendedHandshake {..} = toDict $ @@ -582,9 +588,16 @@ instance PeerMessage ExtendedHandshake where requires _ = Just ExtExtended {-# INLINE requires #-} +-- | Set default values and the specified 'ExtendedCaps'. nullExtendedHandshake :: ExtendedCaps -> ExtendedHandshake -nullExtendedHandshake caps - = ExtendedHandshake Nothing Nothing caps Nothing Nothing Nothing +nullExtendedHandshake caps = ExtendedHandshake + { ehsIPv4 = Nothing + , ehsIPv6 = Nothing + , ehsCaps = caps + , ehsPort = Nothing + , ehsQueueLength = Just defaultQueueLength + , ehsVersion = Just $ T.pack $ render $ pretty libFingerprint + } {----------------------------------------------------------------------- -- Metadata exchange extension @@ -636,6 +649,10 @@ instance PeerMessage ExtendedMetadata where requires _ = Just ExtExtended {-# INLINE requires #-} +{----------------------------------------------------------------------- +-- Extension protocol messages +-----------------------------------------------------------------------} + -- | For more info see data ExtendedMessage = EHandshake ExtendedHandshake -- cgit v1.2.3