util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgTypeQueryPeer     uint16 = 1
	MsgTypePacket        uint16 = 3
	MsgTypeRegisterAck   uint16 = 4
	MsgTypeRegisterSuper uint16 = 5
	HandShakeMsgType     uint16 = 6
	KeepaliveMsgType     uint16 = 7
	HandShakeMsgTypeAck  uint16 = 8
)

Variables

View Source
var (
	UCTL = &user{
		UserId: "123456789abcdef0",
	}
)

Functions

func AddJob

func AddJob(networkId string, fn func(networkId string) error)

func Base64Decode

func Base64Decode(str string) (string, error)

func ExecCommand

func ExecCommand(name string, commands ...string) error

func GetDaemon

func GetDaemon() *daemon.Context

func GetFrameTypeName

func GetFrameTypeName(key uint16) (name string)

func GetPacketHeader

func GetPacketHeader(buff []byte) (packet.Header, error)

func ReplaceLocalConfig

func ReplaceLocalConfig(newCfg *LocalConfig) error

ReplaceLocalConfig update json file

func StringToBase64

func StringToBase64(str string) string

func UpdateLocalConfig

func UpdateLocalConfig(newCfg *LocalConfig) error

UpdateLocalConfig update json file

Types

type Auth

type Auth struct {
	Enable bool `mapstructure:"enable"`
}

type Config

type Config struct {
	NodeCfg     *NodeCfg     `mapstructure:"node"`
	RegistryCfg *RegistryCfg `mapstructure:"registry"`
}

func InitConfig

func InitConfig() (config *Config, err error)

type Encrypt

type Encrypt struct {
	Enable bool `mapstructure:"enable"`
}

type IPHeader

type IPHeader struct {
	SrcIP net.IP
	DstIP net.IP
}

func GetIPFrameHeader

func GetIPFrameHeader(buff []byte) (*IPHeader, error)

GetIPFrameHeader return srcIP, destIP

type IPV6Cfg

type IPV6Cfg struct {
	Enable bool `mapstructure:"enable"`
}

type Local

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

func (*Local) Close

func (l *Local) Close() error

func (*Local) ReadFile

func (l *Local) ReadFile() (config *LocalConfig, err error)

func (*Local) WriteFile

func (l *Local) WriteFile(config *LocalConfig) error

type LocalConfig

type LocalConfig struct {
	Auth   string `json:"auth,omitempty"`
	AppId  string `json:"appId,omitempty"`
	UserId string `json:"userId,omitempty"`
	Debug  bool   `json:"debug,omitempty"`
}

func GetLocalConfig

func GetLocalConfig() (*LocalConfig, error)

type LocalInfo

type LocalInfo struct {
	Username string `json:"username"`
	Password string `json:"password"`
	UserId   string `json:"userId"`
}

func GetLocalUserInfo

func GetLocalUserInfo() (info *LocalInfo, err error)

type LogCfg

type LogCfg struct {
	EnableDebug bool `mapstructure:"debug"`
}

type NodeCfg

type NodeCfg struct {
	Registry   string `mapstructure:"registry"`
	Udp        string `mapstructure:"udp"`
	Listen     int    `mapstructure:"listen"`
	HttpListen string `mapstructure:"httpListen"`
	ConsoleUrl string `mapstructure:"consoleUrl"`
	//Protocol   Protocol `mapstructure:"type"`
	Offset  int32   `mapstructure:"offset"`
	Encrypt Encrypt `mapstructure:"encrypt"`
	Auth    Auth    `mapstructure:"auth"`
	Relay   Relay   `mapstructure:"relay"`
	Log     LogCfg  `mapstructure:"log"`
	IPV6    IPV6Cfg `mapstructure:"ipv6"`
	Driver  string  `mapstructure:"driver"`
}

NodeCfg read from a config file or cmd flags, node and registry configurations are here.

func (*NodeCfg) AuthEnable

func (cfg *NodeCfg) AuthEnable() bool

func (*NodeCfg) ControlUrl

func (cfg *NodeCfg) ControlUrl() string

func (*NodeCfg) EnableAuth

func (cfg *NodeCfg) EnableAuth() bool

func (*NodeCfg) EnableEncrypt

func (cfg *NodeCfg) EnableEncrypt() bool

func (*NodeCfg) EnableRelay

func (cfg *NodeCfg) EnableRelay() bool

func (*NodeCfg) HostUrl

func (cfg *NodeCfg) HostUrl() string

func (*NodeCfg) HttpListenStr

func (cfg *NodeCfg) HttpListenStr() string

func (*NodeCfg) RegistryUrl

func (cfg *NodeCfg) RegistryUrl() string

type Protocol

type Protocol string

type Redis

type Redis struct {
	Enable   bool   `json:"enable"`
	Url      string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type RegistryCfg

type RegistryCfg struct {
	Listen     string `mapstructure:"Listen"`
	HttpListen string `mapstructure:"HttpListen"`
	Redis      Redis  `json:redis`
	Driver     string `mapstructure:"driver"`
}

type Relay

type Relay struct {
	Enable bool `mapstructure:"enable"`
}

type Star

type Star struct {
	Name string
	IP   string
	Mask string
	Mode int //0 tun 1 tap
}

type SuperStar

type SuperStar struct {
	Listen int
}

type UserFunc

type UserFunc interface {
	GetUserId() string
	SetUserId(userId string) error
	SetUserInfo(username, password string) error
}

func NewUser

func NewUser() UserFunc

Jump to

Keyboard shortcuts

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