github.com/sagernet/sing-box@v1.9.0-rc.20/common/mux/v2ray_legacy.go (about) 1 package mux 2 3 import ( 4 "context" 5 "net" 6 7 "github.com/sagernet/sing-box/adapter" 8 vmess "github.com/sagernet/sing-vmess" 9 "github.com/sagernet/sing/common/logger" 10 N "github.com/sagernet/sing/common/network" 11 ) 12 13 type V2RayLegacyRouter struct { 14 router adapter.ConnectionRouter 15 logger logger.ContextLogger 16 } 17 18 func NewV2RayLegacyRouter(router adapter.ConnectionRouter, logger logger.ContextLogger) adapter.ConnectionRouter { 19 return &V2RayLegacyRouter{router, logger} 20 } 21 22 func (r *V2RayLegacyRouter) RouteConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error { 23 if metadata.Destination.Fqdn == vmess.MuxDestination.Fqdn { 24 r.logger.InfoContext(ctx, "inbound legacy multiplex connection") 25 return vmess.HandleMuxConnection(ctx, conn, adapter.NewRouteHandler(metadata, r.router, r.logger)) 26 } 27 return r.router.RouteConnection(ctx, conn, metadata) 28 } 29 30 func (r *V2RayLegacyRouter) RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error { 31 return r.router.RoutePacketConnection(ctx, conn, metadata) 32 }