Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyJSONClientConfig(path string) error
- func ApplyJSONServerConfig(path string) error
- func ApplyURLClientConfig(u string) error
- func ClientConfigToURL(config *pb.ClientConfig) (string, error)
- func ClientUpdaterHistoryPath() (string, error)
- func DeleteClientConfigProfile(profileName string) error
- func DeleteServerUsers(names []string) error
- func FlatPortBindings(bindings []*pb.PortBinding) ([]*pb.PortBinding, error)
- func GetActiveProfileFromConfig(config *pb.ClientConfig, name string) (*pb.ClientProfile, error)
- func GetAppStatus() pb.AppStatus
- func GetJSONClientConfig() (string, error)
- func GetJSONServerConfig() (string, error)
- func GetServerStatusWithRPC(ctx context.Context) (*pb.AppStatusMsg, error)
- func GetURLClientConfig() (string, error)
- func HashUserPassword(user *pb.User, keepPlaintext bool) *pb.User
- func HashUserPasswords(users []*pb.User, keepPlaintext bool) []*pb.User
- func IsClientApp() bool
- func IsClientDaemonRunning(ctx context.Context) error
- func IsServerApp() bool
- func IsServerDaemonRunning(appStatus *pb.AppStatusMsg) error
- func IsServerProxyRunning(appStatus *pb.AppStatusMsg) error
- func LoadClientConfig() (*pb.ClientConfig, error)
- func LoadServerConfig() (*pb.ServerConfig, error)
- func NewClientLifecycleRPCClient() (appctlgrpc.ClientLifecycleServiceClient, error)
- func NewClientLifecycleService() *clientLifecycleService
- func NewServerConfigRPCClient() (appctlgrpc.ServerConfigServiceClient, error)
- func NewServerConfigService() *serverConfigService
- func NewServerLifecycleRPCClient() (appctlgrpc.ServerLifecycleServiceClient, error)
- func NewServerLifecycleService() *serverLifecycleService
- func PortBindingsToUnderlayProperties(portBindings []*pb.PortBinding, mtu int) ([]protocol.UnderlayProperties, error)
- func ServerUDS() string
- func SetAppStatus(status pb.AppStatus)
- func SetAppType(t AppType)
- func SetClientMuxRef(mux *protocol.Mux)
- func SetClientRPCServerRef(server *grpc.Server)
- func SetClientSocks5ServerRef(server *socks5.Server)
- func SetServerMuxRef(mux *protocol.Mux)
- func SetServerRPCServerRef(server *grpc.Server)
- func SetSocks5Server(server *socks5.Server)
- func StoreClientConfig(config *pb.ClientConfig) error
- func StoreServerConfig(config *pb.ServerConfig) error
- func URLToClientConfig(s string) (*pb.ClientConfig, error)
- func UserListToMap(users []*pb.User) map[string]*pb.User
- func ValidateClientConfigPatch(patch *pb.ClientConfig) error
- func ValidateClientConfigSingleProfile(profile *pb.ClientProfile) error
- func ValidateFullClientConfig(config *pb.ClientConfig) error
- func ValidateFullServerConfig(config *pb.ServerConfig) error
- func ValidateServerConfigPatch(patch *pb.ServerConfig) error
- type AppType
- type ConfigFileType
Constants ¶
const ( // RPCTimeout is the timeout to complete a RPC call. // We use a very large timeout that works for embedded computer // and anti-virus sandbox environment. RPCTimeout = time.Second * 10 // MaxRecvMsgSize is the maximum message size in bytes that // can be received in gRPC. MaxRecvMsgSize = math.MaxInt32 )
Variables ¶
var ( // ClientRPCServerStarted is closed when client RPC server is started. ClientRPCServerStarted chan struct{} = make(chan struct{}) // ClientSocks5ServerStarted is closed when client socks5 server is started. ClientSocks5ServerStarted chan struct{} = make(chan struct{}) )
var ( // ServerRPCServerStarted is closed when server RPC server is started. ServerRPCServerStarted chan struct{} = make(chan struct{}) )
Functions ¶
func ApplyJSONClientConfig ¶
ApplyJSONClientConfig applies user provided JSON client config from the given file.
func ApplyJSONServerConfig ¶
ApplyJSONServerConfig applies user provided JSON server config from path.
func ApplyURLClientConfig ¶
ApplyJSONClientConfig applies user provided client config URL.
func ClientConfigToURL ¶
func ClientConfigToURL(config *pb.ClientConfig) (string, error)
ClientConfigToURL creates a URL to share the client configuration.
func ClientUpdaterHistoryPath ¶ added in v3.7.0
ClientUpdaterHistoryPath returns the file path to retrieve client updater history.
func DeleteClientConfigProfile ¶
DeleteClientConfigProfile deletes a profile stored in client config. The profile to delete can't be the active profile.
func DeleteServerUsers ¶
DeleteServerUsers deletes the list of users from server config.
func FlatPortBindings ¶
func FlatPortBindings(bindings []*pb.PortBinding) ([]*pb.PortBinding, error)
FlatPortBindings checks port bindings and convert port range to a list of ports.
func GetActiveProfileFromConfig ¶
func GetActiveProfileFromConfig(config *pb.ClientConfig, name string) (*pb.ClientProfile, error)
GetActiveProfileFromConfig returns the active client profile from client config.
func GetAppStatus ¶
GetAppStatus returns the application running status.
func GetJSONClientConfig ¶
GetJSONClientConfig returns the client config as JSON.
func GetJSONServerConfig ¶
GetJSONServerConfig returns the server config as JSON.
func GetServerStatusWithRPC ¶
func GetServerStatusWithRPC(ctx context.Context) (*pb.AppStatusMsg, error)
GetServerStatusWithRPC gets server application status via ServerLifecycleService.GetStatus() RPC.
func GetURLClientConfig ¶
GetURLClientConfig returns the client config as a URL.
func HashUserPassword ¶
HashUserPassword replaces user's password with hashed password.
func HashUserPasswords ¶
HashUserPasswords replaces user's password with hashed password for a slice of users.
func IsClientApp ¶
func IsClientApp() bool
IsClientApp returns true if our application type is client.
func IsClientDaemonRunning ¶
IsClientDaemonRunning detects if client daemon is running by using ClientLifecycleService.GetStatus() RPC.
func IsServerApp ¶
func IsServerApp() bool
IsServerApp returns true if our application type is server.
func IsServerDaemonRunning ¶
func IsServerDaemonRunning(appStatus *pb.AppStatusMsg) error
IsServerDaemonRunning returns nil if app status shows server daemon is running.
func IsServerProxyRunning ¶
func IsServerProxyRunning(appStatus *pb.AppStatusMsg) error
IsServerProxyRunning returns nil if app status shows proxy function is running.
func LoadClientConfig ¶
func LoadClientConfig() (*pb.ClientConfig, error)
LoadClientConfig reads client config from disk.
func LoadServerConfig ¶
func LoadServerConfig() (*pb.ServerConfig, error)
LoadServerConfig reads server config from disk.
func NewClientLifecycleRPCClient ¶
func NewClientLifecycleRPCClient() (appctlgrpc.ClientLifecycleServiceClient, error)
NewClientLifecycleRPCClient creates a new ClientLifecycleService RPC client. It loads client config to find the server address.
func NewClientLifecycleService ¶
func NewClientLifecycleService() *clientLifecycleService
NewClientLifecycleService creates a new ClientLifecycleService RPC server.
func NewServerConfigRPCClient ¶
func NewServerConfigRPCClient() (appctlgrpc.ServerConfigServiceClient, error)
NewServerConfigRPCClient creates a new ServerConfigService RPC client.
func NewServerConfigService ¶
func NewServerConfigService() *serverConfigService
NewServerConfigService creates a new ServerConfigService RPC server.
func NewServerLifecycleRPCClient ¶
func NewServerLifecycleRPCClient() (appctlgrpc.ServerLifecycleServiceClient, error)
NewServerLifecycleRPCClient creates a new ServerLifecycleService RPC client.
func NewServerLifecycleService ¶
func NewServerLifecycleService() *serverLifecycleService
NewServerLifecycleService creates a new ServerLifecycleService RPC server.
func PortBindingsToUnderlayProperties ¶
func PortBindingsToUnderlayProperties(portBindings []*pb.PortBinding, mtu int) ([]protocol.UnderlayProperties, error)
PortBindingsToUnderlayProperties converts port bindings to underlay properties.
func ServerUDS ¶
func ServerUDS() string
ServerUDS returns the UNIX domain socket that mita server is listening to RPC requests.
func SetAppStatus ¶
SetAppStatus sets the application running status.
func SetAppType ¶
func SetAppType(t AppType)
SetAppType sets the application type. This method is only effective on the first call.
func SetClientMuxRef ¶
func SetClientRPCServerRef ¶
func SetServerMuxRef ¶
func SetServerRPCServerRef ¶
func SetSocks5Server ¶
func StoreClientConfig ¶
func StoreClientConfig(config *pb.ClientConfig) error
StoreClientConfig writes client config to disk.
func StoreServerConfig ¶
func StoreServerConfig(config *pb.ServerConfig) error
StoreServerConfig writes server config to disk.
func URLToClientConfig ¶
func URLToClientConfig(s string) (*pb.ClientConfig, error)
URLToClientConfig returns a client configuration based on the URL.
func UserListToMap ¶
UserListToMap convert a slice of User to a map of <name, User>.
func ValidateClientConfigPatch ¶
func ValidateClientConfigPatch(patch *pb.ClientConfig) error
ValidateClientConfigPatch validates a patch of client config.
A client config patch must satisfy: 1. it has 0 or more profile 2. validate each profile 3. for each socks5 authentication, the user and password are not empty
func ValidateClientConfigSingleProfile ¶ added in v3.6.0
func ValidateClientConfigSingleProfile(profile *pb.ClientProfile) error
ValidateClientConfigSingleProfile validates a single client config profile.
It validates 1. profile name is not empty 2. user name is not empty 3. user has either a password or a hashed password 4. user has no quota 5. it has at least 1 server, and for each server 5.1. the server has either IP address or domain name 5.2. if set, server's IP address is parsable 5.3. the server has at least 1 port binding, and all port bindings are valid 6. if set, MTU is valid
func ValidateFullClientConfig ¶
func ValidateFullClientConfig(config *pb.ClientConfig) error
ValidateFullClientConfig validates the full client config.
In addition to ValidateClientConfigPatch, it also validates: 1. there is at least 1 profile 2. the active profile is available 3. RPC port is valid 4. socks5 port is valid 5. RPC port, socks5 port, http proxy port are different
func ValidateFullServerConfig ¶
func ValidateFullServerConfig(config *pb.ServerConfig) error
ValidateFullServerConfig validates the full server config.
In addition to ValidateServerConfigPatch, it also validates: 1. there is at least 1 port binding
It is not an error if no user is configured. However mita won't be functional.
func ValidateServerConfigPatch ¶
func ValidateServerConfigPatch(patch *pb.ServerConfig) error
ValidateServerConfigPatch validates a patch of server config.
A server config patch must satisfy: 1. port bindings are valid 2. for each user 2.1. user name is not empty 2.2. user has either a password or a hashed password 2.3. for each quota 2.3.1. number of days is valid 2.3.2. traffic volume in megabyte is valid 3. if set, MTU is valid 4. for each egress proxy 4.1. name is not empty 4.2. name is unique 4.3. protocol is valid 4.4. host is not empty 4.5. port is valid 4.6. if socks5 authentication is used, the user and password are not empty 5. there is maximum 1 egress rule 5.1. the IP ranges must be "*" 5.2. the domain names must be "*" 5.3. the action must be "PROXY" 5.4. the proxy name is defined
Types ¶
type ConfigFileType ¶
type ConfigFileType int
const ( INVALID_CONFIG_FILE_TYPE ConfigFileType = iota PROTOBUF_CONFIG_FILE_TYPE JSON_CONFIG_FILE_TYPE )
func FindConfigFileType ¶
func FindConfigFileType(fileName string) ConfigFileType
FindConfigFileType returns the type of configuration file. Similar to Windows, it uses file extension name to make the decision.