update registry
This commit is contained in:
parent
0aee4f0ebd
commit
07132d8de7
2
.github/workflows/buildx.yaml
vendored
2
.github/workflows/buildx.yaml
vendored
@ -36,7 +36,7 @@ jobs:
|
|||||||
# Set output parameters.
|
# Set output parameters.
|
||||||
echo ::set-output name=tags::${TAGS}
|
echo ::set-output name=tags::${TAGS}
|
||||||
echo ::set-output name=docker_image::${DOCKER_IMAGE}
|
echo ::set-output name=docker_image::${DOCKER_IMAGE}
|
||||||
echo ::set-output name=docker_platforms::linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
|
echo ::set-output name=docker_platforms::linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/s390x
|
||||||
|
|
||||||
# https://github.com/crazy-max/ghaction-docker-buildx
|
# https://github.com/crazy-max/ghaction-docker-buildx
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
|
@ -270,10 +270,10 @@ func buildServiceConfig(url *url.URL) (*config.ServiceConfig, error) {
|
|||||||
Addr: url.Host,
|
Addr: url.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
if h := registry.GetHandler(handler); h == nil {
|
if h := registry.HandlerRegistry().Get(handler); h == nil {
|
||||||
handler = "auto"
|
handler = "auto"
|
||||||
}
|
}
|
||||||
if ln := registry.GetListener(listener); ln == nil {
|
if ln := registry.ListenerRegistry().Get(listener); ln == nil {
|
||||||
listener = "tcp"
|
listener = "tcp"
|
||||||
if handler == "ssu" {
|
if handler == "ssu" {
|
||||||
listener = "udp"
|
listener = "udp"
|
||||||
@ -378,10 +378,10 @@ func buildNodeConfig(url *url.URL) (*config.NodeConfig, error) {
|
|||||||
Addr: url.Host,
|
Addr: url.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c := registry.GetConnector(connector); c == nil {
|
if c := registry.ConnectorRegistry().Get(connector); c == nil {
|
||||||
connector = "http"
|
connector = "http"
|
||||||
}
|
}
|
||||||
if d := registry.GetDialer(dialer); d == nil {
|
if d := registry.DialerRegistry().Get(dialer); d == nil {
|
||||||
dialer = "tcp"
|
dialer = "tcp"
|
||||||
if connector == "ssu" {
|
if connector == "ssu" {
|
||||||
dialer = "udp"
|
dialer = "udp"
|
||||||
|
@ -20,7 +20,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
|
|
||||||
for _, autherCfg := range cfg.Authers {
|
for _, autherCfg := range cfg.Authers {
|
||||||
if auther := parsing.ParseAuther(autherCfg); auther != nil {
|
if auther := parsing.ParseAuther(autherCfg); auther != nil {
|
||||||
if err := registry.Auther().Register(autherCfg.Name, auther); err != nil {
|
if err := registry.AutherRegistry().Register(autherCfg.Name, auther); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
|
|
||||||
for _, admissionCfg := range cfg.Admissions {
|
for _, admissionCfg := range cfg.Admissions {
|
||||||
if adm := parsing.ParseAdmission(admissionCfg); adm != nil {
|
if adm := parsing.ParseAdmission(admissionCfg); adm != nil {
|
||||||
if err := registry.Admission().Register(admissionCfg.Name, adm); err != nil {
|
if err := registry.AdmissionRegistry().Register(admissionCfg.Name, adm); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
|
|
||||||
for _, bypassCfg := range cfg.Bypasses {
|
for _, bypassCfg := range cfg.Bypasses {
|
||||||
if bp := parsing.ParseBypass(bypassCfg); bp != nil {
|
if bp := parsing.ParseBypass(bypassCfg); bp != nil {
|
||||||
if err := registry.Bypass().Register(bypassCfg.Name, bp); err != nil {
|
if err := registry.BypassRegistry().Register(bypassCfg.Name, bp); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if r != nil {
|
if r != nil {
|
||||||
if err := registry.Resolver().Register(resolverCfg.Name, r); err != nil {
|
if err := registry.ResolverRegistry().Register(resolverCfg.Name, r); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
|
|
||||||
for _, hostsCfg := range cfg.Hosts {
|
for _, hostsCfg := range cfg.Hosts {
|
||||||
if h := parsing.ParseHosts(hostsCfg); h != nil {
|
if h := parsing.ParseHosts(hostsCfg); h != nil {
|
||||||
if err := registry.Hosts().Register(hostsCfg.Name, h); err != nil {
|
if err := registry.HostsRegistry().Register(hostsCfg.Name, h); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if c != nil {
|
if c != nil {
|
||||||
if err := registry.Chain().Register(chainCfg.Name, c); err != nil {
|
if err := registry.ChainRegistry().Register(chainCfg.Name, c); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ func buildService(cfg *config.Config) (services []service.Service) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if svc != nil {
|
if svc != nil {
|
||||||
if err := registry.Service().Register(svcCfg.Name, svc); err != nil {
|
if err := registry.ServiceRegistry().Register(svcCfg.Name, svc); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func logFromConfig(cfg *config.LogConfig) logger.Logger {
|
|||||||
func buildAPIService(cfg *config.APIConfig) (service.Service, error) {
|
func buildAPIService(cfg *config.APIConfig) (service.Service, error) {
|
||||||
auther := parsing.ParseAutherFromAuth(cfg.Auth)
|
auther := parsing.ParseAutherFromAuth(cfg.Auth)
|
||||||
if cfg.Auther != "" {
|
if cfg.Auther != "" {
|
||||||
auther = registry.Auther().Get(cfg.Auther)
|
auther = registry.AutherRegistry().Get(cfg.Auther)
|
||||||
}
|
}
|
||||||
return api.NewService(
|
return api.NewService(
|
||||||
cfg.Addr,
|
cfg.Addr,
|
||||||
|
@ -42,7 +42,7 @@ func createAdmission(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseAdmission(&req.Data)
|
v := parsing.ParseAdmission(&req.Data)
|
||||||
|
|
||||||
if err := registry.Admission().Register(req.Data.Name, v); err != nil {
|
if err := registry.AdmissionRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func updateAdmission(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Admission().IsRegistered(req.Admission) {
|
if !registry.AdmissionRegistry().IsRegistered(req.Admission) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -95,9 +95,9 @@ func updateAdmission(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseAdmission(&req.Data)
|
v := parsing.ParseAdmission(&req.Data)
|
||||||
|
|
||||||
registry.Admission().Unregister(req.Admission)
|
registry.AdmissionRegistry().Unregister(req.Admission)
|
||||||
|
|
||||||
if err := registry.Admission().Register(req.Admission, v); err != nil {
|
if err := registry.AdmissionRegistry().Register(req.Admission, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,11 +143,11 @@ func deleteAdmission(ctx *gin.Context) {
|
|||||||
var req deleteAdmissionRequest
|
var req deleteAdmissionRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Admission().IsRegistered(req.Admission) {
|
if !registry.AdmissionRegistry().IsRegistered(req.Admission) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Admission().Unregister(req.Admission)
|
registry.AdmissionRegistry().Unregister(req.Admission)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
admissiones := cfg.Admissions
|
admissiones := cfg.Admissions
|
||||||
|
@ -41,7 +41,7 @@ func createAuther(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v := parsing.ParseAuther(&req.Data)
|
v := parsing.ParseAuther(&req.Data)
|
||||||
if err := registry.Auther().Register(req.Data.Name, v); err != nil {
|
if err := registry.AutherRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ func updateAuther(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Auther().IsRegistered(req.Auther) {
|
if !registry.AutherRegistry().IsRegistered(req.Auther) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -93,9 +93,9 @@ func updateAuther(ctx *gin.Context) {
|
|||||||
req.Data.Name = req.Auther
|
req.Data.Name = req.Auther
|
||||||
|
|
||||||
v := parsing.ParseAuther(&req.Data)
|
v := parsing.ParseAuther(&req.Data)
|
||||||
registry.Auther().Unregister(req.Auther)
|
registry.AutherRegistry().Unregister(req.Auther)
|
||||||
|
|
||||||
if err := registry.Auther().Register(req.Auther, v); err != nil {
|
if err := registry.AutherRegistry().Register(req.Auther, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -141,11 +141,11 @@ func deleteAuther(ctx *gin.Context) {
|
|||||||
var req deleteAutherRequest
|
var req deleteAutherRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Auther().IsRegistered(req.Auther) {
|
if !registry.AutherRegistry().IsRegistered(req.Auther) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Auther().Unregister(req.Auther)
|
registry.AutherRegistry().Unregister(req.Auther)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
authers := cfg.Authers
|
authers := cfg.Authers
|
||||||
|
@ -42,7 +42,7 @@ func createBypass(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseBypass(&req.Data)
|
v := parsing.ParseBypass(&req.Data)
|
||||||
|
|
||||||
if err := registry.Bypass().Register(req.Data.Name, v); err != nil {
|
if err := registry.BypassRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func updateBypass(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Bypass().IsRegistered(req.Bypass) {
|
if !registry.BypassRegistry().IsRegistered(req.Bypass) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -95,9 +95,9 @@ func updateBypass(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseBypass(&req.Data)
|
v := parsing.ParseBypass(&req.Data)
|
||||||
|
|
||||||
registry.Bypass().Unregister(req.Bypass)
|
registry.BypassRegistry().Unregister(req.Bypass)
|
||||||
|
|
||||||
if err := registry.Bypass().Register(req.Bypass, v); err != nil {
|
if err := registry.BypassRegistry().Register(req.Bypass, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,11 +143,11 @@ func deleteBypass(ctx *gin.Context) {
|
|||||||
var req deleteBypassRequest
|
var req deleteBypassRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Bypass().IsRegistered(req.Bypass) {
|
if !registry.BypassRegistry().IsRegistered(req.Bypass) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Bypass().Unregister(req.Bypass)
|
registry.BypassRegistry().Unregister(req.Bypass)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
bypasses := cfg.Bypasses
|
bypasses := cfg.Bypasses
|
||||||
|
@ -46,7 +46,7 @@ func createChain(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := registry.Chain().Register(req.Data.Name, v); err != nil {
|
if err := registry.ChainRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func updateChain(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Chain().IsRegistered(req.Chain) {
|
if !registry.ChainRegistry().IsRegistered(req.Chain) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -104,9 +104,9 @@ func updateChain(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.Chain().Unregister(req.Chain)
|
registry.ChainRegistry().Unregister(req.Chain)
|
||||||
|
|
||||||
if err := registry.Chain().Register(req.Chain, v); err != nil {
|
if err := registry.ChainRegistry().Register(req.Chain, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -152,11 +152,11 @@ func deleteChain(ctx *gin.Context) {
|
|||||||
var req deleteChainRequest
|
var req deleteChainRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Chain().IsRegistered(req.Chain) {
|
if !registry.ChainRegistry().IsRegistered(req.Chain) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Chain().Unregister(req.Chain)
|
registry.ChainRegistry().Unregister(req.Chain)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
chains := cfg.Chains
|
chains := cfg.Chains
|
||||||
|
@ -42,7 +42,7 @@ func createHosts(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseHosts(&req.Data)
|
v := parsing.ParseHosts(&req.Data)
|
||||||
|
|
||||||
if err := registry.Hosts().Register(req.Data.Name, v); err != nil {
|
if err := registry.HostsRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func updateHosts(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Hosts().IsRegistered(req.Hosts) {
|
if !registry.HostsRegistry().IsRegistered(req.Hosts) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -95,9 +95,9 @@ func updateHosts(ctx *gin.Context) {
|
|||||||
|
|
||||||
v := parsing.ParseHosts(&req.Data)
|
v := parsing.ParseHosts(&req.Data)
|
||||||
|
|
||||||
registry.Hosts().Unregister(req.Hosts)
|
registry.HostsRegistry().Unregister(req.Hosts)
|
||||||
|
|
||||||
if err := registry.Hosts().Register(req.Hosts, v); err != nil {
|
if err := registry.HostsRegistry().Register(req.Hosts, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,11 +143,11 @@ func deleteHosts(ctx *gin.Context) {
|
|||||||
var req deleteHostsRequest
|
var req deleteHostsRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Hosts().IsRegistered(req.Hosts) {
|
if !registry.HostsRegistry().IsRegistered(req.Hosts) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Hosts().Unregister(req.Hosts)
|
registry.HostsRegistry().Unregister(req.Hosts)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
hosts := cfg.Hosts
|
hosts := cfg.Hosts
|
||||||
|
@ -46,7 +46,7 @@ func createResolver(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := registry.Resolver().Register(req.Data.Name, v); err != nil {
|
if err := registry.ResolverRegistry().Register(req.Data.Name, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func updateResolver(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
if !registry.Resolver().IsRegistered(req.Resolver) {
|
if !registry.ResolverRegistry().IsRegistered(req.Resolver) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -103,9 +103,9 @@ func updateResolver(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.Resolver().Unregister(req.Resolver)
|
registry.ResolverRegistry().Unregister(req.Resolver)
|
||||||
|
|
||||||
if err := registry.Resolver().Register(req.Resolver, v); err != nil {
|
if err := registry.ResolverRegistry().Register(req.Resolver, v); err != nil {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -151,11 +151,11 @@ func deleteResolver(ctx *gin.Context) {
|
|||||||
var req deleteResolverRequest
|
var req deleteResolverRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
if !registry.Resolver().IsRegistered(req.Resolver) {
|
if !registry.ResolverRegistry().IsRegistered(req.Resolver) {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
registry.Resolver().Unregister(req.Resolver)
|
registry.ResolverRegistry().Unregister(req.Resolver)
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
resolvers := cfg.Resolvers
|
resolvers := cfg.Resolvers
|
||||||
|
@ -40,7 +40,7 @@ func createService(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if registry.Service().IsRegistered(req.Data.Name) {
|
if registry.ServiceRegistry().IsRegistered(req.Data.Name) {
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func createService(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := registry.Service().Register(req.Data.Name, svc); err != nil {
|
if err := registry.ServiceRegistry().Register(req.Data.Name, svc); err != nil {
|
||||||
svc.Close()
|
svc.Close()
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
@ -98,7 +98,7 @@ func updateService(ctx *gin.Context) {
|
|||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
ctx.ShouldBindJSON(&req.Data)
|
ctx.ShouldBindJSON(&req.Data)
|
||||||
|
|
||||||
old := registry.Service().Get(req.Service)
|
old := registry.ServiceRegistry().Get(req.Service)
|
||||||
if old == nil {
|
if old == nil {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
@ -113,9 +113,9 @@ func updateService(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.Service().Unregister(req.Service)
|
registry.ServiceRegistry().Unregister(req.Service)
|
||||||
|
|
||||||
if err := registry.Service().Register(req.Service, svc); err != nil {
|
if err := registry.ServiceRegistry().Register(req.Service, svc); err != nil {
|
||||||
svc.Close()
|
svc.Close()
|
||||||
writeError(ctx, ErrDup)
|
writeError(ctx, ErrDup)
|
||||||
return
|
return
|
||||||
@ -164,13 +164,13 @@ func deleteService(ctx *gin.Context) {
|
|||||||
var req deleteServiceRequest
|
var req deleteServiceRequest
|
||||||
ctx.ShouldBindUri(&req)
|
ctx.ShouldBindUri(&req)
|
||||||
|
|
||||||
svc := registry.Service().Get(req.Service)
|
svc := registry.ServiceRegistry().Get(req.Service)
|
||||||
if svc == nil {
|
if svc == nil {
|
||||||
writeError(ctx, ErrNotFound)
|
writeError(ctx, ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.Service().Unregister(req.Service)
|
registry.ServiceRegistry().Unregister(req.Service)
|
||||||
svc.Close()
|
svc.Close()
|
||||||
|
|
||||||
cfg := config.Global()
|
cfg := config.Global()
|
||||||
|
@ -17,7 +17,7 @@ func mwLogger() gin.HandlerFunc {
|
|||||||
ctx.Next()
|
ctx.Next()
|
||||||
duration := time.Since(startTime)
|
duration := time.Since(startTime)
|
||||||
|
|
||||||
logger.Default().WithFields(map[string]interface{}{
|
logger.Default().WithFields(map[string]any{
|
||||||
"kind": "api",
|
"kind": "api",
|
||||||
"method": ctx.Request.Method,
|
"method": ctx.Request.Method,
|
||||||
"uri": ctx.Request.RequestURI,
|
"uri": ctx.Request.RequestURI,
|
||||||
|
@ -181,7 +181,7 @@ func (r *Route) bindLocal(ctx context.Context, network, address string, opts ...
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logger := logger.Default().WithFields(map[string]interface{}{
|
logger := logger.Default().WithFields(map[string]any{
|
||||||
"network": network,
|
"network": network,
|
||||||
"address": address,
|
"address": address,
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 128,
|
size: 128,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 128)
|
b := make([]byte, 128)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -19,7 +19,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 512,
|
size: 512,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 512)
|
b := make([]byte, 512)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -28,7 +28,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 1024,
|
size: 1024,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 1024)
|
b := make([]byte, 1024)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -37,7 +37,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 4096,
|
size: 4096,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 4096)
|
b := make([]byte, 4096)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -46,7 +46,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 8192,
|
size: 8192,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 8192)
|
b := make([]byte, 8192)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -55,7 +55,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 16 * 1024,
|
size: 16 * 1024,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 16*1024)
|
b := make([]byte, 16*1024)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -64,7 +64,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 32 * 1024,
|
size: 32 * 1024,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 32*1024)
|
b := make([]byte, 32*1024)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -73,7 +73,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 64 * 1024,
|
size: 64 * 1024,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 64*1024)
|
b := make([]byte, 64*1024)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
@ -82,7 +82,7 @@ var (
|
|||||||
{
|
{
|
||||||
size: 65 * 1024,
|
size: 65 * 1024,
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
b := make([]byte, 65*1024)
|
b := make([]byte, 65*1024)
|
||||||
return &b
|
return &b
|
||||||
},
|
},
|
||||||
|
@ -95,7 +95,7 @@ func file_gost_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_gost_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
var file_gost_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||||
var file_gost_proto_goTypes = []interface{}{
|
var file_gost_proto_goTypes = []any{
|
||||||
(*Chunk)(nil), // 0: Chunk
|
(*Chunk)(nil), // 0: Chunk
|
||||||
}
|
}
|
||||||
var file_gost_proto_depIdxs = []int32{
|
var file_gost_proto_depIdxs = []int32{
|
||||||
@ -114,7 +114,7 @@ func file_gost_proto_init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !protoimpl.UnsafeEnabled {
|
if !protoimpl.UnsafeEnabled {
|
||||||
file_gost_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
file_gost_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
||||||
switch v := v.(*Chunk); i {
|
switch v := v.(*Chunk); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
|
@ -88,7 +88,7 @@ func RegisterGostTunelServer(s grpc.ServiceRegistrar, srv GostTunelServer) {
|
|||||||
s.RegisterService(&GostTunel_ServiceDesc, srv)
|
s.RegisterService(&GostTunel_ServiceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _GostTunel_Tunnel_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _GostTunel_Tunnel_Handler(srv any, stream grpc.ServerStream) error {
|
||||||
return srv.(GostTunelServer).Tunnel(&gostTunelTunnelServer{stream})
|
return srv.(GostTunelServer).Tunnel(&gostTunelTunnelServer{stream})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func (p *ConnPool) WithLogger(logger logger.Logger) *ConnPool {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) Get(key interface{}) (c *Conn, ok bool) {
|
func (p *ConnPool) Get(key any) (c *Conn, ok bool) {
|
||||||
v, ok := p.m.Load(key)
|
v, ok := p.m.Load(key)
|
||||||
if ok {
|
if ok {
|
||||||
c, ok = v.(*Conn)
|
c, ok = v.(*Conn)
|
||||||
@ -36,11 +36,11 @@ func (p *ConnPool) Get(key interface{}) (c *Conn, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) Set(key interface{}, c *Conn) {
|
func (p *ConnPool) Set(key any, c *Conn) {
|
||||||
p.m.Store(key, c)
|
p.m.Store(key, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnPool) Delete(key interface{}) {
|
func (p *ConnPool) Delete(key any) {
|
||||||
p.m.Delete(key)
|
p.m.Delete(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func (p *ConnPool) Close() {
|
|||||||
|
|
||||||
close(p.closed)
|
close(p.closed)
|
||||||
|
|
||||||
p.m.Range(func(k, v interface{}) bool {
|
p.m.Range(func(k, v any) bool {
|
||||||
if c, ok := v.(*Conn); ok && c != nil {
|
if c, ok := v.(*Conn); ok && c != nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ func (p *ConnPool) idleCheck() {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
size := 0
|
size := 0
|
||||||
idles := 0
|
idles := 0
|
||||||
p.m.Range(func(key, value interface{}) bool {
|
p.m.Range(func(key, value any) bool {
|
||||||
c, ok := value.(*Conn)
|
c, ok := value.(*Conn)
|
||||||
if !ok || c == nil {
|
if !ok || c == nil {
|
||||||
p.Delete(key)
|
p.Delete(key)
|
||||||
|
@ -145,7 +145,7 @@ type ListenerConfig struct {
|
|||||||
Auther string `yaml:",omitempty" json:"auther,omitempty"`
|
Auther string `yaml:",omitempty" json:"auther,omitempty"`
|
||||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||||
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||||
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
|
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandlerConfig struct {
|
type HandlerConfig struct {
|
||||||
@ -155,7 +155,7 @@ type HandlerConfig struct {
|
|||||||
Auther string `yaml:",omitempty" json:"auther,omitempty"`
|
Auther string `yaml:",omitempty" json:"auther,omitempty"`
|
||||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||||
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||||
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
|
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForwarderConfig struct {
|
type ForwarderConfig struct {
|
||||||
@ -167,14 +167,14 @@ type DialerConfig struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||||
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||||
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
|
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectorConfig struct {
|
type ConnectorConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||||
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||||
Metadata map[string]interface{} `yaml:",omitempty" json:"metadata,omitempty"`
|
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
|
@ -16,7 +16,7 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
chainLogger := logger.Default().WithFields(map[string]interface{}{
|
chainLogger := logger.Default().WithFields(map[string]any{
|
||||||
"kind": "chain",
|
"kind": "chain",
|
||||||
"chain": cfg.Name,
|
"chain": cfg.Name,
|
||||||
})
|
})
|
||||||
@ -26,14 +26,14 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
|
|||||||
for _, hop := range cfg.Hops {
|
for _, hop := range cfg.Hops {
|
||||||
group := &chain.NodeGroup{}
|
group := &chain.NodeGroup{}
|
||||||
for _, v := range hop.Nodes {
|
for _, v := range hop.Nodes {
|
||||||
nodeLogger := chainLogger.WithFields(map[string]interface{}{
|
nodeLogger := chainLogger.WithFields(map[string]any{
|
||||||
"kind": "node",
|
"kind": "node",
|
||||||
"connector": v.Connector.Type,
|
"connector": v.Connector.Type,
|
||||||
"dialer": v.Dialer.Type,
|
"dialer": v.Dialer.Type,
|
||||||
"hop": hop.Name,
|
"hop": hop.Name,
|
||||||
"node": v.Name,
|
"node": v.Name,
|
||||||
})
|
})
|
||||||
connectorLogger := nodeLogger.WithFields(map[string]interface{}{
|
connectorLogger := nodeLogger.WithFields(map[string]any{
|
||||||
"kind": "connector",
|
"kind": "connector",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -49,21 +49,21 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cr := registry.GetConnector(v.Connector.Type)(
|
cr := registry.ConnectorRegistry().Get(v.Connector.Type)(
|
||||||
connector.AuthOption(parseAuth(v.Connector.Auth)),
|
connector.AuthOption(parseAuth(v.Connector.Auth)),
|
||||||
connector.TLSConfigOption(tlsConfig),
|
connector.TLSConfigOption(tlsConfig),
|
||||||
connector.LoggerOption(connectorLogger),
|
connector.LoggerOption(connectorLogger),
|
||||||
)
|
)
|
||||||
|
|
||||||
if v.Connector.Metadata == nil {
|
if v.Connector.Metadata == nil {
|
||||||
v.Connector.Metadata = make(map[string]interface{})
|
v.Connector.Metadata = make(map[string]any)
|
||||||
}
|
}
|
||||||
if err := cr.Init(metadata.MapMetadata(v.Connector.Metadata)); err != nil {
|
if err := cr.Init(metadata.MapMetadata(v.Connector.Metadata)); err != nil {
|
||||||
connectorLogger.Error("init: ", err)
|
connectorLogger.Error("init: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dialerLogger := nodeLogger.WithFields(map[string]interface{}{
|
dialerLogger := nodeLogger.WithFields(map[string]any{
|
||||||
"kind": "dialer",
|
"kind": "dialer",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -79,14 +79,14 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
d := registry.GetDialer(v.Dialer.Type)(
|
d := registry.DialerRegistry().Get(v.Dialer.Type)(
|
||||||
dialer.AuthOption(parseAuth(v.Dialer.Auth)),
|
dialer.AuthOption(parseAuth(v.Dialer.Auth)),
|
||||||
dialer.TLSConfigOption(tlsConfig),
|
dialer.TLSConfigOption(tlsConfig),
|
||||||
dialer.LoggerOption(dialerLogger),
|
dialer.LoggerOption(dialerLogger),
|
||||||
)
|
)
|
||||||
|
|
||||||
if v.Dialer.Metadata == nil {
|
if v.Dialer.Metadata == nil {
|
||||||
v.Dialer.Metadata = make(map[string]interface{})
|
v.Dialer.Metadata = make(map[string]any)
|
||||||
}
|
}
|
||||||
if err := d.Init(metadata.MapMetadata(v.Dialer.Metadata)); err != nil {
|
if err := d.Init(metadata.MapMetadata(v.Dialer.Metadata)); err != nil {
|
||||||
dialerLogger.Error("init: ", err)
|
dialerLogger.Error("init: ", err)
|
||||||
@ -112,9 +112,9 @@ func ParseChain(cfg *config.ChainConfig) (chain.Chainer, error) {
|
|||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
Addr: v.Addr,
|
Addr: v.Addr,
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Bypass: registry.Bypass().Get(v.Bypass),
|
Bypass: registry.BypassRegistry().Get(v.Bypass),
|
||||||
Resolver: registry.Resolver().Get(v.Resolver),
|
Resolver: registry.ResolverRegistry().Get(v.Resolver),
|
||||||
Hosts: registry.Hosts().Get(v.Hosts),
|
Hosts: registry.HostsRegistry().Get(v.Hosts),
|
||||||
Marker: &chain.FailMarker{},
|
Marker: &chain.FailMarker{},
|
||||||
}
|
}
|
||||||
group.AddNode(node)
|
group.AddNode(node)
|
||||||
|
@ -87,7 +87,7 @@ func ParseAdmission(cfg *config.AdmissionConfig) admission.Admission {
|
|||||||
return admission.NewAdmissionPatterns(
|
return admission.NewAdmissionPatterns(
|
||||||
cfg.Reverse,
|
cfg.Reverse,
|
||||||
cfg.Matchers,
|
cfg.Matchers,
|
||||||
admission.LoggerOption(logger.Default().WithFields(map[string]interface{}{
|
admission.LoggerOption(logger.Default().WithFields(map[string]any{
|
||||||
"kind": "admission",
|
"kind": "admission",
|
||||||
"admission": cfg.Name,
|
"admission": cfg.Name,
|
||||||
})),
|
})),
|
||||||
@ -101,7 +101,7 @@ func ParseBypass(cfg *config.BypassConfig) bypass.Bypass {
|
|||||||
return bypass.NewBypassPatterns(
|
return bypass.NewBypassPatterns(
|
||||||
cfg.Reverse,
|
cfg.Reverse,
|
||||||
cfg.Matchers,
|
cfg.Matchers,
|
||||||
bypass.LoggerOption(logger.Default().WithFields(map[string]interface{}{
|
bypass.LoggerOption(logger.Default().WithFields(map[string]any{
|
||||||
"kind": "bypass",
|
"kind": "bypass",
|
||||||
"bypass": cfg.Name,
|
"bypass": cfg.Name,
|
||||||
})),
|
})),
|
||||||
@ -116,7 +116,7 @@ func ParseResolver(cfg *config.ResolverConfig) (resolver.Resolver, error) {
|
|||||||
for _, server := range cfg.Nameservers {
|
for _, server := range cfg.Nameservers {
|
||||||
nameservers = append(nameservers, resolver_impl.NameServer{
|
nameservers = append(nameservers, resolver_impl.NameServer{
|
||||||
Addr: server.Addr,
|
Addr: server.Addr,
|
||||||
Chain: registry.Chain().Get(server.Chain),
|
Chain: registry.ChainRegistry().Get(server.Chain),
|
||||||
TTL: server.TTL,
|
TTL: server.TTL,
|
||||||
Timeout: server.Timeout,
|
Timeout: server.Timeout,
|
||||||
ClientIP: net.ParseIP(server.ClientIP),
|
ClientIP: net.ParseIP(server.ClientIP),
|
||||||
@ -128,7 +128,7 @@ func ParseResolver(cfg *config.ResolverConfig) (resolver.Resolver, error) {
|
|||||||
return resolver_impl.NewResolver(
|
return resolver_impl.NewResolver(
|
||||||
nameservers,
|
nameservers,
|
||||||
resolver_impl.LoggerResolverOption(
|
resolver_impl.LoggerResolverOption(
|
||||||
logger.Default().WithFields(map[string]interface{}{
|
logger.Default().WithFields(map[string]any{
|
||||||
"kind": "resolver",
|
"kind": "resolver",
|
||||||
"resolver": cfg.Name,
|
"resolver": cfg.Name,
|
||||||
}),
|
}),
|
||||||
@ -141,7 +141,7 @@ func ParseHosts(cfg *config.HostsConfig) hostspkg.HostMapper {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
hosts := hostspkg.NewHosts()
|
hosts := hostspkg.NewHosts()
|
||||||
hosts.Logger = logger.Default().WithFields(map[string]interface{}{
|
hosts.Logger = logger.Default().WithFields(map[string]any{
|
||||||
"kind": "hosts",
|
"kind": "hosts",
|
||||||
"hosts": cfg.Name,
|
"hosts": cfg.Name,
|
||||||
})
|
})
|
||||||
|
@ -25,14 +25,14 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
Type: "auto",
|
Type: "auto",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serviceLogger := logger.Default().WithFields(map[string]interface{}{
|
serviceLogger := logger.Default().WithFields(map[string]any{
|
||||||
"kind": "service",
|
"kind": "service",
|
||||||
"service": cfg.Name,
|
"service": cfg.Name,
|
||||||
"listener": cfg.Listener.Type,
|
"listener": cfg.Listener.Type,
|
||||||
"handler": cfg.Handler.Type,
|
"handler": cfg.Handler.Type,
|
||||||
})
|
})
|
||||||
|
|
||||||
listenerLogger := serviceLogger.WithFields(map[string]interface{}{
|
listenerLogger := serviceLogger.WithFields(map[string]any{
|
||||||
"kind": "listener",
|
"kind": "listener",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -49,12 +49,12 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
|
|
||||||
auther := ParseAutherFromAuth(cfg.Listener.Auth)
|
auther := ParseAutherFromAuth(cfg.Listener.Auth)
|
||||||
if cfg.Listener.Auther != "" {
|
if cfg.Listener.Auther != "" {
|
||||||
auther = registry.Auther().Get(cfg.Listener.Auther)
|
auther = registry.AutherRegistry().Get(cfg.Listener.Auther)
|
||||||
}
|
}
|
||||||
|
|
||||||
ln := registry.GetListener(cfg.Listener.Type)(
|
ln := registry.ListenerRegistry().Get(cfg.Listener.Type)(
|
||||||
listener.AddrOption(cfg.Addr),
|
listener.AddrOption(cfg.Addr),
|
||||||
listener.ChainOption(registry.Chain().Get(cfg.Listener.Chain)),
|
listener.ChainOption(registry.ChainRegistry().Get(cfg.Listener.Chain)),
|
||||||
listener.AutherOption(auther),
|
listener.AutherOption(auther),
|
||||||
listener.AuthOption(parseAuth(cfg.Listener.Auth)),
|
listener.AuthOption(parseAuth(cfg.Listener.Auth)),
|
||||||
listener.TLSConfigOption(tlsConfig),
|
listener.TLSConfigOption(tlsConfig),
|
||||||
@ -62,14 +62,14 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if cfg.Listener.Metadata == nil {
|
if cfg.Listener.Metadata == nil {
|
||||||
cfg.Listener.Metadata = make(map[string]interface{})
|
cfg.Listener.Metadata = make(map[string]any)
|
||||||
}
|
}
|
||||||
if err := ln.Init(metadata.MapMetadata(cfg.Listener.Metadata)); err != nil {
|
if err := ln.Init(metadata.MapMetadata(cfg.Listener.Metadata)); err != nil {
|
||||||
listenerLogger.Error("init: ", err)
|
listenerLogger.Error("init: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerLogger := serviceLogger.WithFields(map[string]interface{}{
|
handlerLogger := serviceLogger.WithFields(map[string]any{
|
||||||
"kind": "handler",
|
"kind": "handler",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -86,16 +86,16 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
|
|
||||||
auther = ParseAutherFromAuth(cfg.Handler.Auth)
|
auther = ParseAutherFromAuth(cfg.Handler.Auth)
|
||||||
if cfg.Handler.Auther != "" {
|
if cfg.Handler.Auther != "" {
|
||||||
auther = registry.Auther().Get(cfg.Handler.Auther)
|
auther = registry.AutherRegistry().Get(cfg.Handler.Auther)
|
||||||
}
|
}
|
||||||
h := registry.GetHandler(cfg.Handler.Type)(
|
h := registry.HandlerRegistry().Get(cfg.Handler.Type)(
|
||||||
handler.AutherOption(auther),
|
handler.AutherOption(auther),
|
||||||
handler.AuthOption(parseAuth(cfg.Handler.Auth)),
|
handler.AuthOption(parseAuth(cfg.Handler.Auth)),
|
||||||
handler.RetriesOption(cfg.Handler.Retries),
|
handler.RetriesOption(cfg.Handler.Retries),
|
||||||
handler.ChainOption(registry.Chain().Get(cfg.Handler.Chain)),
|
handler.ChainOption(registry.ChainRegistry().Get(cfg.Handler.Chain)),
|
||||||
handler.BypassOption(registry.Bypass().Get(cfg.Bypass)),
|
handler.BypassOption(registry.BypassRegistry().Get(cfg.Bypass)),
|
||||||
handler.ResolverOption(registry.Resolver().Get(cfg.Resolver)),
|
handler.ResolverOption(registry.ResolverRegistry().Get(cfg.Resolver)),
|
||||||
handler.HostsOption(registry.Hosts().Get(cfg.Hosts)),
|
handler.HostsOption(registry.HostsRegistry().Get(cfg.Hosts)),
|
||||||
handler.TLSConfigOption(tlsConfig),
|
handler.TLSConfigOption(tlsConfig),
|
||||||
handler.LoggerOption(handlerLogger),
|
handler.LoggerOption(handlerLogger),
|
||||||
)
|
)
|
||||||
@ -105,7 +105,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Handler.Metadata == nil {
|
if cfg.Handler.Metadata == nil {
|
||||||
cfg.Handler.Metadata = make(map[string]interface{})
|
cfg.Handler.Metadata = make(map[string]any)
|
||||||
}
|
}
|
||||||
if err := h.Init(metadata.MapMetadata(cfg.Handler.Metadata)); err != nil {
|
if err := h.Init(metadata.MapMetadata(cfg.Handler.Metadata)); err != nil {
|
||||||
handlerLogger.Error("init: ", err)
|
handlerLogger.Error("init: ", err)
|
||||||
@ -113,7 +113,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := service.NewService(ln, h,
|
s := service.NewService(ln, h,
|
||||||
service.AdmissionOption(registry.Admission().Get(cfg.Admission)),
|
service.AdmissionOption(registry.AdmissionRegistry().Get(cfg.Admission)),
|
||||||
service.LoggerOption(serviceLogger),
|
service.LoggerOption(serviceLogger),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("forward", NewConnector)
|
registry.ConnectorRegistry().Register("forward", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type forwardConnector struct {
|
type forwardConnector struct {
|
||||||
@ -33,7 +33,7 @@ func (c *forwardConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("http", NewConnector)
|
registry.ConnectorRegistry().Register("http", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpConnector struct {
|
type httpConnector struct {
|
||||||
@ -43,7 +43,7 @@ func (c *httpConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("http2", NewConnector)
|
registry.ConnectorRegistry().Register("http2", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http2Connector struct {
|
type http2Connector struct {
|
||||||
@ -44,7 +44,7 @@ func (c *http2Connector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// Bind implements connector.Binder.
|
// Bind implements connector.Binder.
|
||||||
func (c *relayConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
func (c *relayConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"network": network,
|
"network": network,
|
||||||
"address": address,
|
"address": address,
|
||||||
})
|
})
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("relay", NewConnector)
|
registry.ConnectorRegistry().Register("relay", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type relayConnector struct {
|
type relayConnector struct {
|
||||||
@ -38,7 +38,7 @@ func (c *relayConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("sni", NewConnector)
|
registry.ConnectorRegistry().Register("sni", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sniConnector struct {
|
type sniConnector struct {
|
||||||
@ -34,7 +34,7 @@ func (c *sniConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -15,8 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("socks4", NewConnector)
|
registry.ConnectorRegistry().Register("socks4", NewConnector)
|
||||||
registry.RegiserConnector("socks4a", NewConnector)
|
registry.ConnectorRegistry().Register("socks4a", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type socks4Connector struct {
|
type socks4Connector struct {
|
||||||
@ -40,7 +40,7 @@ func (c *socks4Connector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
// Bind implements connector.Binder.
|
// Bind implements connector.Binder.
|
||||||
func (c *socks5Connector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
func (c *socks5Connector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("socks5", NewConnector)
|
registry.ConnectorRegistry().Register("socks5", NewConnector)
|
||||||
registry.RegiserConnector("socks", NewConnector)
|
registry.ConnectorRegistry().Register("socks", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type socks5Connector struct {
|
type socks5Connector struct {
|
||||||
@ -67,7 +67,7 @@ func (c *socks5Connector) Init(md md.Metadata) (err error) {
|
|||||||
|
|
||||||
// Handshake implements connector.Handshaker.
|
// Handshake implements connector.Handshaker.
|
||||||
func (c *socks5Connector) Handshake(ctx context.Context, conn net.Conn) (net.Conn, error) {
|
func (c *socks5Connector) Handshake(ctx context.Context, conn net.Conn) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
@ -87,7 +87,7 @@ func (c *socks5Connector) Handshake(ctx context.Context, conn net.Conn) (net.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("ss", NewConnector)
|
registry.ConnectorRegistry().Register("ss", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ssConnector struct {
|
type ssConnector struct {
|
||||||
@ -51,7 +51,7 @@ func (c *ssConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ssConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *ssConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("ssu", NewConnector)
|
registry.ConnectorRegistry().Register("ssu", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ssuConnector struct {
|
type ssuConnector struct {
|
||||||
@ -50,7 +50,7 @@ func (c *ssuConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegiserConnector("sshd", NewConnector)
|
registry.ConnectorRegistry().Register("sshd", NewConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshdConnector struct {
|
type sshdConnector struct {
|
||||||
@ -35,7 +35,7 @@ func (c *sshdConnector) Init(md md.Metadata) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
@ -59,7 +59,7 @@ func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
|||||||
|
|
||||||
// Bind implements connector.Binder.
|
// Bind implements connector.Binder.
|
||||||
func (c *sshdConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
func (c *sshdConnector) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error) {
|
||||||
log := c.options.Logger.WithFields(map[string]interface{}{
|
log := c.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"network": network,
|
"network": network,
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("ftcp", NewDialer)
|
registry.DialerRegistry().Register("ftcp", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ftcpDialer struct {
|
type ftcpDialer struct {
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("grpc", NewDialer)
|
registry.DialerRegistry().Register("grpc", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type grpcDialer struct {
|
type grpcDialer struct {
|
||||||
@ -119,7 +119,7 @@ func (d *grpcDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.options.Logger.Error(err)
|
d.options.Logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.options.Logger.WithFields(map[string]interface{}{
|
d.options.Logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -132,7 +132,7 @@ func (d *grpcDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.options.Logger.Error(err)
|
d.options.Logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.options.Logger.WithFields(map[string]interface{}{
|
d.options.Logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("http2", NewDialer)
|
registry.DialerRegistry().Register("http2", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http2Dialer struct {
|
type http2Dialer struct {
|
||||||
@ -102,7 +102,7 @@ func (d *http2Dialer) dial(ctx context.Context, network, addr string, opts *dial
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -115,7 +115,7 @@ func (d *http2Dialer) dial(ctx context.Context, network, addr string, opts *dial
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("h2", NewTLSDialer)
|
registry.DialerRegistry().Register("h2", NewTLSDialer)
|
||||||
registry.RegisterDialer("h2c", NewDialer)
|
registry.DialerRegistry().Register("h2c", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type h2Dialer struct {
|
type h2Dialer struct {
|
||||||
@ -171,7 +171,7 @@ func (d *h2Dialer) dial(ctx context.Context, network, addr string, opts *dialer.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -184,7 +184,7 @@ func (d *h2Dialer) dial(ctx context.Context, network, addr string, opts *dialer.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("http3", NewDialer)
|
registry.DialerRegistry().Register("http3", NewDialer)
|
||||||
registry.RegisterDialer("h3", NewDialer)
|
registry.DialerRegistry().Register("h3", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http3Dialer struct {
|
type http3Dialer struct {
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("kcp", NewDialer)
|
registry.DialerRegistry().Register("kcp", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type kcpDialer struct {
|
type kcpDialer struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("ohttp", NewDialer)
|
registry.DialerRegistry().Register("ohttp", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type obfsHTTPDialer struct {
|
type obfsHTTPDialer struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("otls", NewDialer)
|
registry.DialerRegistry().Register("otls", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type obfsTLSDialer struct {
|
type obfsTLSDialer struct {
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("pht", NewDialer)
|
registry.DialerRegistry().Register("pht", NewDialer)
|
||||||
registry.RegisterDialer("phts", NewTLSDialer)
|
registry.DialerRegistry().Register("phts", NewTLSDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type phtDialer struct {
|
type phtDialer struct {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("quic", NewDialer)
|
registry.DialerRegistry().Register("quic", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type quicDialer struct {
|
type quicDialer struct {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("ssh", NewDialer)
|
registry.DialerRegistry().Register("ssh", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshDialer struct {
|
type sshDialer struct {
|
||||||
@ -141,7 +141,7 @@ func (d *sshDialer) dial(ctx context.Context, network, addr string, opts *dialer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -154,7 +154,7 @@ func (d *sshDialer) dial(ctx context.Context, network, addr string, opts *dialer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("sshd", NewDialer)
|
registry.DialerRegistry().Register("sshd", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshdDialer struct {
|
type sshdDialer struct {
|
||||||
@ -138,7 +138,7 @@ func (d *sshdDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
} else {
|
} else {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -151,7 +151,7 @@ func (d *sshdDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
} else {
|
} else {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("tcp", NewDialer)
|
registry.DialerRegistry().Register("tcp", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpDialer struct {
|
type tcpDialer struct {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("tls", NewDialer)
|
registry.DialerRegistry().Register("tls", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tlsDialer struct {
|
type tlsDialer struct {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("mtls", NewDialer)
|
registry.DialerRegistry().Register("mtls", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mtlsDialer struct {
|
type mtlsDialer struct {
|
||||||
@ -129,7 +129,7 @@ func (d *mtlsDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -142,7 +142,7 @@ func (d *mtlsDialer) dial(ctx context.Context, network, addr string, opts *diale
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("udp", NewDialer)
|
registry.DialerRegistry().Register("udp", NewDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type udpDialer struct {
|
type udpDialer struct {
|
||||||
|
@ -15,8 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("ws", NewDialer)
|
registry.DialerRegistry().Register("ws", NewDialer)
|
||||||
registry.RegisterDialer("wss", NewTLSDialer)
|
registry.DialerRegistry().Register("wss", NewTLSDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type wsDialer struct {
|
type wsDialer struct {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDialer("mws", NewDialer)
|
registry.DialerRegistry().Register("mws", NewDialer)
|
||||||
registry.RegisterDialer("mwss", NewTLSDialer)
|
registry.DialerRegistry().Register("mwss", NewTLSDialer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mwsDialer struct {
|
type mwsDialer struct {
|
||||||
@ -150,7 +150,7 @@ func (d *mwsDialer) dial(ctx context.Context, network, addr string, opts *dialer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debug("dial with dial func")
|
}).Debug("dial with dial func")
|
||||||
@ -163,7 +163,7 @@ func (d *mwsDialer) dial(ctx context.Context, network, addr string, opts *dialer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
} else {
|
} else {
|
||||||
d.logger.WithFields(map[string]interface{}{
|
d.logger.WithFields(map[string]any{
|
||||||
"src": conn.LocalAddr().String(),
|
"src": conn.LocalAddr().String(),
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}).Debugf("dial direct %s/%s", addr, network)
|
}).Debugf("dial direct %s/%s", addr, network)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("auto", NewHandler)
|
registry.HandlerRegistry().Register("auto", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type autoHandler struct {
|
type autoHandler struct {
|
||||||
@ -36,24 +36,24 @@ func NewHandler(opts ...handler.Option) handler.Handler {
|
|||||||
options: options,
|
options: options,
|
||||||
}
|
}
|
||||||
|
|
||||||
if f := registry.GetHandler("http"); f != nil {
|
if f := registry.HandlerRegistry().Get("http"); f != nil {
|
||||||
v := append(opts,
|
v := append(opts,
|
||||||
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "http"})))
|
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "http"})))
|
||||||
h.httpHandler = f(v...)
|
h.httpHandler = f(v...)
|
||||||
}
|
}
|
||||||
if f := registry.GetHandler("socks4"); f != nil {
|
if f := registry.HandlerRegistry().Get("socks4"); f != nil {
|
||||||
v := append(opts,
|
v := append(opts,
|
||||||
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "socks4"})))
|
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks4"})))
|
||||||
h.socks4Handler = f(v...)
|
h.socks4Handler = f(v...)
|
||||||
}
|
}
|
||||||
if f := registry.GetHandler("socks5"); f != nil {
|
if f := registry.HandlerRegistry().Get("socks5"); f != nil {
|
||||||
v := append(opts,
|
v := append(opts,
|
||||||
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "socks5"})))
|
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks5"})))
|
||||||
h.socks5Handler = f(v...)
|
h.socks5Handler = f(v...)
|
||||||
}
|
}
|
||||||
if f := registry.GetHandler("relay"); f != nil {
|
if f := registry.HandlerRegistry().Get("relay"); f != nil {
|
||||||
v := append(opts,
|
v := append(opts,
|
||||||
handler.LoggerOption(options.Logger.WithFields(map[string]interface{}{"type": "relay"})))
|
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "relay"})))
|
||||||
h.relayHandler = f(v...)
|
h.relayHandler = f(v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func (h *autoHandler) Init(md md.Metadata) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *autoHandler) Handle(ctx context.Context, conn net.Conn) {
|
func (h *autoHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
@ -94,7 +94,7 @@ func (h *autoHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
@ -26,7 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("dns", NewHandler)
|
registry.HandlerRegistry().Register("dns", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dnsHandler struct {
|
type dnsHandler struct {
|
||||||
@ -101,14 +101,14 @@ func (h *dnsHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
@ -13,9 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("tcp", NewHandler)
|
registry.HandlerRegistry().Register("tcp", NewHandler)
|
||||||
registry.RegisterHandler("udp", NewHandler)
|
registry.HandlerRegistry().Register("udp", NewHandler)
|
||||||
registry.RegisterHandler("forward", NewHandler)
|
registry.HandlerRegistry().Register("forward", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type forwardHandler struct {
|
type forwardHandler struct {
|
||||||
@ -66,14 +66,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -89,7 +89,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
network = "udp"
|
network = "udp"
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("rtcp", NewHandler)
|
registry.HandlerRegistry().Register("rtcp", NewHandler)
|
||||||
registry.RegisterHandler("rudp", NewHandler)
|
registry.HandlerRegistry().Register("rudp", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type forwardHandler struct {
|
type forwardHandler struct {
|
||||||
@ -60,14 +60,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -83,7 +83,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
network = "udp"
|
network = "udp"
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("http", NewHandler)
|
registry.HandlerRegistry().Register("http", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpHandler struct {
|
type httpHandler struct {
|
||||||
@ -64,13 +64,13 @@ func (h *httpHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -120,7 +120,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
addr = net.JoinHostPort(addr, "80")
|
addr = net.JoinHostPort(addr, "80")
|
||||||
}
|
}
|
||||||
|
|
||||||
fields := map[string]interface{}{
|
fields := map[string]any{
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}
|
}
|
||||||
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization"), log); u != "" {
|
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization"), log); u != "" {
|
||||||
@ -216,7 +216,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"cmd": "udp",
|
"cmd": "udp",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, network, add
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
relay.Run()
|
relay.Run()
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("http2", NewHandler)
|
registry.HandlerRegistry().Register("http2", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http2Handler struct {
|
type http2Handler struct {
|
||||||
@ -66,13 +66,13 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -110,7 +110,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
addr = net.JoinHostPort(addr, "80")
|
addr = net.JoinHostPort(addr, "80")
|
||||||
}
|
}
|
||||||
|
|
||||||
fields := map[string]interface{}{
|
fields := map[string]any{
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
}
|
}
|
||||||
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
|
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
|
||||||
@ -177,7 +177,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Infof("%s <-> %s", req.RemoteAddr, addr)
|
log.Infof("%s <-> %s", req.RemoteAddr, addr)
|
||||||
handler.Transport(&readWriter{r: req.Body, w: flushWriter{w}}, cc)
|
handler.Transport(&readWriter{r: req.Body, w: flushWriter{w}}, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >-< %s", req.RemoteAddr, addr)
|
}).Infof("%s >-< %s", req.RemoteAddr, addr)
|
||||||
return
|
return
|
||||||
|
@ -13,10 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("red", NewHandler)
|
registry.HandlerRegistry().Register("red", NewHandler)
|
||||||
registry.RegisterHandler("redu", NewHandler)
|
registry.HandlerRegistry().Register("redu", NewHandler)
|
||||||
registry.RegisterHandler("redir", NewHandler)
|
registry.HandlerRegistry().Register("redir", NewHandler)
|
||||||
registry.RegisterHandler("redirect", NewHandler)
|
registry.HandlerRegistry().Register("redirect", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type redirectHandler struct {
|
type redirectHandler struct {
|
||||||
@ -56,14 +56,14 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -85,7 +85,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", dstAddr, network),
|
"dst": fmt.Sprintf("%s/%s", dstAddr, network),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
@ -70,7 +70,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||||
})
|
})
|
||||||
log.Debugf("bind on %s OK", ln.Addr())
|
log.Debugf("bind on %s OK", ln.Addr())
|
||||||
@ -107,7 +107,7 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": pc.LocalAddr().String(),
|
"bind": pc.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
log.Debugf("bind on %s OK", pc.LocalAddr())
|
log.Debugf("bind on %s OK", pc.LocalAddr())
|
||||||
@ -120,7 +120,7 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
relay.Run()
|
relay.Run()
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ func (h *relayHandler) serveTCPBind(ctx context.Context, conn net.Conn, ln net.L
|
|||||||
go func(c net.Conn) {
|
go func(c net.Conn) {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"local": ln.Addr().String(),
|
"local": ln.Addr().String(),
|
||||||
"remote": c.RemoteAddr().String(),
|
"remote": c.RemoteAddr().String(),
|
||||||
})
|
})
|
||||||
@ -184,7 +184,7 @@ func (h *relayHandler) serveTCPBind(ctx context.Context, conn net.Conn, ln net.L
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||||
handler.Transport(sc, c)
|
handler.Transport(sc, c)
|
||||||
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
|
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||||
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||||
}(rc)
|
}(rc)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||||
"cmd": "connect",
|
"cmd": "connect",
|
||||||
})
|
})
|
||||||
@ -81,7 +81,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
||||||
"cmd": "forward",
|
"cmd": "forward",
|
||||||
})
|
})
|
||||||
@ -81,7 +81,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("relay", NewHandler)
|
registry.HandlerRegistry().Register("relay", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type relayHandler struct {
|
type relayHandler struct {
|
||||||
@ -59,14 +59,14 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -102,7 +102,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if user != "" {
|
if user != "" {
|
||||||
log = log.WithFields(map[string]interface{}{"user": user})
|
log = log.WithFields(map[string]any{"user": user})
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := relay.Response{
|
resp := relay.Response{
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("sni", NewHandler)
|
registry.HandlerRegistry().Register("sni", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sniHandler struct {
|
type sniHandler struct {
|
||||||
@ -40,9 +40,9 @@ func NewHandler(opts ...handler.Option) handler.Handler {
|
|||||||
options: options,
|
options: options,
|
||||||
}
|
}
|
||||||
|
|
||||||
if f := registry.GetHandler("http"); f != nil {
|
if f := registry.HandlerRegistry().Get("http"); f != nil {
|
||||||
v := append(opts,
|
v := append(opts,
|
||||||
handler.LoggerOption(h.options.Logger.WithFields(map[string]interface{}{"type": "http"})))
|
handler.LoggerOption(h.options.Logger.WithFields(map[string]any{"type": "http"})))
|
||||||
h.httpHandler = f(v...)
|
h.httpHandler = f(v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,14 +77,14 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -125,7 +125,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
target := net.JoinHostPort(host, "443")
|
target := net.JoinHostPort(host, "443")
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": target,
|
"dst": target,
|
||||||
})
|
})
|
||||||
log.Infof("%s >> %s", conn.RemoteAddr(), target)
|
log.Infof("%s >> %s", conn.RemoteAddr(), target)
|
||||||
@ -149,7 +149,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target)
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("socks4", NewHandler)
|
registry.HandlerRegistry().Register("socks4", NewHandler)
|
||||||
registry.RegisterHandler("socks4a", NewHandler)
|
registry.HandlerRegistry().Register("socks4a", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type socks4Handler struct {
|
type socks4Handler struct {
|
||||||
@ -56,14 +56,14 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -102,7 +102,7 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *gosocks4.Request, log logger.Logger) {
|
func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *gosocks4.Request, log logger.Logger) {
|
||||||
addr := req.Addr.String()
|
addr := req.Addr.String()
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
})
|
})
|
||||||
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||||
@ -135,7 +135,7 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
@ -59,7 +59,7 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, a
|
|||||||
}
|
}
|
||||||
log.Debug(reply)
|
log.Debug(reply)
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
|||||||
|
|
||||||
log.Debugf("peer %s accepted", rc.RemoteAddr())
|
log.Debugf("peer %s accepted", rc.RemoteAddr())
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"local": rc.LocalAddr().String(),
|
"local": rc.LocalAddr().String(),
|
||||||
"remote": rc.RemoteAddr().String(),
|
"remote": rc.RemoteAddr().String(),
|
||||||
})
|
})
|
||||||
@ -136,7 +136,7 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Infof("%s <-> %s", rc.LocalAddr(), rc.RemoteAddr())
|
log.Infof("%s <-> %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||||
handler.Transport(pc2, rc)
|
handler.Transport(pc2, rc)
|
||||||
log.WithFields(map[string]interface{}{"duration": time.Since(start)}).
|
log.WithFields(map[string]any{"duration": time.Since(start)}).
|
||||||
Infof("%s >-< %s", rc.LocalAddr(), rc.RemoteAddr())
|
Infof("%s >-< %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||||
|
|
||||||
case err := <-pipe():
|
case err := <-pipe():
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||||
"cmd": "connect",
|
"cmd": "connect",
|
||||||
})
|
})
|
||||||
@ -46,7 +46,7 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("socks5", NewHandler)
|
registry.HandlerRegistry().Register("socks5", NewHandler)
|
||||||
registry.RegisterHandler("socks", NewHandler)
|
registry.HandlerRegistry().Register("socks", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type socks5Handler struct {
|
type socks5Handler struct {
|
||||||
@ -64,14 +64,14 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||||
"cmd": "mbind",
|
"cmd": "mbind",
|
||||||
})
|
})
|
||||||
@ -60,7 +60,7 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
log.Debug(reply)
|
log.Debug(reply)
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
|
|||||||
go func(c net.Conn) {
|
go func(c net.Conn) {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"local": rc.LocalAddr().String(),
|
"local": rc.LocalAddr().String(),
|
||||||
"remote": rc.RemoteAddr().String(),
|
"remote": rc.RemoteAddr().String(),
|
||||||
})
|
})
|
||||||
@ -127,7 +127,7 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||||
handler.Transport(sc, c)
|
handler.Transport(sc, c)
|
||||||
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
|
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||||
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||||
}(rc)
|
}(rc)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger.Logger) {
|
func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"cmd": "udp",
|
"cmd": "udp",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
|||||||
}
|
}
|
||||||
log.Debug(reply)
|
log.Debug(reply)
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", cc.LocalAddr(), cc.LocalAddr().Network()),
|
"bind": fmt.Sprintf("%s/%s", cc.LocalAddr(), cc.LocalAddr().Network()),
|
||||||
})
|
})
|
||||||
log.Debugf("bind on %s OK", cc.LocalAddr())
|
log.Debugf("bind on %s OK", cc.LocalAddr())
|
||||||
@ -77,6 +77,6 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), cc.LocalAddr())
|
log.Infof("%s <-> %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||||
io.Copy(ioutil.Discard, conn)
|
io.Copy(ioutil.Discard, conn)
|
||||||
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
|
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||||
Infof("%s >-< %s", conn.RemoteAddr(), cc.LocalAddr())
|
Infof("%s >-< %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) {
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"cmd": "udp-tun",
|
"cmd": "udp-tun",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
relay.Run()
|
relay.Run()
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("ss", NewHandler)
|
registry.HandlerRegistry().Register("ss", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ssHandler struct {
|
type ssHandler struct {
|
||||||
@ -66,14 +66,14 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -93,7 +93,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": addr.String(),
|
"dst": addr.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("ssu", NewHandler)
|
registry.HandlerRegistry().Register("ssu", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ssuHandler struct {
|
type ssuHandler struct {
|
||||||
@ -67,14 +67,14 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -111,7 +111,7 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
log.Infof("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
||||||
h.relayPacket(pc, cc, log)
|
h.relayPacket(pc, cc, log)
|
||||||
log.WithFields(map[string]interface{}{"duration": time.Since(t)}).
|
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||||
Infof("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
Infof("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("sshd", NewHandler)
|
registry.HandlerRegistry().Register("sshd", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type forwardHandler struct {
|
type forwardHandler struct {
|
||||||
@ -62,7 +62,7 @@ func (h *forwardHandler) Init(md md.Metadata) (err error) {
|
|||||||
func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]interface{}{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
@ -81,7 +81,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_util.DirectForwardConn, log logger.Logger) {
|
func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_util.DirectForwardConn, log logger.Logger) {
|
||||||
targetAddr := conn.DstAddr()
|
targetAddr := conn.DstAddr()
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", targetAddr, "tcp"),
|
"dst": fmt.Sprintf("%s/%s", targetAddr, "tcp"),
|
||||||
"cmd": "connect",
|
"cmd": "connect",
|
||||||
})
|
})
|
||||||
@ -102,7 +102,7 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", cc.LocalAddr(), targetAddr)
|
log.Infof("%s <-> %s", cc.LocalAddr(), targetAddr)
|
||||||
handler.Transport(conn, cc)
|
handler.Transport(conn, cc)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", cc.LocalAddr(), targetAddr)
|
}).Infof("%s >-< %s", cc.LocalAddr(), targetAddr)
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
network := "tcp"
|
network := "tcp"
|
||||||
addr := net.JoinHostPort(t.Host, strconv.Itoa(int(t.Port)))
|
addr := net.JoinHostPort(t.Host, strconv.Itoa(int(t.Port)))
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", addr, network),
|
"dst": fmt.Sprintf("%s/%s", addr, network),
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
@ -132,7 +132,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
}
|
}
|
||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||||
})
|
})
|
||||||
log.Debugf("bind on %s OK", ln.Addr())
|
log.Debugf("bind on %s OK", ln.Addr())
|
||||||
@ -167,7 +167,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
go func(conn net.Conn) {
|
go func(conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
log := log.WithFields(map[string]interface{}{
|
log := log.WithFields(map[string]any{
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
})
|
})
|
||||||
@ -195,7 +195,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.LocalAddr(), conn.RemoteAddr())
|
log.Infof("%s <-> %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||||
handler.Transport(ch, conn)
|
handler.Transport(ch, conn)
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Infof("%s >-< %s", conn.LocalAddr(), conn.RemoteAddr())
|
}).Infof("%s >-< %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||||
}(cc)
|
}(cc)
|
||||||
@ -205,7 +205,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
tm := time.Now()
|
tm := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
<-conn.Done()
|
<-conn.Done()
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(tm),
|
"duration": time.Since(tm),
|
||||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("tap", NewHandler)
|
registry.HandlerRegistry().Register("tap", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tapHandler struct {
|
type tapHandler struct {
|
||||||
@ -91,14 +91,14 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -114,7 +114,7 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
||||||
})
|
})
|
||||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||||
@ -214,7 +214,7 @@ func (h *tapHandler) transport(tap net.Conn, conn net.PacketConn, raddr net.Addr
|
|||||||
|
|
||||||
// server side, broadcast.
|
// server side, broadcast.
|
||||||
if waterutil.IsBroadcast(dst) {
|
if waterutil.IsBroadcast(dst) {
|
||||||
go h.routes.Range(func(k, v interface{}) bool {
|
go h.routes.Range(func(k, v any) bool {
|
||||||
conn.WriteTo((*b)[:n], v.(net.Addr))
|
conn.WriteTo((*b)[:n], v.(net.Addr))
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -281,7 +281,7 @@ func (h *tapHandler) transport(tap net.Conn, conn net.PacketConn, raddr net.Addr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if waterutil.IsBroadcast(dst) {
|
if waterutil.IsBroadcast(dst) {
|
||||||
go h.routes.Range(func(k, v interface{}) bool {
|
go h.routes.Range(func(k, v any) bool {
|
||||||
if k.(tapRouteKey) != rkey {
|
if k.(tapRouteKey) != rkey {
|
||||||
conn.WriteTo((*b)[:n], v.(net.Addr))
|
conn.WriteTo((*b)[:n], v.(net.Addr))
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterHandler("tun", NewHandler)
|
registry.HandlerRegistry().Register("tun", NewHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tunHandler struct {
|
type tunHandler struct {
|
||||||
@ -94,14 +94,14 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
@ -117,7 +117,7 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn) {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log = log.WithFields(map[string]interface{}{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
||||||
})
|
})
|
||||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("dns", NewListener)
|
registry.ListenerRegistry().Register("dns", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dnsListener struct {
|
type dnsListener struct {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("ftcp", NewListener)
|
registry.ListenerRegistry().Register("ftcp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ftcpListener struct {
|
type ftcpListener struct {
|
||||||
@ -69,7 +69,7 @@ func (l *ftcpListener) Accept() (conn net.Conn, err error) {
|
|||||||
|
|
||||||
func (l *ftcpListener) Close() error {
|
func (l *ftcpListener) Close() error {
|
||||||
err := l.conn.Close()
|
err := l.conn.Close()
|
||||||
l.connPool.Range(func(k interface{}, v *serverConn) bool {
|
l.connPool.Range(func(k any, v *serverConn) bool {
|
||||||
v.Close()
|
v.Close()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -128,7 +128,7 @@ type connPool struct {
|
|||||||
m sync.Map
|
m sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *connPool) Get(key interface{}) (conn *serverConn, ok bool) {
|
func (p *connPool) Get(key any) (conn *serverConn, ok bool) {
|
||||||
v, ok := p.m.Load(key)
|
v, ok := p.m.Load(key)
|
||||||
if ok {
|
if ok {
|
||||||
conn, ok = v.(*serverConn)
|
conn, ok = v.(*serverConn)
|
||||||
@ -136,18 +136,18 @@ func (p *connPool) Get(key interface{}) (conn *serverConn, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *connPool) Set(key interface{}, conn *serverConn) {
|
func (p *connPool) Set(key any, conn *serverConn) {
|
||||||
p.m.Store(key, conn)
|
p.m.Store(key, conn)
|
||||||
atomic.AddInt64(&p.size, 1)
|
atomic.AddInt64(&p.size, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *connPool) Delete(key interface{}) {
|
func (p *connPool) Delete(key any) {
|
||||||
p.m.Delete(key)
|
p.m.Delete(key)
|
||||||
atomic.AddInt64(&p.size, -1)
|
atomic.AddInt64(&p.size, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *connPool) Range(f func(key interface{}, value *serverConn) bool) {
|
func (p *connPool) Range(f func(key any, value *serverConn) bool) {
|
||||||
p.m.Range(func(k, v interface{}) bool {
|
p.m.Range(func(k, v any) bool {
|
||||||
return f(k, v.(*serverConn))
|
return f(k, v.(*serverConn))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("grpc", NewListener)
|
registry.ListenerRegistry().Register("grpc", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type grpcListener struct {
|
type grpcListener struct {
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("h2c", NewListener)
|
registry.ListenerRegistry().Register("h2c", NewListener)
|
||||||
registry.RegisterListener("h2", NewTLSListener)
|
registry.ListenerRegistry().Register("h2", NewTLSListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type h2Listener struct {
|
type h2Listener struct {
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("http2", NewListener)
|
registry.ListenerRegistry().Register("http2", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http2Listener struct {
|
type http2Listener struct {
|
||||||
|
@ -12,8 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("http3", NewListener)
|
registry.ListenerRegistry().Register("http3", NewListener)
|
||||||
registry.RegisterListener("h3", NewListener)
|
registry.ListenerRegistry().Register("h3", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type http3Listener struct {
|
type http3Listener struct {
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("kcp", NewListener)
|
registry.ListenerRegistry().Register("kcp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type kcpListener struct {
|
type kcpListener struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("ohttp", NewListener)
|
registry.ListenerRegistry().Register("ohttp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type obfsListener struct {
|
type obfsListener struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("otls", NewListener)
|
registry.ListenerRegistry().Register("otls", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type obfsListener struct {
|
type obfsListener struct {
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("pht", NewListener)
|
registry.ListenerRegistry().Register("pht", NewListener)
|
||||||
registry.RegisterListener("phts", NewTLSListener)
|
registry.ListenerRegistry().Register("phts", NewTLSListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type phtListener struct {
|
type phtListener struct {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("quic", NewListener)
|
registry.ListenerRegistry().Register("quic", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type quicListener struct {
|
type quicListener struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("redu", NewListener)
|
registry.ListenerRegistry().Register("redu", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type redirectListener struct {
|
type redirectListener struct {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("rtcp", NewListener)
|
registry.ListenerRegistry().Register("rtcp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type rtcpListener struct {
|
type rtcpListener struct {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("rudp", NewListener)
|
registry.ListenerRegistry().Register("rudp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type rudpListener struct {
|
type rudpListener struct {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("ssh", NewListener)
|
registry.ListenerRegistry().Register("ssh", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshListener struct {
|
type sshListener struct {
|
||||||
@ -99,7 +99,7 @@ func (l *sshListener) serveConn(conn net.Conn) {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
l.logger.WithFields(map[string]interface{}{
|
l.logger.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
@ -23,7 +23,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("sshd", NewListener)
|
registry.ListenerRegistry().Register("sshd", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshdListener struct {
|
type sshdListener struct {
|
||||||
@ -108,7 +108,7 @@ func (l *sshdListener) serveConn(conn net.Conn) {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
l.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
l.logger.WithFields(map[string]interface{}{
|
l.logger.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("tap", NewListener)
|
registry.ListenerRegistry().Register("tap", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tapListener struct {
|
type tapListener struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("tcp", NewListener)
|
registry.ListenerRegistry().Register("tcp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpListener struct {
|
type tcpListener struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("tls", NewListener)
|
registry.ListenerRegistry().Register("tls", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tlsListener struct {
|
type tlsListener struct {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("mtls", NewListener)
|
registry.ListenerRegistry().Register("mtls", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mtlsListener struct {
|
type mtlsListener struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("tun", NewListener)
|
registry.ListenerRegistry().Register("tun", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type tunListener struct {
|
type tunListener struct {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("udp", NewListener)
|
registry.ListenerRegistry().Register("udp", NewListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type udpListener struct {
|
type udpListener struct {
|
||||||
|
@ -15,8 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("ws", NewListener)
|
registry.ListenerRegistry().Register("ws", NewListener)
|
||||||
registry.RegisterListener("wss", NewTLSListener)
|
registry.ListenerRegistry().Register("wss", NewTLSListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type wsListener struct {
|
type wsListener struct {
|
||||||
@ -121,7 +121,7 @@ func (l *wsListener) Addr() net.Addr {
|
|||||||
|
|
||||||
func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||||
log := l.logger.WithFields(map[string]interface{}{
|
log := l.logger.WithFields(map[string]any{
|
||||||
"local": l.addr.String(),
|
"local": l.addr.String(),
|
||||||
"remote": r.RemoteAddr,
|
"remote": r.RemoteAddr,
|
||||||
})
|
})
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterListener("mws", NewListener)
|
registry.ListenerRegistry().Register("mws", NewListener)
|
||||||
registry.RegisterListener("mwss", NewTLSListener)
|
registry.ListenerRegistry().Register("mwss", NewTLSListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mwsListener struct {
|
type mwsListener struct {
|
||||||
@ -126,7 +126,7 @@ func (l *mwsListener) Addr() net.Addr {
|
|||||||
|
|
||||||
func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||||
log := l.logger.WithFields(map[string]interface{}{
|
log := l.logger.WithFields(map[string]any{
|
||||||
"local": l.addr.String(),
|
"local": l.addr.String(),
|
||||||
"remote": r.RemoteAddr,
|
"remote": r.RemoteAddr,
|
||||||
})
|
})
|
||||||
|
@ -61,60 +61,60 @@ func NewLogger(opts ...LoggerOption) Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithFields adds new fields to log.
|
// WithFields adds new fields to log.
|
||||||
func (l *logger) WithFields(fields map[string]interface{}) Logger {
|
func (l *logger) WithFields(fields map[string]any) Logger {
|
||||||
return &logger{
|
return &logger{
|
||||||
logger: l.logger.WithFields(logrus.Fields(fields)),
|
logger: l.logger.WithFields(logrus.Fields(fields)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug logs a message at level Debug.
|
// Debug logs a message at level Debug.
|
||||||
func (l *logger) Debug(args ...interface{}) {
|
func (l *logger) Debug(args ...any) {
|
||||||
l.log(logrus.DebugLevel, args...)
|
l.log(logrus.DebugLevel, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf logs a message at level Debug.
|
// Debugf logs a message at level Debug.
|
||||||
func (l *logger) Debugf(format string, args ...interface{}) {
|
func (l *logger) Debugf(format string, args ...any) {
|
||||||
l.logf(logrus.DebugLevel, format, args...)
|
l.logf(logrus.DebugLevel, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info logs a message at level Info.
|
// Info logs a message at level Info.
|
||||||
func (l *logger) Info(args ...interface{}) {
|
func (l *logger) Info(args ...any) {
|
||||||
l.log(logrus.InfoLevel, args...)
|
l.log(logrus.InfoLevel, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof logs a message at level Info.
|
// Infof logs a message at level Info.
|
||||||
func (l *logger) Infof(format string, args ...interface{}) {
|
func (l *logger) Infof(format string, args ...any) {
|
||||||
l.logf(logrus.InfoLevel, format, args...)
|
l.logf(logrus.InfoLevel, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn logs a message at level Warn.
|
// Warn logs a message at level Warn.
|
||||||
func (l *logger) Warn(args ...interface{}) {
|
func (l *logger) Warn(args ...any) {
|
||||||
l.log(logrus.WarnLevel, args...)
|
l.log(logrus.WarnLevel, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf logs a message at level Warn.
|
// Warnf logs a message at level Warn.
|
||||||
func (l *logger) Warnf(format string, args ...interface{}) {
|
func (l *logger) Warnf(format string, args ...any) {
|
||||||
l.logf(logrus.WarnLevel, format, args...)
|
l.logf(logrus.WarnLevel, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error logs a message at level Error.
|
// Error logs a message at level Error.
|
||||||
func (l *logger) Error(args ...interface{}) {
|
func (l *logger) Error(args ...any) {
|
||||||
l.log(logrus.ErrorLevel, args...)
|
l.log(logrus.ErrorLevel, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf logs a message at level Error.
|
// Errorf logs a message at level Error.
|
||||||
func (l *logger) Errorf(format string, args ...interface{}) {
|
func (l *logger) Errorf(format string, args ...any) {
|
||||||
l.logf(logrus.ErrorLevel, format, args...)
|
l.logf(logrus.ErrorLevel, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal logs a message at level Fatal then the process will exit with status set to 1.
|
// Fatal logs a message at level Fatal then the process will exit with status set to 1.
|
||||||
func (l *logger) Fatal(args ...interface{}) {
|
func (l *logger) Fatal(args ...any) {
|
||||||
l.log(logrus.FatalLevel, args...)
|
l.log(logrus.FatalLevel, args...)
|
||||||
l.logger.Logger.Exit(1)
|
l.logger.Logger.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf logs a message at level Fatal then the process will exit with status set to 1.
|
// Fatalf logs a message at level Fatal then the process will exit with status set to 1.
|
||||||
func (l *logger) Fatalf(format string, args ...interface{}) {
|
func (l *logger) Fatalf(format string, args ...any) {
|
||||||
l.logf(logrus.FatalLevel, format, args...)
|
l.logf(logrus.FatalLevel, format, args...)
|
||||||
l.logger.Logger.Exit(1)
|
l.logger.Logger.Exit(1)
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ func (l *logger) IsLevelEnabled(level LogLevel) bool {
|
|||||||
return l.logger.Logger.IsLevelEnabled(lvl)
|
return l.logger.Logger.IsLevelEnabled(lvl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) log(level logrus.Level, args ...interface{}) {
|
func (l *logger) log(level logrus.Level, args ...any) {
|
||||||
lg := l.logger
|
lg := l.logger
|
||||||
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
|
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
|
||||||
lg = lg.WithField("caller", l.caller(3))
|
lg = lg.WithField("caller", l.caller(3))
|
||||||
@ -136,7 +136,7 @@ func (l *logger) log(level logrus.Level, args ...interface{}) {
|
|||||||
lg.Log(level, args...)
|
lg.Log(level, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) logf(level logrus.Level, format string, args ...interface{}) {
|
func (l *logger) logf(level logrus.Level, format string, args ...any) {
|
||||||
lg := l.logger
|
lg := l.logger
|
||||||
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
|
if l.logger.Logger.IsLevelEnabled(logrus.DebugLevel) {
|
||||||
lg = lg.WithField("caller", l.caller(3))
|
lg = lg.WithField("caller", l.caller(3))
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user