Skip to content

Commit

Permalink
1. Trackers UDP sockets stability
Browse files Browse the repository at this point in the history
2. Trackers announce re-requesting (recursively) for more peers
3. BitSwarm's Scheduler more adjustments
  • Loading branch information
SuRGeoNix committed Nov 6, 2020
1 parent c92fa16 commit 580e21e
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 241 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.1.0</AssemblyVersion>
<FileVersion>2.2.1.0</FileVersion>
<Version>2.2.1</Version>
<AssemblyVersion>2.2.2.0</AssemblyVersion>
<FileVersion>2.2.2.0</FileVersion>
<Version>2.2.2</Version>
</PropertyGroup>

<ItemGroup>
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.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]
[assembly: AssemblyVersion("2.2.2.0")]
[assembly: AssemblyFileVersion("2.2.2.0")]
4 changes: 0 additions & 4 deletions BitSwarm (WinForms Demo)/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ private void button1_Click(object sender, EventArgs e)
{
opt = new BitSwarm.DefaultOptions();

opt.SleepModeLimit = 1600;

opt.DownloadPath = downPath.Text;

opt.MaxThreads = int.Parse(maxCon.Text);
Expand All @@ -60,8 +58,6 @@ private void button1_Click(object sender, EventArgs e)
opt.PieceTimeout = int.Parse(pieceTimeout.Text);
opt.MetadataTimeout = int.Parse(metaTimeout.Text);

opt.EnableDHT = true;

opt.Verbosity = 0;
opt.LogDHT = false;
opt.LogStats = false;
Expand Down
188 changes: 114 additions & 74 deletions BitSwarm/BitSwarm.cs

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions BitSwarm/BitSwarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>bitswarm bittorrent torrent client streaming dht</PackageTags>
<Copyright>© SuRGeoNix 2020</Copyright>
<Version>2.2.1</Version>
<Version>2.2.2</Version>
<PackageReleaseNotes>Alpha Testing &amp; Deep Analysis (Bugs &amp; Performance Issues / Improvements)

Additions/Improvements:-
Expand All @@ -25,16 +25,18 @@ Additions/Improvements:-
4. Adding support for Allow Fast (Fast Extension)
5. Adding support for external Trackers list
6. Direct requests after each piece receive
7. Trackers announce re-requesting (recursively) for more peers (added on 2.2.2)

Critical Issues:-

1. Dropping peers that it shouldn't drop
2. Synchronizing socket buffer sizes with receiving network stream
3. CPU performance issues (improvements especially with bitfields hotpaths)
4. Scheduler re-design and transfer jobs direct in Peers (will do the same for timeouts)
5. DHT issues (Fixed on 2.2.1 - issue with Local EndPoint on Receive)</PackageReleaseNotes>
<FileVersion>2.2.1.0</FileVersion>
<AssemblyVersion>2.2.1.0</AssemblyVersion>
5. DHT issues (Fixed on 2.2.1 - issue with Local EndPoint on Receive)
6. Trackers UDP sockets stability (Fixed on 2.2.2)</PackageReleaseNotes>
<FileVersion>2.2.2.0</FileVersion>
<AssemblyVersion>2.2.2.0</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
12 changes: 2 additions & 10 deletions BitSwarm/DHT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public enum Status
}

public Status status { get; private set; }
public ConcurrentDictionary<string, int>CachedPeers { get; private set; }
public long StartedAt { get; private set; }
public long StoppedAt { get; private set; }

Expand Down Expand Up @@ -104,7 +103,6 @@ public DHT(string infoHash, Options? opt = null)
bucketNodes = new Dictionary<string, Node>();
bucketNodes2 = new Dictionary<string, Node>();
rememberBadNodes= new HashSet<string>();
CachedPeers = new ConcurrentDictionary<string, int>();
infoHashBytes = Utils.StringHexToArray(infoHash);
this.infoHash = infoHash;

Expand Down Expand Up @@ -359,10 +357,9 @@ private void GetPeers(Node node, int selfRecursionLevel = 0)
//if (options.Verbosity > 0) Log($"[{node.distance}] [{node.host}] [PEER] {curIP}:{curPort}");

curPeers[curIP] = curPort;
CachedPeers[curIP] = curPort;
}

options.Beggar.FillPeersFromDHT(curPeers); // options.NewPeersClbk?.Invoke(curPeers, true);
options.Beggar.FillPeersFromStorage(curPeers, BitSwarm.PeersStorage.DHTNEW);

//if (options.Verbosity > 0) Log($"[{node.distance}] [{node.host}] [NEW PEERS] {newPeers}");

Expand Down Expand Up @@ -480,7 +477,7 @@ private void Beggar()
curSeconds++;

