2fa2f7f816
Changelog: Share link import and mrs rule sets
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package core
|
|
|
|
import (
|
|
"github.com/metacubex/mihomo/component/resolver"
|
|
"github.com/metacubex/mihomo/tunnel/statistic"
|
|
)
|
|
|
|
func handleGetTraffic(onlyStatisticsProxy bool) Traffic {
|
|
up, down := statistic.DefaultManager.NowTraffic(onlyStatisticsProxy)
|
|
return Traffic{Up: up, Down: down}
|
|
}
|
|
|
|
func handleGetTotalTraffic(onlyStatisticsProxy bool) Traffic {
|
|
up, down := statistic.DefaultManager.TotalTraffic(onlyStatisticsProxy)
|
|
return Traffic{Up: up, Down: down}
|
|
}
|
|
|
|
func handleResetTraffic() {
|
|
statistic.DefaultManager.ResetStatistic()
|
|
}
|
|
|
|
func handleGetConnections() *statistic.Snapshot {
|
|
return statistic.DefaultManager.Snapshot()
|
|
}
|
|
|
|
func handleGetConnectionCount() int {
|
|
count := 0
|
|
statistic.DefaultManager.Range(func(statistic.Tracker) bool {
|
|
count++
|
|
return true
|
|
})
|
|
return count
|
|
}
|
|
|
|
func handleCloseConnections() bool {
|
|
statistic.DefaultManager.Range(func(c statistic.Tracker) bool {
|
|
_ = c.Close()
|
|
return true
|
|
})
|
|
return true
|
|
}
|
|
|
|
func handleResetConnections() bool {
|
|
resolver.ResetConnection()
|
|
return true
|
|
}
|
|
|
|
// A connection that went out over a network the device has left hangs until
|
|
// TCP gives up on it, and so do the DNS clients' pooled connections.
|
|
func handleResetNetwork() {
|
|
handleCloseConnections()
|
|
resolver.ResetConnection()
|
|
}
|
|
|
|
func handleCloseConnection(connectionId string) bool {
|
|
c := statistic.DefaultManager.Get(connectionId)
|
|
if c == nil {
|
|
return false
|
|
}
|
|
_ = c.Close()
|
|
return true
|
|
}
|