summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-08 07:41:18 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-08 07:41:18 +0400
commitab3f921e04cf817a66c155b05e593a20c884c085 (patch)
tree8dd8b449448058e7af011a6823168dfc9a0131de /src/Network
parent6e5d3aacb36d7b6353a5a2b397fa237193f1e1e7 (diff)
Add stubs for connection statistics
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs46
1 files 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
11 Wire 11 Wire
12 12
13 -- ** Exceptions 13 -- ** Exceptions
14 , ChannelSide
14 , ProtocolError (..) 15 , ProtocolError (..)
15 , WireFailure (..) 16 , WireFailure (..)
16 , isWireFailure 17 , isWireFailure
17 , disconnectPeer 18 , disconnectPeer
18 19
19 -- ** Connection 20 -- ** Connection
20 , Connection (..) 21 , Connection
22 ( connCaps, connTopic
23 , connRemotePeerId, connThisPeerId
24 )
25 , getConnection
21 26
22 -- ** Setup 27 -- ** Setup
23 , runWire 28 , runWire
@@ -25,8 +30,11 @@ module Network.BitTorrent.Exchange.Wire
25 , acceptWire 30 , acceptWire
26 31
27 -- ** Query 32 -- ** Query
28 , getConnection
29 , getExtCaps 33 , getExtCaps
34
35 -- ** Stats
36 , ConnectionStats (..)
37 , getStats
30 ) where 38 ) where
31 39
32import Control.Exception 40import Control.Exception
@@ -100,6 +108,38 @@ isWireFailure :: Monad m => WireFailure -> m ()
100isWireFailure _ = return () 108isWireFailure _ = return ()
101 109
102{----------------------------------------------------------------------- 110{-----------------------------------------------------------------------
111-- Stats
112-----------------------------------------------------------------------}
113
114data MessageStats = MessageStats
115 { overhead :: {-# UNPACK #-} !Int
116 , payload :: {-# UNPACK #-} !Int
117 } deriving Show
118
119messageSize :: MessageStats -> Int
120messageSize = undefined
121
122data ConnectionStats = ConnectionStats
123 { a :: !MessageStats
124 , b :: !MessageStats
125 }
126
127sentBytes :: ConnectionStats -> Int
128sentBytes = undefined
129
130recvBytes :: ConnectionStats -> Int
131recvBytes = undefined
132
133wastedBytes :: ConnectionStats -> Int
134wastedBytes = undefined
135
136payloadBytes :: ConnectionStats -> Int
137payloadBytes = undefined
138
139getStats :: Wire ConnectionStats
140getStats = undefined
141
142{-----------------------------------------------------------------------
103-- Connection 143-- Connection
104-----------------------------------------------------------------------} 144-----------------------------------------------------------------------}
105 145
@@ -123,10 +163,10 @@ isAllowed Connection {..} msg
123-- Hanshaking 163-- Hanshaking
124-----------------------------------------------------------------------} 164-----------------------------------------------------------------------}
125 165
126-- | TODO remove socket stuff to corresponding module
127sendHandshake :: Socket -> Handshake -> IO () 166sendHandshake :: Socket -> Handshake -> IO ()
128sendHandshake sock hs = sendAll sock (S.encode hs) 167sendHandshake sock hs = sendAll sock (S.encode hs)
129 168
169-- TODO drop connection if protocol string do not match
130recvHandshake :: Socket -> IO Handshake 170recvHandshake :: Socket -> IO Handshake
131recvHandshake sock = do 171recvHandshake sock = do
132 header <- BS.recv sock 1 172 header <- BS.recv sock 1