|
| 1 | +using Netorrent.Extensions; |
1 | 2 | using Netorrent.P2P; |
2 | 3 | using Netorrent.P2P.Download; |
3 | 4 | using Netorrent.P2P.Measurement; |
4 | 5 | using Netorrent.P2P.Messages; |
5 | 6 | using R3; |
6 | 7 |
|
7 | | -internal class FakePeerConnection : IPeerConnection |
| 8 | +internal class FakePeerConnection(Bitfield myBitfield) : IPeerConnection |
8 | 9 | { |
9 | 10 | public Subject<Block> SentBlocks = new(); |
10 | | - public ReactiveProperty<bool> AmChoking => new(true); |
| 11 | + public SynchronizedReactiveProperty<bool> AmChoking { get; } = new(true); |
11 | 12 |
|
12 | | - public ReactiveProperty<bool> AmInterested => new(false); |
| 13 | + public SynchronizedReactiveProperty<bool> AmInterested { get; } = new(false); |
13 | 14 |
|
14 | | - public ReactiveProperty<bool> PeerChoking => new(true); |
| 15 | + public SynchronizedReactiveProperty<bool> PeerChoking { get; } = new(true); |
15 | 16 |
|
16 | | - public ReactiveProperty<bool> PeerInterested => new(false); |
| 17 | + public SynchronizedReactiveProperty<bool> PeerInterested { get; } = new(false); |
17 | 18 |
|
18 | 19 | public TimeSpan ConnectionDuration => throw new NotImplementedException(); |
19 | 20 |
|
20 | | - public SpeedTracker DownloadSpeedTracker => throw new NotImplementedException(); |
| 21 | + public SpeedTracker DownloadTracker => new(); |
21 | 22 |
|
22 | | - public SpeedTracker UploadSpeedTracker => throw new NotImplementedException(); |
| 23 | + public SpeedTracker UploadTracker => new(); |
23 | 24 |
|
24 | 25 | public PeerEndpoint PeerEndpoint => throw new NotImplementedException(); |
25 | 26 |
|
26 | 27 | public int RequestedBlocksCount => throw new NotImplementedException(); |
27 | 28 |
|
28 | 29 | public int UploadRequestedBlocksCount => _uploadRequestedCount; |
29 | 30 |
|
30 | | - public Bitfield MyBitField => throw new NotImplementedException(); |
| 31 | + public Bitfield MyBitField => myBitfield; |
31 | 32 |
|
32 | 33 | public Bitfield? PeerBitField => throw new NotImplementedException(); |
33 | 34 |
|
34 | 35 | public PeerRequestWindow PeerRequestWindow => throw new NotImplementedException(); |
35 | 36 |
|
| 37 | + ReadOnlyReactiveProperty<bool> IPeerConnection.AmChoking => AmChoking; |
| 38 | + |
| 39 | + ReadOnlyReactiveProperty<bool> IPeerConnection.AmInterested => AmInterested; |
| 40 | + |
| 41 | + ReadOnlyReactiveProperty<bool> IPeerConnection.PeerChoking => PeerChoking; |
| 42 | + |
| 43 | + ReadOnlyReactiveProperty<bool> IPeerConnection.PeerInterested => PeerInterested; |
| 44 | + |
| 45 | + public TimeSpan TimeSinceReceivedBlock => 0.Seconds; |
| 46 | + |
| 47 | + public TimeSpan TimeSinceSentBlock => 0.Seconds; |
| 48 | + |
36 | 49 | private int _uploadRequestedCount = 0; |
37 | 50 |
|
38 | 51 | public int DecrementRequestedBlock() |
@@ -72,9 +85,13 @@ public bool TrySendRequest(RequestBlock nextBlock) |
72 | 85 | throw new NotImplementedException(); |
73 | 86 | } |
74 | 87 |
|
75 | | - public bool TrySendUnchoked() |
| 88 | + public async ValueTask UnchokeAsync(CancellationToken cancellationToken) |
76 | 89 | { |
77 | 90 | AmChoking.Value = false; |
78 | | - return true; |
| 91 | + } |
| 92 | + |
| 93 | + public async ValueTask ChokeAsync(CancellationToken cancellationToken) |
| 94 | + { |
| 95 | + AmChoking.Value = true; |
79 | 96 | } |
80 | 97 | } |
0 commit comments