common

package
v0.0.0-...-197f44b Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VERSION = "2.0.0-dev"
	//
	BOOT_CLIENT  BootMode = 0
	BOOT_STORAGE BootMode = 1
	BOOT_TRACKER BootMode = 2
	BOOT_AGENT   BootMode = 3
	//
	GROUP_PATTERN       = "^[0-9a-zA-Z-_]{1,30}$"
	SECRET_PATTERN      = "^[^@]{1,30}$"
	SERVER_PATTERN      = "^(([^@^,]{1,30})@)?([^@]+):([1-9][0-9]{0,5})$"
	HTTP_AUTH_PATTERN   = "^([^:]+):([^:]+)$"
	INSTANCE_ID_PATTERN = "^[0-9a-z-]{8}$"
	FILE_META_PATTERN   = "^([0-9a-zA-Z-_]{1,30})/([0-9A-F]{2})/([0-9A-F]{2})/([0-9a-f]{32})$"
	//
	DEFAULT_STORAGE_TCP_PORT  = 10706
	DEFAULT_STORAGE_HTTP_PORT = 11222
	DEFAULT_TRACKER_TCP_PORT  = 11706
	DEFAULT_TRACKER_HTTP_PORT = 12222
	DEFAULT_AGENT_TCP_PORT    = 12706
	DEFAULT_AGENT_HTTP_PORT   = 13222
	BUFFER_SIZE               = 1 << 15 // 32k
	DEFAULT_GROUP             = "G01"
	//
	OPERATION_RESPONSE       Operation = 0
	OPERATION_CONNECT        Operation = 1
	OPERATION_UPLOAD         Operation = 2
	OPERATION_DOWNLOAD       Operation = 3
	OPERATION_QUERY          Operation = 4
	OPERATION_SYNC_INSTANCES Operation = 5
	OPERATION_PUSH_BINLOGS   Operation = 6
	OPERATION_SYNC_BINLOGS   Operation = 7
	//
	SUCCESS           OperationResult = 0
	ERROR             OperationResult = 1
	UNAUTHORIZED      OperationResult = 2
	NOT_FOUND         OperationResult = 3
	UNKNOWN_OPERATION OperationResult = 4
	//
	CMD_SHOW_HELP      Command = 0
	CMD_SHOW_VERSION   Command = 1
	CMD_UPDATE_CONFIG  Command = 2
	CMD_SHOW_CONFIG    Command = 3
	CMD_UPLOAD_FILE    Command = 4
	CMD_DOWNLOAD_FILE  Command = 5
	CMD_INSPECT_FILE   Command = 6
	CMD_BOOT_TRACKER   Command = 7
	CMD_BOOT_STORAGE   Command = 8
	CMD_TEST_UPLOAD    Command = 9
	CMD_GENERATE_TOKEN Command = 10
	CMD_BOOT_AGENT     Command = 11
	//
	ROLE_TRACKER Role = 1
	ROLE_STORAGE Role = 2
	ROLE_PROXY   Role = 3
	ROLE_CLIENT  Role = 4
	ROLE_ANY     Role = 5
	//
	REGISTER_HOLD RegisterState = 1
	REGISTER_FREE RegisterState = 2
	//
	REGISTER_INTERVAL    = time.Second * 30
	SYNCHRONIZE_INTERVAL = time.Second * 45

	FILE_ID_SIZE = 86

	BUCKET_KEY_CONFIGMAP         = "configMap"
	BUCKET_KEY_FAILED_BINLOG_POS = "failedBinlogPos"
	BUCKET_KEY_FILEID            = "fileIds"
)

Variables

View Source
var (
	NotFoundErr                     = errors.New("file not found")
	ServerErr                       = errors.New("server internal error")
	InitializedTrackerConfiguration *TrackerConfig
	InitializedStorageConfiguration *StorageConfig
	InitializedAgentConfiguration   *AgentConfig
	InitializedClientConfiguration  *ClientConfig
	FileMetaPatternRegexp           = regexp.MustCompile(FILE_META_PATTERN)
	ServerPatternRegexp             = regexp.MustCompile(SERVER_PATTERN)
	BootAs                          BootMode

	CusterSecret = make(map[string]string)
)

