summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2014-01-04 04:13:25 +0000
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-04 21:42:43 +0400
commit9000a995bddfd85a2e2a25e23eb23ebc53489a1d (patch)
tree2964fa86c2cc46247f93b46d1f70799298f8e13e
parentc3bcc1e84f7f7f49de1fcd75e589ed4099bff2ea (diff)
Add type 'Cached a' for caching the binary represntation of bencodable datastructures
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs22
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
429data Cached a = Cached { unCache :: a, cached :: BS.ByteString }
430
431cache :: (BEncode a) => a -> Cached a
432cache s = Cached s (BSL.toStrict $ BE.encode s)
433
434data 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.
430data Connection = Connection 452data Connection = Connection
431 { -- | /Both/ peers handshaked with this protocol string. The only 453 { -- | /Both/ peers handshaked with this protocol string. The only