mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 23:34:02 +03:00
+11
-17
@@ -40,7 +40,7 @@ func crashManager() {
|
||||
}
|
||||
}
|
||||
|
||||
func connectionManager() { // nolint: gocyclo
|
||||
func connectionManager() {
|
||||
for event := range connectionsChan {
|
||||
instance.mutex.RLock()
|
||||
|
||||
@@ -53,27 +53,21 @@ func connectionManager() { // nolint: gocyclo
|
||||
switch event.connectionType {
|
||||
case mtproto.ConnectionTypeAbridged:
|
||||
if isIPv4 {
|
||||
instance.ActiveConnections.Abridged.IPv4 += inc
|
||||
if event.connected {
|
||||
instance.AllConnections.Abridged.IPv4 += inc
|
||||
}
|
||||
instance.Connections.Abridged.IPv4 += inc
|
||||
} else {
|
||||
instance.ActiveConnections.Abridged.IPv6 += inc
|
||||
if event.connected {
|
||||
instance.AllConnections.Abridged.IPv6 += inc
|
||||
}
|
||||
instance.Connections.Abridged.IPv6 += inc
|
||||
}
|
||||
case mtproto.ConnectionTypeSecure:
|
||||
if isIPv4 {
|
||||
instance.Connections.Secure.IPv4 += inc
|
||||
} else {
|
||||
instance.Connections.Secure.IPv6 += inc
|
||||
}
|
||||
default:
|
||||
if isIPv4 {
|
||||
instance.ActiveConnections.Intermediate.IPv4 += inc
|
||||
if event.connected {
|
||||
instance.AllConnections.Intermediate.IPv4 += inc
|
||||
}
|
||||
instance.Connections.Intermediate.IPv4 += inc
|
||||
} else {
|
||||
instance.ActiveConnections.Intermediate.IPv6 += inc
|
||||
if event.connected {
|
||||
instance.AllConnections.Intermediate.IPv6 += inc
|
||||
}
|
||||
instance.Connections.Intermediate.IPv6 += inc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-9
@@ -52,20 +52,23 @@ type connections struct {
|
||||
All connectionType `json:"all"`
|
||||
Abridged connectionType `json:"abridged"`
|
||||
Intermediate connectionType `json:"intermediate"`
|
||||
Secure connectionType `json:"secure"`
|
||||
}
|
||||
|
||||
func (c connections) MarshalJSON() ([]byte, error) {
|
||||
c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4
|
||||
c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6
|
||||
c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4 + c.Secure.IPv4
|
||||
c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6 + c.Secure.IPv6
|
||||
|
||||
value := struct {
|
||||
All connectionType `json:"all"`
|
||||
Abridged connectionType `json:"abridged"`
|
||||
Intermediate connectionType `json:"intermediate"`
|
||||
Secure connectionType `json:"secure"`
|
||||
}{
|
||||
All: c.All,
|
||||
Abridged: c.Abridged,
|
||||
Intermediate: c.Intermediate,
|
||||
Secure: c.Secure,
|
||||
}
|
||||
|
||||
return json.Marshal(value)
|
||||
@@ -87,13 +90,12 @@ type speed struct {
|
||||
}
|
||||
|
||||
type stats struct {
|
||||
URLs config.IPURLs `json:"urls"`
|
||||
ActiveConnections connections `json:"active_connections"`
|
||||
AllConnections connections `json:"all_connections"`
|
||||
Traffic traffic `json:"traffic"`
|
||||
Speed speed `json:"speed"`
|
||||
Uptime uptime `json:"uptime"`
|
||||
Crashes uint32 `json:"crashes"`
|
||||
URLs config.IPURLs `json:"urls"`
|
||||
Connections connections `json:"connections"`
|
||||
Traffic traffic `json:"traffic"`
|
||||
Speed speed `json:"speed"`
|
||||
Uptime uptime `json:"uptime"`
|
||||
Crashes uint32 `json:"crashes"`
|
||||
|
||||
speedCurrent speed
|
||||
mutex *sync.RWMutex
|
||||
|
||||
Reference in New Issue
Block a user