Compare commits

..
Author SHA1 Message Date
Fangliding 6de10652d7 Do not start tun in init 2026-06-05 18:03:19 +08:00
3 changed files with 15 additions and 24 deletions
-20
View File
@@ -57,26 +57,6 @@ func NewMetricsHandler(ctx context.Context, config *Config) (*MetricsHandler, er
})
return resp
}))
expvar.Publish("online", expvar.Func(func() interface{} {
resp := map[string]interface{}{}
c.statsManager.VisitOnlineMaps(func(name string, om feature_stats.OnlineMap) bool {
user := name
if parts := strings.Split(name, ">>>"); len(parts) >= 2 {
user = parts[1]
}
ips := map[string]int64{}
om.ForEach(func(ip string, lastSeen int64) bool {
ips[ip] = lastSeen
return true
})
resp[user] = map[string]interface{}{
"count": om.Count(),
"ips": ips,
}
return true
})
return resp
}))
expvar.Publish("observatory", expvar.Func(func() interface{} {
if c.observatory == nil {
common.Must(core.RequireFeatures(ctx, func(observatory extension.Observatory) error {
+6
View File
@@ -170,6 +170,12 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
// Start implements common.Runnable.
func (h *AlwaysOnInboundHandler) Start() error {
// for inbound without worker (TUN)
if run, ok := h.proxy.(common.Runnable); ok {
if err := run.Start(); err != nil {
return errors.New("failed to start proxy").Base(err)
}
}
for _, worker := range h.workers {
if err := worker.Start(); err != nil {
return err
+9 -4
View File
@@ -40,10 +40,11 @@ type ConnectionHandler interface {
// Handler implements ConnectionHandler
var _ ConnectionHandler = (*Handler)(nil)
// Handler implements common.Runnable
var _ common.Runnable = (*Handler)(nil)
// Init the Handler instance with necessary parameters
func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routing.Dispatcher) error {
var err error
// Retrieve tag and sniffing config from context (set by AlwaysOnInboundHandler)
if inbound := session.InboundFromContext(ctx); inbound != nil {
t.tag = inbound.Tag
@@ -56,6 +57,10 @@ func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routin
t.policyManager = pm
t.dispatcher = dispatcher
return nil
}
func (t *Handler) Start() error {
tunName := t.config.Name
tunInterface, err := NewTun(t.config)
if err != nil {
@@ -92,7 +97,7 @@ func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routin
tunStackOptions := StackOptions{
Tun: tunInterface,
IdleTimeout: pm.ForLevel(t.config.UserLevel).Timeouts.ConnectionIdle,
IdleTimeout: t.policyManager.ForLevel(t.config.UserLevel).Timeouts.ConnectionIdle,
}
tunStack, err := NewStack(t.ctx, tunStackOptions, t)
if err != nil {
@@ -167,7 +172,7 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) {
// Close implements common.Closable.
func (t *Handler) Close() error {
return errors.Combine(t.stack.Close(), t.tun.Close())
return errors.Combine(common.CloseIfExists(t.stack), common.CloseIfExists(t.tun))
}
// Network implements proxy.Inbound