fix api, smux, nat

This commit is contained in:
Page Fault
2020-06-11 06:06:05 +00:00
parent 4a33464097
commit e06c06dc91
26 changed files with 46 additions and 39 deletions
+5 -2
View File
@@ -53,14 +53,17 @@ func (s *ClientAPI) GetTraffic(ctx context.Context, req *GetTrafficRequest) (*Ge
}
func RunClientAPI(ctx context.Context, auth statistic.Authenticator) error {
cfg := config.FromContext(ctx, Name).(*Config)
if !cfg.API.Enabled {
return nil
}
server := grpc.NewServer()
service := &ClientAPI{
ctx: ctx,
auth: auth,
}
RegisterTrojanClientServiceServer(server, service)
cfg := config.FromContext(ctx, Name).(*Config)
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.APIHost, cfg.APIPort))
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.API.APIHost, cfg.API.APIPort))
if err != nil {
return err
}
+1 -1
View File
@@ -11,7 +11,7 @@ type APIConfig struct {
}
type Config struct {
APIConfig `json,yaml:"api"`
API APIConfig `json,yaml:"api"`
}
func init() {
+5 -2
View File
@@ -166,13 +166,16 @@ func (s *ServerAPI) ListUsers(req *ListUsersRequest, stream TrojanServerService_
}
func RunServerAPI(ctx context.Context, auth statistic.Authenticator) error {
cfg := config.FromContext(ctx, Name).(*Config)
if !cfg.API.Enabled {
return nil
}
server := grpc.NewServer()
service := &ServerAPI{
auth: auth,
}
RegisterTrojanServerServiceServer(server, service)
cfg := config.FromContext(ctx, Name).(*Config)
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.APIHost, cfg.APIPort))
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.API.APIHost, cfg.API.APIPort))
if err != nil {
return err
}