Skip to content

Commit ff76576

Browse files
committed
chore: cleanup import path for listener
1 parent 1d5890a commit ff76576

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

config/config.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
P "github.com/metacubex/mihomo/constant/provider"
2929
snifferTypes "github.com/metacubex/mihomo/constant/sniffer"
3030
"github.com/metacubex/mihomo/dns"
31-
L "github.com/metacubex/mihomo/listener"
31+
"github.com/metacubex/mihomo/listener"
3232
LC "github.com/metacubex/mihomo/listener/config"
3333
"github.com/metacubex/mihomo/log"
3434
R "github.com/metacubex/mihomo/rules"
@@ -653,11 +653,11 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
653653
config.Proxies = proxies
654654
config.Providers = providers
655655

656-
listener, err := parseListeners(rawCfg)
656+
listeners, err := parseListeners(rawCfg)
657657
if err != nil {
658658
return nil, err
659659
}
660-
config.Listeners = listener
660+
config.Listeners = listeners
661661

662662
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
663663
log.Infoln("Geosite Matcher implementation: %s", geodata.SiteMatcherName())
@@ -957,16 +957,17 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
957957
func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err error) {
958958
listeners = make(map[string]C.InboundListener)
959959
for index, mapping := range cfg.Listeners {
960-
listener, err := L.ParseListener(mapping)
960+
inboundListener, err := listener.ParseListener(mapping)
961961
if err != nil {
962962
return nil, fmt.Errorf("proxy %d: %w", index, err)
963963
}
964964

965-
if _, exist := mapping[listener.Name()]; exist {
966-
return nil, fmt.Errorf("listener %s is the duplicate name", listener.Name())
965+
name := inboundListener.Name()
966+
if _, exist := mapping[name]; exist {
967+
return nil, fmt.Errorf("listener %s is the duplicate name", name)
967968
}
968969

969-
listeners[listener.Name()] = listener
970+
listeners[name] = inboundListener
970971

971972
}
972973
return

hub/route/configs.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/metacubex/mihomo/config"
1414
C "github.com/metacubex/mihomo/constant"
1515
"github.com/metacubex/mihomo/hub/executor"
16-
P "github.com/metacubex/mihomo/listener"
16+
"github.com/metacubex/mihomo/listener"
1717
LC "github.com/metacubex/mihomo/listener/config"
1818
"github.com/metacubex/mihomo/log"
1919
"github.com/metacubex/mihomo/tunnel"
@@ -306,7 +306,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
306306
}
307307

308308
if general.AllowLan != nil {
309-
P.SetAllowLan(*general.AllowLan)
309+
listener.SetAllowLan(*general.AllowLan)
310310
}
311311

312312
if general.SkipAuthPrefixes != nil {
@@ -322,7 +322,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
322322
}
323323

324324
if general.BindAddress != nil {
325-
P.SetBindAddress(*general.BindAddress)
325+
listener.SetBindAddress(*general.BindAddress)
326326
}
327327

328328
if general.Sniffing != nil {
@@ -337,17 +337,17 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
337337
dialer.DefaultInterface.Store(*general.InterfaceName)
338338
}
339339

340-
ports := P.GetPorts()
341-
342-
P.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel)
343-
P.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel)
344-
P.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel)
345-
P.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
346-
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
347-
P.ReCreateTun(pointerOrDefaultTun(general.Tun, P.LastTunConf), tunnel.Tunnel)
348-
P.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
349-
P.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
350-
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tunnel.Tunnel)
340+
ports := listener.GetPorts()
341+
342+
listener.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel)
343+
listener.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel)
344+
listener.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel)
345+
listener.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
346+
listener.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
347+
listener.ReCreateTun(pointerOrDefaultTun(general.Tun, listener.LastTunConf), tunnel.Tunnel)
348+
listener.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
349+
listener.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
350+
listener.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, listener.LastTuicConf), tunnel.Tunnel)
351351

352352
if general.Mode != nil {
353353
tunnel.SetMode(*general.Mode)

0 commit comments

Comments
 (0)