Skip to content

Commit

Permalink
[core] Make some more of IPieceRequestor readonly
Browse files Browse the repository at this point in the history
The consumer of this interface shouldn't be able to set the
'IsChoking' status. That's controlled purely by whether or not
the remote peer ahs sent an Unchoke message. Similarly for
SupportsFastPeer.

This is just some cleanup now that things have been migrated to
the new interface.
  • Loading branch information
alanmcgovern committed Aug 30, 2019
1 parent c204682 commit edc0ea1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/MonoTorrent.Tests/Client/StandardPickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class TestTorrentData : ITorrentData
}

BitField bitfield;
IPieceRequester peer;
List<IPieceRequester> peers;
PeerId peer;
List<PeerId> peers;
PiecePicker picker;
TestTorrentData torrentData;

Expand All @@ -68,7 +68,7 @@ public void Setup()
PieceLength = pieceLength,
Size = pieceLength * pieceCount
};
peers = new List<IPieceRequester>();
peers = new List<PeerId>();

picker = new StandardPicker();
picker.Initialise (bitfield, torrentData, Enumerable.Empty<Piece> ());
Expand Down Expand Up @@ -162,7 +162,7 @@ public void StandardPicker_PickStandardPiece ()

peers [1].IsChoking = false;
peers [1].BitField.SetAll (true);
peers [1].HashedPiece (false);
peers [1].Peer.HashedPiece (false);
message = picker.PickPiece (peers [1], bitfield.Clone ().Not (), peers, 1, 0, 10);
Assert.AreEqual (2, message[0].PieceIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public partial class PeerId : IPieceRequester
{
int IPieceRequester.AmRequestingPiecesCount { get => AmRequestingPiecesCount; set => AmRequestingPiecesCount = value; }
List<int> IPieceRequester.IsAllowedFastPieces => IsAllowedFastPieces;
bool IPieceRequester.IsChoking { get => IsChoking; set => IsChoking = value; }
bool IPieceRequester.IsChoking => IsChoking;
Stopwatch IPieceRequester.LastMessageReceived => LastMessageReceived;
int IPieceRequester.RepeatedHashFails => Peer.RepeatedHashFails;
List<int> IPieceRequester.SuggestedPieces => SuggestedPieces;
bool IPieceRequester.SupportsFastPeer { get => SupportsFastPeer; set => SupportsFastPeer = value; }
bool IPieceRequester.SupportsFastPeer => SupportsFastPeer;
int IPieceRequester.TotalHashFails => Peer.TotalHashFails;

void IPieceRequester.Cancel (int pieceIndex, int pieceOffset, int requestLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ namespace MonoTorrent.Client.PiecePicking
{
public interface IPieceRequester
{
// FIXME: Make these readonly
bool IsChoking { get; set; }
bool SupportsFastPeer { get; set; }
// FIXME: Make these readonly

int AmRequestingPiecesCount { get; set; }
BitField BitField { get; }
List<int> IsAllowedFastPieces { get; }
bool IsChoking { get; }
Stopwatch LastMessageReceived { get; }
int RepeatedHashFails { get; }
List<int> SuggestedPieces { get; }
bool SupportsFastPeer { get; }
int TotalHashFails { get; }

void Cancel (int pieceIndex, int pieceOffset, int requestLength);
Expand Down

0 comments on commit edc0ea1

Please sign in to comment.