diff options
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Wire.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 19 |
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 | ||
95 | import Data.BEncode as BE | 98 | import Data.BEncode as BE |
96 | import Data.Torrent | 99 | import Data.Torrent |
97 | import Data.Torrent.Bitfield | 100 | import Data.Torrent.Bitfield as BF |
98 | import Data.Torrent.InfoHash | 101 | import Data.Torrent.InfoHash |
99 | import Data.Torrent.Piece | 102 | import Data.Torrent.Piece |
100 | import Network.BitTorrent.Core | 103 | import 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 | ||
762 | getRemoteBitfield :: Wire s Bitfield | ||
763 | getRemoteBitfield = lift $ use connBitfield | ||
764 | |||
765 | updateRemoteBitfield :: (Bitfield -> Bitfield) -> Wire s () | ||
766 | updateRemoteBitfield f = lift $ connBitfield %= f | ||
767 | |||
768 | -- | Used when size of bitfield becomes known. | ||
769 | resizeBitfield :: Int -> Wire s () | ||
770 | resizeBitfield n = updateRemoteBitfield (adjustSize n) | ||
771 | |||
755 | {----------------------------------------------------------------------- | 772 | {----------------------------------------------------------------------- |
756 | -- Metadata exchange | 773 | -- Metadata exchange |
757 | -----------------------------------------------------------------------} | 774 | -----------------------------------------------------------------------} |