mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-18 22:49:52 +02:00
scripts moved to makefile, tcp/udp connections can now close gracefully, but udp is still failing testing with palworld server
This commit is contained in:
@@ -8,16 +8,12 @@ import (
|
||||
)
|
||||
|
||||
type Routes struct {
|
||||
HTTPRoutes map[string][]HTTPRoute // id -> path
|
||||
StreamRoutes map[string]*StreamRoute // id -> target
|
||||
HTTPRoutes *SafeMap[string, []HTTPRoute] // id -> path
|
||||
StreamRoutes *SafeMap[string, StreamRoute] // id -> target
|
||||
Mutex sync.Mutex
|
||||
}
|
||||
|
||||
var routes = Routes{
|
||||
HTTPRoutes: make(map[string][]HTTPRoute),
|
||||
StreamRoutes: make(map[string]*StreamRoute),
|
||||
Mutex: sync.Mutex{},
|
||||
}
|
||||
var routes = Routes{}
|
||||
|
||||
var streamSchemes = []string{"tcp", "udp"} // TODO: support "tcp:udp", "udp:tcp"
|
||||
var httpSchemes = []string{"http", "https"}
|
||||
@@ -43,23 +39,23 @@ func isStreamScheme(scheme string) bool {
|
||||
}
|
||||
|
||||
func initRoutes() {
|
||||
routes.Mutex.Lock()
|
||||
defer routes.Mutex.Unlock()
|
||||
|
||||
utils.resetPortsInUse()
|
||||
routes.StreamRoutes = make(map[string]*StreamRoute)
|
||||
routes.HTTPRoutes = make(map[string][]HTTPRoute)
|
||||
routes.HTTPRoutes = NewSafeMap[string, []HTTPRoute](
|
||||
func() []HTTPRoute {
|
||||
return make([]HTTPRoute, 0)
|
||||
},
|
||||
)
|
||||
routes.StreamRoutes = NewSafeMap[string, StreamRoute]()
|
||||
}
|
||||
|
||||
func countRoutes() int {
|
||||
return len(routes.HTTPRoutes) + len(routes.StreamRoutes)
|
||||
return routes.HTTPRoutes.Size() + routes.StreamRoutes.Size()
|
||||
}
|
||||
|
||||
func createRoute(config *ProxyConfig) {
|
||||
if isStreamScheme(config.Scheme) {
|
||||
_, inMap := routes.StreamRoutes[config.id]
|
||||
if inMap {
|
||||
log.Printf("[Build] Duplicated stream %s, ignoring", config.id)
|
||||
if routes.StreamRoutes.Contains(config.id) {
|
||||
log.Printf("[Build] Duplicated %s stream %s, ignoring", config.Scheme, config.id)
|
||||
return
|
||||
}
|
||||
route, err := NewStreamRoute(config)
|
||||
@@ -67,20 +63,15 @@ func createRoute(config *ProxyConfig) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
routes.Mutex.Lock()
|
||||
routes.StreamRoutes[config.id] = route
|
||||
routes.Mutex.Unlock()
|
||||
routes.StreamRoutes.Set(config.id, route)
|
||||
} else {
|
||||
routes.Mutex.Lock()
|
||||
_, inMap := routes.HTTPRoutes[config.Alias]
|
||||
if !inMap {
|
||||
routes.HTTPRoutes[config.Alias] = make([]HTTPRoute, 0)
|
||||
}
|
||||
routes.HTTPRoutes.Ensure(config.Alias)
|
||||
url, err := url.Parse(fmt.Sprintf("%s://%s:%s", config.Scheme, config.Host, config.Port))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
routes.HTTPRoutes[config.Alias] = append(routes.HTTPRoutes[config.Alias], NewHTTPRoute(url, config.Path))
|
||||
routes.Mutex.Unlock()
|
||||
route := NewHTTPRoute(url, config.Path)
|
||||
routes.HTTPRoutes.Set(config.Alias, append(routes.HTTPRoutes.Get(config.Alias), route))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user