Skip to content

Commit

Permalink
Merge pull request #5026 from GibMeMyPacket/feat/singbox/exp_cachefile
Browse files Browse the repository at this point in the history
Add `Enable cache file for sing-box`
  • Loading branch information
2dust committed Apr 27, 2024
2 parents 870955f + 8078399 commit 855fd4f
Show file tree
Hide file tree
Showing 12 changed files with 480 additions and 401 deletions.
3 changes: 2 additions & 1 deletion v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static int LoadConfig(ref Config? config)
{
logEnabled = false,
loglevel = "warning",

muxEnabled = false,
enableCacheFile4Sbox = false,
};
}

Expand Down Expand Up @@ -305,6 +305,7 @@ public static int ImportOldGuiConfig(Config config, string fileName)
logEnabled = configOld.logEnabled,
loglevel = configOld.loglevel,
muxEnabled = configOld.muxEnabled,
enableCacheFile4Sbox = false,
};
}

Expand Down
74 changes: 55 additions & 19 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int GenerateClientConfigContent(ProfileItem node, out SingboxConfig? sing

GenDns(node, singboxConfig);

GenStatistic(singboxConfig);
GenExperimental(singboxConfig);

ConvertGeo2Ruleset(singboxConfig);

Expand Down Expand Up @@ -822,30 +822,66 @@ private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
return 0;
}

private int GenStatistic(SingboxConfig singboxConfig)
private int GenExperimentalStatistic(SingboxConfig singboxConfig)
{
if (_config.guiItem.enableStatistics)
{
singboxConfig.experimental = new Experimental4Sbox()
singboxConfig.experimental ??= new Experimental4Sbox();
singboxConfig.experimental.clash_api = new Clash_Api4Sbox()
{
cache_file = new CacheFile4Sbox()
{
enabled = true
},
//v2ray_api = new V2ray_Api4Sbox()
//{
// listen = $"{Global.Loopback}:{Global.StatePort}",
// stats = new Stats4Sbox()
// {
// enabled = true,
// }
//},
clash_api = new Clash_Api4Sbox()
{
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
}
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
};
// singboxConfig.experimental.v2ray_api = new V2ray_Api4Sbox()
// {
// listen = $"{Global.Loopback}:{Global.StatePort}",
// stats = new Stats4Sbox()
// {
// enabled = true,
// }
// };
// singboxConfig.experimental = new Experimental4Sbox()
// {
// cache_file = new CacheFile4Sbox()
// {
// enabled = true
// },
// //v2ray_api = new V2ray_Api4Sbox()
// //{
// // listen = $"{Global.Loopback}:{Global.StatePort}",
// // stats = new Stats4Sbox()
// // {
// // enabled = true,
// // }
// //},
// clash_api = new Clash_Api4Sbox()
// {
// external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
// }
// };
}
return 0;
}

private int GenExperimentalCacheFile(SingboxConfig singboxConfig)
{
if (_config.coreBasicItem.enableCacheFile4Sbox)
{
singboxConfig.experimental ??= new Experimental4Sbox();
singboxConfig.experimental.cache_file = new CacheFile4Sbox()
{
enabled = true
};
}

return 0;
}

private int GenExperimental(SingboxConfig singboxConfig)
{
var r = GenExperimentalStatistic(singboxConfig);
if (r != 0) return r;
r = GenExperimentalCacheFile(singboxConfig);
if (r != 0) return r;
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions v2rayN/v2rayN/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class CoreBasicItem
public string defUserAgent { get; set; }

public bool enableFragment { get; set; }

public bool enableCacheFile4Sbox { get; set; }
}

[Serializable]
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Models/SingboxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SingboxConfig
public List<Inbound4Sbox> inbounds { get; set; }
public List<Outbound4Sbox> outbounds { get; set; }
public Route4Sbox route { get; set; }
public Experimental4Sbox experimental { get; set; }
public Experimental4Sbox? experimental { get; set; }
}

public class Log4Sbox
Expand Down
Loading

0 comments on commit 855fd4f

Please sign in to comment.