Skip to content

Commit

Permalink
🧹 all: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Jul 23, 2024
1 parent 0c1d7dc commit e589b77
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
"certFile": "",
"keyFile": "",
"clientCertFile": "",
"secretPath": "4paZvyoK3dCjyQXU33md5huJMMYVD9o8",
"secretPath": "/4paZvyoK3dCjyQXU33md5huJMMYVD9o8",
"fiberConfigPath": ""
}
}
5 changes: 5 additions & 0 deletions jsonhelper/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import "time"
// Duration is [time.Duration] but implements [encoding.TextMarshaler] and [encoding.TextUnmarshaler].
type Duration time.Duration

// Value returns the duration as [time.Duration].
func (d Duration) Value() time.Duration {
return time.Duration(d)
}

// MarshalText implements [encoding.TextMarshaler.MarshalText].
func (d Duration) MarshalText() ([]byte, error) {
return []byte(time.Duration(d).String()), nil
Expand Down
16 changes: 9 additions & 7 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Config struct {
}

// Router creates a router from the RouterConfig.
func (rc *Config) Router(logger *zap.Logger, resolvers []dns.SimpleResolver, resolverMap map[string]dns.SimpleResolver, tcpClientMap map[string]zerocopy.TCPClient, udpClientMap map[string]zerocopy.UDPClient, serverIndexByName map[string]int) (*Router, error) {
func (rc *Config) Router(logger *zap.Logger, resolvers []dns.SimpleResolver, resolverMap map[string]dns.SimpleResolver, tcpClientMap map[string]zerocopy.TCPClient, udpClientMap map[string]zerocopy.UDPClient, serverIndexByName map[string]int) (r *Router, err error) {
defaultRoute := Route{name: "default"}

switch rc.DefaultTCPClientName {
Expand All @@ -38,7 +38,7 @@ func (rc *Config) Router(logger *zap.Logger, resolvers []dns.SimpleResolver, res
default:
defaultRoute.tcpClient = tcpClientMap[rc.DefaultTCPClientName]
if defaultRoute.tcpClient == nil {
return nil, fmt.Errorf("default TCP client not found: %s", rc.DefaultTCPClientName)
return nil, fmt.Errorf("default TCP client not found: %q", rc.DefaultTCPClientName)
}
}

Expand All @@ -53,20 +53,22 @@ func (rc *Config) Router(logger *zap.Logger, resolvers []dns.SimpleResolver, res
default:
defaultRoute.udpClient = udpClientMap[rc.DefaultUDPClientName]
if defaultRoute.udpClient == nil {
return nil, fmt.Errorf("default UDP client not found: %s", rc.DefaultUDPClientName)
return nil, fmt.Errorf("default UDP client not found: %q", rc.DefaultUDPClientName)
}
}

var (
geoip *geoip2.Reader
err error
)
var geoip *geoip2.Reader

if rc.GeoLite2CountryDbPath != "" {
geoip, err = geoip2.Open(rc.GeoLite2CountryDbPath)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
_ = geoip.Close()
}
}()
}

domainSetMap := make(map[string]domainset.DomainSet, len(rc.DomainSets))
Expand Down
4 changes: 2 additions & 2 deletions service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (lnc *TCPListenerConfig) Configure(listenConfigCache conn.ListenConfigCache
return tcpRelayListener{}, fmt.Errorf("invalid network: %s", lnc.Network)
}

initialPayloadWaitTimeout := time.Duration(lnc.InitialPayloadWaitTimeout)
initialPayloadWaitTimeout := lnc.InitialPayloadWaitTimeout.Value()

switch {
case initialPayloadWaitTimeout == 0:
Expand Down Expand Up @@ -177,7 +177,7 @@ func (lnc *UDPListenerConfig) Configure(listenConfigCache conn.ListenConfigCache
return udpRelayServerConn{}, err
}

natTimeout := time.Duration(lnc.NATTimeout)
natTimeout := lnc.NATTimeout.Value()

switch {
case natTimeout == 0:
Expand Down

0 comments on commit e589b77

Please sign in to comment.