mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
fix api, smux, nat
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type APIConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
APIConfig `json,yaml:"api"`
|
||||
API APIConfig `json,yaml:"api"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user