mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-03 15:06:36 +08:00
63cd906cfc
- Merge all files inside openflare-server to the repository root directory. - Relocate agent, relay, and flared subprojects from internal/ to internal/apps/. - Combine docker-compose files and update build context paths to root. - Update GitHub workflows and Dockerfiles to refer to new directories and package names. - Rewrite Go package imports across all files. - Resolve database renew test race condition and clean up docs.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package dashboard
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
ofws "github.com/Rain-kl/Wavelet/internal/apps/openflare/websocket"
|
|
"github.com/Rain-kl/Wavelet/internal/model"
|
|
)
|
|
|
|
const (
|
|
nodeStatusOnline = "online"
|
|
nodeStatusOffline = "offline"
|
|
nodeStatusPending = "pending"
|
|
)
|
|
|
|
func computeNodeStatus(node *model.OpenFlareNode) string {
|
|
if node == nil {
|
|
return nodeStatusOffline
|
|
}
|
|
if node.LastSeenAt == nil || node.LastSeenAt.IsZero() {
|
|
return nodeStatusPending
|
|
}
|
|
if time.Since(*node.LastSeenAt) > model.NodeOfflineThreshold {
|
|
return nodeStatusOffline
|
|
}
|
|
return nodeStatusOnline
|
|
}
|
|
|
|
func nodeViewLastSeenAt(node *model.OpenFlareNode) any {
|
|
if node == nil {
|
|
return time.Time{}
|
|
}
|
|
nodeType := strings.TrimSpace(node.NodeType)
|
|
if nodeType == "" {
|
|
nodeType = "edge_node"
|
|
}
|
|
if nodeType == "tunnel_relay" && ofws.IsRelayConnected(node.NodeID) {
|
|
return ofws.RelayWSConnectedLastSeenValue
|
|
}
|
|
if nodeType == "tunnel_client" && ofws.IsFlaredConnected(node.NodeID) {
|
|
return ofws.FlaredWSConnectedLastSeenValue
|
|
}
|
|
if ofws.IsAgentConnected(node.NodeID) {
|
|
return ofws.AgentWSConnectedLastSeenValue
|
|
}
|
|
if node.LastSeenAt == nil {
|
|
return time.Time{}
|
|
}
|
|
return *node.LastSeenAt
|
|
}
|