summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs
index 5cd9ec70..1fca6a66 100644
--- a/src/Network/BitTorrent/Exchange/Wire.hs
+++ b/src/Network/BitTorrent/Exchange/Wire.hs
@@ -49,6 +49,7 @@ module Network.BitTorrent.Exchange.Wire
49 , runWire 49 , runWire
50 , connectWire 50 , connectWire
51 , acceptWire 51 , acceptWire
52 , resizeBitfield
52 53
53 -- ** Messaging 54 -- ** Messaging
54 , recvMessage 55 , recvMessage
@@ -59,7 +60,9 @@ module Network.BitTorrent.Exchange.Wire
59 , getConnection 60 , getConnection
60 , getSession 61 , getSession
61 , getStatus 62 , getStatus
63 , getRemoteBitfield
62 , updateConnStatus 64 , updateConnStatus
65 , updateRemoteBitfield
63 , getExtCaps 66 , getExtCaps
64 , getStats 67 , getStats
65 , getMetadata 68 , getMetadata
@@ -94,7 +97,7 @@ import System.Timeout
94 97
95import Data.BEncode as BE 98import Data.BEncode as BE
96import Data.Torrent 99import Data.Torrent
97import Data.Torrent.Bitfield 100import Data.Torrent.Bitfield as BF
98import Data.Torrent.InfoHash 101import Data.Torrent.InfoHash
99import Data.Torrent.Piece 102import Data.Torrent.Piece
100import Network.BitTorrent.Core 103import Network.BitTorrent.Core
@@ -450,6 +453,9 @@ data ConnectionState = ConnectionState {
450 453
451 , _connStatus :: !ConnectionStatus 454 , _connStatus :: !ConnectionStatus
452 455
456 -- | Bitfield of remote endpoint.
457 , _connBitfield :: !Bitfield
458
453 -- | Infodict associated with this Connection's connTopic. 459 -- | Infodict associated with this Connection's connTopic.
454 , _connMetadata :: Maybe (Cached InfoDict) 460 , _connMetadata :: Maybe (Cached InfoDict)
455 } 461 }
@@ -707,6 +713,7 @@ connectWire session hs addr extCaps chan wire =
707 , incomingFlow = FlowStats 1 $ handshakeStats hs' 713 , incomingFlow = FlowStats 1 $ handshakeStats hs'
708 } 714 }
709 , _connStatus = def 715 , _connStatus = def
716 , _connBitfield = BF.haveNone 0
710 , _connMetadata = Nothing 717 , _connMetadata = Nothing
711 } 718 }
712 719
@@ -752,6 +759,16 @@ updateConnStatus side u = lift $ do
752 statusSide ThisPeer = clientStatus 759 statusSide ThisPeer = clientStatus
753 statusSide RemotePeer = remoteStatus 760 statusSide RemotePeer = remoteStatus
754 761
762getRemoteBitfield :: Wire s Bitfield
763getRemoteBitfield = lift $ use connBitfield
764
765updateRemoteBitfield :: (Bitfield -> Bitfield) -> Wire s ()
766updateRemoteBitfield f = lift $ connBitfield %= f
767
768-- | Used when size of bitfield becomes known.
769resizeBitfield :: Int -> Wire s ()
770resizeBitfield n = updateRemoteBitfield (adjustSize n)
771
755{----------------------------------------------------------------------- 772{-----------------------------------------------------------------------
756-- Metadata exchange 773-- Metadata exchange
757-----------------------------------------------------------------------} 774-----------------------------------------------------------------------}