1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-27 04:25:44 -05:00

Merged latest master

This commit is contained in:
Shelikhoo
2016-06-12 12:58:20 +08:00
17 changed files with 115 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ package blackhole
import (
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/common/loader"
"github.com/v2ray/v2ray-core/proxy/internal"
@@ -15,7 +16,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JSONConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("Blackhole: Failed to parse config: " + err.Error())
}
this.Response = new(NoneResponse)
@@ -25,7 +26,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
loader.RegisterCreator("http", func() interface{} { return new(HTTPResponse) })
response, err := loader.Load(jsonConfig.Response)
if err != nil {
return err
return errors.New("Blackhole: Failed to parse response config: " + err.Error())
}
this.Response = response.(Response)
}

View File

@@ -5,8 +5,9 @@ import (
)
type Config struct {
Address v2net.Address
Port v2net.Port
Network *v2net.NetworkList
Timeout int
FollowRedirect bool
Address v2net.Address
Port v2net.Port
Network *v2net.NetworkList
Timeout int
}

View File

@@ -4,6 +4,7 @@ package dokodemo
import (
"encoding/json"
"errors"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/internal"
@@ -15,15 +16,17 @@ func (this *Config) UnmarshalJSON(data []byte) error {
PortValue v2net.Port `json:"port"`
NetworkList *v2net.NetworkList `json:"network"`
TimeoutValue int `json:"timeout"`
Redirect bool `json:"followRedirect"`
}
rawConfig := new(DokodemoConfig)
if err := json.Unmarshal(data, rawConfig); err != nil {
return err
return errors.New("Dokodemo: Failed to parse config: " + err.Error())
}
this.Address = rawConfig.Host.Address
this.Port = rawConfig.PortValue
this.Network = rawConfig.NetworkList
this.Timeout = rawConfig.TimeoutValue
this.FollowRedirect = rawConfig.Redirect
return nil
}

View File

@@ -129,7 +129,16 @@ func (this *DokodemoDoor) ListenTCP() error {
func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) {
defer conn.Close()
ray := this.packetDispatcher.DispatchToOutbound(v2net.TCPDestination(this.address, this.port))
dest := v2net.TCPDestination(this.address, this.port)
if this.config.FollowRedirect {
originalDest := GetOriginalDestination(conn)
if originalDest != nil {
log.Info("Dokodemo: Following redirect to: ", originalDest)
dest = originalDest
}
}
ray := this.packetDispatcher.DispatchToOutbound(dest)
defer ray.InboundOutput().Release()
var inputFinish, outputFinish sync.Mutex

View File

@@ -0,0 +1,30 @@
// +build linux
package dokodemo
import (
"syscall"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/hub"
)
const SO_ORIGINAL_DST = 80
func GetOriginalDestination(conn *hub.Connection) v2net.Destination {
fd, err := conn.SysFd()
if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err)
return nil
}
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
if err != nil {
log.Info("Dokodemo: Failed to call getsockopt: ", err)
return nil
}
ip := v2net.IPAddress(addr.Multiaddr[4:8])
port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
return v2net.TCPDestination(ip, v2net.Port(port))
}

View File

@@ -0,0 +1,12 @@
// +build !linux
package dokodemo
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/hub"
)
func GetOriginalDestination(conn *hub.Connection) v2net.Destination {
return nil
}

View File

@@ -4,6 +4,7 @@ package freedom
import (
"encoding/json"
"errors"
"strings"
"github.com/v2ray/v2ray-core/proxy/internal"
@@ -16,7 +17,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("Freedom: Failed to parse config: " + err.Error())
}
this.DomainStrategy = DomainStrategyAsIs
domainStrategy := strings.ToLower(jsonConfig.DomainStrategy)

View File

@@ -5,6 +5,7 @@ package http
import (
"crypto/tls"
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/proxy/internal"
)
@@ -18,7 +19,7 @@ func (this *CertificateConfig) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("HTTP: Failed to parse certificate config: " + err.Error())
}
cert, err := tls.LoadX509KeyPair(jsonConfig.CertFile, jsonConfig.KeyFile)
@@ -38,7 +39,7 @@ func (this *TLSConfig) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("HTTP: Failed to parse TLS config: " + err.Error())
}
this.Enabled = jsonConfig.Enabled
@@ -53,7 +54,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("HTTP: Failed to parse config: " + err.Error())
}
this.TLSConfig = jsonConfig.Tls

View File

@@ -4,6 +4,7 @@ package shadowsocks
import (
"encoding/json"
"errors"
"strings"
"github.com/v2ray/v2ray-core/common/log"
@@ -21,7 +22,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("Shadowsocks: Failed to parse config: " + err.Error())
}
this.UDP = jsonConfig.UDP

View File

@@ -4,6 +4,7 @@ package socks
import (
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
@@ -30,7 +31,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
rawConfig := new(SocksConfig)
if err := json.Unmarshal(data, rawConfig); err != nil {
return err
return errors.New("Socks: Failed to parse config: " + err.Error())
}
if rawConfig.AuthMethod == AuthMethodNoAuth {
this.AuthType = AuthTypeNoAuth

View File

@@ -4,6 +4,7 @@ package inbound
import (
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal"
@@ -15,7 +16,7 @@ func (this *DetourConfig) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonDetourConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("VMessIn: Failed to parse detour config: " + err.Error())
}
this.ToTag = jsonConfig.ToTag
return nil
@@ -27,7 +28,7 @@ func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonFeaturesConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("VMessIn: Failed to parse features config: " + err.Error())
}
this.Detour = jsonConfig.Detour
return nil
@@ -40,7 +41,7 @@ func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonDefaultConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("VMessIn: Failed to parse default config: " + err.Error())
}
this.AlterIDs = jsonConfig.AlterIDs
if this.AlterIDs == 0 {
@@ -59,7 +60,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
return errors.New("VMessIn: Failed to parse config: " + err.Error())
}
this.AllowedUsers = jsonConfig.Users
this.Features = jsonConfig.Features // Backward compatibility

View File

@@ -4,6 +4,7 @@ package outbound
import (
"encoding/json"
"errors"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/proxy/internal"
@@ -16,10 +17,10 @@ func (this *Config) UnmarshalJSON(data []byte) error {
rawOutbound := &RawOutbound{}
err := json.Unmarshal(data, rawOutbound)
if err != nil {
return err
return errors.New("VMessOut: Failed to parse config: " + err.Error())
}
if len(rawOutbound.Receivers) == 0 {
log.Error("VMess: 0 VMess receiver configured.")
log.Error("VMessOut: 0 VMess receiver configured.")
return internal.ErrorBadConfiguration
}
this.Receivers = rawOutbound.Receivers