├── alpha.txt
├── version.txt
├── docs
└── index.md
├── pack.bat
├── src
├── MonoTorrent.Dht
│ ├── MonoTorrent.Dht
│ │ ├── NodeId.cs
│ │ ├── NodeState.cs
│ │ ├── MessageException.cs
│ │ └── TransactionId.cs
│ ├── MonoTorrent.Dht.csproj
│ └── MonoTorrent.Dht.Messages
│ │ ├── PingResponse.cs
│ │ └── AnnouncePeerResponse.cs
├── Tests
│ ├── Directory.Build.props
│ ├── Tests.MonoTorrent.Client
│ │ ├── test_torrent_128.torrent
│ │ ├── test_torrent_256.torrent
│ │ ├── test_torrent_512.torrent
│ │ ├── test_torrent_64.torrent
│ │ ├── MonoTorrent
│ │ │ ├── bittorrent-v2-test.torrent
│ │ │ ├── bittorrent-v2-hybrid-test.torrent
│ │ │ ├── CustomFileSource.cs
│ │ │ ├── CacheTests.cs
│ │ │ ├── VersionInfoTests.cs
│ │ │ └── HashesTests.cs
│ │ ├── MonoTorrent.Client
│ │ │ ├── ConnectionFactoryTests.cs
│ │ │ ├── PeerExchangeManagerTests.cs
│ │ │ ├── TorrentSettingsTests.cs
│ │ │ └── MainLoopTests.cs
│ │ ├── MessageQueueExtensions.cs
│ │ ├── TempDir.cs
│ │ └── EnumerableExtensions.cs
│ ├── Tests.MonoTorrent
│ │ ├── Tests.MonoTorrent.csproj
│ │ ├── MerkleRootTests.cs
│ │ └── BitOpsTests.cs
│ ├── Tests.MonoTorrent.BEncoding
│ │ ├── Tests.MonoTorrent.BEncoding.csproj
│ │ └── MemoryExtensionsTests.cs
│ ├── Tests.MonoTorrent.Messages
│ │ ├── Tests.MonoTorrent.Messages.csproj
│ │ └── HaveBundleTests.cs
│ ├── Tests.MonoTorrent.Dht
│ │ ├── Tests.MonoTorrent.Dht.csproj
│ │ └── MonoTorrent.Dht
│ │ │ ├── DhtEngineTests.cs
│ │ │ └── TestHelper.cs
│ ├── Tests.MonoTorrent.Trackers
│ │ └── Tests.MonoTorrent.Trackers.csproj
│ ├── Tests.MonoTorrent.IntegrationTests
│ │ └── Tests.MonoTorrent.IntegrationTests.csproj
│ ├── Tests.MonoTorrent.PiecePicking
│ │ └── Tests.MonoTorrent.PiecePicking.csproj
│ ├── Directory.Build.targets
│ └── Tests.MonoTorrent.PieceWriter
│ │ └── Tests.MonoTorrent.PieceWriter.csproj
├── MonoTorrent
│ ├── MonoTorrent.Connections
│ │ ├── ListenerStatus.cs
│ │ ├── ISocketConnector.cs
│ │ ├── ISocketListener.cs
│ │ ├── IListener.cs
│ │ └── ISocketMessageListener.cs
│ ├── MonoTorrent.PieceWriter
│ │ ├── CachePolicy.cs
│ │ └── FileCreationOptions.cs
│ ├── MonoTorrent.Trackers
│ │ ├── ScrapeInfo.cs
│ │ ├── ScrapeRequest.cs
│ │ ├── ScrapeResponse.cs
│ │ └── TrackerState.cs
│ ├── MonoTorrent
│ │ ├── Constants.cs
│ │ ├── TorrentEvent.cs
│ │ ├── Priority.cs
│ │ ├── ITorrentManagerInfo.cs
│ │ └── ByteBufferPool.ByteBuffer.cs
│ ├── MonoTorrent.csproj
│ ├── MonoTorrent.PortForwarding
│ │ └── Protocol.cs
│ ├── MonoTorrent.Dht
│ │ ├── DhtState.cs
│ │ └── PeersFoundEventArgs.cs
│ ├── MonoTorrent.Connections.Dht
│ │ └── IDhtListener.cs
│ ├── MonoTorrent.Logging
│ │ ├── ILogger.cs
│ │ ├── IRootLogger.cs
│ │ ├── NullLogger.cs
│ │ ├── TextWriterLogger.cs
│ │ └── Logger.cs
│ ├── MonoTorrent.Connections.Peer
│ │ ├── LocalPeerFoundEventArgs.cs
│ │ └── PeerConnectionEventArgs.cs
│ └── MonoTorrent.Connections.TrackerServer
│ │ └── ITrackerListener.cs
├── MonoTorrent.Client
│ ├── MonoTorrent.Client
│ │ ├── EventArgs
│ │ │ ├── StateUpdateEventArgs.cs
│ │ │ ├── CriticalExceptionEventArgs.cs
│ │ │ ├── AttemptConnectionStage.cs
│ │ │ ├── PeerEventArgs.cs
│ │ │ ├── ScrapeResponseEventArgs.cs
│ │ │ ├── TorrentEventArgs.cs
│ │ │ ├── DhtPeersAdded.cs
│ │ │ ├── LocalPeersAdded.cs
│ │ │ ├── TrackerPeersAdded.cs
│ │ │ ├── PeerExchangePeersAdded.cs
│ │ │ └── AnnounceResponseEventArgs.cs
│ │ ├── Managers
│ │ │ └── IPeerExchangeSource.cs
│ │ ├── Unchokers
│ │ │ ├── TorrentManagerUnchokeable.cs
│ │ │ ├── IUnchoker.cs
│ │ │ └── IUnchokeable.cs
│ │ ├── Error.cs
│ │ ├── PeerDisconnectedEventArgs.cs
│ │ └── Exceptions
│ │ │ └── ProtocolException.cs
│ ├── MonoTorrent
│ │ ├── ConnectionClosedException.cs
│ │ ├── SpanExtensions.cs
│ │ ├── SemaphoreLocked.cs
│ │ ├── ITorrentFileSource.cs
│ │ ├── IDisposableExtensions.cs
│ │ ├── VersionInfo.cs
│ │ ├── Enums.cs
│ │ ├── IPieceHashes.cs
│ │ ├── ReadOnlyPieceHash.cs
│ │ ├── NewConnectionEventArgs.cs
│ │ ├── TorrentException.cs
│ │ ├── TorrentType.cs
│ │ └── FileMapping.cs
│ ├── GlobalSuppressions.cs
│ ├── MonoTorrent.Client.Tracker
│ │ ├── ITrackerRequestFactory.cs
│ │ └── StringExtensions.cs
│ ├── MonoTorrent.TrackerServer
│ │ ├── AnnounceEventArgs.cs
│ │ ├── TimedOutEventArgs.cs
│ │ ├── PeerEventArgs.cs
│ │ ├── ScrapeEventArgs.cs
│ │ ├── ITrackable.cs
│ │ ├── PeerIdComparer.cs
│ │ └── ClientAddressComparer.cs
│ ├── MonoTorrent.Connections.Peer.Encryption
│ │ ├── IEncryption.cs
│ │ ├── RC4Header.cs
│ │ ├── IEncryptor.cs
│ │ └── PlainTextEncryption.cs
│ ├── MonoTorrent.TorrentWatchers
│ │ ├── ITorrentWatcher.cs
│ │ └── TorrentWatcherEventArgs.cs
│ ├── MonoTorrent.Dht
│ │ └── IDht.cs
│ └── MonoTorrent.Client.RateLimiters
│ │ ├── UnlimitedRateLimiter.cs
│ │ ├── PauseLimiter.cs
│ │ ├── DiskWriterLimiter.cs
│ │ └── IRateLimiter.cs
├── MonoTorrent.Messages
│ ├── MonoTorrent.Messages
│ │ ├── IRentable.cs
│ │ ├── IMessage.cs
│ │ └── MessageException.cs
│ ├── MonoTorrent.Messages.csproj
│ ├── MonoTorrent.Messages.Peer.FastPeer
│ │ └── IFastPeerMessage.cs
│ └── MonoTorrent.Messages.Peer.Libtorrent
│ │ └── ExtensionSupport.cs
├── Samples
│ ├── DhtSampleClient
│ │ └── DhtSample.csproj
│ ├── Directory.Build.targets
│ ├── Directory.Build.props
│ ├── TrackerApp
│ │ └── TrackerSample.csproj
│ ├── Benchmark
│ │ └── Benchmark.csproj
│ └── SampleClient
│ │ ├── ClientSample.csproj
│ │ └── Top10Listener.cs
├── MonoTorrent.Connections
│ ├── MonoTorrent.Connections.csproj
│ ├── MonoTorrent.Connections.Dht
│ │ └── DhtListener.cs
│ └── MonoTorrent.Connections
│ │ └── SocketListener.cs
├── MonoTorrent.PiecePicking
│ └── MonoTorrent.PiecePicking.csproj
├── MonoTorrent.PortForwarding
│ └── MonoTorrent.PortForwarding.csproj
├── MonoTorrent.PieceWriter
│ └── MonoTorrent.PieceWriter.csproj
├── MonoTorrent.Trackers
│ ├── MonoTorrent.Trackers.csproj
│ ├── MonoTorrent.Client.Messages.UdpTracker
│ │ ├── MessageType.cs
│ │ └── ScrapeDetails.cs
│ └── MonoTorrent.Trackers
│ │ └── TrackerException.cs
├── MonoTorrent.BEncoding
│ ├── MonoTorrent.BEncoding.csproj
│ ├── RawInfoHashes.cs
│ └── MonoTorrent.BEncoding
│ │ └── BEncodingException.cs
├── ICacheable.cs
├── MonoTorrent.Factories
│ └── MonoTorrent.Factories.csproj
├── UdpClientExtensions.cs
└── IListExtensions.cs
├── .gitignore
├── .gitattributes
├── coverage.bat
├── Makefile
├── .github
└── FUNDING.yml
└── LICENSE
/alpha.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/version.txt:
--------------------------------------------------------------------------------
1 | 3.0.3
2 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | Hello World
2 |
3 |
--------------------------------------------------------------------------------
/pack.bat:
--------------------------------------------------------------------------------
1 | msbuild /restore /t:Pack /p:Configuration=Release
2 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht/NodeId.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/MonoTorrent.Dht/MonoTorrent.Dht/NodeId.cs
--------------------------------------------------------------------------------
/src/Tests/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .vs/
3 | bin/
4 | obj/
5 | /src/MonoTorrent.sln.DotSettings.user
6 | /build/
7 | /coveragereport
8 | /out/
9 | /src/.vs
10 | *.csproj.user
11 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/test_torrent_128.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/test_torrent_128.torrent
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/test_torrent_256.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/test_torrent_256.torrent
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/test_torrent_512.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/test_torrent_512.torrent
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/test_torrent_64.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/test_torrent_64.torrent
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/bittorrent-v2-test.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/bittorrent-v2-test.torrent
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/bittorrent-v2-hybrid-test.torrent:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alanmcgovern/monotorrent/HEAD/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/bittorrent-v2-hybrid-test.torrent
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections/ListenerStatus.cs:
--------------------------------------------------------------------------------
1 | namespace MonoTorrent.Connections
2 | {
3 | public enum ListenerStatus
4 | {
5 | Listening,
6 | PortNotFree,
7 | NotListening
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.cs text
2 | *.csproj text
3 | *.dll.config text
4 | *.DotSettings text
5 | *.exe.config text
6 | *.md text
7 | *.proj text
8 | *.props text
9 | *.resx text
10 | *.sh text eol=lf
11 | *.sln text eol=crlf
12 | *.targets text
13 | *.txt text
14 |
--------------------------------------------------------------------------------
/coverage.bat:
--------------------------------------------------------------------------------
1 | dotnet test --maxcpucount:10 --collect:"XPlat Code Coverage" src\MonoTorrent.sln
2 | "%UserProfile%\.nuget\packages\reportgenerator\5.3.7\tools\net8.0\ReportGenerator.exe" -reports:**\coverage.cobertura.xml -targetdir:coveragereport
3 | coveragereport\index.html
4 |
5 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/StateUpdateEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MonoTorrent.Client
4 | {
5 | public class StatsUpdateEventArgs : EventArgs
6 | {
7 | public StatsUpdateEventArgs ()
8 | {
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.PieceWriter/CachePolicy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MonoTorrent.PieceWriter
6 | {
7 | public enum CachePolicy
8 | {
9 | WritesOnly,
10 | ReadsAndWrites,
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages/IRentable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MonoTorrent.Messages
8 | {
9 | public interface IRentable
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/ConnectionClosedException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MonoTorrent
4 | {
5 | class ConnectionClosedException : Exception
6 | {
7 | public ConnectionClosedException (string message)
8 | : base (message)
9 | {
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | XBUILD=msbuild
3 | XBUILD_ARGS=/nologo /restore
4 |
5 | all:
6 | @echo Building
7 | $(XBUILD) $(XBUILD_ARGS)
8 |
9 | clean:
10 | @echo Cleaning $(MAIN_SLN)
11 | $(XBUILD) $(XBUILD_ARGS) /t:Clean
12 |
13 | pack:
14 | @echo Creating the nupkg
15 | $(XBUILD) $(XBUILD_ARGS) /t:Pack /p:Configuration=Release
16 |
17 | .PHONY: all clean
18 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Managers/IPeerExchangeSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MonoTorrent.Client
8 | {
9 | interface IPeerExchangeSource
10 | {
11 | TorrentSettings Settings { get; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections/ISocketConnector.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Sockets;
3 | using System.Threading;
4 |
5 | using ReusableTasks;
6 |
7 | namespace MonoTorrent.Connections
8 | {
9 | public interface ISocketConnector
10 | {
11 | public ReusableTask ConnectAsync (Uri uri, CancellationToken token);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent/Tests.MonoTorrent.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.BEncoding/Tests.MonoTorrent.BEncoding.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Messages/Tests.MonoTorrent.Messages.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client/ConnectionFactoryTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using NUnit.Framework;
6 |
7 | namespace MonoTorrent.Client
8 | {
9 | [TestFixture]
10 | public class PeerConnectionFactoryTests
11 | {
12 | [Test]
13 | public void InvalidPort ()
14 | {
15 | Assert.IsNull (Factories.Default.CreatePeerConnection (new Uri ("ipv4://127.0.1.2")));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 |
2 | // This file is used by Code Analysis to maintain SuppressMessage
3 | // attributes that are applied to this project.
4 | // Project-level suppressions either have no target or are given
5 | // a specific target and scoped to a namespace, type, member, etc.
6 |
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage ("Potential Code Quality Issues", "RECS0165:Asynchronous methods should return a Task instead of void", Justification = "Refactoring work and everything is async void")]
8 |
9 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Trackers/ScrapeInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MonoTorrent.Trackers
6 | {
7 | public readonly struct ScrapeInfo
8 | {
9 | public int Complete { get; }
10 | public int Downloaded { get; }
11 | public int Incomplete { get; }
12 |
13 | public ScrapeInfo (int complete, int downloaded, int incomplete)
14 | => (Complete, Downloaded, Incomplete) = (complete, downloaded, incomplete);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Dht/Tests.MonoTorrent.Dht.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/Samples/DhtSampleClient/DhtSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net6.0;netcoreapp3.1;net472
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Trackers/Tests.MonoTorrent.Trackers.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Samples/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/SpanExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MonoTorrent
8 | {
9 | static class SpanExtensions
10 | {
11 | #if NETSTANDARD2_0 || NETSTANDARD2_1
12 | public static bool Contains (this ReadOnlySpan span, int value)
13 | {
14 | for (int i = 0; i < span.Length; i++)
15 | if (span[i] == value)
16 | return true;
17 | return false;
18 | }
19 | #endif
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/CriticalExceptionEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MonoTorrent.Client
4 | {
5 | public class CriticalExceptionEventArgs : EventArgs
6 | {
7 | public ClientEngine Engine { get; }
8 |
9 | public Exception Exception { get; }
10 |
11 |
12 | public CriticalExceptionEventArgs (Exception ex, ClientEngine engine)
13 | {
14 | Engine = engine ?? throw new ArgumentNullException (nameof (engine));
15 | Exception = ex ?? throw new ArgumentNullException (nameof (ex));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Samples/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 | 3.*
13 | 4.*
14 | 4.5.5
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/CustomFileSource.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace MonoTorrent.Common
4 | {
5 | public class CustomFileSource : ITorrentFileSource
6 | {
7 | public IEnumerable Files {
8 | get; private set;
9 | }
10 |
11 | public bool IgnoreHidden {
12 | get { return false; }
13 | }
14 |
15 | public string TorrentName {
16 | get { return "Name"; }
17 | }
18 |
19 | public CustomFileSource (List files)
20 | {
21 | Files = files;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Samples/TrackerApp/TrackerSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net6.0;netcoreapp3.1;net472
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.IntegrationTests/Tests.MonoTorrent.IntegrationTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Connections/MonoTorrent.Connections.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Messages/HaveBundleTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NUnit.Framework;
8 |
9 | namespace MonoTorrent.Messages.Peer
10 | {
11 | [TestFixture]
12 | public class HaveBundleTests
13 | {
14 | [Test]
15 | public void HaveBundleIsCached ()
16 | {
17 | (var msg, var releaser) = PeerMessage.Rent ();
18 | releaser.Dispose ();
19 | (var msg2, var releaser2) = PeerMessage.Rent ();
20 | releaser2.Dispose ();
21 | Assert.AreSame (msg, msg2);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.PiecePicking/Tests.MonoTorrent.PiecePicking.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: monotorrent
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/src/MonoTorrent.PiecePicking/MonoTorrent.PiecePicking.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 | true
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/MonoTorrent.PortForwarding/MonoTorrent.PortForwarding.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Tests/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Samples/Benchmark/Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;netcoreapp3.1;net472
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 | true
12 | true
13 | true
14 | true
15 | true
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/MonoTorrent.PieceWriter/MonoTorrent.PieceWriter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 | true
12 | true
13 | true
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.PieceWriter/Tests.MonoTorrent.PieceWriter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;net472
5 |
6 |
7 |
8 | true
9 | true
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Samples/SampleClient/ClientSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net6.0;netcoreapp3.1;net472
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Trackers/MonoTorrent.Trackers.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 | true
12 | true
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Dht/MonoTorrent.Dht/DhtEngineTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | using NUnit.Framework;
9 |
10 | namespace MonoTorrent.Dht
11 | {
12 | [TestFixture]
13 | public class DhtEngineTests
14 | {
15 | [Test]
16 | public void AddRawNodesBeforeStarting ()
17 | {
18 | int count = 0;
19 | var engine = new DhtEngine ();
20 | engine.MessageLoop.QuerySent += (o, e) => count++;
21 | engine.Add (new ReadOnlyMemory[] { new byte[100] });
22 | Assert.AreEqual (0, engine.MessageLoop.PendingQueries);
23 | Assert.AreEqual (0, count);
24 | Assert.AreEqual (0, engine.RoutingTable.CountNodes ());
25 | Assert.AreEqual (0, engine.MessageLoop.DhtMessageFactory.RegisteredMessages);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/MonoTorrent.BEncoding/MonoTorrent.BEncoding.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 | true
6 |
7 |
8 |
9 | true
10 | true
11 | true
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace MonoTorrent
2 | {
3 | public class Constants
4 | {
5 | ///
6 | /// Blocks are always 16kB
7 | ///
8 | public const int BlockSize = 16 * 1024;
9 |
10 | ///
11 | /// Maximum supported piece length. Value is in bytes.
12 | ///
13 | public static readonly int MaximumPieceLength = 128 * 1024 * 1024;
14 |
15 | ///
16 | /// The default maximum concurrent requests which can be made to a single peer.
17 | ///
18 | public const int DefaultMaxPendingRequests = 256;
19 |
20 | ///
21 | /// The length of the initial handshake message, in bytes, for a V1 connection
22 | ///
23 | public const int HandshakeLengthV100 = 68;
24 |
25 | ///
26 | /// Protocol string for version 1.0 of Bittorrent Protocol
27 | ///
28 | public const string ProtocolStringV100 = "BitTorrent protocol";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 | true
9 | true
10 | true
11 | true
12 | true
13 | true
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MessageQueueExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using MonoTorrent.Messages.Peer;
8 | using MonoTorrent.Messages.Peer.Libtorrent;
9 |
10 | namespace MonoTorrent.Client
11 | {
12 | static class MessageQueueExtensions
13 | {
14 | public static PeerId AddConnectedPeer (this TorrentManager manager, bool supportsLTMetdata = false)
15 | {
16 | var peer = PeerId.CreateNull (manager.Bitfield.Length, manager.InfoHashes.V1OrV2);
17 | manager.Peers.ConnectedPeers.Add (peer);
18 | if (supportsLTMetdata) {
19 | peer.SupportsFastPeer = true;
20 | peer.SupportsLTMessages = true;
21 | peer.ExtensionSupports.Add (LTMetadata.Support);
22 | }
23 | return peer;
24 | }
25 |
26 | public static PeerMessage TryDequeue (this MessageQueue queue)
27 | => queue.TryDequeue (out PeerMessage message, out PeerMessage.Releaser releaser) ? message : null;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (C) 2006 Alan McGovern, Olivier Dufour
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent/MerkleRootTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NUnit.Framework;
8 |
9 | namespace MonoTorrent
10 | {
11 | [TestFixture]
12 | public class MerkleRootTests
13 | {
14 | [Test]
15 | public void Equality ()
16 | {
17 | Func allZeros = () => new MerkleRoot (new byte[32]);
18 | Func allOnes = () => new MerkleRoot (Enumerable.Repeat ((byte) 1, 32).ToArray ());
19 |
20 | Assert.IsTrue (allZeros ().Equals (allZeros ()));
21 | Assert.IsFalse (allOnes ().Equals (allZeros ()));
22 |
23 | Assert.IsTrue (allOnes () != allZeros ());
24 | Assert.IsFalse (allOnes () == allZeros ());
25 |
26 | Assert.IsTrue (allOnes () == allOnes ());
27 | Assert.IsFalse (allOnes () != allOnes ());
28 |
29 | Assert.IsFalse (allZeros () == MerkleRoot.Empty);
30 | Assert.IsFalse (allOnes () == MerkleRoot.Empty);
31 | Assert.IsTrue (MerkleRoot.Empty == MerkleRoot.Empty);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/TempDir.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Threading;
5 |
6 | namespace MonoTorrent
7 | {
8 | static class TempDir
9 | {
10 | public readonly struct Releaser : IDisposable
11 | {
12 | public string Path { get; }
13 |
14 | public Releaser (string path)
15 | => Path = path;
16 |
17 | public void Dispose ()
18 | {
19 | Directory.Delete (Path, true);
20 | }
21 | }
22 | static SpinLocked RandomLocker = SpinLocked.Create (new Random ());
23 | public static Releaser Create ()
24 | {
25 | using (RandomLocker.Enter (out var random)) {
26 | var tmp = Path.Combine (
27 | Path.GetTempPath (),
28 | "monotorrent_tests",
29 | random.Next (10000, 99999).ToString (),
30 | $"_dir{Thread.CurrentThread.ManagedThreadId}-{Process.GetCurrentProcess ().Id}"
31 | );
32 | Directory.CreateDirectory (tmp);
33 | return new Releaser (tmp);
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/CacheTests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace MonoTorrent.Common
4 | {
5 | [TestFixture]
6 | public class CacheTests
7 | {
8 | class Cacheable : ICacheable
9 | {
10 | public int Initialised { get; set; }
11 |
12 | public void Initialise ()
13 | {
14 | Initialised++;
15 | }
16 | }
17 |
18 | [Test]
19 | public void Dequeue_WithAutocreate ()
20 | {
21 | var cache = new SynchronizedCache (() => new Cacheable ());
22 | Assert.AreEqual (0, cache.Count);
23 | Assert.IsTrue (cache.Dequeue ().Initialised == 1);
24 | }
25 |
26 | [Test]
27 | public void UseTwice ()
28 | {
29 | // Should be initialised twice.
30 | var cache = new Cache (() => new Cacheable ());
31 | var item = cache.Dequeue ();
32 | Assert.AreEqual (1, item.Initialised);
33 |
34 | cache.Enqueue (item);
35 | Assert.AreEqual (2, item.Initialised);
36 |
37 | Assert.AreSame (item, cache.Dequeue ());
38 | Assert.AreEqual (2, item.Initialised);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/AttemptConnectionStage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MonoTorrent.Client
8 | {
9 | ///
10 | /// Peers can be banned at two points, when the connection has been opened, or after the handshakes have been transferred.
11 | ///
12 | public enum AttemptConnectionStage
13 | {
14 | ///
15 | /// This is invoked before an outgoing connection attempt is made so peers can be discarded at the earliest point in time.
16 | /// For incoming connections, this is invoked before any data is sent or received through the connection.
17 | /// At this stage the only information available is the peers , which contains the
18 | /// IP address and port of the remote peer.
19 | ///
20 | BeforeConnectionEstablished,
21 |
22 | ///
23 | /// At this stage both and are known as the BitTorrent
24 | /// handshakes have been exchanged.
25 | ///
26 | HandshakeComplete,
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Dht/MonoTorrent.Dht/TestHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Net;
3 |
4 | namespace MonoTorrent.Dht
5 | {
6 | static class TestHelper
7 | {
8 | internal static void ManyNodes (out RoutingTable routingTable, out List nodes)
9 | {
10 | // Generate our local id
11 | byte[] id = new byte[20];
12 | id[19] = 7;
13 |
14 | nodes = new List ();
15 | RoutingTable table = new RoutingTable (new NodeId (id));
16 |
17 | for (int i = 0; i <= 30; i++) {
18 | if (i == 7)
19 | continue;
20 |
21 | id = new byte[20];
22 | id[19] = (byte) i;
23 | nodes.Add (new NodeId (id));
24 | table.Add (new Node (new NodeId (id), new IPEndPoint (IPAddress.Any, 0)));
25 | }
26 |
27 | nodes.Sort (delegate (NodeId left, NodeId right) {
28 | NodeId dLeft = left ^ table.LocalNodeId;
29 | NodeId dRight = right ^ table.LocalNodeId;
30 | return dLeft.CompareTo (dRight);
31 | });
32 |
33 | nodes.RemoveAll (n => table.FindNode (n) == null);
34 | routingTable = table;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Unchokers/TorrentManagerUnchokeable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace MonoTorrent.Client
5 | {
6 | class TorrentManagerUnchokeable : IUnchokeable
7 | {
8 | TorrentManager Manager { get; }
9 |
10 | public event EventHandler StateChanged {
11 | add { Manager.TorrentStateChanged += value; }
12 | remove { Manager.TorrentStateChanged -= value; }
13 | }
14 |
15 | public bool Seeding => Manager.Complete;
16 |
17 | public long DownloadSpeed => Manager.Monitor.DownloadRate;
18 |
19 | public long UploadSpeed => Manager.Monitor.UploadRate;
20 |
21 | public long MaximumDownloadSpeed => Manager.Settings.MaximumDownloadRate;
22 |
23 | public long MaximumUploadSpeed => Manager.Settings.MaximumUploadRate;
24 |
25 | public int UploadSlots => Manager.Settings.UploadSlots;
26 |
27 | public int UploadingTo {
28 | get => Manager.UploadingTo;
29 | set => Manager.UploadingTo = value;
30 | }
31 |
32 | public List Peers => Manager.Peers.ConnectedPeers;
33 |
34 | public TorrentManagerUnchokeable (TorrentManager manager)
35 | {
36 | Manager = manager;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Samples/SampleClient/Top10Listener.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Diagnostics;
3 | using System.IO;
4 |
5 | namespace ClientSample
6 | {
7 | ///
8 | /// Keeps track of the X most recent number of events recorded by the listener. X is specified in the constructor
9 | ///
10 | public class Top10Listener : TraceListener
11 | {
12 | private readonly int capacity;
13 | private readonly LinkedList traces;
14 |
15 | public Top10Listener (int capacity)
16 | {
17 | this.capacity = capacity;
18 | this.traces = new LinkedList ();
19 | }
20 |
21 | public override void Write (string message)
22 | {
23 | lock (traces)
24 | traces.Last.Value += message;
25 | }
26 |
27 | public override void WriteLine (string message)
28 | {
29 | lock (traces) {
30 | if (traces.Count >= capacity)
31 | traces.RemoveFirst ();
32 |
33 | traces.AddLast (message);
34 | }
35 | }
36 |
37 | public void ExportTo (TextWriter output)
38 | {
39 | lock (traces)
40 | foreach (string s in this.traces)
41 | output.WriteLine (s);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/VersionInfoTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using NUnit.Framework;
4 |
5 | namespace MonoTorrent.Common
6 | {
7 | [TestFixture]
8 | public class VersionInfoTests
9 | {
10 | [Test]
11 | public void ValidVersionNumber ()
12 | {
13 | GitInfoHelper.Initialize (new Version (1, 2, 3));
14 | Assert.AreEqual (GitInfoHelper.ClientIdentifier + "1203", GitInfoHelper.ClientVersion);
15 | Assert.AreEqual (GitInfoHelper.DhtClientVersion, GitInfoHelper.ClientVersion);
16 | }
17 |
18 | [Test]
19 | public void MajorTooLarge ()
20 | {
21 | Assert.Throws (() => GitInfoHelper.Initialize (new Version (10, 2, 3)));
22 | }
23 |
24 | [Test]
25 | public void MinorTooLarge ()
26 | {
27 | Assert.Throws (() => GitInfoHelper.Initialize (new Version (1, 10, 3)));
28 | }
29 |
30 | [Test]
31 | public void BuildMissing ()
32 | {
33 | Assert.Throws (() => GitInfoHelper.Initialize (new Version (1, 2)));
34 | }
35 |
36 | [Test]
37 | public void BuildTooLarge ()
38 | {
39 | Assert.Throws (() => GitInfoHelper.Initialize (new Version (1, 10, 100)));
40 | }
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/src/ICacheable.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ICacheable.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent
31 | {
32 | internal interface ICacheable
33 | {
34 | void Initialise();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Factories/MonoTorrent.Factories.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net5.0;netcoreapp3.0;netstandard2.1;netstandard2.0;net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.PortForwarding/Protocol.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Protocol.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2020 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | namespace MonoTorrent.PortForwarding
30 | {
31 | public enum Protocol
32 | {
33 | Tcp,
34 | Udp
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Unchokers/IUnchoker.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IUnchoker.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client
31 | {
32 | interface IUnchoker
33 | {
34 | void UnchokeReview ();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Dht/DhtState.cs:
--------------------------------------------------------------------------------
1 | //
2 | // DhtState.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Dht
31 | {
32 | public enum DhtState
33 | {
34 | NotReady,
35 | Initialising,
36 | Ready
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages.Peer.FastPeer/IFastPeerMessage.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IFastPeerMessage.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Messages.Peer.FastPeer
31 | {
32 | public interface IFastPeerMessage
33 | {
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections.Dht/IDhtListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IDhtListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Connections.Dht
31 | {
32 | public interface IDhtListener : ISocketMessageListener
33 | {
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht/NodeState.cs:
--------------------------------------------------------------------------------
1 | //
2 | // NodeState.cs
3 | //
4 | // Authors:
5 | // Jérémie Laval
6 | //
7 | // Copyright (C) 2008 Jérémie Laval
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | namespace MonoTorrent.Dht
30 | {
31 | enum NodeState
32 | {
33 | Unknown,
34 | Good,
35 | Questionable,
36 | Bad
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/SemaphoreLocked.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 |
8 | using ReusableTasks;
9 |
10 | namespace MonoTorrent
11 | {
12 | class SemaphoreLocked
13 | {
14 | internal static SemaphoreLocked Create (T value)
15 | {
16 | return SemaphoreLocked.Create (value);
17 | }
18 | }
19 |
20 | class SemaphoreLocked
21 | {
22 | ReusableSemaphore Locker = new ReusableSemaphore (1);
23 |
24 | T Value { get; }
25 |
26 | internal static SemaphoreLocked Create (T value)
27 | {
28 | return new SemaphoreLocked (value);
29 | }
30 |
31 | SemaphoreLocked (T value)
32 | {
33 | Value = value;
34 | }
35 |
36 | public async ReusableTask EnterAsync ()
37 | {
38 | return new Accessor (Value, await Locker.EnterAsync ());
39 | }
40 |
41 | public readonly struct Accessor : IDisposable
42 | {
43 | public T Value { get; }
44 | ReusableSemaphore.Releaser InnerReleaser { get; }
45 |
46 | internal Accessor (T value, ReusableSemaphore.Releaser releaser)
47 | => (Value, InnerReleaser) = (value, releaser);
48 |
49 | public void Dispose ()
50 | => InnerReleaser.Dispose ();
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent/TorrentEvent.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentEvent.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2021 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent
31 | {
32 | public enum TorrentEvent
33 | {
34 | None,
35 | Started,
36 | Stopped,
37 | Completed
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Trackers/MonoTorrent.Client.Messages.UdpTracker/MessageType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // MessageType.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Messages.UdpTracker
31 | {
32 | public enum MessageType
33 | {
34 | Request,
35 | Response
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent/HashesTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | using NUnit.Framework;
5 |
6 | namespace MonoTorrent.Common
7 | {
8 | [TestFixture]
9 | public class HashesTests
10 | {
11 | IPieceHashes Hashes { get; set; }
12 |
13 | [SetUp]
14 | public void Setup ()
15 | {
16 | Hashes = new PieceHashesV1 (new byte[20 * 10], 20);
17 | }
18 |
19 | [Test]
20 | public void IsValid_DoesNotMatch ()
21 | {
22 | var other = new PieceHash (Enumerable.Repeat ((byte) 20, 20).ToArray (), default);
23 | Assert.IsFalse (Hashes.IsValid (other, 0));
24 | }
25 |
26 | [Test]
27 | public void IsValid_InvalidIndex ()
28 | {
29 | Assert.Throws (() => Hashes.IsValid (new PieceHash (new byte[20], default), -1));
30 | Assert.Throws (() => Hashes.IsValid (new PieceHash (new byte[20], default), Hashes.Count));
31 | }
32 |
33 | [Test]
34 | public void IsValid_Matches ()
35 | {
36 | Assert.IsTrue (Hashes.IsValid (new PieceHash (new byte[20]), 0));
37 | }
38 |
39 | [Test]
40 | public void Read_InvalidIndex ()
41 | {
42 | Assert.Throws (() => Hashes.GetHash (-1));
43 | Assert.Throws (() => Hashes.GetHash (Hashes.Count));
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections/ISocketListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ISocketListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.Net;
31 |
32 | namespace MonoTorrent.Connections
33 | {
34 | public interface ISocketListener : IListener
35 | {
36 | IPEndPoint? LocalEndPoint { get; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Logging/ILogger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ILogger.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2024 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Logging
31 | {
32 | public interface ILogger
33 | {
34 | void Info (string message);
35 | void Debug (string message);
36 | void Error (string message);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent/Priority.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Enums.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | namespace MonoTorrent
30 | {
31 | public enum Priority
32 | {
33 | DoNotDownload = 0,
34 | Lowest = 1,
35 | Low = 2,
36 | Normal = 4,
37 | High = 8,
38 | Highest = 16,
39 | Immediate = 32
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/ITorrentFileSource.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ITorrentFileSource.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.Collections.Generic;
31 |
32 | namespace MonoTorrent
33 | {
34 | public interface ITorrentFileSource
35 | {
36 | IEnumerable Files { get; }
37 | string TorrentName { get; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.BEncoding/MemoryExtensionsTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | using NUnit.Framework;
9 |
10 | using MonoTorrent;
11 |
12 | namespace MonoTorrent.BEncoding
13 | {
14 | [TestFixture]
15 | public class MemoryExtensionsTests
16 | {
17 | [Test]
18 | public void HashLargeBuffer ()
19 | {
20 | var buffer = new byte[12345];
21 | new Random ().NextBytes (buffer);
22 |
23 | var hash = SHA1.Create ().ComputeHash (buffer);
24 |
25 | byte[] destination = new byte[20];
26 | SHA1.Create ().TryComputeHash (buffer, destination, out int written);
27 | Assert.AreEqual (20, written);
28 | Assert.IsTrue (hash.AsSpan ().SequenceEqual (destination.AsSpan ()));
29 | }
30 |
31 | [Test]
32 | public void IncrementalHashLargeBuffer ()
33 | {
34 | var buffer = new byte[12345];
35 | new Random ().NextBytes (buffer);
36 |
37 | var hasher = IncrementalHash.CreateHash (HashAlgorithmName.SHA1);
38 | hasher.AppendData (buffer, 0, 11345);
39 | var hash = hasher.GetHashAndReset ();
40 |
41 | hasher.AppendData (new Memory (buffer).Span.Slice (0, 11345));
42 | byte[] destination = hasher.GetHashAndReset ();
43 |
44 | Assert.IsTrue (hash.AsSpan ().SequenceEqual (destination.AsSpan ()));
45 |
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/ITrackerRequestFactory.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ITrackerRequestFactory.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Trackers
31 | {
32 | interface ITrackerRequestFactory
33 | {
34 | AnnounceRequest CreateAnnounce (TorrentEvent clientEvent);
35 | ScrapeRequest CreateScrape ();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Logging/IRootLogger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IRootLogger.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2020 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Logging
31 | {
32 | public interface IRootLogger
33 | {
34 | void Info (string name, string message);
35 | void Debug (string name, string message);
36 | void Error (string name, string message);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client/PeerExchangeManagerTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | using MonoTorrent.BEncoding;
7 | using MonoTorrent.Messages.Peer.Libtorrent;
8 |
9 | using NUnit.Framework;
10 |
11 | namespace MonoTorrent.Client
12 | {
13 | [TestFixture]
14 | public class PeerExchangeManagerTests
15 | {
16 | class PeerExchangeSource : IPeerExchangeSource
17 | {
18 | public TorrentSettings Settings { get; } = new TorrentSettings ();
19 | }
20 |
21 | byte counter = 0;
22 | PeerId CreatePeer () => PeerId.CreateNull (10, new InfoHash (Enumerable.Repeat (counter++, 20).ToArray ()));
23 |
24 | [Test]
25 | public async Task TestPeerExchangeManager ()
26 | {
27 | var peer = CreatePeer ();
28 | var pex = new PeerExchangeManager (new PeerExchangeSource (), peer);
29 |
30 | await ClientEngine.MainLoop;
31 |
32 | pex.OnAdd (CreatePeer ());
33 | pex.OnAdd (CreatePeer ());
34 | pex.OnAdd (CreatePeer ());
35 | pex.OnAdd (CreatePeer ());
36 | pex.OnDrop (CreatePeer ());
37 | pex.OnDrop (CreatePeer ());
38 |
39 | pex.OnTick ();
40 |
41 | var message = (PeerExchangeMessage) peer.MessageQueue.TryDequeue ();
42 | Assert.AreEqual (4 * 6, message.Added.Length);
43 | Assert.AreEqual (4, message.AddedDotF.Length);
44 | Assert.AreEqual (2 * 6, message.Dropped.Length);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections/IListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Connections
33 | {
34 | public interface IListener
35 | {
36 | event EventHandler StatusChanged;
37 |
38 | ListenerStatus Status { get; }
39 |
40 | void Start ();
41 | void Stop ();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Trackers/ScrapeRequest.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ScrapeRequest.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Trackers
31 | {
32 | public sealed class ScrapeRequest
33 | {
34 | public InfoHashes InfoHashes { get; }
35 |
36 | public ScrapeRequest (InfoHashes infoHashes)
37 | {
38 | InfoHashes = infoHashes;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/AnnounceEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // AnnounceEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.TrackerServer
31 | {
32 | public sealed class AnnounceEventArgs : PeerEventArgs
33 | {
34 | public AnnounceEventArgs (Peer peer, ITrackerItem torrent)
35 | : base (peer, torrent)
36 | {
37 |
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/TimedOutEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TimedOutEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.TrackerServer
31 | {
32 | public sealed class TimedOutEventArgs : PeerEventArgs
33 | {
34 | public TimedOutEventArgs (Peer peer, ITrackerItem torrent)
35 | : base (peer, torrent)
36 | {
37 |
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Connections/MonoTorrent.Connections.Dht/DhtListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // DhtListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.Net;
31 |
32 | namespace MonoTorrent.Connections.Dht
33 | {
34 | public class DhtListener : UdpListener, IDhtListener
35 | {
36 | public DhtListener (IPEndPoint endpoint)
37 | : base (endpoint)
38 | {
39 |
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Unchokers/IUnchokeable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace MonoTorrent.Client
5 | {
6 | interface IUnchokeable
7 | {
8 | ///
9 | /// Raised whenever the torrent manager's state changes.
10 | ///
11 | event EventHandler StateChanged;
12 |
13 | ///
14 | /// True if we are currently seeding.
15 | ///
16 | bool Seeding { get; }
17 |
18 | ///
19 | /// Download speed in bytes/second.
20 | ///
21 | long DownloadSpeed { get; }
22 |
23 | ///
24 | /// Upload speed in bytes/second.
25 | ///
26 | long UploadSpeed { get; }
27 |
28 | ///
29 | /// Maximum download speed in bytes/second.
30 | ///
31 | long MaximumDownloadSpeed { get; }
32 |
33 | ///
34 | /// Maximum upload speed in bytes/second
35 | ///
36 | long MaximumUploadSpeed { get; }
37 |
38 | ///
39 | /// The maximum number of peers which can be unchoked concurrently. 0 means unlimited.
40 | ///
41 | int UploadSlots { get; }
42 |
43 | ///
44 | /// The number of peers which are currently unchoked.
45 | ///
46 | int UploadingTo { get; set; }
47 |
48 | ///
49 | /// List of peers which can be choked/unchoked
50 | ///
51 | List Peers { get; }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Connections.Peer.Encryption/IEncryption.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IEncryption.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Connections.Peer.Encryption
33 | {
34 | interface IEncryption
35 | {
36 | void Decrypt (Span buffer);
37 |
38 | void Encrypt (Span buffer);
39 |
40 | EncryptionType EncryptionType { get; }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages/IMessage.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IMessage.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Messages
33 | {
34 | public interface IMessage
35 | {
36 | int ByteLength { get; }
37 |
38 | ReadOnlyMemory Encode ();
39 |
40 | int Encode (Span buffer);
41 |
42 | void Decode (ReadOnlySpan buffer);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/PeerEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | namespace MonoTorrent.Client
30 | {
31 | class PeerEventArgs : TorrentEventArgs
32 | {
33 | public PeerId Peer { get; }
34 |
35 | public PeerEventArgs (TorrentManager manager, PeerId peer)
36 | : base (manager)
37 | {
38 | Peer = peer;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/ScrapeResponseEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ScrapeResponseEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Trackers
31 | {
32 | public class ScrapeResponseEventArgs : TrackerResponseEventArgs
33 | {
34 | public ScrapeResponseEventArgs (ITracker tracker, bool successful)
35 | : base (tracker, successful)
36 | {
37 |
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht/MessageException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // MessageException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Dht
33 | {
34 | class MessageException : Exception
35 | {
36 | public ErrorCode ErrorCode { get; }
37 |
38 | public MessageException (ErrorCode errorCode, string message) : base (message)
39 | {
40 | ErrorCode = errorCode;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/TorrentEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Client
33 | {
34 | public class TorrentEventArgs : EventArgs
35 | {
36 | public TorrentManager TorrentManager { get; }
37 |
38 | protected TorrentEventArgs (TorrentManager manager)
39 | {
40 | TorrentManager = manager;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TorrentWatchers/ITorrentWatcher.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentWatcher.cs
3 | //
4 | // Authors:
5 | // Stephane Zanoni stephane@ethernal.net
6 | //
7 | // Copyright (C) 2006 Stephane Zanoni
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System;
30 | namespace MonoTorrent.TorrentWatcher
31 | {
32 | public interface ITorrentWatcher
33 | {
34 | event EventHandler TorrentFound;
35 | event EventHandler TorrentLost;
36 |
37 | void Start ();
38 | void Stop ();
39 | void ForceScan ();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/MonoTorrent.BEncoding/RawInfoHashes.cs:
--------------------------------------------------------------------------------
1 | //
2 | // InfoHashes.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2022 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.BEncoding
33 | {
34 | public readonly struct RawInfoHashes
35 | {
36 | public ReadOnlyMemory SHA1 { get; }
37 | public ReadOnlyMemory SHA256 { get; }
38 |
39 | internal RawInfoHashes (ReadOnlyMemory sha1, ReadOnlyMemory sha256)
40 | => (SHA1, SHA256) = (sha1, sha256);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/IDisposableExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IDisposableExtensions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent
33 | {
34 | static class IDisposableExtensions
35 | {
36 | public static void SafeDispose (this IDisposable disposable)
37 | {
38 | try {
39 | disposable?.Dispose ();
40 | } catch {
41 | // Ignore
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections/ISocketMessageListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ISocketMessageListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Net;
32 | using System.Threading.Tasks;
33 |
34 | namespace MonoTorrent.Connections
35 | {
36 | public interface ISocketMessageListener : ISocketListener
37 | {
38 | event Action, IPEndPoint> MessageReceived;
39 |
40 | Task SendAsync (ReadOnlyMemory buffer, IPEndPoint endpoint);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/VersionInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // VersionInfo.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent
33 | {
34 | public static class VersionInfo
35 | {
36 | ///
37 | /// The full version of this library in the form 'A.B.C'.
38 | /// 'A' and 'B' are guaranteed to be 1 digit each. 'C' can be one or two digits.
39 | ///
40 | public static readonly Version Version = GitInfoHelper.Version;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent/BitOpsTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Numerics;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | using NUnit.Framework;
9 |
10 | namespace MonoTorrent
11 | {
12 | [TestFixture]
13 | public class BitOpsTests
14 | {
15 | [Test]
16 | public void CeilLog2_int ()
17 | {
18 | for (int i = 0; i < 31; i++)
19 | Assert.AreEqual (i, BitOps.CeilLog2 (1 << i));
20 |
21 | Assert.AreEqual (31, BitOps.CeilLog2 (Int32.MaxValue));
22 | }
23 |
24 | [Test]
25 | public void CeilLog2_uint ()
26 | {
27 | for (int i = 0; i < 32; i++)
28 | Assert.AreEqual (i, BitOps.CeilLog2 (1u << i));
29 |
30 | Assert.AreEqual (32, BitOps.CeilLog2 (UInt32.MaxValue));
31 | }
32 |
33 | [Test]
34 | public void CeilLog2_ulong ()
35 | {
36 | for (int i = 0; i < 64; i++)
37 | Assert.AreEqual (i, BitOps.CeilLog2 (1ul << i));
38 |
39 | Assert.AreEqual (64, BitOps.CeilLog2 (UInt64.MaxValue));
40 | }
41 |
42 | [Test]
43 | public void CeilLog10_long ()
44 | {
45 | for (int i = 0; i < 63; i++)
46 | Assert.AreEqual ((1L << i).ToString ().Length - 1, BitOps.CeilLog10 ((1L << i)));
47 |
48 | Assert.AreEqual (0, BitOps.CeilLog10 ((1u << 64)));
49 | }
50 |
51 | [Test]
52 | public void RoundUpToNextPowerOfTwo ()
53 | {
54 | for (int i = 0; i < 31; i++)
55 | Assert.AreEqual ((1u << (i + 1)), BitOps.RoundUpToPowerOf2 ((1 << i) + 1));
56 |
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/DhtPeersAdded.cs:
--------------------------------------------------------------------------------
1 | //
2 | // DhtPeersAdded.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client
31 | {
32 | ///
33 | /// Indicates peers were received using DHT
34 | ///
35 | public sealed class DhtPeersAdded : PeersAddedEventArgs
36 | {
37 | public DhtPeersAdded (TorrentManager manager, int peersAdded, int total)
38 | : base (manager, peersAdded, total)
39 | {
40 |
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Connections.Peer.Encryption/RC4Header.cs:
--------------------------------------------------------------------------------
1 | //
2 | // RC4Header.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Connections.Peer.Encryption
33 | {
34 | class RC4Header : IEncryption
35 | {
36 | public EncryptionType EncryptionType => EncryptionType.RC4Header;
37 |
38 | public void Decrypt (Span buffer)
39 | {
40 | }
41 |
42 | public void Encrypt (Span buffer)
43 | {
44 | }
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/PeerEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.TrackerServer
33 | {
34 | public abstract class PeerEventArgs : EventArgs
35 | {
36 | public Peer Peer { get; }
37 | public ITrackerItem Torrent { get; }
38 |
39 | protected PeerEventArgs (Peer peer, ITrackerItem torrent)
40 | {
41 | Peer = peer;
42 | Torrent = torrent;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/LocalPeersAdded.cs:
--------------------------------------------------------------------------------
1 | //
2 | // LocalPeersAdded.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client
31 | {
32 | ///
33 | /// Indicates peers were received from Local Peer Discovery
34 | ///
35 | public sealed class LocalPeersAdded : PeersAddedEventArgs
36 | {
37 | public LocalPeersAdded (TorrentManager manager, int peersAdded, int total)
38 | : base (manager, peersAdded, total)
39 | {
40 |
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/ScrapeEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ScrapeEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 |
33 | namespace MonoTorrent.TrackerServer
34 | {
35 | public class ScrapeEventArgs : EventArgs
36 | {
37 | public IList Torrents { get; }
38 |
39 | public ScrapeEventArgs (List torrents)
40 | {
41 | Torrents = new List (torrents).AsReadOnly ();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht.Messages/PingResponse.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PingResponse.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using MonoTorrent.BEncoding;
31 |
32 | namespace MonoTorrent.Dht.Messages
33 | {
34 | sealed class PingResponse : ResponseMessage
35 | {
36 | public PingResponse (NodeId id, BEncodedValue transactionId)
37 | : base (id, transactionId)
38 | {
39 | }
40 |
41 | public PingResponse (BEncodedDictionary d)
42 | : base (d)
43 | {
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections.Peer/LocalPeerFoundEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // LocalPeerFoundEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Jared Hendry
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Connections.Peer
33 | {
34 | public class LocalPeerFoundEventArgs : EventArgs
35 | {
36 | public InfoHash InfoHash { get; }
37 | public Uri Uri { get; }
38 |
39 | public LocalPeerFoundEventArgs (InfoHash infoHash, Uri uri)
40 | {
41 | InfoHash = infoHash;
42 | Uri = uri;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent/ITorrentManagerInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ITorrentManagerInfo.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.Collections.Generic;
31 |
32 | namespace MonoTorrent
33 | {
34 | public interface ITorrentManagerInfo
35 | {
36 | ///
37 | /// The files contained within the Torrent
38 | ///
39 | IList Files { get; }
40 |
41 | InfoHashes InfoHashes { get; }
42 |
43 | string Name { get; }
44 |
45 | ITorrentInfo? TorrentInfo { get; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client/TorrentSettingsTests.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentSettingsTests.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2021 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using NUnit.Framework;
31 |
32 | namespace MonoTorrent.Client
33 | {
34 | [TestFixture]
35 | public class TorrentSettingsTests
36 | {
37 | [Test]
38 | public void EncodeDecode ()
39 | {
40 | var value = Serializer.DeserializeTorrentSettings (Serializer.Serialize (new TorrentSettings ()));
41 | Assert.AreEqual (value, new TorrentSettings ());
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Connections.Peer.Encryption/IEncryptor.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IEncryptor.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | using ReusableTasks;
33 |
34 | namespace MonoTorrent.Connections.Peer.Encryption
35 | {
36 | interface IEncryptor : IDisposable
37 | {
38 | ReusableTask HandshakeAsync (IPeerConnection socket);
39 |
40 | ReusableTask HandshakeAsync (IPeerConnection socket, Memory initialBuffer);
41 |
42 | IEncryption? Encryptor { get; }
43 | IEncryption? Decryptor { get; }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Trackers/MonoTorrent.Client.Messages.UdpTracker/ScrapeDetails.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ScrapeDetails.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Messages.UdpTracker
31 | {
32 | public class ScrapeDetails
33 | {
34 | public int Complete { get; }
35 | public int Leeches { get; }
36 | public int Seeds { get; }
37 |
38 | public ScrapeDetails (int seeds, int leeches, int complete)
39 | {
40 | Complete = complete;
41 | Leeches = leeches;
42 | Seeds = seeds;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Error.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Error.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Client
33 | {
34 | public enum Reason
35 | {
36 | ReadFailure,
37 | WriteFailure
38 | }
39 |
40 | public class Error
41 | {
42 | public Exception Exception { get; }
43 | public Reason Reason { get; }
44 |
45 | public Error (Reason reason, Exception exception)
46 | {
47 | Reason = reason;
48 | Exception = exception;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Dht/IDht.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IDht.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2022 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 | using System;
29 | using System.Collections.Generic;
30 | using System.Text;
31 |
32 | using MonoTorrent.Dht;
33 |
34 | namespace MonoTorrent.Client
35 | {
36 | public interface IDht
37 | {
38 | event EventHandler StateChanged;
39 |
40 | ITransferMonitor Monitor { get; }
41 |
42 | int NodeCount { get; }
43 |
44 | DhtState State { get; }
45 |
46 | TimeSpan AnnounceInterval { get; }
47 |
48 | TimeSpan MinimumAnnounceInterval { get; }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht/TransactionId.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TransactionId.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System.Threading;
30 |
31 | using MonoTorrent.BEncoding;
32 |
33 | namespace MonoTorrent.Dht
34 | {
35 | static class TransactionId
36 | {
37 | static int current;
38 |
39 | public static BEncodedString NextId ()
40 | {
41 | int value = Interlocked.Increment (ref current);
42 | byte[] data = new[] { (byte) (value >> 8), (byte) value };
43 | return BEncodedString.FromMemory (data);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Dht/MonoTorrent.Dht.Messages/AnnouncePeerResponse.cs:
--------------------------------------------------------------------------------
1 | //
2 | // AnnouncePeerResponse.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using MonoTorrent.BEncoding;
31 |
32 | namespace MonoTorrent.Dht.Messages
33 | {
34 | sealed class AnnouncePeerResponse : ResponseMessage
35 | {
36 | public AnnouncePeerResponse (NodeId id, BEncodedValue transactionId)
37 | : base (id, transactionId)
38 | {
39 |
40 | }
41 |
42 | public AnnouncePeerResponse (BEncodedDictionary d)
43 | : base (d)
44 | {
45 |
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections.TrackerServer/ITrackerListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ITrackerListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | using MonoTorrent.TrackerServer;
33 |
34 | namespace MonoTorrent.Connections.TrackerServer
35 | {
36 | ///
37 | /// Listens for incoming Announce or Scrape requests and sends the response back.
38 | ///
39 | public interface ITrackerListener : IListener, IDisposable
40 | {
41 | event EventHandler ScrapeReceived;
42 | event EventHandler AnnounceReceived;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Trackers/MonoTorrent.Trackers/TrackerException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TrackerException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Trackers
33 | {
34 | public class TrackerException : Exception
35 | {
36 | public TrackerException ()
37 | {
38 | }
39 |
40 | public TrackerException (string message)
41 | : base (message)
42 | {
43 | }
44 |
45 |
46 | public TrackerException (string message, Exception innerException)
47 | : base (message, innerException)
48 | {
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Logging/NullLogger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // NullLogger.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2024 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 | using System.Linq;
33 | using System.Text;
34 | using System.Threading.Tasks;
35 |
36 | namespace MonoTorrent.Logging
37 | {
38 | class NullLogger : IRootLogger
39 | {
40 | public void Debug (string name, string message)
41 | {
42 | }
43 |
44 | public void Error (string name, string message)
45 | {
46 | }
47 |
48 | public void Info (string name, string message)
49 | {
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/ITrackable.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IPAddressComparer.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.TrackerServer
31 | {
32 | ///
33 | /// The tracker monitors peers for any ITrackable item
34 | ///
35 | public interface ITrackable
36 | {
37 | ///
38 | /// The infohash of the torrent being tracked
39 | ///
40 | InfoHash InfoHash { get; }
41 |
42 | ///
43 | /// The name of the torrent being tracked
44 | ///
45 | string Name { get; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.RateLimiters/UnlimitedRateLimiter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // UnlimitedRateLimiter.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client.RateLimiters
31 | {
32 | sealed class UnlimitedRateLimiter : IRateLimiter
33 | {
34 | public static readonly IRateLimiter Instance = new UnlimitedRateLimiter ();
35 |
36 | UnlimitedRateLimiter ()
37 | {
38 | }
39 |
40 | public int? PreferredChunkSize => null;
41 |
42 | public bool Unlimited => true;
43 |
44 | public bool TryProcess (long amount)
45 | {
46 | return true;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Dht/PeersFoundEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeersFoundEventArgs.cs
3 | //
4 | // Authors:
5 | // Olivier Dufour
6 | //
7 | // Copyright (C) 2008 Olivier Dufour
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 | using System.Collections.ObjectModel;
33 |
34 | namespace MonoTorrent.Dht
35 | {
36 | public class PeersFoundEventArgs : EventArgs
37 | {
38 | public IList Peers { get; }
39 | public InfoHash InfoHash { get; }
40 |
41 | public PeersFoundEventArgs (InfoHash infoHash, IList peers)
42 | {
43 | InfoHash = infoHash;
44 | Peers = new ReadOnlyCollection (peers);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Trackers/ScrapeResponse.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ScrapeResponse.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System.Collections.Generic;
30 |
31 | namespace MonoTorrent.Trackers
32 | {
33 | public class ScrapeResponse : TrackerResponse
34 | {
35 | public ScrapeResponse (
36 | TrackerState state,
37 | Dictionary? scrapeInfo = null,
38 | string warningMessage = "",
39 | string failureMessage = ""
40 | )
41 | : base (state, scrapeInfo ?? new Dictionary (), warningMessage, failureMessage)
42 | {
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages.Peer.Libtorrent/ExtensionSupport.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ExtensionSupport.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Messages.Peer.Libtorrent
31 | {
32 | public struct ExtensionSupport
33 | {
34 | public byte MessageId { get; }
35 | public string Name { get; }
36 |
37 | public ExtensionSupport (string name, byte messageId)
38 | {
39 | MessageId = messageId;
40 | Name = name;
41 | }
42 |
43 | public override string ToString ()
44 | {
45 | return string.Format ("{1}: {0}", Name, MessageId);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.RateLimiters/PauseLimiter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PauseLimiter.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client.RateLimiters
31 | {
32 | sealed class PauseLimiter : IRateLimiter
33 | {
34 | readonly TorrentManager manager;
35 |
36 | public int? PreferredChunkSize => null;
37 |
38 | public bool Unlimited => manager.State != TorrentState.Paused;
39 |
40 | public PauseLimiter (TorrentManager manager)
41 | {
42 | this.manager = manager;
43 | }
44 |
45 | public bool TryProcess (long amount)
46 | {
47 | return Unlimited;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/PeerDisconnectedEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerConnectionEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client
31 | {
32 | ///
33 | /// Used by the event
34 | ///
35 | public sealed class PeerDisconnectedEventArgs : TorrentEventArgs
36 | {
37 | ///
38 | /// The peer whose connection was terminated.
39 | ///
40 | public PeerId Peer { get; }
41 |
42 | internal PeerDisconnectedEventArgs (TorrentManager manager, PeerId id)
43 | : base (manager)
44 | {
45 | Peer = id;
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent/ByteBufferPool.ByteBuffer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ByteBufferPool.ByteBuffer.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Net.Sockets;
32 |
33 | namespace MonoTorrent
34 | {
35 | public partial class ByteBufferPool
36 | {
37 | internal sealed class ByteBuffer
38 | {
39 | // Used to prevent double-frees
40 | internal int Counter { get; set; }
41 |
42 | public Memory Memory => Segment.AsMemory ();
43 |
44 | public ArraySegment Segment { get; private set; }
45 |
46 | public ByteBuffer (ArraySegment segment)
47 | {
48 | Segment = segment;
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/TrackerPeersAdded.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TrackerPeersAdded.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System;
30 |
31 | using MonoTorrent.Trackers;
32 |
33 | namespace MonoTorrent.Client
34 | {
35 | ///
36 | /// Indicates peers were received from a Tracker
37 | ///
38 | public sealed class TrackerPeersAdded : PeersAddedEventArgs
39 | {
40 | public ITracker Tracker { get; }
41 |
42 | internal TrackerPeersAdded (TorrentManager manager, int peersAdded, int total, ITracker tracker)
43 | : base (manager, peersAdded, total)
44 | {
45 | Tracker = tracker ?? throw new ArgumentNullException (nameof (tracker));
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/Enums.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Enums.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client
31 | {
32 | public enum TorrentState
33 | {
34 | Stopped,
35 | Paused,
36 | Starting,
37 | Downloading,
38 | Seeding,
39 | Hashing,
40 | HashingPaused,
41 | Stopping,
42 | Error,
43 | Metadata,
44 | FetchingHashes
45 | }
46 | }
47 |
48 | namespace MonoTorrent
49 | {
50 | public enum Direction
51 | {
52 | None,
53 | Incoming,
54 | Outgoing
55 | }
56 |
57 | enum PeerListType
58 | {
59 | NascentPeers,
60 | CandidatePeers,
61 | OptimisticUnchokeCandidatePeers
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // StringExtensions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Text;
32 | using System.Web;
33 |
34 | namespace MonoTorrent
35 | {
36 | static class StringExtensions
37 | {
38 | static readonly Encoding UTF8 = Encoding.UTF8;
39 |
40 | public static string UrlEncodeQueryUTF8 (this string str)
41 | => HttpUtility.UrlEncode (str, UTF8).Replace("+", "%20");
42 |
43 | public static string UrlEncodeUTF8 (this string str)
44 | => HttpUtility.UrlEncode (str, UTF8);
45 |
46 | public static string UrlDecodeUTF8 (this string str)
47 | => HttpUtility.UrlDecode (str, Encoding.UTF8);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/IPieceHashes.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IPieceHashes.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2022 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Diagnostics.CodeAnalysis;
32 |
33 | namespace MonoTorrent
34 | {
35 | public interface IPieceHashes
36 | {
37 | int Count { get; }
38 | bool HasV1Hashes { get; }
39 | bool HasV2Hashes { get; }
40 |
41 | ReadOnlyPieceHash GetHash (int hashIndex);
42 | bool IsValid (ReadOnlyPieceHash hashes, int hashIndex);
43 | bool TryGetV2Hashes (MerkleRoot piecesRoot, [NotNullWhen (true)] out ReadOnlyMerkleTree? merkleTree);
44 | bool TryGetV2Hashes (MerkleRoot piecesRoot, int layer, int index, int count, int proofCount, Span hashesAndProofsBuffer, out int bytesWritten);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Connections/MonoTorrent.Connections/SocketListener.cs:
--------------------------------------------------------------------------------
1 | //
2 | // SocketListener.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.Net;
31 | using System.Threading;
32 |
33 | namespace MonoTorrent.Connections
34 | {
35 | public abstract class SocketListener : Listener, ISocketListener
36 | {
37 | public IPEndPoint? LocalEndPoint { get; protected set; }
38 |
39 | public IPEndPoint PreferredLocalEndPoint { get; set; }
40 |
41 | protected SocketListener (IPEndPoint endPoint)
42 | {
43 | PreferredLocalEndPoint = endPoint;
44 | }
45 |
46 | protected override void Start (CancellationToken token)
47 | {
48 | token.Register (() => LocalEndPoint = null);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client/MainLoopTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | using NUnit.Framework;
5 |
6 | namespace MonoTorrent.Client
7 | {
8 | [TestFixture]
9 | public class MainLoopTests
10 | {
11 | private int count;
12 | MainLoop loop;
13 |
14 | [OneTimeSetUp]
15 | public void FixtureSetup ()
16 | {
17 | loop = new MainLoop ("Test Loop");
18 | }
19 |
20 | [OneTimeTearDown]
21 | public void FixtureTeardown ()
22 | {
23 | //loop.Dispose();
24 | }
25 |
26 | [SetUp]
27 | public void Setup ()
28 | {
29 | count = 0;
30 | }
31 |
32 | [Test]
33 | public void RepeatedTask ()
34 | {
35 | //Console.WriteLine("Starting");
36 | ManualResetEvent handle = new ManualResetEvent (false);
37 | loop.QueueTimeout (TimeSpan.FromMilliseconds (0), delegate {
38 | this.count++;
39 | if (count == 3) {
40 | handle.Set ();
41 | return false;
42 | }
43 |
44 | return true;
45 | });
46 | Assert.IsTrue (handle.WaitOne (5000, true), "#1: Executed {0} times", count);
47 | Assert.AreEqual (3, count, "#2");
48 | }
49 |
50 | [Test]
51 | public void LongRunningTask ()
52 | {
53 | ManualResetEvent handle = new ManualResetEvent (false);
54 | loop.QueueTimeout (TimeSpan.FromMilliseconds (10), delegate {
55 | Thread.Sleep (50);
56 | if (++count == 3) {
57 | handle.Set ();
58 | return false;
59 | }
60 |
61 | return true;
62 | });
63 | Assert.IsTrue (handle.WaitOne (5000, false), "#1: Executed {0} times", count);
64 | Assert.AreEqual (3, count, "#2");
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.RateLimiters/DiskWriterLimiter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // DiskWriterLimiter.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client.RateLimiters
31 | {
32 | sealed class DiskWriterLimiter : IRateLimiter
33 | {
34 | // 4MB
35 | const int MaxPendingWriteBytes = 4 * 1024 * 1024;
36 |
37 | DiskManager Manager { get; }
38 |
39 | public int? PreferredChunkSize => null;
40 |
41 | public bool Unlimited => Manager.PendingWriteBytes < MaxPendingWriteBytes;
42 |
43 | public DiskWriterLimiter (DiskManager manager)
44 | {
45 | Manager = manager;
46 | }
47 |
48 | public bool TryProcess (long amount)
49 | {
50 | return Unlimited;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Connections.Peer/PeerConnectionEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerConnectionEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2021 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System;
30 |
31 | namespace MonoTorrent.Connections.Peer
32 | {
33 | public class PeerConnectionEventArgs : EventArgs
34 | {
35 | public IPeerConnection Connection { get; }
36 |
37 | public InfoHash? InfoHash { get; }
38 |
39 | public PeerConnectionEventArgs (IPeerConnection connection, InfoHash? infoHash)
40 | {
41 | if (!connection.IsIncoming && infoHash == null)
42 | throw new InvalidOperationException ("An outgoing connection must specify the torrent manager it belongs to");
43 |
44 | Connection = connection;
45 | InfoHash = infoHash;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Tests/Tests.MonoTorrent.Client/EnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // EnumerableExtensions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 | using System.Linq;
33 |
34 | namespace MonoTorrent
35 | {
36 | public static class EnumerableExtensions
37 | {
38 | public static IEnumerable Partition (this IEnumerable enumerable, int partitionSize)
39 | {
40 | var array = enumerable.ToArray ();
41 | for (int i = 0; i < array.Length; i += partitionSize) {
42 | var partition = new T[Math.Min (partitionSize, array.Length - i)];
43 | Array.Copy (array, i, partition, 0, partition.Length);
44 | yield return partition;
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client.RateLimiters/IRateLimiter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IRateLimiter.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.Client.RateLimiters
31 | {
32 | interface IRateLimiter
33 | {
34 | ///
35 | /// Returns true if there is sufficient capacity left in the rate limiter to
36 | /// process the specified amount of data. Also returns true if
37 | /// returns true.
38 | ///
39 | ///
40 | ///
41 | bool TryProcess (long amount);
42 |
43 | ///
44 | /// Returns true when the rate limiter is not actively enforcing a limit.
45 | ///
46 | bool Unlimited { get; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/PeerExchangePeersAdded.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerExchangeAdded.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2008 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Client
33 | {
34 | ///
35 | /// Indicates peers were received using Peer Exchange
36 | ///
37 | public sealed class PeerExchangePeersAdded : PeersAddedEventArgs
38 | {
39 | ///
40 | /// The peer who provided the list of additional peers.
41 | ///
42 | public PeerId Id { get; }
43 |
44 | public PeerExchangePeersAdded (TorrentManager manager, int count, int total, PeerId id)
45 | : base (manager, count, total)
46 | {
47 | Id = id ?? throw new ArgumentNullException (nameof (id));
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/PeerIdComparer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // PeerIdComparer.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.TrackerServer
31 | {
32 | ///
33 | /// Uses the field to compare peers when handling Announce or Scrape requests.
34 | ///
35 | public class PeerIdComparer : IPeerComparer
36 | {
37 | ///
38 | /// Returns the field to use to compare peers.
39 | ///
40 | /// The data sent as part of the Announce request
41 | ///
42 | public object GetKey (AnnounceRequest parameters)
43 | {
44 | return parameters.PeerId;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/ReadOnlyPieceHash.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ReadOnlyPieceHash.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2022 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent
33 | {
34 | public readonly struct ReadOnlyPieceHash
35 | {
36 | public ReadOnlyMemory V1Hash { get; }
37 | public ReadOnlyMemory V2Hash { get; }
38 |
39 | internal ReadOnlyPieceHash (ReadOnlyMemory v1Hash, ReadOnlyMemory v2Hash)
40 | {
41 | if (!v1Hash.IsEmpty && v1Hash.Length != 20)
42 | throw new ArgumentException ("V1 hashes must be 20 bytes long");
43 | if (!v2Hash.IsEmpty && v2Hash.Length != 32)
44 | throw new ArgumentNullException ("V2 hashes must be 32 bytes long");
45 |
46 | (V1Hash, V2Hash) = (v1Hash, v2Hash);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.PieceWriter/FileCreationOptions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // FileCreationOptions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2024 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.PieceWriter
31 | {
32 | public enum FileCreationOptions
33 | {
34 | ///
35 | /// On filesystems where sparse files can be created, an attempt will be made to create a sparse file.
36 | /// Otherwise an empty file will be created.
37 | ///
38 | PreferSparse,
39 | ///
40 | /// On filesystems which support preallocation the space required for the file will be reserved as soon
41 | /// as the file is created. Otherwise, a best effort to pre-allocate will be made by writing 1 byte at
42 | /// the end of the file.
43 | ///
44 | PreferPreallocation,
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Messages/MonoTorrent.Messages/MessageException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // MessageException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2007 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Messages
33 | {
34 | public class MessageException : Exception
35 | {
36 | public MessageException ()
37 | {
38 | }
39 |
40 |
41 | public MessageException (string message)
42 | : base (message)
43 | {
44 | }
45 |
46 |
47 | public MessageException (string message, Exception innerException)
48 | : base (message, innerException)
49 | {
50 | }
51 |
52 |
53 | public MessageException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
54 | : base (info, context)
55 | {
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/UdpClientExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // UdpClientExtensions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2024 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System;
30 | using System.Collections.Generic;
31 | using System.Linq;
32 | using System.Net;
33 | using System.Net.Sockets;
34 | using System.Text;
35 | using System.Threading.Tasks;
36 |
37 | namespace MonoTorrent
38 | {
39 | #if NET472 || NET5_0 || NET6_0 || NETCOREAPP3_0 || NETSTANDARD2_0 || NETSTANDARD2_1
40 | static class UdpClientExtensions
41 | {
42 | public static Task SendAsync (this UdpClient client, ReadOnlyMemory datagram, int bytes, IPEndPoint? endPoint)
43 | => client.SendAsync (datagram.ToArray (), bytes, endPoint);
44 |
45 | public static int Send (this UdpClient client, ReadOnlyMemory datagram, int bytes)
46 | => client.Send (datagram.ToArray (), bytes);
47 |
48 | }
49 | #endif
50 | }
51 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/EventArgs/AnnounceResponseEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // AnnounceResponseEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | using System;
30 | using System.Collections.Generic;
31 |
32 | namespace MonoTorrent.Trackers
33 | {
34 | public class AnnounceResponseEventArgs : TrackerResponseEventArgs
35 | {
36 | public IDictionary> Peers { get; }
37 |
38 | public AnnounceResponseEventArgs (ITracker tracker, bool successful)
39 | : this (tracker, successful, new Dictionary> ())
40 | {
41 |
42 | }
43 |
44 | public AnnounceResponseEventArgs (ITracker tracker, bool successful, Dictionary> peers)
45 | : base (tracker, successful)
46 | {
47 | Peers = peers;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/NewConnectionEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // NewConnectionEventArgs.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2019 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | using MonoTorrent.Connections.Peer;
33 |
34 | namespace MonoTorrent.Client
35 | {
36 | public class NewConnectionEventArgs : TorrentEventArgs
37 | {
38 | public IPeerConnection Connection { get; }
39 | public PeerInfo Peer { get; }
40 |
41 | public NewConnectionEventArgs (PeerInfo peer, IPeerConnection connection, TorrentManager manager)
42 | : base (manager)
43 | {
44 | if (!connection.IsIncoming && manager == null)
45 | throw new InvalidOperationException ("An outgoing connection must specify the torrent manager it belongs to");
46 |
47 | Connection = connection;
48 | Peer = peer;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/TorrentException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent
33 | {
34 | [Serializable]
35 | public class TorrentException : Exception
36 | {
37 | public TorrentException ()
38 | : base ()
39 | {
40 | }
41 |
42 | public TorrentException (string message)
43 | : base (message)
44 | {
45 | }
46 |
47 | public TorrentException (string message, Exception innerException)
48 | : base (message, innerException)
49 | {
50 | }
51 |
52 | public TorrentException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
53 | : base (info, context)
54 | {
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TrackerServer/ClientAddressComparer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ClientAddressComparer.cs
3 | //
4 | // Authors:
5 | // Alan McGovern
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent.TrackerServer
31 | {
32 | ///
33 | /// Uses the field to compare peers when handling Announce or Scrape requests.
34 | ///
35 | public class ClientAddressComparer : IPeerComparer
36 | {
37 | ///
38 | /// Returns the field to use to compare peers.
39 | ///
40 | /// The data sent as part of the Announce request
41 | ///
42 | public object GetKey (AnnounceRequest parameters)
43 | {
44 | return parameters.ClientAddress;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Trackers/TrackerState.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TrackerState.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2021 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 | namespace MonoTorrent.Trackers
30 | {
31 | public enum TrackerState
32 | {
33 | ///
34 | /// A request has not been sent yet.
35 | ///
36 | Unknown,
37 | ///
38 | /// Currently sending a request.
39 | ///
40 | Connecting,
41 | ///
42 | /// The most recent request completed successfully.
43 | ///
44 | Ok,
45 | ///
46 | /// The tracker was unreachable/offline.
47 | ///
48 | Offline,
49 | ///
50 | /// The tracker was reachable but the response it sent was invalid.
51 | ///
52 | InvalidResponse
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/TorrentType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentCreator.cs
3 | //
4 | // Authors:
5 | // Gregor Burger burger.gregor@gmail.com
6 | // Alan McGovern alan.mcgovern@gmail.com
7 | //
8 | // Copyright (C) 2006-2007 Gregor Burger and Alan McGovern
9 | //
10 | // Permission is hereby granted, free of charge, to any person obtaining
11 | // a copy of this software and associated documentation files (the
12 | // "Software"), to deal in the Software without restriction, including
13 | // without limitation the rights to use, copy, modify, merge, publish,
14 | // distribute, sublicense, and/or sell copies of the Software, and to
15 | // permit persons to whom the Software is furnished to do so, subject to
16 | // the following conditions:
17 | //
18 | // The above copyright notice and this permission notice shall be
19 | // included in all copies or substantial portions of the Software.
20 | //
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | //
29 |
30 | namespace MonoTorrent
31 | {
32 | public enum TorrentType
33 | {
34 | ///
35 | /// Generates a V1 compatible torrent.
36 | ///
37 | V1Only,
38 | ///
39 | /// A torrent file with BitTorrent V1 metadata. All files are padded so they align to piece boundaries.
40 | ///
41 | V1OnlyWithPaddingFiles,
42 | ///
43 | /// A torrent file with BitTorrent V1 and BitTorrent V2 metadata
44 | ///
45 | V1V2Hybrid,
46 | ///
47 | /// A torrent file with BitTorrent V2 metadata
48 | ///
49 | V2Only,
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Logging/TextWriterLogger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TextWriterLogger.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2020 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System.IO;
31 |
32 | namespace MonoTorrent.Logging
33 | {
34 | public class TextWriterLogger : IRootLogger
35 | {
36 | TextWriter Writer { get; }
37 |
38 | public TextWriterLogger (TextWriter writer)
39 | => Writer = writer;
40 |
41 | public void Debug (string prefix, string message)
42 | {
43 | Writer?.WriteLine ($"DEBUG:{prefix}:{message}");
44 | }
45 |
46 | public void Error (string prefix, string message)
47 | {
48 | Writer?.WriteLine ($"ERROR:{prefix}:{message}");
49 | }
50 |
51 | public void Info (string prefix, string message)
52 | {
53 | Writer?.WriteLine ($"INFO: {prefix}:{message}");
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/IListExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IListExtensions.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2020 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 |
33 | namespace MonoTorrent
34 | {
35 | static class IListExtensions
36 | {
37 | public static int BinarySearch (this IList list, Func predicate, TState comparand)
38 | {
39 | int min = 0;
40 | int max = list.Count - 1;
41 | while (min <= max) {
42 | var mid = (min + max) / 2;
43 | var result = predicate (list[mid], comparand);
44 | if (result == 0)
45 | return mid;
46 | if (result < 0)
47 | min = mid + 1;
48 | if (result > 0)
49 | max = mid - 1;
50 | }
51 | return ~min;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/MonoTorrent.BEncoding/MonoTorrent.BEncoding/BEncodingException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // BEncodingException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Runtime.Serialization;
32 |
33 | namespace MonoTorrent.BEncoding
34 | {
35 | [Serializable]
36 | public class BEncodingException : Exception
37 | {
38 | public BEncodingException ()
39 | : base ()
40 | {
41 | }
42 |
43 | public BEncodingException (string message)
44 | : base (message)
45 | {
46 | }
47 |
48 | public BEncodingException (string message, Exception innerException)
49 | : base (message, innerException)
50 | {
51 | }
52 |
53 | protected BEncodingException (SerializationInfo info, StreamingContext context)
54 | : base (info, context)
55 | {
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Connections.Peer.Encryption/PlainTextEncryption.cs:
--------------------------------------------------------------------------------
1 | //
2 | // NullEncryption.cs
3 | //
4 | // Authors:
5 | // Yiduo Wang planetbeing@gmail.com
6 | // Alan McGovern alan.mcgovern@gmail.com
7 | //
8 | // Copyright (C) 2007 Yiduo Wang
9 | //
10 | // Permission is hereby granted, free of charge, to any person obtaining
11 | // a copy of this software and associated documentation files (the
12 | // "Software"), to deal in the Software without restriction, including
13 | // without limitation the rights to use, copy, modify, merge, publish,
14 | // distribute, sublicense, and/or sell copies of the Software, and to
15 | // permit persons to whom the Software is furnished to do so, subject to
16 | // the following conditions:
17 | //
18 | // The above copyright notice and this permission notice shall be
19 | // included in all copies or substantial portions of the Software.
20 | //
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | //
29 |
30 |
31 | using System;
32 |
33 | namespace MonoTorrent.Connections.Peer.Encryption
34 | {
35 | ///
36 | /// Plaintext "encryption"
37 | ///
38 | class PlainTextEncryption : IEncryption
39 | {
40 | public static PlainTextEncryption Instance = new PlainTextEncryption ();
41 |
42 | public EncryptionType EncryptionType => EncryptionType.PlainText;
43 |
44 | PlainTextEncryption ()
45 | {
46 | }
47 |
48 | public void Decrypt (Span buffer)
49 | {
50 | // Nothing
51 | }
52 |
53 | public void Encrypt (Span buffer)
54 | {
55 | // Nothing
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.TorrentWatchers/TorrentWatcherEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | // TorrentWatcher.cs
3 | //
4 | // Authors:
5 | // Stephane Zanoni stephane@ethernal.net
6 | //
7 | // Copyright (C) 2006 Stephane Zanoni
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.TorrentWatcher
33 | {
34 | ///
35 | /// Provides the data needed to handle a TorrentWatcher event
36 | ///
37 | public class TorrentWatcherEventArgs : EventArgs
38 | {
39 | ///
40 | /// The full path of the torrent
41 | ///
42 | public string TorrentPath { get; }
43 |
44 | ///
45 | /// Creates a new TorrentWatcherEventArgs
46 | ///
47 | /// The full path to the torrent file
48 | public TorrentWatcherEventArgs (string torrentPath)
49 | {
50 | TorrentPath = torrentPath;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/MonoTorrent/MonoTorrent.Logging/Logger.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Logger.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2024 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 | using System.Collections.Generic;
32 | using System.Linq;
33 | using System.Text;
34 | using System.Threading.Tasks;
35 |
36 | namespace MonoTorrent.Logging
37 | {
38 | class Logger : ILogger
39 | {
40 | public string Name { get; }
41 |
42 | public Logger(string name)
43 | => Name = name;
44 |
45 | public void Debug (string message)
46 | {
47 | LoggerFactory.RootLogger.Debug (Name, message);
48 | }
49 |
50 | public void Error (string message)
51 | {
52 | LoggerFactory.RootLogger.Debug (Name, message);
53 | }
54 |
55 | public void Info (string message)
56 | {
57 | LoggerFactory.RootLogger.Debug (Name, message);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent.Client/Exceptions/ProtocolException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // ProtocolException.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2006 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | using System;
31 |
32 | namespace MonoTorrent.Client
33 | {
34 | class ProtocolException : TorrentException
35 | {
36 | public ProtocolException ()
37 | : base ()
38 | {
39 | }
40 |
41 |
42 | public ProtocolException (string message)
43 | : base (message)
44 | {
45 | }
46 |
47 |
48 | public ProtocolException (string message, Exception innerException)
49 | : base (message, innerException)
50 | {
51 | }
52 |
53 |
54 | public ProtocolException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
55 | : base (info, context)
56 | {
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/MonoTorrent.Client/MonoTorrent/FileMapping.cs:
--------------------------------------------------------------------------------
1 | //
2 | // FileMapping.cs
3 | //
4 | // Authors:
5 | // Alan McGovern alan.mcgovern@gmail.com
6 | //
7 | // Copyright (C) 2009 Alan McGovern
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining
10 | // a copy of this software and associated documentation files (the
11 | // "Software"), to deal in the Software without restriction, including
12 | // without limitation the rights to use, copy, modify, merge, publish,
13 | // distribute, sublicense, and/or sell copies of the Software, and to
14 | // permit persons to whom the Software is furnished to do so, subject to
15 | // the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be
18 | // included in all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | //
28 |
29 |
30 | namespace MonoTorrent
31 | {
32 | public struct FileMapping
33 | {
34 | ///
35 | /// This is the full path to the file on disk
36 | ///
37 | public string Source { get; }
38 |
39 | ///
40 | /// This is the relative path to the file within the Torrent
41 | ///
42 | public string Destination { get; }
43 |
44 | ///
45 | /// The length of the file
46 | ///
47 | public long Length { get; }
48 |
49 | public FileMapping (string source, string destination, long length)
50 | {
51 | Source = source;
52 | Destination = destination;
53 | Length = length;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------