mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-06 00:31:03 +00:00
support using specific address
This commit is contained in:
1 parent
6c31ff91e6
commit
a4d76dc394
48 files changed
+412
-301
No files matched your search
@@ -23,12 +23,14 @@ type FreedomConnection struct {
|
||||
domainStrategy DomainStrategy
|
||||
timeout uint32
|
||||
dns dns.Server
|
||||
sendThrough v2net.Address
|
||||
}
|
||||
|
||||
func NewFreedomConnection(config *Config, space app.Space) *FreedomConnection {
|
||||
func NewFreedomConnection(config *Config, space app.Space, sendThrough v2net.Address) *FreedomConnection {
|
||||
f := &FreedomConnection{
|
||||
domainStrategy: config.DomainStrategy,
|
||||
timeout: config.Timeout,
|
||||
sendThrough: sendThrough,
|
||||
}
|
||||
space.InitializeApplication(func() error {
|
||||
if config.DomainStrategy == DomainStrategyUseIP {
|
||||
@@ -78,7 +80,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
|
||||
destination = this.ResolveIP(destination)
|
||||
}
|
||||
err := retry.Timed(5, 100).On(func() error {
|
||||
rawConn, err := hub.DialWithoutCache(destination)
|
||||
rawConn, err := hub.DialWithoutCache(this.sendThrough, destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,7 +140,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
|
||||
|
||||
func init() {
|
||||
internal.MustRegisterOutboundHandlerCreator("freedom",
|
||||
func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
||||
return NewFreedomConnection(config.(*Config), space), nil
|
||||
func(space app.Space, config interface{}, sendThrough v2net.Address) (proxy.OutboundHandler, error) {
|
||||
return NewFreedomConnection(config.(*Config), space, sendThrough), nil
|
||||
})
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func TestSinglePacket(t *testing.T) {
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
space := app.NewSpace()
|
||||
freedom := NewFreedomConnection(&Config{}, space)
|
||||
freedom := NewFreedomConnection(&Config{}, space, v2net.AnyIP)
|
||||
space.Initialize()
|
||||
|
||||
traffic := ray.NewRay()
|
||||
@@ -57,7 +57,7 @@ func TestSinglePacket(t *testing.T) {
|
||||
func TestUnreachableDestination(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
freedom := NewFreedomConnection(&Config{}, app.NewSpace())
|
||||
freedom := NewFreedomConnection(&Config{}, app.NewSpace(), v2net.AnyIP)
|
||||
traffic := ray.NewRay()
|
||||
data2Send := "Data to be sent to remote"
|
||||
payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
|
||||
@@ -81,7 +81,7 @@ func TestIPResolution(t *testing.T) {
|
||||
})
|
||||
space.BindApp(dns.APP_ID, dnsServer)
|
||||
|
||||
freedom := NewFreedomConnection(&Config{DomainStrategy: DomainStrategyUseIP}, space)
|
||||
freedom := NewFreedomConnection(&Config{DomainStrategy: DomainStrategyUseIP}, space, v2net.AnyIP)
|
||||
|
||||
space.Initialize()
|
||||
|
||||
|
||||
Reference in new issue
Block a user