From ab3f921e04cf817a66c155b05e593a20c884c085 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 8 Dec 2013 07:41:18 +0400 Subject: Add stubs for connection statistics --- src/Network/BitTorrent/Exchange/Wire.hs | 46 ++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index 2c8eb316..b04bd378 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs @@ -11,13 +11,18 @@ module Network.BitTorrent.Exchange.Wire Wire -- ** Exceptions + , ChannelSide , ProtocolError (..) , WireFailure (..) , isWireFailure , disconnectPeer -- ** Connection - , Connection (..) + , Connection + ( connCaps, connTopic + , connRemotePeerId, connThisPeerId + ) + , getConnection -- ** Setup , runWire @@ -25,8 +30,11 @@ module Network.BitTorrent.Exchange.Wire , acceptWire -- ** Query - , getConnection , getExtCaps + + -- ** Stats + , ConnectionStats (..) + , getStats ) where import Control.Exception @@ -99,6 +107,38 @@ instance Pretty WireFailure where isWireFailure :: Monad m => WireFailure -> m () isWireFailure _ = return () +{----------------------------------------------------------------------- +-- Stats +-----------------------------------------------------------------------} + +data MessageStats = MessageStats + { overhead :: {-# UNPACK #-} !Int + , payload :: {-# UNPACK #-} !Int + } deriving Show + +messageSize :: MessageStats -> Int +messageSize = undefined + +data ConnectionStats = ConnectionStats + { a :: !MessageStats + , b :: !MessageStats + } + +sentBytes :: ConnectionStats -> Int +sentBytes = undefined + +recvBytes :: ConnectionStats -> Int +recvBytes = undefined + +wastedBytes :: ConnectionStats -> Int +wastedBytes = undefined + +payloadBytes :: ConnectionStats -> Int +payloadBytes = undefined + +getStats :: Wire ConnectionStats +getStats = undefined + {----------------------------------------------------------------------- -- Connection -----------------------------------------------------------------------} @@ -123,10 +163,10 @@ isAllowed Connection {..} msg -- Hanshaking -----------------------------------------------------------------------} --- | TODO remove socket stuff to corresponding module sendHandshake :: Socket -> Handshake -> IO () sendHandshake sock hs = sendAll sock (S.encode hs) +-- TODO drop connection if protocol string do not match recvHandshake :: Socket -> IO Handshake recvHandshake sock = do header <- BS.recv sock 1 -- cgit v1.2.3