diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-08 07:41:18 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-08 07:41:18 +0400 |
commit | ab3f921e04cf817a66c155b05e593a20c884c085 (patch) | |
tree | 8dd8b449448058e7af011a6823168dfc9a0131de /src/Network/BitTorrent | |
parent | 6e5d3aacb36d7b6353a5a2b397fa237193f1e1e7 (diff) |
Add stubs for connection statistics
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 46 |
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 | ||
32 | import Control.Exception | 40 | import Control.Exception |
@@ -100,6 +108,38 @@ isWireFailure :: Monad m => WireFailure -> m () | |||
100 | isWireFailure _ = return () | 108 | isWireFailure _ = return () |
101 | 109 | ||
102 | {----------------------------------------------------------------------- | 110 | {----------------------------------------------------------------------- |
111 | -- Stats | ||
112 | -----------------------------------------------------------------------} | ||
113 | |||
114 | data MessageStats = MessageStats | ||
115 | { overhead :: {-# UNPACK #-} !Int | ||
116 | , payload :: {-# UNPACK #-} !Int | ||
117 | } deriving Show | ||
118 | |||
119 | messageSize :: MessageStats -> Int | ||
120 | messageSize = undefined | ||
121 | |||
122 | data ConnectionStats = ConnectionStats | ||
123 | { a :: !MessageStats | ||
124 | , b :: !MessageStats | ||
125 | } | ||
126 | |||
127 | sentBytes :: ConnectionStats -> Int | ||
128 | sentBytes = undefined | ||
129 | |||
130 | recvBytes :: ConnectionStats -> Int | ||
131 | recvBytes = undefined | ||
132 | |||
133 | wastedBytes :: ConnectionStats -> Int | ||
134 | wastedBytes = undefined | ||
135 | |||
136 | payloadBytes :: ConnectionStats -> Int | ||
137 | payloadBytes = undefined | ||
138 | |||
139 | getStats :: Wire ConnectionStats | ||
140 | getStats = 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 | ||
127 | sendHandshake :: Socket -> Handshake -> IO () | 166 | sendHandshake :: Socket -> Handshake -> IO () |
128 | sendHandshake sock hs = sendAll sock (S.encode hs) | 167 | sendHandshake sock hs = sendAll sock (S.encode hs) |
129 | 168 | ||
169 | -- TODO drop connection if protocol string do not match | ||
130 | recvHandshake :: Socket -> IO Handshake | 170 | recvHandshake :: Socket -> IO Handshake |
131 | recvHandshake sock = do | 171 | recvHandshake sock = do |
132 | header <- BS.recv sock 1 | 172 | header <- BS.recv sock 1 |