support using specific address

This commit is contained in:
v2ray committed 2016-06-04 00:38:22 +02:00
1 parent 6c31ff91e6
commit a4d76dc394
48 files changed
+412 -301

No files matched your search

+6 -4
View File
@@ -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
})
}
+3 -3
View File
@@ -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()