diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2014-01-04 04:13:25 +0000 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-04 21:42:43 +0400 |
commit | 9000a995bddfd85a2e2a25e23eb23ebc53489a1d (patch) | |
tree | 2964fa86c2cc46247f93b46d1f70799298f8e13e /src/Network/BitTorrent | |
parent | c3bcc1e84f7f7f49de1fcd75e589ed4099bff2ea (diff) |
Add type 'Cached a' for caching the binary represntation of bencodable datastructures
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index 427d7676..0897f482 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs | |||
@@ -426,6 +426,28 @@ instance Default Options where | |||
426 | -- Connection | 426 | -- Connection |
427 | -----------------------------------------------------------------------} | 427 | -----------------------------------------------------------------------} |
428 | 428 | ||
429 | data Cached a = Cached { unCache :: a, cached :: BS.ByteString } | ||
430 | |||
431 | cache :: (BEncode a) => a -> Cached a | ||
432 | cache s = Cached s (BSL.toStrict $ BE.encode s) | ||
433 | |||
434 | data ConnectionState = ConnectionState { | ||
435 | -- | If @not (allowed ExtExtended connCaps)@ then this set is always | ||
436 | -- empty. Otherwise it has the BEP10 extension protocol mandated mapping of | ||
437 | -- 'MessageId' to the message type for the remote peer. | ||
438 | _connExtCaps :: !ExtendedCaps | ||
439 | |||
440 | -- | Current extended handshake information from the remote peer | ||
441 | , _connRemoteEhs :: !ExtendedHandshake | ||
442 | |||
443 | -- | Various stats about messages sent and received. Stats can be | ||
444 | -- used to protect /this/ peer against flood attacks. | ||
445 | , _connStats :: !ConnectionStats | ||
446 | |||
447 | -- | Infodict associated with this Connection's connTopic. | ||
448 | , _connMetadata :: Maybe (Cached InfoDict) | ||
449 | } | ||
450 | |||
429 | -- | Connection keep various info about both peers. | 451 | -- | Connection keep various info about both peers. |
430 | data Connection = Connection | 452 | data Connection = Connection |
431 | { -- | /Both/ peers handshaked with this protocol string. The only | 453 | { -- | /Both/ peers handshaked with this protocol string. The only |