|  | @@ -5,6 +5,7 @@ import (
 | 
											
												
													
														|  |  	"net"
 |  |  	"net"
 | 
											
												
													
														|  |  	"sync"
 |  |  	"sync"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +	"v2ray.com/core/common"
 | 
											
												
													
														|  |  	"v2ray.com/core/common/signal"
 |  |  	"v2ray.com/core/common/signal"
 | 
											
												
													
														|  |  	"v2ray.com/core/transport/ray"
 |  |  	"v2ray.com/core/transport/ray"
 | 
											
												
													
														|  |  )
 |  |  )
 | 
											
										
											
												
													
														|  | @@ -24,6 +25,7 @@ func (l *OutboundListener) add(conn net.Conn) {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +// Accept implements net.Listener.
 | 
											
												
													
														|  |  func (l *OutboundListener) Accept() (net.Conn, error) {
 |  |  func (l *OutboundListener) Accept() (net.Conn, error) {
 | 
											
												
													
														|  |  	select {
 |  |  	select {
 | 
											
												
													
														|  |  	case <-l.done.C():
 |  |  	case <-l.done.C():
 | 
											
										
											
												
													
														|  | @@ -33,8 +35,9 @@ func (l *OutboundListener) Accept() (net.Conn, error) {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +// Close implement net.Listener.
 | 
											
												
													
														|  |  func (l *OutboundListener) Close() error {
 |  |  func (l *OutboundListener) Close() error {
 | 
											
												
													
														|  | -	l.done.Close()
 |  | 
 | 
											
												
													
														|  | 
 |  | +	common.Must(l.done.Close())
 | 
											
												
													
														|  |  L:
 |  |  L:
 | 
											
												
													
														|  |  	for {
 |  |  	for {
 | 
											
												
													
														|  |  		select {
 |  |  		select {
 | 
											
										
											
												
													
														|  | @@ -47,6 +50,7 @@ L:
 | 
											
												
													
														|  |  	return nil
 |  |  	return nil
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +// Addr implements net.Listener.
 | 
											
												
													
														|  |  func (l *OutboundListener) Addr() net.Addr {
 |  |  func (l *OutboundListener) Addr() net.Addr {
 | 
											
												
													
														|  |  	return &net.TCPAddr{
 |  |  	return &net.TCPAddr{
 | 
											
												
													
														|  |  		IP:   net.IP{0, 0, 0, 0},
 |  |  		IP:   net.IP{0, 0, 0, 0},
 | 
											
										
											
												
													
														|  | @@ -54,8 +58,8 @@ func (l *OutboundListener) Addr() net.Addr {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -// CommanderOutbound is a core.OutboundHandler that handles gRPC connections.
 |  | 
 | 
											
												
													
														|  | -type CommanderOutbound struct {
 |  | 
 | 
											
												
													
														|  | 
 |  | +// Outbound is a core.OutboundHandler that handles gRPC connections.
 | 
											
												
													
														|  | 
 |  | +type Outbound struct {
 | 
											
												
													
														|  |  	tag      string
 |  |  	tag      string
 | 
											
												
													
														|  |  	listener *OutboundListener
 |  |  	listener *OutboundListener
 | 
											
												
													
														|  |  	access   sync.RWMutex
 |  |  	access   sync.RWMutex
 | 
											
										
											
												
													
														|  | @@ -63,7 +67,7 @@ type CommanderOutbound struct {
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  // Dispatch implements core.OutboundHandler.
 |  |  // Dispatch implements core.OutboundHandler.
 | 
											
												
													
														|  | -func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (co *Outbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
 | 
											
												
													
														|  |  	co.access.RLock()
 |  |  	co.access.RLock()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	if co.closed {
 |  |  	if co.closed {
 | 
											
										
											
												
													
														|  | @@ -81,12 +85,12 @@ func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  // Tag implements core.OutboundHandler.
 |  |  // Tag implements core.OutboundHandler.
 | 
											
												
													
														|  | -func (co *CommanderOutbound) Tag() string {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (co *Outbound) Tag() string {
 | 
											
												
													
														|  |  	return co.tag
 |  |  	return co.tag
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  // Start implements common.Runnable.
 |  |  // Start implements common.Runnable.
 | 
											
												
													
														|  | -func (co *CommanderOutbound) Start() error {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (co *Outbound) Start() error {
 | 
											
												
													
														|  |  	co.access.Lock()
 |  |  	co.access.Lock()
 | 
											
												
													
														|  |  	co.closed = false
 |  |  	co.closed = false
 | 
											
												
													
														|  |  	co.access.Unlock()
 |  |  	co.access.Unlock()
 | 
											
										
											
												
													
														|  | @@ -94,11 +98,10 @@ func (co *CommanderOutbound) Start() error {
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  // Close implements common.Closable.
 |  |  // Close implements common.Closable.
 | 
											
												
													
														|  | -func (co *CommanderOutbound) Close() error {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (co *Outbound) Close() error {
 | 
											
												
													
														|  |  	co.access.Lock()
 |  |  	co.access.Lock()
 | 
											
												
													
														|  | -	co.closed = true
 |  | 
 | 
											
												
													
														|  | -	co.listener.Close()
 |  | 
 | 
											
												
													
														|  | -	co.access.Unlock()
 |  | 
 | 
											
												
													
														|  | 
 |  | +	defer co.access.Unlock()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -	return nil
 |  | 
 | 
											
												
													
														|  | 
 |  | +	co.closed = true
 | 
											
												
													
														|  | 
 |  | +	return co.listener.Close()
 | 
											
												
													
														|  |  }
 |  |  }
 |