smarter port selection

This commit is contained in:
yusing 2024-03-29 13:35:10 +00:00
parent fdab026a3b
commit 73dfc17a82
3 changed files with 20 additions and 1 deletions

Binary file not shown.

View file

@ -42,6 +42,14 @@ var (
}()
)
var wellKnownHTTPPorts = map[uint16]bool{
80: true,
8000: true,
8008: true, // alternative HTTP port
8080: true,
3000: true, // adguardhome, gogs, etc
}
var (
StreamSchemes = []string{StreamType_TCP, StreamType_UDP} // TODO: support "tcp:udp", "udp:tcp"
HTTPSchemes = []string{"http", "https"}
@ -92,6 +100,7 @@ var (
Timeout: 5 * time.Second,
KeepAlive: 5 * time.Second,
}).DialContext,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
)

View file

@ -201,6 +201,11 @@ func selectPort(c *types.Container) uint16 {
}
func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uint16 {
for _, p := range c.Ports {
if isWellKnownHTTPPort(p.PrivatePort) {
return getPort(p)
}
}
for _, p := range c.Ports {
if port := getPort(p); port != 0 {
return port
@ -208,3 +213,8 @@ func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uin
}
return 0
}
func isWellKnownHTTPPort(port uint16) bool {
_, ok := wellKnownHTTPPorts[port]
return ok
}