Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
icon: material/alert-decagram
---

#### 1.14.0-alpha.20

** Fixes and improvements

#### 1.14.0-alpha.19

* Preserve comments between formatting
Expand Down
23 changes: 21 additions & 2 deletions protocol/group/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,23 @@ func (s *Selector) SelectOutbound(tag string) bool {
}

func (s *Selector) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
conn, err := s.selected.Load().DialContext(ctx, network, destination)
selected := s.selected.Load()
if selected == nil {
return nil, E.New("selector ", s.Tag(), " has no selected outbound")
}
conn, err := selected.DialContext(ctx, network, destination)
if err != nil {
return nil, err
}
return s.interruptGroup.NewConn(conn, interrupt.IsExternalConnectionFromContext(ctx)), nil
}

func (s *Selector) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
conn, err := s.selected.Load().ListenPacket(ctx, destination)
selected := s.selected.Load()
if selected == nil {
return nil, E.New("selector ", s.Tag(), " has no selected outbound")
}
conn, err := selected.ListenPacket(ctx, destination)
if err != nil {
return nil, err
}
Expand All @@ -159,6 +167,10 @@ func (s *Selector) ListenPacket(ctx context.Context, destination M.Socksaddr) (n
func (s *Selector) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
ctx = interrupt.ContextWithIsExternalConnection(ctx)
selected := s.selected.Load()
if selected == nil {
N.CloseOnHandshakeFailure(conn, onClose, E.New("selector ", s.Tag(), " has no selected outbound"))
return
}
if outboundHandler, isHandler := selected.(adapter.ConnectionHandler); isHandler {
outboundHandler.NewConnection(ctx, conn, metadata, onClose)
} else {
Expand All @@ -169,6 +181,10 @@ func (s *Selector) NewConnection(ctx context.Context, conn net.Conn, metadata ad
func (s *Selector) NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
ctx = interrupt.ContextWithIsExternalConnection(ctx)
selected := s.selected.Load()
if selected == nil {
N.CloseOnHandshakeFailure(conn, onClose, E.New("selector ", s.Tag(), " has no selected outbound"))
return
}
if outboundHandler, isHandler := selected.(adapter.PacketConnectionHandler); isHandler {
outboundHandler.NewPacketConnection(ctx, conn, metadata, onClose)
} else {
Expand All @@ -178,6 +194,9 @@ func (s *Selector) NewPacketConnection(ctx context.Context, conn N.PacketConn, m

func (s *Selector) NewDirectRouteConnection(metadata adapter.InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error) {
selected := s.selected.Load()
if selected == nil {
return nil, E.New("selector ", s.Tag(), " has no selected outbound")
}
if !common.Contains(selected.Network(), metadata.Network) {
return nil, E.New(metadata.Network, " is not supported by outbound: ", selected.Tag())
}
Expand Down