Skip to content

Commit

Permalink
- Adding support for IPv4 & IPv6 Peer Exchange (PEX) / BEP 11
Browse files Browse the repository at this point in the history
- Fixing critical but rare issue with null reference and missing lock in FillStats (was crashing the application)
- Fixing critical issue with metadata extension (was listening for receive on remote extension id instead of local)
- Fixing DHT/Tracker sockets issue by ensuring that will listen on IPv4 interface (until IPv6 will be added)
- Fixing a minor issue with DumpStats (was not clearing the line buffer before printing the new one)
  • Loading branch information
SuRGeoNix committed Nov 18, 2020
1 parent 9d1d512 commit 4ea1c5e
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>BitSwarmConsole</RootNamespace>
<AssemblyName>bswarm</AssemblyName>
<AssemblyVersion>2.2.6.0</AssemblyVersion>
<FileVersion>2.2.6.0</FileVersion>
<Version>2.2.6</Version>
<AssemblyVersion>2.2.7.0</AssemblyVersion>
<FileVersion>2.2.7.0</FileVersion>
<Version>2.2.7</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
43 changes: 22 additions & 21 deletions BitSwarm (Console Core Demo)/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class Program

static bool sessionFinished = false;
static bool preventOnce = true;
static bool resized = false;
static int consoleLastTop = -1;
static int prevHeight;
static int consoleStatsPos = 0;

static void Main(string[] args)
{
Expand All @@ -42,12 +40,7 @@ static void Main(string[] args)

// Prepare Options
opt = new BitSwarm.DefaultOptions();
if (args.Length >= 2)
{
if (!Directory.Exists(args[1])) Directory.CreateDirectory(args[1]);
opt.DownloadPath = args[1];
}

if (args.Length >= 2) opt.DownloadPath = args[1];
if (args.Length >= 3) opt.MinThreads = int.Parse(args[2]);
if (args.Length >= 4) opt.MaxThreads = int.Parse(args[3]);
if (args.Length >= 5) opt.SleepModeLimit = int.Parse(args[4]);
Expand All @@ -63,21 +56,25 @@ static void Main(string[] args)

// More Options

// [Feeders]
//opt.EnablePEX = false;
//opt.EnableDHT = false;
//opt.EnableTrackers= false;
//opt.TrackersPath = @"c:\root\trackers.txt";

// [Timeouts]
//opt.ConnectionTimeout = 1200;
//opt.HandshakeTimeout = 2400;
//opt.MetadataTimeout = 1600;
//opt.PieceTimeout = 7000;
//opt.PieceTimeout = 2000;
//opt.PieceRetries = 3; // Re-requests timed-out pieces on the first timeout

// Initialize BitSwarm
bitSwarm = new BitSwarm(opt);

bitSwarm.StatsUpdated += BitSwarm_StatsUpdated;
bitSwarm.MetadataReceived += BitSwarm_MetadataReceived;
bitSwarm.StatusChanged += BitSwarm_StatusChanged;
bitSwarm.MetadataReceived += BitSwarm_MetadataReceived; // Receives torrent data [on torrent file will fire directly, on magnetlink will fire on metadata received]
bitSwarm.StatsUpdated += BitSwarm_StatsUpdated; // Stats refresh every 2 seconds
bitSwarm.StatusChanged += BitSwarm_StatusChanged; // Paused/Stopped or Finished

if (File.Exists(args[0]))
bitSwarm.Initiliaze(args[0]);
Expand All @@ -88,13 +85,8 @@ static void Main(string[] args)
bitSwarm.Start();

Console.CancelKeyPress += new ConsoleCancelEventHandler(CtrlC);
prevHeight = Console.WindowHeight;

while (!sessionFinished)
{
if (Console.WindowHeight != prevHeight) { prevHeight = Console.WindowHeight; resized = true; }
Thread.Sleep(500);
}
while (!sessionFinished) Thread.Sleep(500);
}
protected static void CtrlC(object sender, ConsoleCancelEventArgs args)
{
Expand All @@ -121,11 +113,20 @@ private static void BitSwarm_MetadataReceived(object source, BitSwarm.MetadataRe
{
torrent = e.Torrent;
Console.Clear();
if (Utils.IsWindows) { Console.WriteLine(bitSwarm.DumpTorrent() + "\r\n"); consoleStatsPos = Console.CursorTop; }
}
private static void BitSwarm_StatsUpdated(object source, BitSwarm.StatsUpdatedArgs e)
{
Console.SetCursorPosition(0, 0);
Console.WriteLine(bitSwarm.DumpTorrent() + "\r\n");
if (Utils.IsWindows)
{
Console.SetCursorPosition(0, consoleStatsPos);
}
else
{
Console.SetCursorPosition(0, 0);
Console.WriteLine(bitSwarm.DumpTorrent() + "\r\n");
}

Console.WriteLine(bitSwarm.DumpStats());
}
}
Expand Down
4 changes: 2 additions & 2 deletions BitSwarm (WinForms Demo)/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.6.0")]
[assembly: AssemblyFileVersion("2.2.6.0")]
[assembly: AssemblyVersion("2.2.7.0")]
[assembly: AssemblyFileVersion("2.2.7.0")]
Loading

0 comments on commit 4ea1c5e

Please sign in to comment.