Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyJSONClientConfig(path string) error
- func ApplyJSONServerConfig(path string) error
- func DeleteClientConfigProfile(profileName string) error
- func DeleteServerUsers(names []string) 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 GetSocks5ServerGroup() *socks5.ServerGroup
- 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 Marshal(m protoreflect.ProtoMessage) ([]byte, error)
- func NewClientLifecycleRPCClient(ctx context.Context) (pb.ClientLifecycleServiceClient, error)
- func NewClientLifecycleService() *clientLifecycleService
- func NewServerConfigRPCClient() (pb.ServerConfigServiceClient, error)
- func NewServerConfigService() *serverConfigService
- func NewServerLifecycleRPCClient() (pb.ServerLifecycleServiceClient, error)
- func NewServerLifecycleService() *serverLifecycleService
- func RPCTimeout() time.Duration
- func SetAppStatus(status pb.AppStatus)
- func SetAppType(t AppType)
- func SetClientRPCServerRef(server *grpc.Server)
- func SetClientSocks5ServerRef(server *socks5.Server)
- func SetServerRPCServerRef(server *grpc.Server)
- func StoreClientConfig(config *pb.ClientConfig) error
- func StoreServerConfig(config *pb.ServerConfig) error
- func Unmarshal(b []byte, m protoreflect.ProtoMessage) error
- func UserListToMap(users []*pb.User) map[string]*pb.User
- func ValidateClientConfigPatch(patch *pb.ClientConfig) 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 (
// ServerUDS is the UNIX domain socket that server is listening to RPC requests.
ServerUDS = "/var/run/mita.sock"
)
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 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 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 GetSocks5ServerGroup ¶ added in v1.3.0
func GetSocks5ServerGroup() *socks5.ServerGroup
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 Marshal ¶
func Marshal(m protoreflect.ProtoMessage) ([]byte, error)
Marshal returns a JSON representation of protobuf.
func NewClientLifecycleRPCClient ¶
func NewClientLifecycleRPCClient(ctx context.Context) (pb.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() (pb.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() (pb.ServerLifecycleServiceClient, error)
NewServerLifecycleRPCClient creates a new ServerLifecycleService RPC client.
func NewServerLifecycleService ¶
func NewServerLifecycleService() *serverLifecycleService
NewServerLifecycleService creates a new ServerLifecycleService RPC server.
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 SetClientRPCServerRef ¶
func SetServerRPCServerRef ¶
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 Unmarshal ¶
func Unmarshal(b []byte, m protoreflect.ProtoMessage) error
Unmarshal writes protobuf based on JSON data.
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. for each profile 2.1. profile name is not empty 2.2. user name is not empty 2.3. user has either a password or a hashed password 2.4. it has at least 1 server, and for each server 2.4.1. the server has either IP address or domain name 2.4.2. if set, server's IP address is parsable 2.4.3. the server has at least 1 port binding, and for each port binding 2.4.3.1. port number is valid 2.4.3.2. protocol is valid 2.5. 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 mieru 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. for each port binding 1.1. port number is valid 1.2. protocol is valid 2. for each user 2.1. user name is not empty 2.2. user has either a password or a hashed password 3. if set, MTU is valid
Types ¶
type ConfigFileType ¶ added in v1.6.0
type ConfigFileType int
const ( INVALID_CONFIG_FILE_TYPE ConfigFileType = iota PROTOBUF_CONFIG_FILE_TYPE JSON_CONFIG_FILE_TYPE )
func FindConfigFileType ¶ added in v1.6.0
func FindConfigFileType(fileName string) ConfigFileType
FindConfigFileType returns the type of configuration file. Similar to Windows, it uses file extension name to make the decision.