node

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Expiry                                = 300 * time.Second              // Cache expiry time in seconds
	StatusCacheKey                        = "node:status:%d"               // Node status cache key format (Server ID and protocol) Example: node:status:1:shadowsocks
	OnlineUserCacheKeyWithSubscribe       = "node:online:subscribe:%d:%s"  // Online user subscribe cache key format (Server ID and protocol) Example: node:online:subscribe:1:shadowsocks
	OnlineUserSubscribeCacheKeyWithGlobal = "node:online:subscribe:global" // Online user global subscribe cache key
)
View Source
const (
	// ServerUserListCacheKey Server User List Cache Key
	ServerUserListCacheKey = "server:user:"

	// ServerConfigCacheKey Server Config Cache Key
	ServerConfigCacheKey = "server:config:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterNodeParams

type FilterNodeParams struct {
	Page     int      // Page Number
	Size     int      // Page Size
	ServerId []int64  // Server IDs
	Tag      []string // Tags
	Search   string   // Search Address or Name
	Protocol string   // Protocol
	Preload  bool     // Preload Server
}

type FilterParams

type FilterParams struct {
	Page   int
	Size   int
	Ids    []int64 // Server IDs
	Search string
}

FilterParams Filter Server Params

type Model

type Model interface {
	NodeModel
	// contains filtered or unexported methods
}

func NewModel

func NewModel(conn *gorm.DB, cache *redis.Client) Model

NewModel returns a model for the database table.

type Node

type Node struct {
	Id        int64     `gorm:"primary_key"`
	Name      string    `gorm:"type:varchar(100);not null;default:'';comment:Node Name"`
	Tags      string    `gorm:"type:varchar(255);not null;default:'';comment:Tags"`
	Port      uint16    `gorm:"not null;default:0;comment:Connect Port"`
	Address   string    `gorm:"type:varchar(255);not null;default:'';comment:Connect Address"`
	ServerId  int64     `gorm:"not null;default:0;comment:Server ID"`
	Server    *Server   `gorm:"foreignKey:ServerId;references:Id"`
	Protocol  string    `gorm:"type:varchar(100);not null;default:'';comment:Protocol"`
	Enabled   *bool     `gorm:"type:boolean;not null;default:true;comment:Enabled"`
	Sort      int       `gorm:"uniqueIndex;not null;default:0;comment:Sort"`
	CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
	UpdatedAt time.Time `gorm:"comment:Update Time"`
}

func (*Node) BeforeCreate

func (n *Node) BeforeCreate(tx *gorm.DB) error

func (*Node) BeforeDelete

func (n *Node) BeforeDelete(tx *gorm.DB) error

func (*Node) BeforeUpdate

func (n *Node) BeforeUpdate(tx *gorm.DB) error

func (*Node) TableName

func (n *Node) TableName() string

type NodeModel

type NodeModel interface {
	InsertNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
	FindOneNode(ctx context.Context, id int64) (*Node, error)
	UpdateNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
	DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error
}

type OnlineUserSubscribe

type OnlineUserSubscribe map[int64][]string

type Protocol

type Protocol struct {
	Type                 string `json:"type"`
	Port                 uint16 `json:"port"`
	Security             string `json:"security,omitempty"`
	SNI                  string `json:"sni,omitempty"`
	AllowInsecure        bool   `json:"allow_insecure,omitempty"`
	Fingerprint          string `json:"fingerprint,omitempty"`
	RealityServerAddr    string `json:"reality_server_addr,omitempty"`
	RealityServerPort    int    `json:"reality_server_port,omitempty"`
	RealityPrivateKey    string `json:"reality_private_key,omitempty"`
	RealityPublicKey     string `json:"reality_public_key,omitempty"`
	RealityShortId       string `json:"reality_short_id,omitempty"`
	Transport            string `json:"transport,omitempty"`
	Host                 string `json:"host,omitempty"`
	Path                 string `json:"path,omitempty"`
	ServiceName          string `json:"service_name,omitempty"`
	Cipher               string `json:"cipher,omitempty"`
	ServerKey            string `json:"server_key,omitempty"`
	Flow                 string `json:"flow,omitempty"`
	HopPorts             string `json:"hop_ports,omitempty"`
	HopInterval          int    `json:"hop_interval,omitempty"`
	ObfsPassword         string `json:"obfs_password,omitempty"`
	DisableSNI           bool   `json:"disable_sni,omitempty"`
	ReduceRtt            bool   `json:"reduce_rtt,omitempty"`
	UDPRelayMode         string `json:"udp_relay_mode,omitempty"`
	CongestionController string `json:"congestion_controller,omitempty"`
	Plugin               string `json:"plugin,omitempty"`         // obfs, v2ray-plugin, simple-obfs
	PluginOptions        string `json:"plugin_options,omitempty"` // plugin options, eg: obfs=http;obfs-host=www.bing.com
	Multiplex            string `json:"multiplex,omitempty"`      // mux, eg: off/low/medium/high
	PaddingScheme        string `json:"padding_scheme,omitempty"` // padding scheme
	UpMbps               int    `json:"up_mbps,omitempty"`        // upload speed limit
	DownMbps             int    `json:"down_mbps,omitempty"`      // download speed limit
}

func (*Protocol) Marshal

func (m *Protocol) Marshal() ([]byte, error)

Marshal protocol to json

func (*Protocol) Unmarshal

func (m *Protocol) Unmarshal(data []byte) error

Unmarshal json to protocol

type Server

type Server struct {
	Id             int64      `gorm:"primary_key"`
	Name           string     `gorm:"type:varchar(100);not null;default:'';comment:Server Name"`
	Country        string     `gorm:"type:varchar(128);not null;default:'';comment:Country"`
	City           string     `gorm:"type:varchar(128);not null;default:'';comment:City"`
	Ratio          float32    `gorm:"type:DECIMAL(4,2);not null;default:0;comment:Traffic Ratio"`
	Address        string     `gorm:"type:varchar(100);not null;default:'';comment:Server Address"`
	Sort           int        `gorm:"type:int;not null;default:0;comment:Sort"`
	Protocols      string     `gorm:"type:text;default:null;comment:Protocol"`
	LastReportedAt *time.Time `gorm:"comment:Last Reported Time"`
	CreatedAt      time.Time  `gorm:"<-:create;comment:Creation Time"`
	UpdatedAt      time.Time  `gorm:"comment:Update Time"`
}

func (*Server) BeforeCreate

func (m *Server) BeforeCreate(tx *gorm.DB) error

func (*Server) BeforeDelete

func (m *Server) BeforeDelete(tx *gorm.DB) error

func (*Server) BeforeUpdate

func (m *Server) BeforeUpdate(tx *gorm.DB) error

func (*Server) MarshalProtocols

func (m *Server) MarshalProtocols(list []Protocol) error

MarshalProtocols Marshal server protocols to json

func (*Server) TableName

func (*Server) TableName() string

func (*Server) UnmarshalProtocols

func (m *Server) UnmarshalProtocols() ([]Protocol, error)

UnmarshalProtocols Unmarshal server protocols from json

type Status

type Status struct {
	Cpu       float64 `json:"cpu"`
	Mem       float64 `json:"mem"`
	Disk      float64 `json:"disk"`
	UpdatedAt int64   `json:"updated_at"`
}

func (*Status) Marshal

func (s *Status) Marshal() string

Marshal to json string

func (*Status) Unmarshal

func (s *Status) Unmarshal(data string) error

Unmarshal from json string

Jump to

Keyboard shortcuts

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