Skip to content

Commit

Permalink
[core] Changes HttpSeeds to IList<Uri>
Browse files Browse the repository at this point in the history
Breaking change. Changes HttpSeeds from a string to a Uri. Internally, HttpSeeds  is only used in one place and its contents are immediately converted to an Uri.
  • Loading branch information
phil-scott-78 authored and alanmcgovern committed Apr 1, 2021
1 parent 61bcc56 commit 4961054
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/MonoTorrent.Tests/Client/TestWebSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void GotContext (IAsyncResult result)
}

var files = rig.Manager.Torrent.Files;
if (files.Count == 1 && rig.Torrent.HttpSeeds[0] == c.Request.Url.OriginalString) {
if (files.Count == 1 && rig.Torrent.HttpSeeds[0] == c.Request.Url) {
globalStart = 0;
exists = start < files[0].Length && end < files[0].Length;
}
Expand Down Expand Up @@ -361,10 +361,10 @@ public async Task SingleFileTorrent ()
{
rig.Dispose ();
rig = TestRig.CreateSingleFile ();
rig.Torrent.HttpSeeds.Add ($"{ListenerURL}File1.exe");
rig.Torrent.HttpSeeds.Add (new Uri($"{ListenerURL}File1.exe"));

string url = rig.Torrent.HttpSeeds[0];
connection = new HttpConnection (new Uri (url));
Uri url = rig.Torrent.HttpSeeds[0];
connection = new HttpConnection (url);
connection.Manager = rig.Manager;
rig.Manager.UnhashedPieces.SetAll (false);

Expand Down
2 changes: 1 addition & 1 deletion src/MonoTorrent.Tests/Common/TorrentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void Files ()
public void HttpSeeds ()
{
Assert.IsTrue (torrent.HttpSeeds.Count == 1);
Assert.AreEqual("https://example.com/8/items/", torrent.HttpSeeds[0]);
Assert.AreEqual(new Uri("https://example.com/8/items/"), torrent.HttpSeeds[0]);
}

[Test]
Expand Down
3 changes: 1 addition & 2 deletions src/MonoTorrent/MonoTorrent.Client/Modes/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,9 @@ void PostLogicTick (int counter)
void DownloadLogic (int counter)
{
if (ClientEngine.SupportsWebSeed && (DateTime.Now - Manager.StartTime) > Manager.Settings.WebSeedDelay && Manager.Monitor.DownloadSpeed < Manager.Settings.WebSeedSpeedTrigger) {
foreach (string seedUri in Manager.Torrent.HttpSeeds) {
foreach (Uri uri in Manager.Torrent.HttpSeeds) {
BEncodedString peerId = HttpConnection.CreatePeerId ();

var uri = new Uri (seedUri);
var peer = new Peer (peerId, uri);

var connection = (HttpConnection) ConnectionFactory.Create (uri);
Expand Down
12 changes: 6 additions & 6 deletions src/MonoTorrent/MonoTorrent/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public sealed class Torrent : IEquatable<Torrent>
/// <summary>
/// This is the http-based seeding (getright protocole)
/// </summary>
public IList<string> HttpSeeds { get; }
public IList<Uri> HttpSeeds { get; }

/// <summary>
/// This is the infohash that is generated by putting the "Info" section of a .torrent
Expand Down Expand Up @@ -155,7 +155,7 @@ public sealed class Torrent : IEquatable<Torrent>
Name = string.Empty;
Publisher = string.Empty;
PublisherUrl = string.Empty;
HttpSeeds = new List<string> ();
HttpSeeds = new List<Uri> ();
}

public override bool Equals (object obj)
Expand Down Expand Up @@ -676,13 +676,13 @@ void LoadInternal (BEncodedDictionary torrentInformation, InfoHash infoHash)

case ("url-list"):
if (keypair.Value is BEncodedString httpSeedString) {
if (Uri.IsWellFormedUriString (httpSeedString.Text, UriKind.Absolute)) {
HttpSeeds.Add (httpSeedString.Text);
if (Uri.TryCreate (httpSeedString.Text, UriKind.Absolute, out Uri httpSeedUri)) {
HttpSeeds.Add (httpSeedUri);
}
} else if (keypair.Value is BEncodedList httpSeedList) {
foreach (BEncodedString str in httpSeedList)
if (Uri.IsWellFormedUriString (str.Text, UriKind.Absolute)) {
HttpSeeds.Add (str.Text);
if (Uri.TryCreate (str.Text, UriKind.Absolute, out Uri httpSeedUri)) {
HttpSeeds.Add (httpSeedUri);
}
}
break;
Expand Down

0 comments on commit 4961054

Please sign in to comment.