Functions

func AddSecret

func AddSecret(instanceId string, secret ...string)

func AddWebMimeType

func AddWebMimeType(ext string, mimetype string)

func GetMimeType

func GetMimeType(ext string) string

GetContentTypeHeader gets mime type by file ext

func GetSecret

func GetSecret(secret string) (instance string)

func SetConfigMap

func SetConfigMap(config *ConfigMap)

Types

type AgentConfig

type AgentConfig struct {
	Trackers              []string `json:"trackers"`
	Secret                string   `json:"secret"`
	BindAddress           string   `json:"bindAddress"`
	Port                  int      `json:"port"`
	DataDir               string   `json:"dataDir"`
	LogLevel              string   `json:"logLevel"`
	LogDir                string   `json:"logDir"`
	SaveLog2File          bool     `json:"saveLog2File"`
	MaxRollingLogfileSize int      `json:"maxRollingLogfileSize"`
	LogRotationInterval   string   `json:"logRotationInterval"`
	HttpPort              int      `json:"httpPort"`
	InstanceId            string
	HistorySecrets        map[string]string
	TmpDir                string
	ParsedTrackers        []Server
}

type BingLog

type BingLog struct {
	SourceInstance [8]byte // file source instance
	FileLength     [8]byte // file length
	FileId         []byte  // fileId
}

type BingLogDTO

type BingLogDTO struct {
	SourceInstance string
	FileLength     int64
	FileId         string
}

type BinlogQueryDTO

type BinlogQueryDTO struct {
	FileIndex int   `json:"fileIndex"`
	Offset    int64 `json:"offset"`
}

BinlogQueryDTO is the binlog query entity between storage servers.

type BinlogQueryResultDTO

type BinlogQueryResultDTO struct {
	BinlogQueryDTO
	Logs []BingLogDTO `json:"logs"`
}

BinlogQueryResultDTO is the binlog query result entity between storage servers.

type BootMode

type BootMode uint32

type ClientConfig

type ClientConfig struct {
	Trackers       []string `json:"trackers"`
	Storages       []string `json:"storages"`
	LogLevel       string   `json:"logLevel"`
	Secret         string   `json:"secret"`
	PrivateUpload  bool     `json:"private_upload"`
	TestScale      int      `json:"test_scale"`
	TestThread     int      `json:"test_thread"`
	ParsedTrackers []Server
}

type Command

type Command uint32

type ConfigMap

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

func GetConfigMap

func GetConfigMap() *ConfigMap

func NewConfigMap

func NewConfigMap(path string) (*ConfigMap, error)

func (*ConfigMap) BatchUpdate

func (c *ConfigMap) BatchUpdate(w func(tx *bolt.Tx) error) error

func (*ConfigMap) GetConfig

func (c *ConfigMap) GetConfig(key string) (ret []byte, err error)

func (*ConfigMap) GetFile

func (c *ConfigMap) GetFile(key string) (ret []byte, err error)

func (*ConfigMap) IteratorFailedBinlog

func (c *ConfigMap) IteratorFailedBinlog(iterator func(c *bolt.Cursor) error) error

func (*ConfigMap) PutConfig

func (c *ConfigMap) PutConfig(key string, value []byte) error

func (*ConfigMap) PutFailedBinlogPos

func (c *ConfigMap) PutFailedBinlogPos(binlogPos *BinlogQueryDTO) error

func (*ConfigMap) PutFile

func (c *ConfigMap) PutFile(binlogs []BingLogDTO) error

type FileId

type FileId struct {
	FileId     string
	InstanceId string
	Timestamp  time.Time
}

FileId is a file

type FileInfo

