Skip to content

Commit

Permalink
Update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcgovern committed Mar 18, 2021
1 parent 37d1ba3 commit 0c42635
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ public int DiskCacheBytes {

/// <summary>
/// The UDP port used for DHT communications. Use 0 to choose a random available port.
/// Choose -1 to disable DHT. Defaults to 52139.
/// Choose -1 to disable DHT. Defaults to 0.
/// </summary>
public int DhtPort {
get => dhtPort;
set => dhtPort = CheckPort (value);
}

/// <summary>
/// The TCP port the engine should listen on for incoming connections. Defaults to 52138.
/// The TCP port the engine should listen on for incoming connections. Use 0 to choose a random
/// available port. Choose -1 to disable listening for incoming connections. Defaults to 0.
/// </summary>
public int ListenPort {
get => listenPort;
Expand Down
34 changes: 32 additions & 2 deletions src/SampleClient/main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,43 @@ static void Main (string[] args)

static async Task MainAsync (string[] args, CancellationToken token)
{
Task task;
// Give an example of how settings can be modified for the engine.
var settingBuilder = new EngineSettingsBuilder {
// Allow the engine to automatically forward ports using upnp/nat-pmp (if a compatible router is available)
AllowPortForwarding = true,

// Automatically save a cache of the DHT table when all torrents are stopped.
AutoSaveLoadDhtCache = true,

// Automatically save 'FastResume' data when TorrentManager.StopAsync is invoked, automatically load it
// before hash checking the torrent. Fast Resume data will be loaded as part of 'engine.AddAsync' if
// torrent metadata is available. Otherwise, if a magnetlink is used to download a torrent, fast resume
// data will be loaded after the metadata has been downloaded.
AutoSaveLoadFastResume = true,

// If a MagnetLink is used to download a torrent, the engine will try to load a copy of the metadata
// it's cache directory. Otherwise the metadata will be downloaded and stored in the cache directory
// so it can be reloaded later.
AutoSaveLoadMagnetLinkMetadata = true,

using var engine = new ClientEngine ();
// Use a random port to accept incoming connections from other peers.
ListenPort = 0,

// Use a random port for DHT communications.
DhtPort = 0,
};
using var engine = new ClientEngine (settingBuilder.ToSettings ());

Task task;
if (args.Length == 1 && MagnetLink.TryParse (args[0], out MagnetLink link)) {
task = new MagnetLinkStreaming (engine).DownloadAsync (link, token);
} else {
task = new StandardDownloader (engine).DownloadAsync (token);
}

if (engine.Settings.AllowPortForwarding)
Console.WriteLine ("uPnP or NAT-PMP port mappings will be created for any ports needed by MonoTorrent");

try {
await task;
} catch (OperationCanceledException) {
Expand All @@ -57,6 +84,9 @@ static async Task MainAsync (string[] args, CancellationToken token)

if (engine.Settings.AutoSaveLoadDhtCache)
Console.WriteLine ($"DHT cache has been written to disk.");

if (engine.Settings.AllowPortForwarding)
Console.WriteLine ("uPnP and NAT-PMP port mappings have been removed");
}
}
}

0 comments on commit 0c42635

Please sign in to comment.