Add proxy speed measurement, connection logs and standalone Android packaging

This commit is contained in:
shen
2026-10-13 23:08:57 -07:00
parent f94dab0555
commit 72566b9a8a
22 changed files with 551 additions and 91 deletions
+15 -3
View File
@@ -11,6 +11,7 @@ import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/protocol/mixed"
"github.com/sagernet/sing-box/protocol/socks"
N "github.com/sagernet/sing/common/network"
)
@@ -61,7 +62,8 @@ func (s *connectionSet) closeAll() {
}
type trackedInbound struct {
*socks.Inbound
adapter.Inbound
handler adapter.TCPInjectableInbound
listener *listener.Listener
connections connectionSet
}
@@ -73,13 +75,23 @@ func registerTrackedInbound(registry *inbound.Registry) {
if err != nil {
return nil, err
}
tracked := &trackedInbound{Inbound: delegate.(*socks.Inbound), connections: connectionSet{connections: make(map[*trackedConnection]struct{})}}
tracked := &trackedInbound{Inbound: delegate, handler: delegate.(*socks.Inbound), connections: connectionSet{connections: make(map[*trackedConnection]struct{})}}
// The delegate only handles the protocol. This listener owns the
// accepted TCP controls; its options also constrain UDP association
// allocation through the delegate's original packet-listener helper.
tracked.listener = listener.New(listener.Options{Context: ctx, Logger: logger, Network: []string{N.NetworkTCP}, Listen: options.ListenOptions, ConnectionHandler: tracked})
return tracked, nil
})
inbound.Register[option.HTTPMixedInboundOptions](registry, C.TypeMixed,
func(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.HTTPMixedInboundOptions) (adapter.Inbound, error) {
delegate, err := mixed.NewInbound(ctx, router, logger, tag, options)
if err != nil {
return nil, err
}
tracked := &trackedInbound{Inbound: delegate, handler: delegate.(*mixed.Inbound), connections: connectionSet{connections: make(map[*trackedConnection]struct{})}}
tracked.listener = listener.New(listener.Options{Context: ctx, Logger: logger, Network: []string{N.NetworkTCP}, Listen: options.ListenOptions, ConnectionHandler: tracked})
return tracked, nil
})
}
func (h *trackedInbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
@@ -103,5 +115,5 @@ func (h *trackedInbound) NewConnection(ctx context.Context, conn net.Conn, metad
_ = conn.Close()
return
}
h.Inbound.NewConnection(ctx, tracked, metadata, onClose)
h.handler.NewConnection(ctx, tracked, metadata, onClose)
}