Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 6, 2024
1 parent a49455f commit 80ed834
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
9 changes: 6 additions & 3 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,18 +776,21 @@ private int GenStatistic(SingboxConfig singboxConfig)
{
singboxConfig.experimental = new Experimental4Sbox()
{
//cache_file = new CacheFile4Sbox()
//{
// enabled = true
//},
//v2ray_api = new V2ray_Api4Sbox()
//{
// listen = $"{Global.Loopback}:{Global.statePort}",
// listen = $"{Global.Loopback}:{Global.StatePort}",
// stats = new Stats4Sbox()
// {
// enabled = true,
// }
//}
//},
clash_api = new Clash_Api4Sbox()
{
external_controller = $"{Global.Loopback}:{Global.StatePort}",
store_selected = true
}
};
}
Expand Down
14 changes: 6 additions & 8 deletions v2rayN/v2rayN/Handler/StatisticsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ private int GetFreePort()
{
return defaultPort;
}
for (int i = 0; i < 3; i++)
{
TcpListener l = new(IPAddress.Loopback, 0);
l.Start();
int port = ((IPEndPoint)l.LocalEndpoint).Port;
l.Stop();
return port;
}

TcpListener l = new(IPAddress.Loopback, 0);
l.Start();
int port = ((IPEndPoint)l.LocalEndpoint).Port;
l.Stop();
return port;
}
catch
{
Expand Down
19 changes: 13 additions & 6 deletions v2rayN/v2rayN/Handler/StatisticsV2ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace v2rayN.Handler
internal class StatisticsV2ray
{
private Mode.Config _config;
private GrpcChannel _channel;
private StatsService.StatsServiceClient _client;
private GrpcChannel? _channel;
private StatsService.StatsServiceClient? _client;
private bool _exitFlag;
private Action<ServerSpeedItem> _updateFunc;

Expand All @@ -26,10 +26,17 @@ public StatisticsV2ray(Mode.Config config, Action<ServerSpeedItem> update)

private void GrpcInit()
{
if (_channel == null)
if (_channel is null)
{
_channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{Global.StatePort}");
_client = new StatsService.StatsServiceClient(_channel);
try
{
_channel = GrpcChannel.ForAddress($"{Global.HttpProtocol}{Global.Loopback}:{Global.StatePort}");
_client = new StatsService.StatsServiceClient(_channel);
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
}
}

Expand All @@ -44,7 +51,7 @@ private async void Run()
{
try
{
if (_channel.State == ConnectivityState.Ready)
if (_channel?.State == ConnectivityState.Ready)
{
QueryStatsResponse? res = null;
try
Expand Down
17 changes: 13 additions & 4 deletions v2rayN/v2rayN/Mode/SingboxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public class Server4Sbox

public class Experimental4Sbox
{
public V2ray_Api4Sbox v2ray_api { get; set; }
public Clash_Api4Sbox clash_api { get; set; }
public CacheFile4Sbox? cache_file { get; set; }
public V2ray_Api4Sbox? v2ray_api { get; set; }
public Clash_Api4Sbox? clash_api { get; set; }
}

public class V2ray_Api4Sbox
Expand All @@ -192,8 +193,8 @@ public class V2ray_Api4Sbox

public class Clash_Api4Sbox
{
public string external_controller { get; set; }
public bool store_selected { get; set; }
public string? external_controller { get; set; }
public bool? store_selected { get; set; }
}

public class Stats4Sbox
Expand All @@ -210,4 +211,12 @@ public class Fakeip4Sbox
public string inet4_range { get; set; }
public string inet6_range { get; set; }
}

public class CacheFile4Sbox
{
public bool enabled { get; set; }
public string? path { get; set; }
public string? cache_id { get; set; }
public bool? store_fakeip { get; set; }
}
}
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Tool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,13 @@ public static string GetVersion(bool blFull = true)
if (blFull)
{
return string.Format("v2rayN - V{0} - {1}",
FileVersionInfo.GetVersionInfo(location).FileVersion.ToString(),
FileVersionInfo.GetVersionInfo(location).FileVersion?.ToString(),
File.GetLastWriteTime(location).ToString("yyyy/MM/dd"));
}
else
{
return string.Format("v2rayN/{0}",
FileVersionInfo.GetVersionInfo(location).FileVersion.ToString());
FileVersionInfo.GetVersionInfo(location).FileVersion?.ToString());
}
}
catch (Exception ex)
Expand Down

0 comments on commit 80ed834

Please sign in to comment.