trying to get back tracker stats

This commit is contained in:
Ben 2024-09-18 12:21:45 +02:00
parent d03dd9f954
commit 0bed02ed73
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
4 changed files with 27 additions and 5 deletions

View File

@ -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";

View File

@ -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);

View File

@ -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)
{

View File

@ -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;
}
}
}