mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-16 17:08:20 -04:00
split listening settings from inbound proxies and apply context
This commit is contained in:
parent
3bbdf2a065
commit
ca721230e1
@ -1,14 +1,15 @@
|
||||
package dispatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
// Interface dispatch a packet and possibly further network payload to its destination.
|
||||
type Interface interface {
|
||||
DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay
|
||||
DispatchToOutbound(ctx context.Context) ray.InboundRay
|
||||
}
|
||||
|
||||
func FromSpace(space app.Space) Interface {
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/log"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
@ -43,12 +42,15 @@ func (DefaultDispatcher) Interface() interface{} {
|
||||
return (*dispatcher.Interface)(nil)
|
||||
}
|
||||
|
||||
func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay {
|
||||
func (v *DefaultDispatcher) DispatchToOutbound(ctx context.Context) ray.InboundRay {
|
||||
dispatcher := v.ohm.GetDefaultHandler()
|
||||
destination := session.Destination
|
||||
destination := proxy.DestinationFromContext(ctx)
|
||||
if !destination.IsValid() {
|
||||
panic("Dispatcher: Invalid destination.")
|
||||
}
|
||||
|
||||
if v.router != nil {
|
||||
if tag, err := v.router.TakeDetour(session); err == nil {
|
||||
if tag, err := v.router.TakeDetour(ctx); err == nil {
|
||||
if handler := v.ohm.GetHandler(tag); handler != nil {
|
||||
log.Info("DefaultDispatcher: Taking detour [", tag, "] for [", destination, "].")
|
||||
dispatcher = handler
|
||||
@ -60,9 +62,9 @@ func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.I
|
||||
}
|
||||
}
|
||||
|
||||
direct := ray.NewRay()
|
||||
direct := ray.NewRay(ctx)
|
||||
var waitFunc func() error
|
||||
if session.Inbound != nil && session.Inbound.AllowPassiveConnection {
|
||||
if allowPassiveConnection, ok := proxy.AllowPassiveConnectionFromContext(ctx); ok && allowPassiveConnection {
|
||||
waitFunc = noOpWait()
|
||||
} else {
|
||||
wdi := &waitDataInspector{
|
||||
@ -72,12 +74,12 @@ func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.I
|
||||
waitFunc = waitForData(wdi)
|
||||
}
|
||||
|
||||
go v.waitAndDispatch(waitFunc, destination, direct, dispatcher)
|
||||
go v.waitAndDispatch(ctx, waitFunc, direct, dispatcher)
|
||||
|
||||
return direct
|
||||
}
|
||||
|
||||
func (v *DefaultDispatcher) waitAndDispatch(wait func() error, destination net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) {
|
||||
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()
|
||||
@ -85,7 +87,7 @@ func (v *DefaultDispatcher) waitAndDispatch(wait func() error, destination net.D
|
||||
return
|
||||
}
|
||||
|
||||
dispatcher.Dispatch(destination, link)
|
||||
dispatcher.Dispatch(ctx, link)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -1,19 +1,18 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/log"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet/udp"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -101,7 +100,7 @@ func (v *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
|
||||
}
|
||||
|
||||
// Private: Visible for testing.
|
||||
func (v *UDPNameServer) HandleResponse(dest v2net.Destination, payload *buf.Buffer) {
|
||||
func (v *UDPNameServer) HandleResponse(payload *buf.Buffer) {
|
||||
msg := new(dns.Msg)
|
||||
err := msg.Unpack(payload.Bytes())
|
||||
if err != nil {
|
||||
@ -165,15 +164,12 @@ func (v *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer {
|
||||
return buffer
|
||||
}
|
||||
|
||||
func (v *UDPNameServer) DispatchQuery(payload *buf.Buffer) {
|
||||
v.udpServer.Dispatch(&proxy.SessionInfo{Source: pseudoDestination, Destination: v.address}, payload, v.HandleResponse)
|
||||
}
|
||||
|
||||
func (v *UDPNameServer) QueryA(domain string) <-chan *ARecord {
|
||||
response := make(chan *ARecord, 1)
|
||||
id := v.AssignUnusedID(response)
|
||||
|
||||
v.DispatchQuery(v.BuildQueryA(domain, id))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*8)
|
||||
v.udpServer.Dispatch(ctx, v.address, v.BuildQueryA(domain, id), v.HandleResponse)
|
||||
|
||||
go func() {
|
||||
for i := 0; i < 2; i++ {
|
||||
@ -182,11 +178,12 @@ func (v *UDPNameServer) QueryA(domain string) <-chan *ARecord {
|
||||
_, found := v.requests[id]
|
||||
v.Unlock()
|
||||
if found {
|
||||
v.DispatchQuery(v.BuildQueryA(domain, id))
|
||||
v.udpServer.Dispatch(ctx, v.address, v.BuildQueryA(domain, id), v.HandleResponse)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}()
|
||||
|
||||
return response
|
||||
|
@ -1,42 +0,0 @@
|
||||
package proxy
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Config struct {
|
||||
}
|
||||
|
||||
func (m *Config) Reset() { *m = Config{} }
|
||||
func (m *Config) String() string { return proto.CompactTextString(m) }
|
||||
func (*Config) ProtoMessage() {}
|
||||
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Config)(nil), "v2ray.core.app.proxy.Config")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("v2ray.com/core/app/proxy/config.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 128 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x33, 0x2a, 0x4a,
|
||||
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x2c, 0x28, 0xd0, 0x2f,
|
||||
0x28, 0xca, 0xaf, 0xa8, 0xd4, 0x4f, 0xce, 0xcf, 0x4b, 0xcb, 0x4c, 0xd7, 0x2b, 0x28, 0xca, 0x2f,
|
||||
0xc9, 0x17, 0x12, 0x81, 0x29, 0x2b, 0x4a, 0xd5, 0x4b, 0x2c, 0x28, 0xd0, 0x03, 0x2b, 0x51, 0xe2,
|
||||
0xe0, 0x62, 0x73, 0x06, 0xab, 0x72, 0x72, 0xe5, 0x92, 0x48, 0xce, 0xcf, 0xd5, 0xc3, 0xa6, 0xca,
|
||||
0x89, 0x1b, 0xa2, 0x26, 0x00, 0x64, 0x50, 0x14, 0x2b, 0x58, 0x6c, 0x15, 0x93, 0x48, 0x98, 0x51,
|
||||
0x50, 0x62, 0xa5, 0x9e, 0x33, 0x48, 0xa9, 0x63, 0x41, 0x81, 0x5e, 0x00, 0x48, 0x38, 0x89, 0x0d,
|
||||
0x6c, 0x9b, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x16, 0xbe, 0x54, 0x50, 0x96, 0x00, 0x00, 0x00,
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package v2ray.core.app.proxy;
|
||||
option csharp_namespace = "V2Ray.Core.App.Proxy";
|
||||
option go_package = "proxy";
|
||||
option java_package = "com.v2ray.core.app.proxy";
|
||||
option java_outer_classname = "ConfigProto";
|
||||
|
||||
message Config {
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/log"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
type OutboundProxy struct {
|
||||
outboundManager proxyman.OutboundHandlerManager
|
||||
}
|
||||
|
||||
func NewOutboundProxy(ctx context.Context, config *Config) (*OutboundProxy, error) {
|
||||
space := app.SpaceFromContext(ctx)
|
||||
if space == nil {
|
||||
return nil, errors.New("OutboundProxy: No space in context.")
|
||||
}
|
||||
proxy := new(OutboundProxy)
|
||||
space.OnInitialize(func() error {
|
||||
proxy.outboundManager = proxyman.OutboundHandlerManagerFromSpace(space)
|
||||
if proxy.outboundManager == nil {
|
||||
return errors.New("Proxy: Outbound handler manager not found in space.")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
func (OutboundProxy) Interface() interface{} {
|
||||
return (*OutboundProxy)(nil)
|
||||
}
|
||||
|
||||
func (v *OutboundProxy) RegisterDialer() {
|
||||
internet.ProxyDialer = v.Dial
|
||||
}
|
||||
|
||||
// Dial implements internet.Dialer.
|
||||
func (v *OutboundProxy) Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (internet.Connection, error) {
|
||||
handler := v.outboundManager.GetHandler(options.Proxy.Tag)
|
||||
if handler == nil {
|
||||
log.Warning("Proxy: Failed to get outbound handler with tag: ", options.Proxy.Tag)
|
||||
return internet.Dial(src, dest, internet.DialerOptions{
|
||||
Stream: options.Stream,
|
||||
})
|
||||
}
|
||||
log.Info("Proxy: Dialing to ", dest)
|
||||
stream := ray.NewRay()
|
||||
go handler.Dispatch(dest, stream)
|
||||
return NewConnection(src, dest, stream), nil
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
stream ray.Ray
|
||||
closed bool
|
||||
localAddr net.Addr
|
||||
remoteAddr net.Addr
|
||||
|
||||
reader *buf.BufferToBytesReader
|
||||
writer *buf.BytesToBufferWriter
|
||||
}
|
||||
|
||||
func NewConnection(src v2net.Address, dest v2net.Destination, stream ray.Ray) *Connection {
|
||||
return &Connection{
|
||||
stream: stream,
|
||||
localAddr: &net.TCPAddr{
|
||||
IP: []byte{0, 0, 0, 0},
|
||||
Port: 0,
|
||||
},
|
||||
remoteAddr: &net.TCPAddr{
|
||||
IP: []byte{0, 0, 0, 0},
|
||||
Port: 0,
|
||||
},
|
||||
reader: buf.NewBytesReader(stream.InboundOutput()),
|
||||
writer: buf.NewBytesWriter(stream.InboundInput()),
|
||||
}
|
||||
}
|
||||
|
||||
// Read implements net.Conn.Read().
|
||||
func (v *Connection) Read(b []byte) (int, error) {
|
||||
if v.closed {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return v.reader.Read(b)
|
||||
}
|
||||
|
||||
// Write implements net.Conn.Write().
|
||||
func (v *Connection) Write(b []byte) (int, error) {
|
||||
if v.closed {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
return v.writer.Write(b)
|
||||
}
|
||||
|
||||
// Close implements net.Conn.Close().
|
||||
func (v *Connection) Close() error {
|
||||
v.closed = true
|
||||
v.stream.InboundInput().Close()
|
||||
v.stream.InboundOutput().CloseError()
|
||||
return nil
|
||||
}
|
||||
|
||||
// LocalAddr implements net.Conn.LocalAddr().
|
||||
func (v *Connection) LocalAddr() net.Addr {
|
||||
return v.localAddr
|
||||
}
|
||||
|
||||
// RemoteAddr implements net.Conn.RemoteAddr().
|
||||
func (v *Connection) RemoteAddr() net.Addr {
|
||||
return v.remoteAddr
|
||||
}
|
||||
|
||||
func (v *Connection) SetDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Connection) SetReadDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Connection) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Connection) Reusable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (v *Connection) SetReusable(bool) {
|
||||
|
||||
}
|
||||
|
||||
func OutboundProxyFromSpace(space app.Space) *OutboundProxy {
|
||||
app := space.GetApplication((*OutboundProxy)(nil))
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
return app.(*OutboundProxy)
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
return NewOutboundProxy(ctx, config.(*Config))
|
||||
}))
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package proxy_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core/app"
|
||||
. "v2ray.com/core/app/proxy"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
_ "v2ray.com/core/app/proxyman/outbound"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/proxy/freedom"
|
||||
"v2ray.com/core/testing/assert"
|
||||
"v2ray.com/core/testing/servers/tcp"
|
||||
"v2ray.com/core/transport/internet"
|
||||
_ "v2ray.com/core/transport/internet/tcp"
|
||||
)
|
||||
|
||||
func TestProxyDial(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
space := app.NewSpace()
|
||||
ctx := app.ContextWithSpace(context.Background(), space)
|
||||
assert.Error(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig))).IsNil()
|
||||
outboundManager := proxyman.OutboundHandlerManagerFromSpace(space)
|
||||
freedom, err := freedom.New(proxy.ContextWithOutboundMeta(ctx, &proxy.OutboundHandlerMeta{
|
||||
Tag: "tag",
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_TCP,
|
||||
},
|
||||
}), &freedom.Config{})
|
||||
assert.Error(err).IsNil()
|
||||
common.Must(outboundManager.SetHandler("tag", freedom))
|
||||
|
||||
assert.Error(app.AddApplicationToSpace(ctx, new(Config))).IsNil()
|
||||
proxy := OutboundProxyFromSpace(space)
|
||||
assert.Error(space.Initialize()).IsNil()
|
||||
|
||||
xor := func(b []byte) []byte {
|
||||
for idx, x := range b {
|
||||
b[idx] = x ^ 'c'
|
||||
}
|
||||
return b
|
||||
}
|
||||
tcpServer := &tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
conn, err := proxy.Dial(net.LocalHostIP, dest, internet.DialerOptions{
|
||||
Stream: &internet.StreamConfig{
|
||||
Protocol: internet.TransportProtocol_TCP,
|
||||
},
|
||||
Proxy: &internet.ProxyConfig{
|
||||
Tag: "tag",
|
||||
},
|
||||
})
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
_, err = conn.Write([]byte{'a', 'b', 'c', 'd'})
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
b := make([]byte, 10)
|
||||
nBytes, err := conn.Read(b)
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
assert.Bytes(xor(b[:nBytes])).Equals([]byte{'a', 'b', 'c', 'd'})
|
||||
|
||||
common.Must(conn.Close())
|
||||
tcpServer.Close()
|
||||
}
|
@ -134,88 +134,72 @@ func (m *AllocationStrategy_AllocationStrategyRefresh) GetValue() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type StreamReceiverConfig struct {
|
||||
PortRange *v2ray_core_common_net1.PortRange `protobuf:"bytes,1,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
|
||||
Listen *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,2,opt,name=listen" json:"listen,omitempty"`
|
||||
AllocationStrategy *AllocationStrategy `protobuf:"bytes,3,opt,name=allocation_strategy,json=allocationStrategy" json:"allocation_strategy,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,4,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
type ReceiverConfig struct {
|
||||
PortRange *v2ray_core_common_net1.PortRange `protobuf:"bytes,1,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
|
||||
Listen *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,2,opt,name=listen" json:"listen,omitempty"`
|
||||
AllocationStrategy *AllocationStrategy `protobuf:"bytes,3,opt,name=allocation_strategy,json=allocationStrategy" json:"allocation_strategy,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,4,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
ReceiveOriginalDestination bool `protobuf:"varint,5,opt,name=receive_original_destination,json=receiveOriginalDestination" json:"receive_original_destination,omitempty"`
|
||||
AllowPassiveConnection bool `protobuf:"varint,6,opt,name=allow_passive_connection,json=allowPassiveConnection" json:"allow_passive_connection,omitempty"`
|
||||
}
|
||||
|
||||
func (m *StreamReceiverConfig) Reset() { *m = StreamReceiverConfig{} }
|
||||
func (m *StreamReceiverConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*StreamReceiverConfig) ProtoMessage() {}
|
||||
func (*StreamReceiverConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||
func (m *ReceiverConfig) Reset() { *m = ReceiverConfig{} }
|
||||
func (m *ReceiverConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*ReceiverConfig) ProtoMessage() {}
|
||||
func (*ReceiverConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||
|
||||
func (m *StreamReceiverConfig) GetPortRange() *v2ray_core_common_net1.PortRange {
|
||||
func (m *ReceiverConfig) GetPortRange() *v2ray_core_common_net1.PortRange {
|
||||
if m != nil {
|
||||
return m.PortRange
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *StreamReceiverConfig) GetListen() *v2ray_core_common_net.IPOrDomain {
|
||||
func (m *ReceiverConfig) GetListen() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
return m.Listen
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *StreamReceiverConfig) GetAllocationStrategy() *AllocationStrategy {
|
||||
func (m *ReceiverConfig) GetAllocationStrategy() *AllocationStrategy {
|
||||
if m != nil {
|
||||
return m.AllocationStrategy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *StreamReceiverConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
func (m *ReceiverConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
if m != nil {
|
||||
return m.StreamSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DatagramReceiverConfig struct {
|
||||
PortRange *v2ray_core_common_net1.PortRange `protobuf:"bytes,1,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
|
||||
Listen *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,2,opt,name=listen" json:"listen,omitempty"`
|
||||
AllocationStrategy *AllocationStrategy `protobuf:"bytes,3,opt,name=allocation_strategy,json=allocationStrategy" json:"allocation_strategy,omitempty"`
|
||||
func (m *ReceiverConfig) GetReceiveOriginalDestination() bool {
|
||||
if m != nil {
|
||||
return m.ReceiveOriginalDestination
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *DatagramReceiverConfig) Reset() { *m = DatagramReceiverConfig{} }
|
||||
func (m *DatagramReceiverConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*DatagramReceiverConfig) ProtoMessage() {}
|
||||
func (*DatagramReceiverConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
|
||||
func (m *DatagramReceiverConfig) GetPortRange() *v2ray_core_common_net1.PortRange {
|
||||
func (m *ReceiverConfig) GetAllowPassiveConnection() bool {
|
||||
if m != nil {
|
||||
return m.PortRange
|
||||
return m.AllowPassiveConnection
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DatagramReceiverConfig) GetListen() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
return m.Listen
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DatagramReceiverConfig) GetAllocationStrategy() *AllocationStrategy {
|
||||
if m != nil {
|
||||
return m.AllocationStrategy
|
||||
}
|
||||
return nil
|
||||
return false
|
||||
}
|
||||
|
||||
type InboundHandlerConfig struct {
|
||||
Tag string `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
|
||||
ReceiverSettings []*v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,rep,name=receiver_settings,json=receiverSettings" json:"receiver_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
Tag string `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
|
||||
ReceiverSettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,opt,name=receiver_settings,json=receiverSettings" json:"receiver_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
}
|
||||
|
||||
func (m *InboundHandlerConfig) Reset() { *m = InboundHandlerConfig{} }
|
||||
func (m *InboundHandlerConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*InboundHandlerConfig) ProtoMessage() {}
|
||||
func (*InboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
func (*InboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
|
||||
func (m *InboundHandlerConfig) GetTag() string {
|
||||
if m != nil {
|
||||
@ -224,7 +208,7 @@ func (m *InboundHandlerConfig) GetTag() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *InboundHandlerConfig) GetReceiverSettings() []*v2ray_core_common_serial.TypedMessage {
|
||||
func (m *InboundHandlerConfig) GetReceiverSettings() *v2ray_core_common_serial.TypedMessage {
|
||||
if m != nil {
|
||||
return m.ReceiverSettings
|
||||
}
|
||||
@ -244,60 +228,35 @@ type OutboundConfig struct {
|
||||
func (m *OutboundConfig) Reset() { *m = OutboundConfig{} }
|
||||
func (m *OutboundConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*OutboundConfig) ProtoMessage() {}
|
||||
func (*OutboundConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
func (*OutboundConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
|
||||
type StreamSenderConfig struct {
|
||||
type SenderConfig struct {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
Via *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,1,opt,name=via" json:"via,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,2,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_transport_internet.ProxyConfig `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
}
|
||||
|
||||
func (m *StreamSenderConfig) Reset() { *m = StreamSenderConfig{} }
|
||||
func (m *StreamSenderConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*StreamSenderConfig) ProtoMessage() {}
|
||||
func (*StreamSenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||
func (m *SenderConfig) Reset() { *m = SenderConfig{} }
|
||||
func (m *SenderConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*SenderConfig) ProtoMessage() {}
|
||||
func (*SenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
|
||||
func (m *StreamSenderConfig) GetVia() *v2ray_core_common_net.IPOrDomain {
|
||||
func (m *SenderConfig) GetVia() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
return m.Via
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *StreamSenderConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
func (m *SenderConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
if m != nil {
|
||||
return m.StreamSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *StreamSenderConfig) GetProxySettings() *v2ray_core_transport_internet.ProxyConfig {
|
||||
if m != nil {
|
||||
return m.ProxySettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DatagramSenderConfig struct {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
Via *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,1,opt,name=via" json:"via,omitempty"`
|
||||
ProxySettings *v2ray_core_transport_internet.ProxyConfig `protobuf:"bytes,2,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
}
|
||||
|
||||
func (m *DatagramSenderConfig) Reset() { *m = DatagramSenderConfig{} }
|
||||
func (m *DatagramSenderConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*DatagramSenderConfig) ProtoMessage() {}
|
||||
func (*DatagramSenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||
|
||||
func (m *DatagramSenderConfig) GetVia() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
return m.Via
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DatagramSenderConfig) GetProxySettings() *v2ray_core_transport_internet.ProxyConfig {
|
||||
func (m *SenderConfig) GetProxySettings() *v2ray_core_transport_internet.ProxyConfig {
|
||||
if m != nil {
|
||||
return m.ProxySettings
|
||||
}
|
||||
@ -305,15 +264,17 @@ func (m *DatagramSenderConfig) GetProxySettings() *v2ray_core_transport_internet
|
||||
}
|
||||
|
||||
type OutboundHandlerConfig struct {
|
||||
Tag string `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
|
||||
SenderSettings []*v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,rep,name=sender_settings,json=senderSettings" json:"sender_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
Tag string `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
|
||||
SenderSettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,opt,name=sender_settings,json=senderSettings" json:"sender_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
Expire int64 `protobuf:"varint,4,opt,name=expire" json:"expire,omitempty"`
|
||||
Comment string `protobuf:"bytes,5,opt,name=comment" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
func (m *OutboundHandlerConfig) Reset() { *m = OutboundHandlerConfig{} }
|
||||
func (m *OutboundHandlerConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*OutboundHandlerConfig) ProtoMessage() {}
|
||||
func (*OutboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
|
||||
func (*OutboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||
|
||||
func (m *OutboundHandlerConfig) GetTag() string {
|
||||
if m != nil {
|
||||
@ -322,7 +283,7 @@ func (m *OutboundHandlerConfig) GetTag() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *OutboundHandlerConfig) GetSenderSettings() []*v2ray_core_common_serial.TypedMessage {
|
||||
func (m *OutboundHandlerConfig) GetSenderSettings() *v2ray_core_common_serial.TypedMessage {
|
||||
if m != nil {
|
||||
return m.SenderSettings
|
||||
}
|
||||
@ -336,17 +297,29 @@ func (m *OutboundHandlerConfig) GetProxySettings() *v2ray_core_common_serial.Typ
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *OutboundHandlerConfig) GetExpire() int64 {
|
||||
if m != nil {
|
||||
return m.Expire
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *OutboundHandlerConfig) GetComment() string {
|
||||
if m != nil {
|
||||
return m.Comment
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*InboundConfig)(nil), "v2ray.core.app.proxyman.InboundConfig")
|
||||
proto.RegisterType((*AllocationStrategy)(nil), "v2ray.core.app.proxyman.AllocationStrategy")
|
||||
proto.RegisterType((*AllocationStrategy_AllocationStrategyConcurrency)(nil), "v2ray.core.app.proxyman.AllocationStrategy.AllocationStrategyConcurrency")
|
||||
proto.RegisterType((*AllocationStrategy_AllocationStrategyRefresh)(nil), "v2ray.core.app.proxyman.AllocationStrategy.AllocationStrategyRefresh")
|
||||
proto.RegisterType((*StreamReceiverConfig)(nil), "v2ray.core.app.proxyman.StreamReceiverConfig")
|
||||
proto.RegisterType((*DatagramReceiverConfig)(nil), "v2ray.core.app.proxyman.DatagramReceiverConfig")
|
||||
proto.RegisterType((*ReceiverConfig)(nil), "v2ray.core.app.proxyman.ReceiverConfig")
|
||||
proto.RegisterType((*InboundHandlerConfig)(nil), "v2ray.core.app.proxyman.InboundHandlerConfig")
|
||||
proto.RegisterType((*OutboundConfig)(nil), "v2ray.core.app.proxyman.OutboundConfig")
|
||||
proto.RegisterType((*StreamSenderConfig)(nil), "v2ray.core.app.proxyman.StreamSenderConfig")
|
||||
proto.RegisterType((*DatagramSenderConfig)(nil), "v2ray.core.app.proxyman.DatagramSenderConfig")
|
||||
proto.RegisterType((*SenderConfig)(nil), "v2ray.core.app.proxyman.SenderConfig")
|
||||
proto.RegisterType((*OutboundHandlerConfig)(nil), "v2ray.core.app.proxyman.OutboundHandlerConfig")
|
||||
proto.RegisterEnum("v2ray.core.app.proxyman.AllocationStrategy_Type", AllocationStrategy_Type_name, AllocationStrategy_Type_value)
|
||||
}
|
||||
@ -354,48 +327,52 @@ func init() {
|
||||
func init() { proto.RegisterFile("v2ray.com/core/app/proxyman/config.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 683 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe4, 0x55, 0xdd, 0x6e, 0xd3, 0x30,
|
||||
0x18, 0x25, 0xe9, 0x18, 0xdb, 0x57, 0xd6, 0x15, 0x53, 0x58, 0x29, 0x42, 0x2a, 0x15, 0x82, 0x0a,
|
||||
0x50, 0x32, 0x3a, 0x71, 0xc1, 0x15, 0xda, 0x9f, 0xc4, 0x2e, 0xc6, 0x8a, 0x3b, 0x71, 0x81, 0x90,
|
||||
0x2a, 0x2f, 0xf1, 0x42, 0x44, 0x62, 0x47, 0xb6, 0x5b, 0x96, 0x97, 0xe1, 0x01, 0x78, 0x0a, 0xae,
|
||||
0x90, 0x90, 0x78, 0x9a, 0x3d, 0x01, 0x72, 0x9c, 0x74, 0xd5, 0xda, 0xb2, 0x8d, 0x8a, 0x2b, 0xee,
|
||||
0x5c, 0xf7, 0x3b, 0xc7, 0x3e, 0xe7, 0x7c, 0xfe, 0x02, 0xed, 0x61, 0x47, 0x90, 0xd4, 0xf1, 0x78,
|
||||
0xec, 0x7a, 0x5c, 0x50, 0x97, 0x24, 0x89, 0x9b, 0x08, 0x7e, 0x92, 0xc6, 0x84, 0xb9, 0x1e, 0x67,
|
||||
0xc7, 0x61, 0xe0, 0x24, 0x82, 0x2b, 0x8e, 0xd6, 0x8a, 0x4a, 0x41, 0x1d, 0x92, 0x24, 0x4e, 0x51,
|
||||
0xd5, 0x58, 0x3f, 0x47, 0xe1, 0xf1, 0x38, 0xe6, 0xcc, 0x95, 0x54, 0x84, 0x24, 0x72, 0x55, 0x9a,
|
||||
0x50, 0xbf, 0x1f, 0x53, 0x29, 0x49, 0x40, 0x0d, 0x55, 0xe3, 0xc9, 0x74, 0x04, 0xa3, 0xca, 0x25,
|
||||
0xbe, 0x2f, 0xa8, 0x94, 0x79, 0xe1, 0xa3, 0xd9, 0x85, 0x09, 0x17, 0x2a, 0xaf, 0x72, 0xce, 0x55,
|
||||
0x29, 0x41, 0x98, 0xd4, 0xff, 0xbb, 0x21, 0x53, 0x54, 0xe8, 0xea, 0x71, 0x25, 0xad, 0x55, 0x58,
|
||||
0xd9, 0x63, 0x47, 0x7c, 0xc0, 0xfc, 0xed, 0x6c, 0xbb, 0xf5, 0xbd, 0x04, 0x68, 0x33, 0x8a, 0xb8,
|
||||
0x47, 0x54, 0xc8, 0x59, 0x4f, 0x09, 0xa2, 0x68, 0x90, 0xa2, 0x1d, 0x58, 0xd0, 0xb7, 0xaf, 0x5b,
|
||||
0x4d, 0xab, 0x5d, 0xe9, 0xac, 0x3b, 0x33, 0x0c, 0x70, 0x26, 0xa1, 0xce, 0x61, 0x9a, 0x50, 0x9c,
|
||||
0xa1, 0xd1, 0x67, 0x28, 0x7b, 0x9c, 0x79, 0x03, 0x21, 0x28, 0xf3, 0xd2, 0xba, 0xdd, 0xb4, 0xda,
|
||||
0xe5, 0xce, 0xde, 0x55, 0xc8, 0x26, 0xb7, 0xb6, 0xcf, 0x08, 0xf1, 0x38, 0x3b, 0xea, 0xc3, 0x0d,
|
||||
0x41, 0x8f, 0x05, 0x95, 0x9f, 0xea, 0xa5, 0xec, 0xa0, 0xdd, 0xf9, 0x0e, 0xc2, 0x86, 0x0c, 0x17,
|
||||
0xac, 0x8d, 0x97, 0xf0, 0xe0, 0x8f, 0xd7, 0x41, 0x35, 0xb8, 0x3e, 0x24, 0xd1, 0xc0, 0xb8, 0xb6,
|
||||
0x82, 0xcd, 0x8f, 0xc6, 0x0b, 0xb8, 0x37, 0x93, 0x7c, 0x3a, 0xa4, 0xf5, 0x1c, 0x16, 0xb4, 0x8b,
|
||||
0x08, 0x60, 0x71, 0x33, 0xfa, 0x42, 0x52, 0x59, 0xbd, 0xa6, 0xd7, 0x98, 0x30, 0x9f, 0xc7, 0x55,
|
||||
0x0b, 0xdd, 0x84, 0xa5, 0xdd, 0x13, 0x1d, 0x2f, 0x89, 0xaa, 0x76, 0xeb, 0x87, 0x0d, 0xb5, 0x9e,
|
||||
0x12, 0x94, 0xc4, 0x98, 0x7a, 0x34, 0x1c, 0x52, 0x61, 0xb2, 0x45, 0xaf, 0x01, 0x74, 0x2b, 0xf4,
|
||||
0x05, 0x61, 0x81, 0x39, 0xa1, 0xdc, 0x69, 0x8e, 0x9b, 0x62, 0x7a, 0xca, 0x61, 0x54, 0x39, 0x5d,
|
||||
0x2e, 0x14, 0xd6, 0x75, 0x78, 0x39, 0x29, 0x96, 0xe8, 0x15, 0x2c, 0x46, 0xa1, 0x54, 0x94, 0xe5,
|
||||
0xd1, 0x3d, 0x9c, 0x01, 0xde, 0xeb, 0x1e, 0x88, 0x1d, 0x1e, 0x93, 0x90, 0xe1, 0x1c, 0x80, 0x3e,
|
||||
0xc2, 0x6d, 0x32, 0x52, 0xdd, 0x97, 0xb9, 0xec, 0x3c, 0x99, 0x67, 0x57, 0x48, 0x06, 0x23, 0x32,
|
||||
0xd9, 0x9e, 0x87, 0xb0, 0x2a, 0x33, 0xc5, 0x7d, 0x49, 0x95, 0x0a, 0x59, 0x20, 0xeb, 0x0b, 0x93,
|
||||
0xcc, 0xa3, 0xc7, 0xe0, 0x14, 0x8f, 0xc1, 0x31, 0x3e, 0x19, 0x7f, 0x70, 0xc5, 0x70, 0xf4, 0x72,
|
||||
0x8a, 0xd6, 0xa9, 0x05, 0x77, 0x77, 0x88, 0x22, 0x81, 0xf8, 0x7f, 0xac, 0x6c, 0xfd, 0xb2, 0xa0,
|
||||
0x96, 0x8f, 0x84, 0x37, 0x84, 0xf9, 0xd1, 0x48, 0x72, 0x15, 0x4a, 0x8a, 0x04, 0x99, 0xd6, 0x65,
|
||||
0xac, 0x97, 0xa8, 0x07, 0xb7, 0x44, 0x6e, 0xcb, 0x99, 0xef, 0x76, 0xb3, 0xd4, 0x2e, 0x77, 0x1e,
|
||||
0x4f, 0x91, 0x63, 0xa6, 0x60, 0x36, 0x0f, 0xfc, 0x7d, 0x33, 0x04, 0x71, 0xb5, 0x20, 0x28, 0x4c,
|
||||
0x47, 0xfb, 0x50, 0xc9, 0xae, 0x7c, 0xc6, 0x68, 0x84, 0x5d, 0x96, 0x71, 0x25, 0x43, 0x8f, 0x32,
|
||||
0xac, 0x42, 0xe5, 0x60, 0xa0, 0xc6, 0x27, 0xdc, 0xa9, 0x05, 0xa8, 0x97, 0x07, 0xcd, 0xfc, 0x91,
|
||||
0xbc, 0x0d, 0x28, 0x0d, 0x43, 0x92, 0x47, 0x79, 0x89, 0x34, 0x74, 0xf5, 0xb4, 0xbe, 0xb3, 0xe7,
|
||||
0xee, 0x3b, 0xf4, 0x6e, 0x86, 0x05, 0x4f, 0x2f, 0x20, 0xed, 0x6a, 0x50, 0xce, 0x79, 0xce, 0x86,
|
||||
0xaf, 0x16, 0xd4, 0x8a, 0x56, 0x9e, 0x5f, 0xf6, 0xe4, 0x05, 0xed, 0x79, 0x2f, 0xf8, 0xd3, 0x82,
|
||||
0x3b, 0x45, 0x50, 0x17, 0xf5, 0xdd, 0x01, 0xac, 0xca, 0x4c, 0xc3, 0xdf, 0x76, 0x5d, 0xc5, 0xc0,
|
||||
0xff, 0x51, 0xcf, 0x6d, 0xbd, 0x85, 0xfb, 0x1e, 0x8f, 0x67, 0x3d, 0xc4, 0xad, 0xb2, 0x11, 0xd6,
|
||||
0xd5, 0x1f, 0xe0, 0x0f, 0x4b, 0xc5, 0xf6, 0x37, 0x7b, 0xed, 0x7d, 0x07, 0x93, 0xd4, 0xd9, 0xd6,
|
||||
0x80, 0xcd, 0x24, 0x31, 0x6e, 0xc5, 0x84, 0x1d, 0x2d, 0x66, 0xdf, 0xea, 0x8d, 0xdf, 0x01, 0x00,
|
||||
0x00, 0xff, 0xff, 0x18, 0xce, 0x1c, 0x24, 0xa1, 0x08, 0x00, 0x00,
|
||||
// 737 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x55, 0xd1, 0x6e, 0xdb, 0x36,
|
||||
0x14, 0x9d, 0xec, 0xc4, 0x49, 0xae, 0x13, 0xc7, 0xe3, 0xb2, 0xc4, 0xf3, 0x36, 0xc0, 0x33, 0x86,
|
||||
0xcd, 0xd8, 0x06, 0x29, 0x73, 0x30, 0x60, 0x7b, 0xda, 0x12, 0x27, 0xc0, 0xf2, 0x90, 0xd9, 0xa3,
|
||||
0x83, 0x3e, 0x14, 0x05, 0x04, 0x46, 0x62, 0x5c, 0xa1, 0x12, 0x29, 0x90, 0xb4, 0x13, 0xfd, 0x52,
|
||||
0xbf, 0xa1, 0x0f, 0xfd, 0x80, 0x7e, 0x4a, 0xff, 0xa0, 0x2f, 0x05, 0x49, 0xc9, 0x36, 0x62, 0xbb,
|
||||
0x69, 0x1a, 0xf4, 0x4d, 0x24, 0xcf, 0x39, 0xe4, 0x3d, 0x87, 0x97, 0x82, 0xce, 0xa4, 0x2b, 0x48,
|
||||
0xe6, 0x06, 0x3c, 0xf1, 0x02, 0x2e, 0xa8, 0x47, 0xd2, 0xd4, 0x4b, 0x05, 0xbf, 0xcd, 0x12, 0xc2,
|
||||
0xbc, 0x80, 0xb3, 0xeb, 0x68, 0xe4, 0xa6, 0x82, 0x2b, 0x8e, 0x0e, 0x0a, 0xa4, 0xa0, 0x2e, 0x49,
|
||||
0x53, 0xb7, 0x40, 0x35, 0x0f, 0xef, 0x48, 0x04, 0x3c, 0x49, 0x38, 0xf3, 0x24, 0x15, 0x11, 0x89,
|
||||
0x3d, 0x95, 0xa5, 0x34, 0xf4, 0x13, 0x2a, 0x25, 0x19, 0x51, 0x2b, 0xd5, 0xfc, 0x79, 0x39, 0x83,
|
||||
0x51, 0xe5, 0x91, 0x30, 0x14, 0x54, 0xca, 0x1c, 0xf8, 0xe3, 0x6a, 0x60, 0xca, 0x85, 0xca, 0x51,
|
||||
0xee, 0x1d, 0x94, 0x12, 0x84, 0x49, 0xbd, 0xee, 0x45, 0x4c, 0x51, 0xa1, 0xd1, 0xf3, 0x95, 0xb4,
|
||||
0x77, 0x61, 0xe7, 0x9c, 0x5d, 0xf1, 0x31, 0x0b, 0x7b, 0x66, 0xba, 0xfd, 0xba, 0x0c, 0xe8, 0x38,
|
||||
0x8e, 0x79, 0x40, 0x54, 0xc4, 0xd9, 0x50, 0x09, 0xa2, 0xe8, 0x28, 0x43, 0xa7, 0xb0, 0xa6, 0x4f,
|
||||
0xdf, 0x70, 0x5a, 0x4e, 0xa7, 0xd6, 0x3d, 0x74, 0x57, 0x18, 0xe0, 0x2e, 0x52, 0xdd, 0xcb, 0x2c,
|
||||
0xa5, 0xd8, 0xb0, 0xd1, 0x0b, 0xa8, 0x06, 0x9c, 0x05, 0x63, 0x21, 0x28, 0x0b, 0xb2, 0x46, 0xa9,
|
||||
0xe5, 0x74, 0xaa, 0xdd, 0xf3, 0x87, 0x88, 0x2d, 0x4e, 0xf5, 0x66, 0x82, 0x78, 0x5e, 0x1d, 0xf9,
|
||||
0xb0, 0x21, 0xe8, 0xb5, 0xa0, 0xf2, 0x79, 0xa3, 0x6c, 0x36, 0x3a, 0x7b, 0xdc, 0x46, 0xd8, 0x8a,
|
||||
0xe1, 0x42, 0xb5, 0xf9, 0x07, 0x7c, 0xff, 0xc1, 0xe3, 0xa0, 0x3d, 0x58, 0x9f, 0x90, 0x78, 0x6c,
|
||||
0x5d, 0xdb, 0xc1, 0x76, 0xd0, 0xfc, 0x1d, 0xbe, 0x59, 0x29, 0xbe, 0x9c, 0xd2, 0xfe, 0x0d, 0xd6,
|
||||
0xb4, 0x8b, 0x08, 0xa0, 0x72, 0x1c, 0xdf, 0x90, 0x4c, 0xd6, 0xbf, 0xd0, 0xdf, 0x98, 0xb0, 0x90,
|
||||
0x27, 0x75, 0x07, 0x6d, 0xc3, 0xe6, 0xd9, 0xad, 0x8e, 0x97, 0xc4, 0xf5, 0x52, 0xfb, 0x55, 0x19,
|
||||
0x6a, 0x98, 0x06, 0x34, 0x9a, 0x50, 0x61, 0x53, 0x45, 0x7f, 0x03, 0xe8, 0x4b, 0xe0, 0x0b, 0xc2,
|
||||
0x46, 0x56, 0xbb, 0xda, 0x6d, 0xcd, 0xdb, 0x61, 0x6f, 0x93, 0xcb, 0xa8, 0x72, 0x07, 0x5c, 0x28,
|
||||
0xac, 0x71, 0x78, 0x2b, 0x2d, 0x3e, 0xd1, 0x5f, 0x50, 0x89, 0x23, 0xa9, 0x28, 0xcb, 0x43, 0xfb,
|
||||
0x61, 0x05, 0xf9, 0x7c, 0xd0, 0x17, 0xa7, 0x3c, 0x21, 0x11, 0xc3, 0x39, 0x01, 0x3d, 0x83, 0xaf,
|
||||
0xc8, 0xb4, 0x5e, 0x5f, 0xe6, 0x05, 0xe7, 0x99, 0xfc, 0xfa, 0x80, 0x4c, 0x30, 0x22, 0x8b, 0x17,
|
||||
0xf3, 0x12, 0x76, 0xa5, 0x12, 0x94, 0x24, 0xbe, 0xa4, 0x4a, 0x45, 0x6c, 0x24, 0x1b, 0x6b, 0x8b,
|
||||
0xca, 0xd3, 0x36, 0x70, 0x8b, 0x36, 0x70, 0x87, 0x86, 0x65, 0xfd, 0xc1, 0x35, 0xab, 0x31, 0xcc,
|
||||
0x25, 0xd0, 0x3f, 0xf0, 0x9d, 0xb0, 0x0e, 0xfa, 0x5c, 0x44, 0xa3, 0x88, 0x91, 0xd8, 0x0f, 0xa9,
|
||||
0x54, 0x11, 0x33, 0xbb, 0x37, 0xd6, 0x5b, 0x4e, 0x67, 0x13, 0x37, 0x73, 0x4c, 0x3f, 0x87, 0x9c,
|
||||
0xce, 0x10, 0xe8, 0x4f, 0x68, 0xe8, 0xd3, 0xde, 0xf8, 0x29, 0x91, 0x52, 0xeb, 0x04, 0x9c, 0x31,
|
||||
0x1a, 0x18, 0x76, 0xc5, 0xb0, 0xf7, 0xcd, 0xfa, 0xc0, 0x2e, 0xf7, 0xa6, 0xab, 0xed, 0x37, 0x0e,
|
||||
0xec, 0xe5, 0x3d, 0xf9, 0x2f, 0x61, 0x61, 0x3c, 0x0d, 0xb1, 0x0e, 0x65, 0x45, 0x46, 0x26, 0xbd,
|
||||
0x2d, 0xac, 0x3f, 0xd1, 0x10, 0xbe, 0xcc, 0x8f, 0x20, 0x66, 0xe5, 0xdb, 0x80, 0x7e, 0x5a, 0x12,
|
||||
0x90, 0x7d, 0x86, 0x4c, 0x43, 0x86, 0x17, 0xf6, 0x15, 0xc2, 0xf5, 0x42, 0x60, 0x5a, 0xfb, 0x05,
|
||||
0xd4, 0x4c, 0x08, 0x33, 0xc5, 0xf2, 0x83, 0x14, 0x77, 0x0c, 0xbb, 0x90, 0x6b, 0xd7, 0xa1, 0xd6,
|
||||
0x1f, 0xab, 0xf9, 0x27, 0xe6, 0xad, 0x03, 0xdb, 0x43, 0xca, 0xc2, 0x69, 0x61, 0x47, 0x50, 0x9e,
|
||||
0x44, 0x24, 0xbf, 0x96, 0x1f, 0x71, 0xb3, 0x34, 0x7a, 0x59, 0xf0, 0xa5, 0xc7, 0x07, 0xff, 0xff,
|
||||
0x8a, 0xe2, 0x7f, 0xb9, 0x47, 0x74, 0xa0, 0x49, 0xb9, 0xe6, 0x1d, 0x03, 0xde, 0x39, 0xf0, 0x75,
|
||||
0xe1, 0xc0, 0x7d, 0x81, 0xf6, 0x61, 0x57, 0x1a, 0x67, 0x3e, 0x35, 0xce, 0x9a, 0xa5, 0x7f, 0xa6,
|
||||
0x30, 0xd1, 0x3e, 0x54, 0xe8, 0x6d, 0x1a, 0x09, 0x6a, 0x9a, 0xac, 0x8c, 0xf3, 0x11, 0x6a, 0xc0,
|
||||
0x86, 0x16, 0xa1, 0x4c, 0x99, 0xd6, 0xd8, 0xc2, 0xc5, 0xf0, 0xe4, 0x3f, 0xf8, 0x36, 0xe0, 0xc9,
|
||||
0xaa, 0x2e, 0x3f, 0xa9, 0x5a, 0x2b, 0x06, 0xfa, 0x67, 0xf4, 0x74, 0xb3, 0x98, 0x7e, 0x59, 0x3a,
|
||||
0x78, 0xd2, 0xc5, 0x24, 0x73, 0x7b, 0x9a, 0x70, 0x9c, 0xa6, 0xd6, 0xdf, 0x84, 0xb0, 0xab, 0x8a,
|
||||
0xf9, 0x6f, 0x1d, 0xbd, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x26, 0xa3, 0xe8, 0x2c, 0xad, 0x07, 0x00,
|
||||
0x00,
|
||||
}
|
||||
|
@ -46,22 +46,18 @@ message AllocationStrategy {
|
||||
AllocationStrategyRefresh refresh = 3;
|
||||
}
|
||||
|
||||
message StreamReceiverConfig {
|
||||
message ReceiverConfig {
|
||||
v2ray.core.common.net.PortRange port_range = 1;
|
||||
v2ray.core.common.net.IPOrDomain listen = 2;
|
||||
AllocationStrategy allocation_strategy = 3;
|
||||
v2ray.core.transport.internet.StreamConfig stream_settings = 4;
|
||||
}
|
||||
|
||||
message DatagramReceiverConfig {
|
||||
v2ray.core.common.net.PortRange port_range = 1;
|
||||
v2ray.core.common.net.IPOrDomain listen = 2;
|
||||
AllocationStrategy allocation_strategy = 3;
|
||||
bool receive_original_destination = 5;
|
||||
bool allow_passive_connection = 6;
|
||||
}
|
||||
|
||||
message InboundHandlerConfig {
|
||||
string tag = 1;
|
||||
repeated v2ray.core.common.serial.TypedMessage receiver_settings = 2;
|
||||
v2ray.core.common.serial.TypedMessage receiver_settings = 2;
|
||||
v2ray.core.common.serial.TypedMessage proxy_settings = 3;
|
||||
}
|
||||
|
||||
@ -69,21 +65,17 @@ message OutboundConfig {
|
||||
|
||||
}
|
||||
|
||||
message StreamSenderConfig {
|
||||
message SenderConfig {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
v2ray.core.common.net.IPOrDomain via = 1;
|
||||
v2ray.core.transport.internet.StreamConfig stream_settings = 2;
|
||||
v2ray.core.transport.internet.ProxyConfig proxy_settings = 3;
|
||||
}
|
||||
|
||||
message DatagramSenderConfig {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
v2ray.core.common.net.IPOrDomain via = 1;
|
||||
v2ray.core.transport.internet.ProxyConfig proxy_settings = 2;
|
||||
}
|
||||
|
||||
message OutboundHandlerConfig {
|
||||
string tag = 1;
|
||||
repeated v2ray.core.common.serial.TypedMessage sender_settings = 2;
|
||||
v2ray.core.common.serial.TypedMessage sender_settings = 2;
|
||||
v2ray.core.common.serial.TypedMessage proxy_settings = 3;
|
||||
int64 expire = 4;
|
||||
string comment = 5;
|
||||
}
|
||||
|
78
app/proxyman/inbound/always.go
Normal file
78
app/proxyman/inbound/always.go
Normal file
@ -0,0 +1,78 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/log"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
type AlwaysOnInboundHandler struct {
|
||||
proxy proxy.InboundHandler
|
||||
workers []worker
|
||||
}
|
||||
|
||||
func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.ReceiverConfig, proxyConfig interface{}) (*AlwaysOnInboundHandler, error) {
|
||||
p, err := proxy.CreateInboundHandler(ctx, proxyConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
h := &AlwaysOnInboundHandler{
|
||||
proxy: p,
|
||||
}
|
||||
|
||||
nl := p.Network()
|
||||
pr := receiverConfig.PortRange
|
||||
for port := pr.From; port <= pr.To; port++ {
|
||||
if nl.HasNetwork(net.Network_TCP) {
|
||||
log.Debug("Proxyman|DefaultInboundHandler: creating tcp worker on ", receiverConfig.Listen.AsAddress(), ":", port)
|
||||
worker := &tcpWorker{
|
||||
address: receiverConfig.Listen.AsAddress(),
|
||||
port: net.Port(port),
|
||||
proxy: p,
|
||||
stream: receiverConfig.StreamSettings,
|
||||
recvOrigDest: receiverConfig.ReceiveOriginalDestination,
|
||||
tag: tag,
|
||||
allowPassiveConn: receiverConfig.AllowPassiveConnection,
|
||||
}
|
||||
h.workers = append(h.workers, worker)
|
||||
}
|
||||
|
||||
if nl.HasNetwork(net.Network_UDP) {
|
||||
worker := &udpWorker{
|
||||
tag: tag,
|
||||
proxy: p,
|
||||
address: receiverConfig.Listen.AsAddress(),
|
||||
port: net.Port(port),
|
||||
recvOrigDest: receiverConfig.ReceiveOriginalDestination,
|
||||
}
|
||||
h.workers = append(h.workers, worker)
|
||||
}
|
||||
}
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *AlwaysOnInboundHandler) Start() error {
|
||||
for _, worker := range h.workers {
|
||||
if err := worker.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *AlwaysOnInboundHandler) Close() {
|
||||
for _, worker := range h.workers {
|
||||
worker.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *AlwaysOnInboundHandler) GetRandomInboundProxy() (proxy.InboundHandler, net.Port, int) {
|
||||
w := h.workers[dice.Roll(len(h.workers))]
|
||||
return w.Proxy(), w.Port(), 9999
|
||||
}
|
143
app/proxyman/inbound/dynamic.go
Normal file
143
app/proxyman/inbound/dynamic.go
Normal file
@ -0,0 +1,143 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/log"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
type DynamicInboundHandler struct {
|
||||
sync.Mutex
|
||||
tag string
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
proxyConfig interface{}
|
||||
receiverConfig *proxyman.ReceiverConfig
|
||||
portsInUse map[v2net.Port]bool
|
||||
worker []worker
|
||||
worker2Recycle []worker
|
||||
lastRefresh time.Time
|
||||
}
|
||||
|
||||
func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.ReceiverConfig, proxyConfig interface{}) (*DynamicInboundHandler, error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
h := &DynamicInboundHandler{
|
||||
ctx: ctx,
|
||||
tag: tag,
|
||||
cancel: cancel,
|
||||
proxyConfig: proxyConfig,
|
||||
receiverConfig: receiverConfig,
|
||||
portsInUse: make(map[v2net.Port]bool),
|
||||
}
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) allocatePort() v2net.Port {
|
||||
from := int(h.receiverConfig.PortRange.From)
|
||||
delta := int(h.receiverConfig.PortRange.To) - from + 1
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
|
||||
for {
|
||||
r := dice.Roll(delta)
|
||||
port := v2net.Port(from + r)
|
||||
_, used := h.portsInUse[port]
|
||||
if !used {
|
||||
h.portsInUse[port] = true
|
||||
return port
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) refresh() error {
|
||||
h.lastRefresh = time.Now()
|
||||
|
||||
ports2Del := make([]v2net.Port, 0, 16)
|
||||
for _, worker := range h.worker2Recycle {
|
||||
worker.Close()
|
||||
ports2Del = append(ports2Del, worker.Port())
|
||||
}
|
||||
|
||||
h.Lock()
|
||||
for _, port := range ports2Del {
|
||||
delete(h.portsInUse, port)
|
||||
}
|
||||
h.Unlock()
|
||||
|
||||
h.worker2Recycle, h.worker = h.worker, h.worker2Recycle[:0]
|
||||
|
||||
for i := uint32(0); i < h.receiverConfig.AllocationStrategy.GetConcurrencyValue(); i++ {
|
||||
port := h.allocatePort()
|
||||
p, err := proxy.CreateInboundHandler(h.ctx, h.proxyConfig)
|
||||
if err != nil {
|
||||
log.Warning("Proxyman|DefaultInboundHandler: Failed to create proxy instance: ", err)
|
||||
continue
|
||||
}
|
||||
nl := p.Network()
|
||||
if nl.HasNetwork(v2net.Network_TCP) {
|
||||
worker := &tcpWorker{
|
||||
tag: h.tag,
|
||||
address: h.receiverConfig.Listen.AsAddress(),
|
||||
port: port,
|
||||
proxy: p,
|
||||
stream: h.receiverConfig.StreamSettings,
|
||||
recvOrigDest: h.receiverConfig.ReceiveOriginalDestination,
|
||||
allowPassiveConn: h.receiverConfig.AllowPassiveConnection,
|
||||
}
|
||||
if err := worker.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
h.worker = append(h.worker, worker)
|
||||
}
|
||||
|
||||
if nl.HasNetwork(v2net.Network_UDP) {
|
||||
worker := &udpWorker{
|
||||
tag: h.tag,
|
||||
proxy: p,
|
||||
address: h.receiverConfig.Listen.AsAddress(),
|
||||
port: port,
|
||||
recvOrigDest: h.receiverConfig.ReceiveOriginalDestination,
|
||||
}
|
||||
if err := worker.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
h.worker = append(h.worker, worker)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) monitor() {
|
||||
for {
|
||||
select {
|
||||
case <-h.ctx.Done():
|
||||
return
|
||||
case <-time.After(time.Minute * time.Duration(h.receiverConfig.AllocationStrategy.GetRefreshValue())):
|
||||
h.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) Start() error {
|
||||
err := h.refresh()
|
||||
go h.monitor()
|
||||
return err
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) Close() {
|
||||
h.cancel()
|
||||
}
|
||||
|
||||
func (h *DynamicInboundHandler) GetRandomInboundProxy() (proxy.InboundHandler, v2net.Port, int) {
|
||||
w := h.worker[dice.Roll(len(h.worker))]
|
||||
expire := h.receiverConfig.AllocationStrategy.GetRefreshValue() - uint32(time.Since(h.lastRefresh)/time.Minute)
|
||||
return w.Proxy(), w.Port(), int(expire)
|
||||
}
|
94
app/proxyman/inbound/inbound.go
Normal file
94
app/proxyman/inbound/inbound.go
Normal file
@ -0,0 +1,94 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/errors"
|
||||
)
|
||||
|
||||
type DefaultInboundHandlerManager struct {
|
||||
handlers []proxyman.InboundHandler
|
||||
taggedHandlers map[string]proxyman.InboundHandler
|
||||
}
|
||||
|
||||
func New(ctx context.Context, config *proxyman.InboundConfig) (*DefaultInboundHandlerManager, error) {
|
||||
return &DefaultInboundHandlerManager{
|
||||
taggedHandlers: make(map[string]proxyman.InboundHandler),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *proxyman.InboundHandlerConfig) error {
|
||||
rawReceiverSettings, err := config.ReceiverSettings.GetInstance()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
receiverSettings, ok := rawReceiverSettings.(*proxyman.ReceiverConfig)
|
||||
if !ok {
|
||||
return errors.New("Proxyman|DefaultInboundHandlerManager: Not a ReceiverConfig.")
|
||||
}
|
||||
proxySettings, err := config.ProxySettings.GetInstance()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var handler proxyman.InboundHandler
|
||||
tag := config.Tag
|
||||
allocStrategy := receiverSettings.AllocationStrategy
|
||||
if allocStrategy == nil || allocStrategy.Type == proxyman.AllocationStrategy_Always {
|
||||
h, err := NewAlwaysOnInboundHandler(ctx, tag, receiverSettings, proxySettings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler = h
|
||||
} else if allocStrategy.Type == proxyman.AllocationStrategy_Random {
|
||||
h, err := NewDynamicInboundHandler(ctx, tag, receiverSettings, proxySettings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler = h
|
||||
}
|
||||
|
||||
if handler == nil {
|
||||
return errors.New("Proxyman|DefaultInboundHandlerManager: Unknown allocation strategy: ", receiverSettings.AllocationStrategy.Type)
|
||||
}
|
||||
|
||||
m.handlers = append(m.handlers, handler)
|
||||
if len(tag) > 0 {
|
||||
m.taggedHandlers[tag] = handler
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) GetHandler(ctx context.Context, tag string) (proxyman.InboundHandler, error) {
|
||||
handler, found := m.taggedHandlers[tag]
|
||||
if !found {
|
||||
return nil, errors.New("Proxymand|DefaultInboundHandlerManager: Handler not found: ", tag)
|
||||
}
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Start() error {
|
||||
for _, handler := range m.handlers {
|
||||
if err := handler.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Close() {
|
||||
for _, handler := range m.handlers {
|
||||
handler.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Interface() interface{} {
|
||||
return (*proxyman.InboundHandlerManager)(nil)
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*proxyman.InboundConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
return New(ctx, config.(*proxyman.InboundConfig))
|
||||
}))
|
||||
}
|
269
app/proxyman/inbound/worker.go
Normal file
269
app/proxyman/inbound/worker.go
Normal file
@ -0,0 +1,269 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/log"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tcp"
|
||||
"v2ray.com/core/transport/internet/udp"
|
||||
)
|
||||
|
||||
type worker interface {
|
||||
Start() error
|
||||
Close()
|
||||
Port() v2net.Port
|
||||
Proxy() proxy.InboundHandler
|
||||
}
|
||||
|
||||
type tcpWorker struct {
|
||||
address v2net.Address
|
||||
port v2net.Port
|
||||
proxy proxy.InboundHandler
|
||||
stream *internet.StreamConfig
|
||||
recvOrigDest bool
|
||||
tag string
|
||||
allowPassiveConn bool
|
||||
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
hub *internet.TCPHub
|
||||
}
|
||||
|
||||
func (w *tcpWorker) callback(conn internet.Connection) {
|
||||
ctx, cancel := context.WithCancel(w.ctx)
|
||||
if w.recvOrigDest {
|
||||
dest := tcp.GetOriginalDestination(conn)
|
||||
if dest.IsValid() {
|
||||
ctx = proxy.ContextWithOriginalDestination(ctx, dest)
|
||||
}
|
||||
}
|
||||
if len(w.tag) > 0 {
|
||||
ctx = proxy.ContextWithInboundTag(ctx, w.tag)
|
||||
}
|
||||
ctx = proxy.ContextWithAllowPassiveConnection(ctx, w.allowPassiveConn)
|
||||
ctx = proxy.ContextWithInboundDestination(ctx, v2net.TCPDestination(w.address, w.port))
|
||||
w.proxy.Process(ctx, v2net.Network_TCP, conn)
|
||||
cancel()
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
func (w *tcpWorker) Proxy() proxy.InboundHandler {
|
||||
return w.proxy
|
||||
}
|
||||
|
||||
func (w *tcpWorker) Start() error {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
w.ctx = ctx
|
||||
w.cancel = cancel
|
||||
hub, err := internet.ListenTCP(w.address, w.port, w.callback, w.stream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.hub = hub
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *tcpWorker) Close() {
|
||||
log.Debug("Proxyman|TCPWorker: Closed. ", w.port)
|
||||
w.hub.Close()
|
||||
w.cancel()
|
||||
}
|
||||
|
||||
func (w *tcpWorker) Port() v2net.Port {
|
||||
return w.port
|
||||
}
|
||||
|
||||
type udpConn struct {
|
||||
cancel context.CancelFunc
|
||||
lastActivityTime int64 // in seconds
|
||||
input chan []byte
|
||||
output func([]byte) (int, error)
|
||||
closer func() error
|
||||
remote net.Addr
|
||||
local net.Addr
|
||||
}
|
||||
|
||||
func (c *udpConn) updateActivity() {
|
||||
atomic.StoreInt64(&c.lastActivityTime, time.Now().Unix())
|
||||
}
|
||||
|
||||
func (c *udpConn) Read(buf []byte) (int, error) {
|
||||
in, open := <-c.input
|
||||
if !open {
|
||||
return 0, io.EOF
|
||||
}
|
||||
c.updateActivity()
|
||||
return copy(buf, in), nil
|
||||
}
|
||||
|
||||
func (c *udpConn) Write(buf []byte) (int, error) {
|
||||
n, err := c.output(buf)
|
||||
if err == nil {
|
||||
c.updateActivity()
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (c *udpConn) Close() error {
|
||||
close(c.input)
|
||||
c.cancel()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *udpConn) RemoteAddr() net.Addr {
|
||||
return c.remote
|
||||
}
|
||||
|
||||
func (c *udpConn) LocalAddr() net.Addr {
|
||||
return c.remote
|
||||
}
|
||||
|
||||
func (*udpConn) SetDeadline(time.Time) error {
|
||||