-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed tcp/udp I/O, deadlock, nil dereference; improved docker watcher…
…, idlewatcher, loading page
- Loading branch information
yusing
committed
Sep 22, 2024
1 parent
96bce79
commit 090b73d
Showing
31 changed files
with
682 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package autocert | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
E "github.com/yusing/go-proxy/error" | ||
) | ||
|
||
func (p *Provider) Setup(ctx context.Context) (err E.NestedError) { | ||
if err = p.LoadCert(); err != nil { | ||
if !err.Is(os.ErrNotExist) { // ignore if cert doesn't exist | ||
return err | ||
} | ||
logger.Debug("obtaining cert due to error loading cert") | ||
if err = p.ObtainCert(); err != nil { | ||
return err.Warn() | ||
} | ||
} | ||
|
||
go p.ScheduleRenewal(ctx) | ||
|
||
for _, expiry := range p.GetExpiries() { | ||
logger.Infof("certificate expire on %s", expiry) | ||
break | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package config | ||
|
||
import ( | ||
M "github.com/yusing/go-proxy/models" | ||
PR "github.com/yusing/go-proxy/proxy/provider" | ||
R "github.com/yusing/go-proxy/route" | ||
U "github.com/yusing/go-proxy/utils" | ||
F "github.com/yusing/go-proxy/utils/functional" | ||
) | ||
|
||
func (cfg *Config) DumpEntries() map[string]*M.RawEntry { | ||
entries := make(map[string]*M.RawEntry) | ||
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) { | ||
entries[alias] = r.Entry() | ||
}) | ||
return entries | ||
} | ||
|
||
func (cfg *Config) DumpProviders() map[string]*PR.Provider { | ||
entries := make(map[string]*PR.Provider) | ||
cfg.proxyProviders.RangeAll(func(name string, p *PR.Provider) { | ||
entries[name] = p | ||
}) | ||
return entries | ||
} | ||
|
||
func (cfg *Config) RoutesByAlias() map[string]U.SerializedObject { | ||
routes := make(map[string]U.SerializedObject) | ||
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) { | ||
obj, err := U.Serialize(r) | ||
if err.HasError() { | ||
cfg.l.Error(err) | ||
return | ||
} | ||
obj["provider"] = p.GetName() | ||
obj["type"] = string(r.Type()) | ||
routes[alias] = obj | ||
}) | ||
return routes | ||
} | ||
|
||
func (cfg *Config) Statistics() map[string]any { | ||
nTotalStreams := 0 | ||
nTotalRPs := 0 | ||
providerStats := make(map[string]any) | ||
|
||
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) { | ||
s, ok := providerStats[p.GetName()] | ||
if !ok { | ||
s = make(map[string]int) | ||
} | ||
|
||
stats := s.(map[string]int) | ||
switch r.Type() { | ||
case R.RouteTypeStream: | ||
stats["num_streams"]++ | ||
nTotalStreams++ | ||
case R.RouteTypeReverseProxy: | ||
stats["num_reverse_proxies"]++ | ||
nTotalRPs++ | ||
default: | ||
panic("bug: should not reach here") | ||
} | ||
}) | ||
|
||
return map[string]any{ | ||
"num_total_streams": nTotalStreams, | ||
"num_total_reverse_proxies": nTotalRPs, | ||
"providers": providerStats, | ||
} | ||
} | ||
|
||
func (cfg *Config) FindRoute(alias string) R.Route { | ||
return F.MapFind(cfg.proxyProviders, | ||
func(p *PR.Provider) (R.Route, bool) { | ||
if route, ok := p.GetRoute(alias); ok { | ||
return route, true | ||
} | ||
return nil, false | ||
}, | ||
) | ||
} |
Oops, something went wrong.