mirror of https://github.com/v2ray/v2ray-core
completely remove allow passive connection
parent
c245b4506e
commit
d72029211f
|
@ -2,7 +2,6 @@ package impl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"v2ray.com/core/app"
|
"v2ray.com/core/app"
|
||||||
"v2ray.com/core/app/dispatcher"
|
"v2ray.com/core/app/dispatcher"
|
||||||
|
@ -10,7 +9,6 @@ import (
|
||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
"v2ray.com/core/app/router"
|
"v2ray.com/core/app/router"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
|
@ -71,70 +69,13 @@ func (v *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
|
||||||
}
|
}
|
||||||
|
|
||||||
direct := ray.NewRay(ctx)
|
direct := ray.NewRay(ctx)
|
||||||
var waitFunc func() error
|
go dispatcher.Dispatch(ctx, direct)
|
||||||
if allowPassiveConnection, ok := proxy.AllowPassiveConnectionFromContext(ctx); ok && allowPassiveConnection {
|
|
||||||
waitFunc = noOpWait()
|
|
||||||
} else {
|
|
||||||
wdi := &waitDataInspector{
|
|
||||||
hasData: make(chan bool, 1),
|
|
||||||
}
|
|
||||||
direct.AddInspector(wdi)
|
|
||||||
waitFunc = waitForData(wdi)
|
|
||||||
}
|
|
||||||
|
|
||||||
go v.waitAndDispatch(ctx, waitFunc, direct, dispatcher)
|
|
||||||
|
|
||||||
return direct, nil
|
return direct, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *DefaultDispatcher) waitAndDispatch(ctx context.Context, wait func() error, link ray.OutboundRay, dispatcher proxyman.OutboundHandler) {
|
|
||||||
if err := wait(); err != nil {
|
|
||||||
log.Info("DefaultDispatcher: Failed precondition: ", err)
|
|
||||||
link.OutboundInput().CloseError()
|
|
||||||
link.OutboundOutput().CloseError()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatcher.Dispatch(ctx, link)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.Must(common.RegisterConfig((*dispatcher.Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
common.Must(common.RegisterConfig((*dispatcher.Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
return NewDefaultDispatcher(ctx, config.(*dispatcher.Config))
|
return NewDefaultDispatcher(ctx, config.(*dispatcher.Config))
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
type waitDataInspector struct {
|
|
||||||
hasData chan bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (wdi *waitDataInspector) Input(*buf.Buffer) {
|
|
||||||
select {
|
|
||||||
case wdi.hasData <- true:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (wdi *waitDataInspector) WaitForData() bool {
|
|
||||||
select {
|
|
||||||
case <-wdi.hasData:
|
|
||||||
return true
|
|
||||||
case <-time.After(time.Minute):
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func waitForData(wdi *waitDataInspector) func() error {
|
|
||||||
return func() error {
|
|
||||||
if wdi.WaitForData() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errors.New("DefaultDispatcher: No data.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func noOpWait() func() error {
|
|
||||||
return func() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ message ReceiverConfig {
|
||||||
AllocationStrategy allocation_strategy = 3;
|
AllocationStrategy allocation_strategy = 3;
|
||||||
v2ray.core.transport.internet.StreamConfig stream_settings = 4;
|
v2ray.core.transport.internet.StreamConfig stream_settings = 4;
|
||||||
bool receive_original_destination = 5;
|
bool receive_original_destination = 5;
|
||||||
bool allow_passive_connection = 6;
|
bool allow_passive_connection = 6 [deprecated=true];
|
||||||
}
|
}
|
||||||
|
|
||||||
message InboundHandlerConfig {
|
message InboundHandlerConfig {
|
||||||
|
|
|
@ -43,7 +43,6 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
|
||||||
stream: receiverConfig.StreamSettings,
|
stream: receiverConfig.StreamSettings,
|
||||||
recvOrigDest: receiverConfig.ReceiveOriginalDestination,
|
recvOrigDest: receiverConfig.ReceiveOriginalDestination,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
allowPassiveConn: receiverConfig.AllowPassiveConnection,
|
|
||||||
dispatcher: h.mux,
|
dispatcher: h.mux,
|
||||||
}
|
}
|
||||||
h.workers = append(h.workers, worker)
|
h.workers = append(h.workers, worker)
|
||||||
|
|
|
@ -103,7 +103,6 @@ func (h *DynamicInboundHandler) refresh() error {
|
||||||
proxy: p,
|
proxy: p,
|
||||||
stream: h.receiverConfig.StreamSettings,
|
stream: h.receiverConfig.StreamSettings,
|
||||||
recvOrigDest: h.receiverConfig.ReceiveOriginalDestination,
|
recvOrigDest: h.receiverConfig.ReceiveOriginalDestination,
|
||||||
allowPassiveConn: h.receiverConfig.AllowPassiveConnection,
|
|
||||||
dispatcher: h.mux,
|
dispatcher: h.mux,
|
||||||
}
|
}
|
||||||
if err := worker.Start(); err != nil {
|
if err := worker.Start(); err != nil {
|
||||||
|
|
|
@ -32,7 +32,6 @@ type tcpWorker struct {
|
||||||
stream *internet.StreamConfig
|
stream *internet.StreamConfig
|
||||||
recvOrigDest bool
|
recvOrigDest bool
|
||||||
tag string
|
tag string
|
||||||
allowPassiveConn bool
|
|
||||||
dispatcher dispatcher.Interface
|
dispatcher dispatcher.Interface
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
@ -51,7 +50,6 @@ func (w *tcpWorker) callback(conn internet.Connection) {
|
||||||
if len(w.tag) > 0 {
|
if len(w.tag) > 0 {
|
||||||
ctx = proxy.ContextWithInboundTag(ctx, w.tag)
|
ctx = proxy.ContextWithInboundTag(ctx, w.tag)
|
||||||
}
|
}
|
||||||
ctx = proxy.ContextWithAllowPassiveConnection(ctx, w.allowPassiveConn)
|
|
||||||
ctx = proxy.ContextWithInboundDestination(ctx, v2net.TCPDestination(w.address, w.port))
|
ctx = proxy.ContextWithInboundDestination(ctx, v2net.TCPDestination(w.address, w.port))
|
||||||
ctx = proxy.ContextWithSource(ctx, v2net.DestinationFromAddr(conn.RemoteAddr()))
|
ctx = proxy.ContextWithSource(ctx, v2net.DestinationFromAddr(conn.RemoteAddr()))
|
||||||
if err := w.proxy.Process(ctx, v2net.Network_TCP, conn, w.dispatcher); err != nil {
|
if err := w.proxy.Process(ctx, v2net.Network_TCP, conn, w.dispatcher); err != nil {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package ray
|
package ray
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,20 +44,11 @@ func (v *directRay) InboundOutput() InputStream {
|
||||||
return v.Output
|
return v.Output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *directRay) AddInspector(inspector Inspector) {
|
|
||||||
if inspector == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
v.Input.inspector.AddInspector(inspector)
|
|
||||||
v.Output.inspector.AddInspector(inspector)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
buffer chan *buf.Buffer
|
buffer chan *buf.Buffer
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
close chan bool
|
close chan bool
|
||||||
err chan bool
|
err chan bool
|
||||||
inspector *InspectorChain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStream(ctx context.Context) *Stream {
|
func NewStream(ctx context.Context) *Stream {
|
||||||
|
@ -68,7 +57,6 @@ func NewStream(ctx context.Context) *Stream {
|
||||||
buffer: make(chan *buf.Buffer, bufferSize),
|
buffer: make(chan *buf.Buffer, bufferSize),
|
||||||
close: make(chan bool),
|
close: make(chan bool),
|
||||||
err: make(chan bool),
|
err: make(chan bool),
|
||||||
inspector: &InspectorChain{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +127,6 @@ func (v *Stream) Write(data *buf.Buffer) (err error) {
|
||||||
case <-v.close:
|
case <-v.close:
|
||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
case v.buffer <- data:
|
case v.buffer <- data:
|
||||||
v.inspector.Input(data)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package ray
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"v2ray.com/core/common/buf"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Inspector interface {
|
|
||||||
Input(*buf.Buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
type NoOpInspector struct{}
|
|
||||||
|
|
||||||
func (NoOpInspector) Input(*buf.Buffer) {}
|
|
||||||
|
|
||||||
type InspectorChain struct {
|
|
||||||
sync.RWMutex
|
|
||||||
chain []Inspector
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ic *InspectorChain) AddInspector(inspector Inspector) {
|
|
||||||
ic.Lock()
|
|
||||||
defer ic.Unlock()
|
|
||||||
|
|
||||||
ic.chain = append(ic.chain, inspector)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ic *InspectorChain) Input(b *buf.Buffer) {
|
|
||||||
ic.RLock()
|
|
||||||
defer ic.RUnlock()
|
|
||||||
|
|
||||||
for _, inspector := range ic.chain {
|
|
||||||
inspector.Input(b)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -32,7 +32,6 @@ type InboundRay interface {
|
||||||
type Ray interface {
|
type Ray interface {
|
||||||
InboundRay
|
InboundRay
|
||||||
OutboundRay
|
OutboundRay
|
||||||
AddInspector(Inspector)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RayStream interface {
|
type RayStream interface {
|
||||||
|
|
Loading…
Reference in New Issue