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 GetClientRPCServerRef() *grpc.Server
- func GetClientSocks5ServerRef() *socks5.Server
- func GetJSONClientConfig() (string, error)
- func GetJSONServerConfig() (string, error)
- func GetServerRPCServerRef() *grpc.Server
- func GetServerSocks5ServerRef() *socks5.Server
- func GetServerStatusWithRPC(ctx context.Context) (*pb.AppStatusMsg, 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 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 SetServerSocks5ServerRef(server *socks5.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
Constants ¶
const ServerUDS = "/var/run/mita.sock"
ServerUDS is the UNIX domain socket that server is listening to RPC requests.
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{}) // ServerSocks5ServerStarted is closed when server socks5 server is started. ServerSocks5ServerStarted 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 GetClientRPCServerRef ¶
func GetJSONClientConfig ¶
GetJSONClientConfig returns the client config as JSON.
func GetJSONServerConfig ¶
GetJSONServerConfig returns the server config as JSON.
func GetServerRPCServerRef ¶
func GetServerStatusWithRPC ¶
func GetServerStatusWithRPC(ctx context.Context) (*pb.AppStatusMsg, error)
GetServerStatusWithRPC gets server application status via ServerLifecycleService.GetStatus() RPC.
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 exactly 1 server 2.5. either the server's IP address or the server's domain name is available 2.6. the server has exactly 1 port binding 2.7. port number is valid 2.8. protocol 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
func ValidateFullServerConfig ¶
func ValidateFullServerConfig(config *pb.ServerConfig) error
ValidateFullServerConfig validates the full server config.
In addition to ValidateServerConfigPatch, it also validates: 1. there is exactly 1 port binding
func ValidateServerConfigPatch ¶
func ValidateServerConfigPatch(patch *pb.ServerConfig) error
ValidateServerConfigPatch validates a patch of server config.
A server config patch must satisfy: 1. it has 0 or more port binding 2. for each port binding 2.1. port number is valid 2.2. protocol is valid 3. it has 0 or more user 4. for each user 4.1. user name is not empty 4.2. user has either a password or a hashed password