type FileInfo struct {
	Group      string `json:"group"`
	Path       string `json:"path"`
	FileLength int64  `json:"size"`
	InstanceId string `json:"instance"`
	IsPrivate  bool   `json:"isPrivate"`
	CreateTime int64  `json:"createTime"`
}
type Header struct {
	Operation  Operation         `json:"op"`
	Result     OperationResult   `json:"ret"`
	Msg        string            `json:"msg"`
	Attributes map[string]string `json:"ats"`
}

type Instance

type Instance struct {
	Server
	Role         Role              `json:"role"`
	Attributes   map[string]string `json:"ats"`
	RegisterTime int64             `json:"ts"`
	State        RegisterState     `json:"state"`
}

type InstanceMap

type InstanceMap struct {
	Instances map[string]Instance `json:"instances"`
}

type Operation

type Operation byte

type OperationResult

type OperationResult byte

type RegisterState

type RegisterState byte

type Role

type Role byte

type Server

type Server struct {
	Host           string            `json:"host"`
	Port           uint16            `json:"port"`
	HttpPort       uint16            `json:"httpPort"`
	Secret         string            `json:"secret"`
	HistorySecrets map[string]string `json:"history_secret"` // 历史密码
	InstanceId     string            `json:"instanceId"`
}

func (*Server) ConnectionString

func (s *Server) ConnectionString() string

func (*Server) GetHost

func (s *Server) GetHost() string

GetHost returns server's host.

func (*Server) GetPort

func (s *Server) GetPort() uint16

GetPort returns server's port.

type StorageConfig

type StorageConfig struct {
	Trackers              []string `json:"trackers"`
	Secret                string   `json:"secret"`
	Group                 string   `json:"group"`
	BindAddress           string   `json:"bindAddress"`
	Port                  int      `json:"port"`
	AdvertiseAddress      string   `json:"advertiseAddress"`
	AdvertisePort         int      `json:"advertisePort"`
	DataDir               string   `json:"dataDir"`
	PreferredNetworks     string   `json:"preferredNetworks"`
	LogLevel              string   `json:"logLevel"`
	LogDir                string   `json:"logDir"`
	SaveLog2File          bool     `json:"saveLog2File"`
	MaxRollingLogfileSize int      `json:"maxRollingLogfileSize"`
	LogRotationInterval   string   `json:"logRotationInterval"`
	EnableHttp            bool     `json:"enableHttp"`
	HttpPort              int      `json:"httpPort"`
	EnableMimeTypes       bool     `json:"enableMimeTypes"`
	Readonly              bool     `json:"readonly"`
	PublicAccessMode      bool     `json:"publicAccessMode"`
	AllowedDomains        []string `json:"allowedDomains"`
	InstanceId            string
	HistorySecrets        map[string]string
	TmpDir                string
	ParsedTrackers        []Server
}

type StorageServer

type StorageServer struct {
	Server
	Group string `json:"group"`
}

func (*StorageServer) ToServer

func (s *StorageServer) ToServer() *Server

type TrackerConfig

type TrackerConfig struct {
	Trackers              []string `json:"trackers"`
	Secret                string   `json:"secret"`
	InstanceId            string
	BindAddress           string `json:"bindAddress"`
	Port                  int    `json:"port"`
	AdvertiseAddress      string `json:"advertiseAddress"`
	AdvertisePort         int    `json:"advertisePort"`
	DataDir               string `json:"dataDir"`
	PreferredNetworks     string `json:"preferredNetworks"`
	LogLevel              string `json:"logLevel"`
	LogDir                string `json:"logDir"`
	SaveLog2File          bool   `json:"saveLog2File"`
	MaxRollingLogfileSize int    `json:"maxRollingLogfileSize"`
	LogRotationInterval   string `json:"logRotationInterval"`
	EnableHttp            bool   `json:"enableHttp"`
	HttpPort              int    `json:"httpPort"` // TODO add advertise http port
	HistorySecrets        map[string]string
	ParsedTrackers        []Server
}

type UploadResult

type UploadResult struct {
	Group    string `json:"group"`
	Instance string `json:"instance"`
	FileId   string `json:"fileId"`
}

Jump to

Keyboard shortcuts

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