server

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLoginFailCount  = 10
	LoginBlockDuration = 3 * time.Minute
)

Variables

View Source
var DebugMode bool = true

========================== JWT Implementation ==========================

Functions

func AddLoginFail

func AddLoginFail(ip string)

func ClearLoginFail

func ClearLoginFail(ip string)

func GenerateNonce

func GenerateNonce() (string, error)

func GetLimiter

func GetLimiter(ip string) *rate.Limiter

func IsIPBlocked

func IsIPBlocked(ip string) (bool, time.Duration)

func JWTAuth

func JWTAuth() fiber.Handler

func RecordChannelConnectionStart

func RecordChannelConnectionStart(channelID string)

RecordChannelConnectionStart 记录通道连接开始 (供 driver 调用)

func RecordChannelError

func RecordChannelError(channelID string, errType, code, message string)

RecordChannelError 记录通道错误 (供 driver 调用)

func RecordChannelReconnect

func RecordChannelReconnect(channelID string)

RecordChannelReconnect 记录通道重连 (供 driver 调用)

func RecordChannelRequest

func RecordChannelRequest(channelID string, success bool, duration time.Duration, errorType string)

RecordChannelRequest 记录通道请求指标 (供 driver 调用)

func UpdateDeviceMetrics

func UpdateDeviceMetrics(deviceID string, update func(*model.DeviceMetrics))

UpdateDeviceMetrics 更新设备指标 (供 driver 调用)

func ValidateAndConsumeNonce

func ValidateAndConsumeNonce(nonce string) bool

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword string `json:"oldPassword"` // Hashed with nonce
	NewPassword string `json:"newPassword"` // Raw password (will be stored as is, assuming config stores plain text or we hash it here?)
	Nonce       string `json:"nonce"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client for WebSocket connections

type CustomClaims

type CustomClaims struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	jwt.RegisteredClaims
}

type DashboardSummary

type DashboardSummary struct {
	Channels   []core.ChannelStatus    `json:"channels"`
	Northbound []core.NorthboundStatus `json:"northbound"`
	EdgeRules  core.EdgeComputeMetrics `json:"edge_rules"`
	System     SystemStats             `json:"system"`
}

type EdgeLogQuery

type EdgeLogQuery struct {
	RuleID    string `query:"rule_id"`
	Category  string `query:"category"`
	ChannelID string `query:"channel_id"`
	DeviceID  string `query:"device_id"`
	StartDate string `query:"start_date"` // Format: YYYY-MM-DD HH:mm
	EndDate   string `query:"end_date"`   // Format: YYYY-MM-DD HH:mm
}

EdgeLogQuery represents query parameters

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

WebSocket Hub

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

func (*JWT) ParserToken

func (j *JWT) ParserToken(tokenString string) (*CustomClaims, error)

type LoginFailInfo

type LoginFailInfo struct {
	Count      int
	LastFailAt time.Time
	BlockUntil time.Time
}

type LoginRequest

type LoginRequest struct {
	LoginFlag bool   `json:"loginFlag"`
	LoginType string `json:"loginType"` // "local" or "ldap"
	Data      struct {
		Username string `json:"username"`
		Password string `json:"password"`
		Nonce    string `json:"nonce"`
	} `json:"data"`
}

LoginRequest defines the login payload

type LoginResponse

type LoginResponse struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Username    string   `json:"username"`
		Token       string   `json:"token"`
		Permissions []string `json:"permissions"`
	} `json:"data"`
}

LoginResponse defines the successful login response

type Server

type Server struct {
	// contains filtered or unexported fields
}

func (*Server) AuthenticateLDAP

func (s *Server) AuthenticateLDAP(username, password string) (bool, *model.UserConfig, error)

AuthenticateLDAP attempts to authenticate a user against the configured LDAP server

func (*Server) BroadcastShadowPoint

func (s *Server) BroadcastShadowPoint(channelID, deviceID, pointID string, point model.ShadowPoint)

BroadcastShadowPoint 将影子点位快照推送到 WebSocket 客户端。

func (*Server) BroadcastValue

func (s *Server) BroadcastValue(v any)

BroadcastValue sends a value to all connected clients

func (*Server) GetListenPort

func (s *Server) GetListenPort() int

func (*Server) SetRuntimeStartHook added in v0.0.7

func (s *Server) SetRuntimeStartHook(fn func())

SetRuntimeStartHook 注册数据采集/北向启动回调(安装完成后或正常启动时调用)。

func (*Server) SetShadowCore

func (s *Server) SetShadowCore(sc *core.ShadowCore)

SetShadowCore 绑定影子设备核心,并订阅快照变更推送到 WebSocket。

func (*Server) SetStorageAttachHook

func (s *Server) SetStorageAttachHook(fn func(*storage.Storage))

SetStorageAttachHook 注册存储绑定回调(安装流程创建 DB 后回传 main 等组件)。

func (*Server) SetVirtualShadowEngine

func (s *Server) SetVirtualShadowEngine(vse *core.VirtualShadowEngine)

SetVirtualShadowEngine 绑定虚拟影子引擎(公式点位增量计算)。

func (*Server) SetVirtualShadowManager

func (s *Server) SetVirtualShadowManager(vsm *core.VirtualShadowManager)

func (*Server) Start

func (s *Server) Start(addr string) error

func (*Server) StopBackgroundTasks added in v0.0.8

func (s *Server) StopBackgroundTasks()

StopBackgroundTasks 停止后台维护任务(定时 compact 等)。

func (*Server) SwitchPort

func (s *Server) SwitchPort(newPort int) error

func (*Server) ValidateUser

func (s *Server) ValidateUser(username, password, nonce string) (*model.UserConfig, error)

Helper to check login from other parts of the system if needed

type SnapshotResponse

type SnapshotResponse struct {
	ID          string                `json:"id"`
	Name        string                `json:"name"`
	NodeID      string                `json:"node_id"`
	NodeName    string                `json:"node_name"`
	CapturedAt  string                `json:"captured_at"`
	Size        int64                 `json:"size"`
	Description string                `json:"description"`
	Tags        []string              `json:"tags"`
	Data        *syncpkg.NodeSnapshot `json:"data,omitempty"`
}

SnapshotResponse represents a snapshot API response

type SystemStats

type SystemStats struct {
	CPUUsage    float64 `json:"cpu_usage"`
	MemoryUsage float64 `json:"memory_usage"`
	DiskUsage   float64 `json:"disk_usage"`
	GoRoutines  int     `json:"goroutines"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL