mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 12:01:29 +00:00
Fix inbound contexts
This commit is contained in:
parent
6731c374d8
commit
b4de539ae5
|
@ -98,6 +98,10 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
||||||
|
@ -110,6 +114,10 @@ func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
||||||
|
|
|
@ -85,6 +85,10 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
||||||
|
@ -97,6 +101,10 @@ func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
||||||
|
|
|
@ -102,6 +102,10 @@ func (h *Inbound) NewConnection(ctx context.Context, conn net.Conn, metadata ada
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
if userName, _ := auth.UserFromContext[string](ctx); userName != "" {
|
if userName, _ := auth.UserFromContext[string](ctx); userName != "" {
|
||||||
metadata.User = userName
|
metadata.User = userName
|
||||||
h.logger.InfoContext(ctx, "[", userName, "] inbound connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "[", userName, "] inbound connection to ", metadata.Destination)
|
||||||
|
|
|
@ -67,6 +67,10 @@ func (h *Inbound) NewConnectionEx(ctx context.Context, conn net.Conn, metadata a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
||||||
|
@ -79,6 +83,10 @@ func (h *Inbound) newUserConnection(ctx context.Context, conn net.Conn, metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
func (h *Inbound) streamUserPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
user, loaded := auth.UserFromContext[string](ctx)
|
user, loaded := auth.UserFromContext[string](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
||||||
|
|
|
@ -175,6 +175,10 @@ func (h *Inbound) NewConnectionEx(ctx context.Context, conn net.Conn, metadata a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -207,12 +211,20 @@ func (h *Inbound) fallbackConnection(ctx context.Context, conn net.Conn, metadat
|
||||||
}
|
}
|
||||||
fallbackAddr = h.fallbackAddr
|
fallbackAddr = h.fallbackAddr
|
||||||
}
|
}
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
h.logger.InfoContext(ctx, "fallback connection to ", fallbackAddr)
|
h.logger.InfoContext(ctx, "fallback connection to ", fallbackAddr)
|
||||||
metadata.Destination = fallbackAddr
|
metadata.Destination = fallbackAddr
|
||||||
return h.router.RouteConnection(ctx, conn, metadata)
|
return h.router.RouteConnection(ctx, conn, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -233,10 +245,6 @@ type inboundTransportHandler Inbound
|
||||||
|
|
||||||
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
||||||
var metadata adapter.InboundContext
|
var metadata adapter.InboundContext
|
||||||
metadata.Inbound = h.Tag()
|
|
||||||
metadata.InboundType = h.Type()
|
|
||||||
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
|
||||||
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
|
||||||
metadata.Source = source
|
metadata.Source = source
|
||||||
metadata.Destination = destination
|
metadata.Destination = destination
|
||||||
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
||||||
|
|
|
@ -155,6 +155,10 @@ func (h *Inbound) NewConnectionEx(ctx context.Context, conn net.Conn, metadata a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -170,6 +174,10 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -196,10 +204,6 @@ type inboundTransportHandler Inbound
|
||||||
|
|
||||||
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
||||||
var metadata adapter.InboundContext
|
var metadata adapter.InboundContext
|
||||||
metadata.Inbound = h.Tag()
|
|
||||||
metadata.InboundType = h.Type()
|
|
||||||
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
|
||||||
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
|
||||||
metadata.Source = source
|
metadata.Source = source
|
||||||
metadata.Destination = destination
|
metadata.Destination = destination
|
||||||
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
||||||
|
|
|
@ -169,6 +169,10 @@ func (h *Inbound) NewConnectionEx(ctx context.Context, conn net.Conn, metadata a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -184,6 +188,10 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
func (h *Inbound) newPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
||||||
|
metadata.Inbound = h.Tag()
|
||||||
|
metadata.InboundType = h.Type()
|
||||||
|
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
||||||
|
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
||||||
userIndex, loaded := auth.UserFromContext[int](ctx)
|
userIndex, loaded := auth.UserFromContext[int](ctx)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
@ -210,10 +218,6 @@ type inboundTransportHandler Inbound
|
||||||
|
|
||||||
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose N.CloseHandlerFunc) {
|
||||||
var metadata adapter.InboundContext
|
var metadata adapter.InboundContext
|
||||||
metadata.Inbound = h.Tag()
|
|
||||||
metadata.InboundType = h.Type()
|
|
||||||
metadata.InboundDetour = h.listener.ListenOptions().Detour
|
|
||||||
metadata.InboundOptions = h.listener.ListenOptions().InboundOptions
|
|
||||||
metadata.Source = source
|
metadata.Source = source
|
||||||
metadata.Destination = destination
|
metadata.Destination = destination
|
||||||
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
h.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
||||||
|
|
Loading…
Reference in a new issue