register inter-chain profiles for traffic

This commit is contained in:
Nova 2025-03-20 14:31:27 +03:30
parent 77374c268b
commit 43fb62a672
4 changed files with 350 additions and 644 deletions

File diff suppressed because it is too large Load Diff

View File

@ -61,6 +61,7 @@ message TestResp {
message QueryStatsResp{
map<string, int64> ups = 1;
map<string, int64> downs = 2;
repeated string intermediate_tags = 3;
}
enum UpdateAction {

View File

@ -189,33 +189,18 @@ func (s *server) QueryStats(ctx context.Context, _ *gen.EmptyReq) (*gen.QuerySta
return nil, E.New("invalid clash server type")
}
outbounds := service.FromContext[adapter.OutboundManager](boxInstance.Context())
endpoints := service.FromContext[adapter.EndpointManager](boxInstance.Context())
if outbounds == nil {
log.Println("Failed to assert outbound manager")
return nil, E.New("invalid outbound manager type")
}
if endpoints == nil {
log.Println("Failed to assert endpoint manager")
return nil, E.New("invalid endpoint manager type")
}
for _, out := range outbounds.Outbounds() {
if len(out.Dependencies()) > 0 {
// ignore, has detour
continue
resp.IntermediateTags = append(resp.IntermediateTags, out.Tag())
}
u, d := cApi.TrafficManager().TotalOutbound(out.Tag())
resp.Ups[out.Tag()] = u
resp.Downs[out.Tag()] = d
}
for _, end := range endpoints.Endpoints() {
if len(end.Dependencies()) > 0 {
// ignore, has detour
continue
}
u, d := cApi.TrafficManager().TotalOutbound(end.Tag())
resp.Ups[end.Tag()] = u
resp.Downs[end.Tag()] = d
}
}
}

View File

@ -33,6 +33,16 @@ namespace NekoGui_traffic {
item->downlink += down;
item->uplink_rate = up * 1000 / interval;
item->downlink_rate = down * 1000 / interval;
auto isInter = false;
for (const auto& inter_tag : resp.intermediate_tags())
{
if (inter_tag == item->tag)
{
isInter = true;
break;
}
}
if (isInter) continue;
if (item->tag == "direct")
{
direct->uplink_rate = item->uplink_rate;