// Stats
if (options.Verbosity > 0) Log($"[STATS] [REQs: {requested}]\t[RESPs: {responded}]\t[BUCKETSIZE: {bucketNodesPointer.Count}]\t[INBUCKET: {inBucket}]\t[PEERNODES: {havePeers}]\t[PEERS: {CachedPeers.Count}] | [WEIRD]: {weirdPeers} | [NORMAL] {normalPeers}");
if (options.Verbosity > 0) Log($"[STATS] [REQs: {requested}]\t[RESPs: {responded}]\t[BUCKETSIZE: {bucketNodesPointer.Count}]\t[INBUCKET: {inBucket}]\t[PEERNODES: {havePeers}]\t[WEIRD]: {weirdPeers} | [NORMAL] {normalPeers}");

// Flip Strategy
if (curSeconds % 6 == 0) FlipStrategy();
Expand Down Expand Up @@ -520,11 +517,6 @@ public void Stop()

status = Status.STOPPING;
}
public void ClearCachedPeers()
{
CachedPeers.Clear();
Log($"Cached Peers cleaned");
}

// Misc
internal void Log(string msg) { if (options.Verbosity > 0) options.LogFile.Write($"[DHT] {msg}"); }
Expand Down
47 changes: 21 additions & 26 deletions BitSwarm/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,6 @@ public Torrent (string downloadPath)
data.pieceRequests = new List<TorrentData.PieceRequest>();
}

public void FillTrackersFromTrackersPath(string fileName)
{
try
{
if (fileName == null || fileName.Trim() == "" || !File.Exists(fileName)) return;

string[] trackers = File.ReadAllLines(fileName);

foreach (var tracker in trackers)
if (!file.trackers.Contains(new Uri(tracker))) file.trackers.Add(new Uri(tracker));

} catch (Exception) { }
}
public void FillFromMagnetLink(Uri magnetLink)
{
// TODO: Check v2 Magnet Link
Expand Down Expand Up @@ -174,7 +161,7 @@ public void FillFromMagnetLink(Uri magnetLink)
if (tr == null) return;

for (int i=0; i<tr.Length; i++)
if (!file.trackers.Contains(new Uri(tr[i]))) file.trackers.Add(new Uri(tr[i]));
file.trackers.Add(new Uri(tr[i]));
}
public void FillFromTorrentFile(string fileName)
{
Expand All @@ -184,7 +171,7 @@ public void FillFromTorrentFile(string fileName)
if (bdicTorrent["info"] != null)
{
bInfo = (BDictionary) bdicTorrent["info"];
file.trackers = GetTrackersFromTorrent(bdicTorrent);
FillTrackersFromInfo(bdicTorrent);
}
else if (bdicTorrent["name"] != null)
bInfo = bdicTorrent;
Expand Down Expand Up @@ -257,7 +244,19 @@ public void FillFromInfo(BDictionary bInfo)
data.pieceRequests = new List<TorrentData.PieceRequest>();
}

public static List<Uri> GetTrackersFromTorrent(BDictionary torrent)
public void FillTrackersFromTrackersPath(string fileName)
{
try
{
if (fileName == null || fileName.Trim() == "" || !File.Exists(fileName)) return;

string[] trackers = File.ReadAllLines(fileName);

foreach (var tracker in trackers)
try { file.trackers.Add(new Uri(tracker)); } catch (Exception) { }
} catch (Exception) { }
}
public void FillTrackersFromInfo(BDictionary torrent)
{
string tracker = null;
BList trackersBList = null;
Expand All @@ -268,18 +267,14 @@ public static List<Uri> GetTrackersFromTorrent(BDictionary torrent)
if (torrent["announce-list"] != null)
trackersBList = (BList) torrent["announce-list"];

if (trackersBList == null && tracker == null) return new List<Uri>();
if (trackersBList == null) return new List<Uri>() { new Uri(tracker) };

List<Uri> trackers = new List<Uri>();
if (trackersBList != null)
for (int i=0; i<trackersBList.Count; i++)
file.trackers.Add(new Uri(((BString)((BList)trackersBList[i])[0]).ToString()));

for (int i=0; i<trackersBList.Count; i++)
trackers.Add(new Uri(((BString)((BList)trackersBList[i])[0]).ToString()));

if (tracker != null && !trackers.Contains(new Uri(tracker))) trackers.Add(new Uri(tracker));

return trackers;
if (tracker != null)
file.trackers.Add(new Uri(tracker));
}

public static List<string> GetPathsFromInfo(BDictionary info)
{
BList files = (BList) info["files"];
Expand Down
Loading

0 comments on commit 580e21e

Please sign in to comment.