-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stun servers are hardcoded #21
Comments
Hello @Darthagnon, thanks, that's a great idea. |
Not sure if anyone has made any progress on this but I converted the long list of URLs and Ports for the Stun Servers to a
I'm working on converting all the code over to
using System.IO;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
public class StunServer
{
public string? Url { get; set; }
public int Port { get; set; }
/// <summary>
/// Loads list of Stun Servers from a local file path.
/// </summary>
/// <param name="filePath">Full path to the local Stun Server list (.JSON). Example: C:\Users\Administrator\Downloads\StunServers.json</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[]? GetStunServersFromFile(string filePath)
{
string _json = File.ReadAllText(filePath);
return JsonSerializer.Deserialize<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from an HTTP/HTTPS URL.
/// </summary>
/// <param name="fileUrl">Full URL to the Stun Server list (.JSON). Example: "https://raw.github.com/username/repo/files/StunServers.json"</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static async Task<StunServer[]?> GetStunServersFromUrl(string fileUrl)
{
string _json;
using (HttpClient _client = new())
{
_json = await _client.GetStringAsync(fileUrl);
}
return JsonSerializer.Deserialize<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from a pre-populated JSON string.
/// </summary>
/// <param name="json">A string, in JSON format, containing an array of Stun Server objects.</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[]? GetStunServersFromJson(string json)
{
return JsonSerializer.Deserialize<StunServer[]>(json);
}
}
// .NET Framework v4.8
// Requires Newtonsoft.Json
using System.IO;
using System.Net;
using Newtonsoft.Json;
public class StunServer
{
public string Url { get; set; }
public int Port { get; set; }
/// <summary>
/// Loads list of Stun Servers from a local file path.
/// </summary>
/// <param name="filePath">Full path to the local Stun Server list (.JSON). Example: C:\Users\Administrator\Downloads\StunServers.json</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromFile(string filePath)
{
string _json = System.IO.File.ReadAllText(filePath);
return JsonConvert.DeserializeObject<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from an HTTP/HTTPS URL.
/// </summary>
/// <param name="fileUrl">Full URL to the Stun Server list (.JSON). Example: "https://raw.github.com/username/repo/files/StunServers.json"</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromUrl(string fileUrl)
{
string _json;
using (System.Net.WebClient wc = new System.Net.WebClient())
{
_json = wc.DownloadString(fileUrl);
}
return JsonConvert.DeserializeObject<StunServer[]>(_json);
}
/// <summary>
/// Loads list of Stun Servers from a pre-populated JSON string.
/// </summary>
/// <param name="json">A string, in JSON format, containing an array of Stun Server objects.</param>
/// <returns>An array of 'StunServer' objects.</returns>
public static StunServer[] GetStunServersFromJson(string json)
{
return JsonConvert.DeserializeObject<StunServer[]>(json);
}
} Finally if, for whatever reason, you still want/need to generate a list of Tuples from the StunServer object array: List<Tuple<string, int>> stunServers = new List<Tuple<string, int>>();
foreach (var _server in p2p.Models.StunServer.GetStunServersFromFile(@"C:\Dev\StunServers.json"))
{
stunServers.Add(new Tuple<string, int>(_server.Url, _server.Port));
} |
Hey @johngagefaulkner, |
Fair warning, I haven't been to sleep in almost 2 days now (we have a newborn) so please forgive me if this suggestion doesn't make any sense, BUT... I don't think it'd be a bad idea for you, as the author of the project, to be in control of the list of available Stun Servers and their ports. You could always host it on this GitHub repo, hard-code the URL into the project, and download it (for local cache) on each user's machine. I'm not all too familiar with the process but I'd imagine not all 290+ in the list are needed so you could have a shorter list containing only the ones you deem necessary which would reduce bandwidth costs for GitHub. If the user isn't able to use any of what's available in that file, they can click a button to "try additional servers" which would pull the full list. Once one, or both, of the lists are cached locally, you wouldn't need to check for an updated list again unless there were issues using whatever each user had locally. Let me know if you're interested and need any help. |
Hey @johngagefaulkner, Many congratulations for the newborn ❤️ You can try to implement this and send me a PR, that would be great. |
There are a couple servers like |
Hi @mubix, thank you for this news. Sure, I deleted all Hardcoded Stun Servers, only leaving as default [{
"Server": "stun.l.google.com",
"Port": 19302
}] Now you can set your own List of Stun Servers that will be saved in the same dir where the app was run as You can see the lists of Stun Servers by clicking on Stun tab, also add new, save - delete your own. Special Thanks to @Darthagnon (this task) and @johngagefaulkner for the StunServer.cs Thank you and enjoy! |
No thanks needed! I'm sorry I haven't responded, kids & career are working in tandem to hold my free time hostage! |
@johngagefaulkner Deserved, you did a great job for the |
I noticed in 171947c that the stun servers are hardcoded. Wouldn't it be better practice to leave them easily editable in a config file (possibly eventually in the GUI)?
The text was updated successfully, but these errors were encountered: