diff --git a/ProjectPlugins/BittorrentPlugin/BittorrentContainerRecipe.cs b/ProjectPlugins/BittorrentPlugin/BittorrentContainerRecipe.cs index 5e2baf6..9810f68 100644 --- a/ProjectPlugins/BittorrentPlugin/BittorrentContainerRecipe.cs +++ b/ProjectPlugins/BittorrentPlugin/BittorrentContainerRecipe.cs @@ -6,7 +6,7 @@ namespace BittorrentPlugin public class BittorrentContainerRecipe : ContainerRecipeFactory { public override string AppName => "bittorrent"; - public override string Image => "thatbenbierens/bittorrentdriver:init11"; + public override string Image => "thatbenbierens/bittorrentdriver:init12"; public static string ApiPortTag = "API_PORT"; public static string TrackerPortTag = "TRACKER_PORT"; diff --git a/ProjectPlugins/BittorrentPlugin/BittorrentNode.cs b/ProjectPlugins/BittorrentPlugin/BittorrentNode.cs index 0bbcca5..3030bb7 100644 --- a/ProjectPlugins/BittorrentPlugin/BittorrentNode.cs +++ b/ProjectPlugins/BittorrentPlugin/BittorrentNode.cs @@ -96,10 +96,8 @@ namespace BittorrentPlugin public string GetTrackerStats() { - //var http = tools.CreateHttp(TrackerAddress.ToString(), c => { }); - //var endpoint = http.CreateEndpoint(TrackerAddress, "/", container.Name); - //return endpoint.HttpGetString("stats"); - return "no"; + var endpoint = GetEndpoint(); + return endpoint.HttpGetString("stats"); } //public Address TrackerAddress { get; private set; } = new Address("", 0); diff --git a/Tools/BittorrentDriver/Controllers/TorrentController.cs b/Tools/BittorrentDriver/Controllers/TorrentController.cs index 976b1f3..fab0cb3 100644 --- a/Tools/BittorrentDriver/Controllers/TorrentController.cs +++ b/Tools/BittorrentDriver/Controllers/TorrentController.cs @@ -37,6 +37,15 @@ namespace BittorrentDriver.Controllers }); } + [HttpGet("stats")] + public string GetTrackerStats() + { + return Try(() => + { + return tracker.GetStats(); + }); + } + [HttpPost("postfile")] public string PostFile([FromBody] PostFileInput input) { diff --git a/Tools/BittorrentDriver/TorrentTracker.cs b/Tools/BittorrentDriver/TorrentTracker.cs index c12ff01..d9d5ad5 100644 --- a/Tools/BittorrentDriver/TorrentTracker.cs +++ b/Tools/BittorrentDriver/TorrentTracker.cs @@ -5,10 +5,13 @@ namespace BittorrentDriver public class TorrentTracker { private Process? process; + private int? trackerPort; public string Start(int port) { if (process != null) throw new Exception("Already started"); + trackerPort = port; + var info = new ProcessStartInfo { FileName = "bittorrent-tracker", @@ -48,5 +51,17 @@ namespace BittorrentDriver } return "OK"; } + + public string GetStats() + { + if (!trackerPort.HasValue) throw new Exception("Port value not set"); + + using var client = new HttpClient(); + var task = client.GetAsync($"http://localhost:{trackerPort.Value}/stats"); + task.Wait(); + var strTask = task.Result.Content.ReadAsStringAsync(); + strTask.Wait(); + return strTask.Result; + } } }