Compare commits

..

23 Commits

Author SHA1 Message Date
Darien Raymond
67793eb3e0 fix config creator cache 2016-10-03 12:25:36 +02:00
Darien Raymond
fd50e8e12b allow stdin as input source 2016-10-03 11:18:24 +02:00
Darien Raymond
1ee76d31fa Update version 2016-10-03 10:54:27 +02:00
Darien Raymond
1d13f47f9c protobuf for stream settings 2016-10-02 23:43:58 +02:00
Darien Raymond
5ec948f690 integrate tls settings in ws 2016-09-30 16:53:40 +02:00
Darien Raymond
af6abfa3e3 update proto generated code 2016-09-26 15:14:39 +02:00
Darien Raymond
91f2a40dae refine proto package names 2016-09-26 15:14:16 +02:00
Darien Raymond
922e761bef rename server spec user 2016-09-25 22:57:27 +02:00
Darien Raymond
c5f09c64a2 refine socks config 2016-09-25 22:54:18 +02:00
Darien Raymond
c6a7389817 refine cipher settings 2016-09-25 22:19:49 +02:00
Darien Raymond
ce5bc72f0c refine shadowsocks proto 2016-09-25 22:07:32 +02:00
Darien Raymond
5e9017720e check nil 2016-09-24 23:36:26 +02:00
Darien Raymond
24e575f2cd protobuf for vmess 2016-09-24 23:11:58 +02:00
Darien Raymond
60f4292882 protobuf for dokodemo config 2016-09-22 16:49:20 +02:00
Darien Raymond
88ae8248a5 protobuf for network list 2016-09-22 12:14:50 +02:00
Darien Raymond
dc6b7e2e75 protobuf for blackhole config 2016-09-22 12:01:36 +02:00
Darien Raymond
6317768cab use golang 1.7.1 2016-09-21 21:08:22 +02:00
Darien Raymond
b28d718b79 optional field in kcp config 2016-09-21 21:08:05 +02:00
Darien Raymond
1a3f51ade7 protobuf for kcp config 2016-09-21 14:39:07 +02:00
Darien Raymond
8f6a972970 refactor config cache 2016-09-21 13:52:16 +02:00
Darien Raymond
d38e62932d proto for dns config 2016-09-20 16:05:35 +02:00
Darien Raymond
7de7588ec2 proto for destination 2016-09-20 11:53:05 +02:00
Darien Raymond
c518726910 network proto 2016-09-20 10:44:44 +02:00
172 changed files with 3789 additions and 1409 deletions

View File

@@ -1,7 +1,7 @@
language: go
go:
- 1.7
- 1.7.1
go_import_path: v2ray.com/core

View File

@@ -3,10 +3,18 @@ package dns
import (
"net"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/log"
)
type Config struct {
Hosts map[string]net.IP
NameServers []v2net.Destination
func (this *Config) GetInternalHosts() map[string]net.IP {
hosts := make(map[string]net.IP)
for domain, addressPB := range this.GetHosts() {
address := addressPB.AsAddress()
if address.Family().IsDomain() {
log.Warning("DNS: Ignoring domain address in static hosts: ", address.Domain())
continue
}
hosts[domain] = address.IP()
}
return hosts
}

82
app/dns/config.pb.go Normal file
View File

@@ -0,0 +1,82 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/app/dns/config.proto
// DO NOT EDIT!
/*
Package dns is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/app/dns/config.proto
It has these top-level messages:
Config
*/
package dns
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import v2ray_core_common_net "v2ray.com/core/common/net"
import v2ray_core_common_net2 "v2ray.com/core/common/net"
// 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 {
NameServers []*v2ray_core_common_net2.DestinationPB `protobuf:"bytes,1,rep,name=NameServers,json=nameServers" json:"NameServers,omitempty"`
Hosts map[string]*v2ray_core_common_net.AddressPB `protobuf:"bytes,2,rep,name=Hosts,json=hosts" json:"Hosts,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
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 (m *Config) GetNameServers() []*v2ray_core_common_net2.DestinationPB {
if m != nil {
return m.NameServers
}
return nil
}
func (m *Config) GetHosts() map[string]*v2ray_core_common_net.AddressPB {
if m != nil {
return m.Hosts
}
return nil
}
func init() {
proto.RegisterType((*Config)(nil), "v2ray.core.app.dns.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/app/dns/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 270 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x90, 0xcb, 0x4a, 0xc4, 0x30,
0x14, 0x86, 0x49, 0x4b, 0x07, 0x4c, 0x37, 0x92, 0x85, 0x94, 0xae, 0x8a, 0x17, 0x2c, 0x0a, 0x09,
0x54, 0x10, 0xd1, 0x95, 0xf5, 0x82, 0x2b, 0x29, 0x75, 0x37, 0xbb, 0xd8, 0x1c, 0xb5, 0x68, 0x4f,
0x4a, 0x12, 0x0b, 0x7d, 0x64, 0xdf, 0x42, 0xda, 0x20, 0x15, 0x9d, 0xd9, 0x1d, 0xc2, 0xf7, 0x5f,
0xf2, 0xd3, 0x83, 0xa1, 0x30, 0x72, 0xe4, 0x8d, 0xee, 0x44, 0xa3, 0x0d, 0x08, 0xd9, 0xf7, 0x42,
0xa1, 0x15, 0x8d, 0xc6, 0x97, 0xf6, 0x95, 0xf7, 0x46, 0x3b, 0xcd, 0xd8, 0x0f, 0x64, 0x80, 0xcb,
0xbe, 0xe7, 0x0a, 0x6d, 0x7a, 0xfc, 0x47, 0xd8, 0xe8, 0xae, 0xd3, 0x28, 0x10, 0x9c, 0x90, 0x4a,
0x19, 0xb0, 0xd6, 0x8b, 0xd3, 0xd3, 0xed, 0xa0, 0x02, 0xeb, 0x5a, 0x94, 0xae, 0xd5, 0xe8, 0xe1,
0xfd, 0x2f, 0x42, 0x57, 0x37, 0x73, 0x34, 0xbb, 0xa7, 0xf1, 0xa3, 0xec, 0xe0, 0x09, 0xcc, 0x00,
0xc6, 0x26, 0x24, 0x0b, 0xf3, 0xb8, 0x38, 0xe4, 0xbf, 0xaa, 0x78, 0x27, 0x8e, 0xe0, 0xf8, 0xed,
0xe2, 0x54, 0x95, 0x75, 0x8c, 0x8b, 0x90, 0x5d, 0xd1, 0xe8, 0x41, 0x5b, 0x67, 0x93, 0x60, 0x76,
0x38, 0xe2, 0xff, 0x3f, 0xc3, 0x7d, 0x24, 0x9f, 0xb9, 0x3b, 0x74, 0x66, 0xac, 0xa3, 0xb7, 0xe9,
0x4e, 0xd7, 0x94, 0x2e, 0x8f, 0x6c, 0x97, 0x86, 0xef, 0x30, 0x26, 0x24, 0x23, 0xf9, 0x4e, 0x3d,
0x9d, 0xec, 0x9c, 0x46, 0x83, 0xfc, 0xf8, 0x84, 0x24, 0xc8, 0x48, 0x1e, 0x17, 0xd9, 0x96, 0x7a,
0xd7, 0x7e, 0x91, 0xaa, 0xac, 0x3d, 0x7e, 0x19, 0x5c, 0x90, 0xf2, 0x84, 0xee, 0x35, 0xba, 0xdb,
0x50, 0xa7, 0x8c, 0x7d, 0x9f, 0x6a, 0x9a, 0x64, 0x1d, 0x2a, 0xb4, 0xcf, 0xab, 0x79, 0x9e, 0xb3,
0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x17, 0x9a, 0x1d, 0xee, 0xaf, 0x01, 0x00, 0x00,
}

14
app/dns/config.proto Normal file
View File

@@ -0,0 +1,14 @@
syntax = "proto3";
package v2ray.core.app.dns;
option go_package = "dns";
option java_package = "com.v2ray.core.app.dns";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/net/destination.proto";
message Config {
repeated v2ray.core.common.net.DestinationPB NameServers = 1;
map<string, v2ray.core.common.net.AddressPB> Hosts = 2;
}

View File

@@ -4,35 +4,30 @@ package dns
import (
"encoding/json"
"errors"
"net"
v2net "v2ray.com/core/common/net"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Servers []v2net.AddressPB `json:"servers"`
Hosts map[string]v2net.AddressPB `json:"hosts"`
Servers []*v2net.AddressPB `json:"servers"`
Hosts map[string]*v2net.AddressPB `json:"hosts"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.NameServers = make([]v2net.Destination, len(jsonConfig.Servers))
this.NameServers = make([]*v2net.DestinationPB, len(jsonConfig.Servers))
for idx, server := range jsonConfig.Servers {
this.NameServers[idx] = v2net.UDPDestination(server.AsAddress(), v2net.Port(53))
this.NameServers[idx] = &v2net.DestinationPB{
Network: v2net.Network_UDP,
Address: server,
Port: 53,
}
}
if jsonConfig.Hosts != nil {
this.Hosts = make(map[string]net.IP)
for domain, ipOrDomain := range jsonConfig.Hosts {
ip := ipOrDomain.GetIp()
if ip == nil {
return errors.New(ipOrDomain.AsAddress().String() + " is not an IP.")
}
this.Hosts[domain] = net.IP(ip)
}
this.Hosts = jsonConfig.Hosts
}
return nil

View File

@@ -22,7 +22,8 @@ func TestConfigParsing(t *testing.T) {
err := json.Unmarshal([]byte(rawJson), config)
assert.Error(err).IsNil()
assert.Int(len(config.NameServers)).Equals(1)
assert.Destination(config.NameServers[0]).IsUDP()
assert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
assert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
dest := config.NameServers[0].AsDestination()
assert.Destination(dest).IsUDP()
assert.Address(dest.Address).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
assert.Port(dest.Port).Equals(v2net.Port(53))
}

View File

@@ -8,6 +8,7 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"github.com/miekg/dns"
)
@@ -32,7 +33,7 @@ func NewCacheServer(space app.Space, config *Config) *CacheServer {
server := &CacheServer{
records: make(map[string]*DomainRecord),
servers: make([]NameServer, len(config.NameServers)),
hosts: config.Hosts,
hosts: config.GetInternalHosts(),
}
space.InitializeApplication(func() error {
if !space.HasApp(dispatcher.APP_ID) {
@@ -41,11 +42,18 @@ func NewCacheServer(space app.Space, config *Config) *CacheServer {
}
dispatcher := space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
for idx, ns := range config.NameServers {
if ns.Address().Family().IsDomain() && ns.Address().Domain() == "localhost" {
for idx, destPB := range config.NameServers {
address := destPB.Address.AsAddress()
if address.Family().IsDomain() && address.Domain() == "localhost" {
server.servers[idx] = &LocalNameServer{}
} else {
server.servers[idx] = NewUDPNameServer(ns, dispatcher)
dest := destPB.AsDestination()
if dest.Network == v2net.Network_Unknown {
dest.Network = v2net.Network_UDP
}
if dest.Network == v2net.Network_UDP {
server.servers[idx] = NewUDPNameServer(dest, dispatcher)
}
}
}
if len(config.NameServers) == 0 {

View File

@@ -28,8 +28,8 @@ func TestDnsAdd(t *testing.T) {
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
}))
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
@@ -37,9 +37,15 @@ func TestDnsAdd(t *testing.T) {
domain := "local.v2ray.com"
server := NewCacheServer(space, &Config{
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
},
NameServers: []*v2net.DestinationPB{{
Network: v2net.Network_UDP,
Address: &v2net.AddressPB{
Address: &v2net.AddressPB_Ip{
Ip: []byte{8, 8, 8, 8},
},
},
Port: 53,
}},
})
space.BindApp(APP_ID, server)
space.Initialize()

View File

@@ -73,10 +73,10 @@ func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher {
}
func (this *PlainDomainMatcher) Apply(dest v2net.Destination) bool {
if !dest.Address().Family().IsDomain() {
if !dest.Address.Family().IsDomain() {
return false
}
domain := dest.Address().Domain()
domain := dest.Address.Domain()
return strings.Contains(domain, this.pattern)
}
@@ -95,10 +95,10 @@ func NewRegexpDomainMatcher(pattern string) (*RegexpDomainMatcher, error) {
}
func (this *RegexpDomainMatcher) Apply(dest v2net.Destination) bool {
if !dest.Address().Family().IsDomain() {
if !dest.Address.Family().IsDomain() {
return false
}
domain := dest.Address().Domain()
domain := dest.Address.Domain()
return this.pattern.MatchString(strings.ToLower(domain))
}
@@ -117,10 +117,10 @@ func NewCIDRMatcher(ipnet string) (*CIDRMatcher, error) {
}
func (this *CIDRMatcher) Apply(dest v2net.Destination) bool {
if !dest.Address().Family().Either(v2net.AddressFamilyIPv4, v2net.AddressFamilyIPv6) {
if !dest.Address.Family().Either(v2net.AddressFamilyIPv4, v2net.AddressFamilyIPv6) {
return false
}
return this.cidr.Contains(dest.Address().IP())
return this.cidr.Contains(dest.Address.IP())
}
type IPv4Matcher struct {
@@ -134,10 +134,10 @@ func NewIPv4Matcher(ipnet *v2net.IPNet) *IPv4Matcher {
}
func (this *IPv4Matcher) Apply(dest v2net.Destination) bool {
if !dest.Address().Family().Either(v2net.AddressFamilyIPv4) {
if !dest.Address.Family().Either(v2net.AddressFamilyIPv4) {
return false
}
return this.ipv4net.Contains(dest.Address().IP())
return this.ipv4net.Contains(dest.Address.IP())
}
type PortMatcher struct {
@@ -151,7 +151,7 @@ func NewPortMatcher(portRange v2net.PortRange) *PortMatcher {
}
func (this *PortMatcher) Apply(dest v2net.Destination) bool {
return this.port.Contains(dest.Port())
return this.port.Contains(dest.Port)
}
type NetworkMatcher struct {
@@ -165,5 +165,5 @@ func NewNetworkMatcher(network *v2net.NetworkList) *NetworkMatcher {
}
func (this *NetworkMatcher) Apply(dest v2net.Destination) bool {
return this.network.HasNetwork(dest.Network())
return this.network.HasNetwork(dest.Network)
}

View File

@@ -43,16 +43,16 @@ func (this *Router) Release() {
// Private: Visible for testing.
func (this *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
ips := this.dnsServer.Get(dest.Address().Domain())
ips := this.dnsServer.Get(dest.Address.Domain())
if len(ips) == 0 {
return nil
}
dests := make([]v2net.Destination, len(ips))
for idx, ip := range ips {
if dest.Network() == v2net.TCPNetwork {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port())
if dest.Network == v2net.Network_TCP {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port)
} else {
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port())
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port)
}
}
return dests
@@ -64,7 +64,7 @@ func (this *Router) takeDetourWithoutCache(dest v2net.Destination) (string, erro
return rule.Tag, nil
}
}
if this.config.DomainStrategy == UseIPIfNonMatch && dest.Address().Family().IsDomain() {
if this.config.DomainStrategy == UseIPIfNonMatch && dest.Address.Family().IsDomain() {
log.Info("Router: Looking up IP for ", dest)
ipDests := this.ResolveIP(dest)
if ipDests != nil {

View File

@@ -21,7 +21,7 @@ func TestSimpleRouter(t *testing.T) {
Rules: []*Rule{
{
Tag: "test",
Condition: NewNetworkMatcher(v2net.Network("tcp").AsList()),
Condition: NewNetworkMatcher(v2net.Network_TCP.AsList()),
},
},
}

View File

@@ -10,21 +10,21 @@ import (
)
type JSONConfigLoader struct {
*BaseConfigLoader
cache ConfigCreatorCache
idKey string
configKey string
}
func NewJSONConfigLoader(idKey string, configKey string) *JSONConfigLoader {
func NewJSONConfigLoader(cache ConfigCreatorCache, idKey string, configKey string) *JSONConfigLoader {
return &JSONConfigLoader{
idKey: idKey,
configKey: configKey,
BaseConfigLoader: NewBaseConfigLoader(),
idKey: idKey,
configKey: configKey,
cache: cache,
}
}
func (this *JSONConfigLoader) LoadWithID(raw []byte, id string) (interface{}, error) {
config, err := this.CreateConfig(id)
config, err := this.cache.CreateConfig(id)
if err != nil {
return nil, err
}

View File

@@ -0,0 +1,39 @@
// +build json
package loader_test
import (
"testing"
. "v2ray.com/core/common/loader"
"v2ray.com/core/testing/assert"
)
type TestConfigA struct {
V int
}
type TestConfigB struct {
S string
}
func TestCreatorCache(t *testing.T) {
assert := assert.On(t)
cache := ConfigCreatorCache{}
creator1 := func() interface{} { return &TestConfigA{} }
creator2 := func() interface{} { return &TestConfigB{} }
cache.RegisterCreator("1", creator1)
loader := NewJSONConfigLoader(cache, "test", "")
rawA, err := loader.LoadWithID([]byte(`{"V": 2}`), "1")
assert.Error(err).IsNil()
instA := rawA.(*TestConfigA)
assert.Int(instA.V).Equals(2)
cache.RegisterCreator("2", creator2)
rawB, err := loader.LoadWithID([]byte(`{"S": "a"}`), "2")
assert.Error(err).IsNil()
instB := rawB.(*TestConfigB)
assert.String(instB.S).Equals("a")
}

View File

@@ -11,36 +11,26 @@ var (
type ConfigCreator func() interface{}
type ConfigLoader interface {
RegisterCreator(string, ConfigCreator) error
CreateConfig(string) (interface{}, error)
Load([]byte) (interface{}, string, error)
LoadWithID([]byte, string) (interface{}, error)
}
type ConfigCreatorCache map[string]ConfigCreator
type BaseConfigLoader struct {
creators map[string]ConfigCreator
}
func NewBaseConfigLoader() *BaseConfigLoader {
return &BaseConfigLoader{
creators: make(map[string]ConfigCreator),
}
}
func (this *BaseConfigLoader) RegisterCreator(id string, creator ConfigCreator) error {
if _, found := this.creators[id]; found {
func (this ConfigCreatorCache) RegisterCreator(id string, creator ConfigCreator) error {
if _, found := this[id]; found {
return common.ErrDuplicatedName
}
this.creators[id] = creator
this[id] = creator
return nil
}
func (this *BaseConfigLoader) CreateConfig(id string) (interface{}, error) {
creator, found := this.creators[id]
func (this ConfigCreatorCache) CreateConfig(id string) (interface{}, error) {
creator, found := this[id]
if !found {
return nil, ErrUnknownConfigID
}
return creator(), nil
}
type ConfigLoader interface {
Load([]byte) (interface{}, string, error)
LoadWithID([]byte, string) (interface{}, error)
}

View File

@@ -188,6 +188,9 @@ func (this *domainAddress) Equals(another Address) bool {
}
func (this *AddressPB) AsAddress() Address {
if this == nil {
return nil
}
switch addr := this.Address.(type) {
case *AddressPB_Ip:
return IPAddress(addr.Ip)

View File

@@ -7,10 +7,14 @@ Package net is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/common/net/address.proto
v2ray.com/core/common/net/destination.proto
v2ray.com/core/common/net/network.proto
v2ray.com/core/common/net/port.proto
It has these top-level messages:
AddressPB
DestinationPB
NetworkList
PortRange
*/
package net
@@ -144,21 +148,21 @@ func _AddressPB_OneofSizer(msg proto.Message) (n int) {
}
func init() {
proto.RegisterType((*AddressPB)(nil), "com.v2ray.core.common.net.AddressPB")
proto.RegisterType((*AddressPB)(nil), "v2ray.core.common.net.AddressPB")
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/address.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 148 bytes of a gzipped FileDescriptorProto
// 159 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0xd1, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0xd6, 0x2b, 0x28,
0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4c, 0xce, 0xcf, 0xd5, 0x83, 0x29, 0x2e, 0x4a, 0xd5, 0x83, 0x28,
0xd4, 0xcb, 0x4b, 0x2d, 0x51, 0x72, 0xe2, 0xe2, 0x74, 0x84, 0xa8, 0x0d, 0x70, 0x12, 0x12, 0xe0,
0x62, 0xca, 0x2c, 0x90, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0xf1, 0x60, 0x08, 0x62, 0xca, 0x2c, 0x10,
0x92, 0xe0, 0x62, 0x4b, 0xc9, 0xcf, 0x4d, 0xcc, 0xcc, 0x93, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0xf4,
0x60, 0x08, 0x82, 0xf2, 0x9d, 0x38, 0xb9, 0xd8, 0xa1, 0x96, 0x38, 0xb1, 0x46, 0x31, 0xe7, 0xa5,
0x96, 0x24, 0xb1, 0x81, 0x2d, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x04, 0x63, 0x74,
0x97, 0x00, 0x00, 0x00,
0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0x29, 0x2c, 0x4a, 0xd5, 0x83, 0x28, 0xd2, 0xcb, 0x4b, 0x2d,
0x51, 0x72, 0xe2, 0xe2, 0x74, 0x84, 0xa8, 0x0b, 0x70, 0x12, 0x12, 0xe0, 0x62, 0xca, 0x2c, 0x90,
0x60, 0x54, 0x60, 0xd4, 0xe0, 0xf1, 0x60, 0x08, 0x62, 0xca, 0x2c, 0x10, 0x92, 0xe0, 0x62, 0x4b,
0xc9, 0xcf, 0x4d, 0xcc, 0xcc, 0x93, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0xf4, 0x60, 0x08, 0x82, 0xf2,
0x9d, 0x38, 0xb9, 0xd8, 0xa1, 0x16, 0x38, 0xe9, 0x71, 0x49, 0x26, 0xe7, 0xe7, 0xea, 0x61, 0xb5,
0xc0, 0x89, 0x07, 0x66, 0x3c, 0xc8, 0x15, 0x51, 0xcc, 0x79, 0xa9, 0x25, 0x49, 0x6c, 0x60, 0x17,
0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa1, 0xd1, 0xe6, 0x14, 0xbc, 0x00, 0x00, 0x00,
}

View File

@@ -1,7 +1,9 @@
syntax = "proto3";
package com.v2ray.core.common.net;
package v2ray.core.common.net;
option go_package = "net";
option java_package = "com.v2ray.core.common.net";
option java_outer_classname = "AddressProto";
message AddressPB {
oneof address {

View File

@@ -5,16 +5,10 @@ import (
)
// Destination represents a network destination including address and protocol (tcp / udp).
type Destination interface {
Network() Network // Protocol of communication (tcp / udp)
Address() Address // Address of destination
Port() Port
String() string // String representation of the destination
NetAddr() string
Equals(Destination) bool
IsTCP() bool // True if destination is reachable via TCP
IsUDP() bool // True if destination is reachable via UDP
type Destination struct {
Network Network
Address Address
Port Port
}
func DestinationFromAddr(addr net.Addr) Destination {
@@ -30,102 +24,38 @@ func DestinationFromAddr(addr net.Addr) Destination {
// TCPDestination creates a TCP destination with given address
func TCPDestination(address Address, port Port) Destination {
return &tcpDestination{address: address, port: port}
return Destination{
Network: Network_TCP,
Address: address,
Port: port,
}
}
// UDPDestination creates a UDP destination with given address
func UDPDestination(address Address, port Port) Destination {
return &udpDestination{address: address, port: port}
}
type tcpDestination struct {
address Address
port Port
}
func (dest *tcpDestination) Network() Network {
return TCPNetwork
}
func (dest *tcpDestination) Address() Address {
return dest.address
}
func (dest *tcpDestination) NetAddr() string {
return dest.address.String() + ":" + dest.port.String()
}
func (dest *tcpDestination) String() string {
return "tcp:" + dest.NetAddr()
}
func (dest *tcpDestination) IsTCP() bool {
return true
}
func (dest *tcpDestination) IsUDP() bool {
return false
}
func (dest *tcpDestination) Port() Port {
return dest.port
}
func (dest *tcpDestination) Equals(another Destination) bool {
if dest == nil && another == nil {
return true
return Destination{
Network: Network_UDP,
Address: address,
Port: port,
}
if dest == nil || another == nil {
return false
}
func (this Destination) NetAddr() string {
return this.Address.String() + ":" + this.Port.String()
}
func (this Destination) String() string {
return this.Network.UrlPrefix() + ":" + this.NetAddr()
}
func (this Destination) Equals(another Destination) bool {
return this.Network == another.Network && this.Port == another.Port && this.Address.Equals(another.Address)
}
func (this *DestinationPB) AsDestination() Destination {
return Destination{
Network: this.Network,
Address: this.Address.AsAddress(),
Port: Port(this.Port),
}
if another.Network() != TCPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())
}
type udpDestination struct {
address Address
port Port
}
func (dest *udpDestination) Network() Network {
return UDPNetwork
}
func (dest *udpDestination) Address() Address {
return dest.address
}
func (dest *udpDestination) NetAddr() string {
return dest.address.String() + ":" + dest.port.String()
}
func (dest *udpDestination) String() string {
return "udp:" + dest.NetAddr()
}
func (dest *udpDestination) IsTCP() bool {
return false
}
func (dest *udpDestination) IsUDP() bool {
return true
}
func (dest *udpDestination) Port() Port {
return dest.port
}
func (dest *udpDestination) Equals(another Destination) bool {
if dest == nil && another == nil {
return true
}
if dest == nil || another == nil {
return false
}
if another.Network() != UDPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())
}

View File

@@ -0,0 +1,56 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/net/destination.proto
// DO NOT EDIT!
package net
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
type DestinationPB struct {
Network Network `protobuf:"varint,1,opt,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
Address *AddressPB `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"`
Port uint32 `protobuf:"varint,3,opt,name=port" json:"port,omitempty"`
}
func (m *DestinationPB) Reset() { *m = DestinationPB{} }
func (m *DestinationPB) String() string { return proto.CompactTextString(m) }
func (*DestinationPB) ProtoMessage() {}
func (*DestinationPB) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (m *DestinationPB) GetAddress() *AddressPB {
if m != nil {
return m.Address
}
return nil
}
func init() {
proto.RegisterType((*DestinationPB)(nil), "v2ray.core.common.net.DestinationPB")
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/destination.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 209 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x2e, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0xd1, 0x4f, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x2c, 0xc9, 0xcc,
0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0x29, 0x2e, 0x4a, 0xd5, 0x83, 0x28,
0xd4, 0xcb, 0x4b, 0x2d, 0x91, 0x52, 0xc7, 0x6d, 0x46, 0x5e, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0x36,
0x44, 0x3f, 0x3e, 0x85, 0x89, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0x10, 0x85, 0x4a, 0x33, 0x19,
0xb9, 0x78, 0x5d, 0x10, 0xd6, 0x07, 0x38, 0x09, 0x59, 0x70, 0xb1, 0x43, 0xcd, 0x92, 0x60, 0x54,
0x60, 0xd4, 0xe0, 0x33, 0x92, 0xd3, 0xc3, 0xea, 0x18, 0x3d, 0x3f, 0x88, 0xaa, 0x20, 0x98, 0x72,
0x21, 0x2b, 0x2e, 0x76, 0xa8, 0xe1, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x0a, 0x38, 0x74,
0x3a, 0x42, 0x54, 0x05, 0x38, 0x05, 0xc1, 0x34, 0x08, 0x09, 0x71, 0xb1, 0x14, 0xe4, 0x17, 0x95,
0x48, 0x30, 0x2b, 0x30, 0x6a, 0xf0, 0x06, 0x81, 0xd9, 0x4e, 0x46, 0x5c, 0x92, 0xc9, 0xf9, 0xb9,
0xd8, 0xcd, 0x70, 0x12, 0x40, 0x76, 0x35, 0xc8, 0x2b, 0x51, 0xcc, 0x79, 0xa9, 0x25, 0x49, 0x6c,
0x60, 0x6f, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe2, 0xd7, 0x78, 0x9a, 0x6e, 0x01, 0x00,
0x00,
}

View File

@@ -0,0 +1,15 @@
syntax = "proto3";
package v2ray.core.common.net;
option go_package = "net";
option java_package = "com.v2ray.core.common.net";
option java_outer_classname = "DestinationProto";
import "v2ray.com/core/common/net/network.proto";
import "v2ray.com/core/common/net/address.proto";
message DestinationPB {
Network network = 1;
AddressPB address = 2;
uint32 port = 3;
}

View File

@@ -29,7 +29,7 @@ func TestTCPDestinationEquals(t *testing.T) {
assert := assert.On(t)
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(nil)).IsFalse()
assert.Bool(dest.Equals(v2net.Destination{})).IsFalse()
dest2 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest2)).IsTrue()
@@ -45,7 +45,7 @@ func TestUDPDestinationEquals(t *testing.T) {
assert := assert.On(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(nil)).IsFalse()
assert.Bool(dest.Equals(v2net.Destination{})).IsFalse()
dest2 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest2)).IsTrue()

View File

@@ -6,50 +6,77 @@ import (
"v2ray.com/core/common/collect"
)
const (
// TCPNetwork represents the TCP network.
TCPNetwork = Network("tcp")
// UDPNetwork represents the UDP network.
UDPNetwork = Network("udp")
// KCPNetwork represents the KCP network.
KCPNetwork = Network("kcp")
// WSNetwork represents the Websocket over HTTP network.
WSNetwork = Network("ws")
)
// Network represents a communication network on internet.
type Network string
func ParseNetwork(nwStr string) Network {
if network, found := Network_value[nwStr]; found {
return Network(network)
}
switch strings.ToLower(nwStr) {
case "tcp":
return Network_TCP
case "udp":
return Network_UDP
case "kcp":
return Network_KCP
case "ws":
return Network_WebSocket
default:
return Network_Unknown
}
}
func (this Network) AsList() *NetworkList {
list := NetworkList([]Network{this})
return &list
return &NetworkList{
Network: []Network{this},
}
}
func (this Network) String() string {
return string(this)
func (this Network) SystemString() string {
switch this {
case Network_TCP, Network_RawTCP:
return "tcp"
case Network_UDP, Network_KCP:
return "udp"
default:
return "unknown"
}
}
// NetworkList is a list of Networks.
type NetworkList []Network
func (this Network) UrlPrefix() string {
switch this {
case Network_TCP, Network_RawTCP:
return "tcp"
case Network_UDP:
return "udp"
case Network_KCP:
return "kcp"
case Network_WebSocket:
return "ws"
default:
return "unknown"
}
}
// NewNetworkList construsts a NetWorklist from the given StringListeralList.
func NewNetworkList(networks collect.StringList) NetworkList {
list := NetworkList(make([]Network, networks.Len()))
func NewNetworkList(networks collect.StringList) *NetworkList {
list := &NetworkList{
Network: make([]Network, networks.Len()),
}
for idx, network := range networks {
list[idx] = Network(strings.ToLower(strings.TrimSpace(network)))
list.Network[idx] = ParseNetwork(network)
}
return list
}
// HashNetwork returns true if the given network is in this NetworkList.
func (this *NetworkList) HasNetwork(network Network) bool {
for _, value := range *this {
func (this NetworkList) HasNetwork(network Network) bool {
for _, value := range this.Network {
if string(value) == string(network) {
return true
}
}
return false
}
func (this NetworkList) Get(idx int) Network {
return this.Network[idx]
}

80
common/net/network.pb.go Normal file
View File

@@ -0,0 +1,80 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/net/network.proto
// DO NOT EDIT!
package net
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
type Network int32
const (
Network_Unknown Network = 0
Network_RawTCP Network = 1
Network_TCP Network = 2
Network_UDP Network = 3
Network_KCP Network = 4
Network_WebSocket Network = 5
)
var Network_name = map[int32]string{
0: "Unknown",
1: "RawTCP",
2: "TCP",
3: "UDP",
4: "KCP",
5: "WebSocket",
}
var Network_value = map[string]int32{
"Unknown": 0,
"RawTCP": 1,
"TCP": 2,
"UDP": 3,
"KCP": 4,
"WebSocket": 5,
}
func (x Network) String() string {
return proto.EnumName(Network_name, int32(x))
}
func (Network) EnumDescriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
type NetworkList struct {
Network []Network `protobuf:"varint,1,rep,packed,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
}
func (m *NetworkList) Reset() { *m = NetworkList{} }
func (m *NetworkList) String() string { return proto.CompactTextString(m) }
func (*NetworkList) ProtoMessage() {}
func (*NetworkList) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
func init() {
proto.RegisterType((*NetworkList)(nil), "v2ray.core.common.net.NetworkList")
proto.RegisterEnum("v2ray.core.common.net.Network", Network_name, Network_value)
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/network.proto", fileDescriptor2) }
var fileDescriptor2 = []byte{
// 203 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0x01, 0xe1, 0xf2, 0xfc, 0xa2, 0x6c, 0xbd, 0x82, 0xa2, 0xfc, 0x92,
0x7c, 0x21, 0x51, 0x98, 0xc2, 0xa2, 0x54, 0x3d, 0x88, 0x22, 0xbd, 0xbc, 0xd4, 0x12, 0x25, 0x77,
0x2e, 0x6e, 0x3f, 0x88, 0x3a, 0x9f, 0xcc, 0xe2, 0x12, 0x21, 0x0b, 0x2e, 0x76, 0xa8, 0x36, 0x09,
0x46, 0x05, 0x66, 0x0d, 0x3e, 0x23, 0x39, 0x3d, 0xac, 0xfa, 0xf4, 0xa0, 0x9a, 0x82, 0x60, 0xca,
0xb5, 0x7c, 0xb8, 0xd8, 0xa1, 0x62, 0x42, 0xdc, 0x5c, 0xec, 0xa1, 0x79, 0xd9, 0x79, 0xf9, 0xe5,
0x79, 0x02, 0x0c, 0x42, 0x5c, 0x5c, 0x6c, 0x41, 0x89, 0xe5, 0x21, 0xce, 0x01, 0x02, 0x8c, 0x42,
0xec, 0x5c, 0xcc, 0x20, 0x06, 0x13, 0x88, 0x11, 0xea, 0x12, 0x20, 0xc0, 0x0c, 0x62, 0x78, 0x3b,
0x07, 0x08, 0xb0, 0x08, 0xf1, 0x72, 0x71, 0x86, 0xa7, 0x26, 0x05, 0xe7, 0x27, 0x67, 0xa7, 0x96,
0x08, 0xb0, 0x3a, 0xe9, 0x71, 0x49, 0x26, 0xe7, 0xe7, 0x62, 0xb7, 0xdb, 0x89, 0x07, 0x6a, 0x51,
0x00, 0xc8, 0x63, 0x51, 0xcc, 0x79, 0xa9, 0x25, 0x49, 0x6c, 0x60, 0x4f, 0x1a, 0x03, 0x02, 0x00,
0x00, 0xff, 0xff, 0x6e, 0x52, 0xf1, 0x92, 0x0f, 0x01, 0x00, 0x00,
}

19
common/net/network.proto Normal file
View File

@@ -0,0 +1,19 @@
syntax = "proto3";
package v2ray.core.common.net;
option go_package = "net";
option java_package = "com.v2ray.core.common.net";
option java_outer_classname = "NetworkProto";
enum Network {
Unknown = 0;
RawTCP = 1;
TCP = 2;
UDP = 3;
KCP = 4;
WebSocket = 5;
}
message NetworkList {
repeated Network network = 1;
}

View File

@@ -8,11 +8,20 @@ import (
"v2ray.com/core/common/collect"
)
func (this *Network) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
*this = ParseNetwork(str)
return nil
}
func (this *NetworkList) UnmarshalJSON(data []byte) error {
var strlist collect.StringList
if err := json.Unmarshal(data, &strlist); err != nil {
return err
}
*this = NewNetworkList(strlist)
*this = *NewNetworkList(strlist)
return nil
}

View File

@@ -10,14 +10,23 @@ import (
"v2ray.com/core/testing/assert"
)
func TestStringNetwork(t *testing.T) {
assert := assert.On(t)
var network Network
err := json.Unmarshal([]byte(`"tcp"`), &network)
assert.Error(err).IsNil()
assert.Bool(network == Network_TCP).IsTrue()
}
func TestArrayNetworkList(t *testing.T) {
assert := assert.On(t)
var list NetworkList
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse()
}
func TestStringNetworkList(t *testing.T) {
@@ -26,8 +35,8 @@ func TestStringNetworkList(t *testing.T) {
var list NetworkList
err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(Network("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(Network("udp"))).IsFalse()
assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse()
}
func TestInvalidNetworkJson(t *testing.T) {

View File

@@ -22,23 +22,24 @@ type PortRange struct {
func (m *PortRange) Reset() { *m = PortRange{} }
func (m *PortRange) String() string { return proto.CompactTextString(m) }
func (*PortRange) ProtoMessage() {}
func (*PortRange) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (*PortRange) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{0} }
func init() {
proto.RegisterType((*PortRange)(nil), "com.v2ray.core.common.net.PortRange")
proto.RegisterType((*PortRange)(nil), "v2ray.core.common.net.PortRange")
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/port.proto", fileDescriptor1) }
func init() { proto.RegisterFile("v2ray.com/core/common/net/port.proto", fileDescriptor3) }
var fileDescriptor1 = []byte{
// 137 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x34, 0xcc, 0xb1, 0x0a, 0xc2, 0x40,
0x0c, 0x87, 0x71, 0x7a, 0x56, 0xc1, 0x03, 0x1d, 0x6e, 0xaa, 0x9b, 0x88, 0x83, 0x53, 0x02, 0xfa,
0x06, 0x0e, 0xce, 0x52, 0x9c, 0xdc, 0xea, 0x11, 0x9d, 0x92, 0x7f, 0x09, 0x41, 0xf0, 0xed, 0x85,
0x8a, 0xeb, 0xc7, 0x8f, 0x2f, 0xef, 0xdf, 0x47, 0x1f, 0x3e, 0x54, 0xa1, 0x5c, 0xe1, 0xc2, 0x15,
0xaa, 0x30, 0x36, 0x09, 0x1e, 0xe1, 0x41, 0xa3, 0x23, 0x50, 0x36, 0x15, 0x4a, 0x7f, 0xe9, 0x42,
0x3f, 0x45, 0x26, 0xb1, 0xe3, 0xbc, 0xbc, 0xc2, 0xa3, 0x1f, 0xec, 0x25, 0xa5, 0xe4, 0xf6, 0xe2,
0xd0, 0xae, 0xd9, 0x36, 0x87, 0x55, 0xdf, 0x3e, 0x1d, 0x5a, 0xd6, 0x39, 0xdd, 0xd0, 0xa5, 0xa9,
0xa4, 0xc0, 0x79, 0x7e, 0x9f, 0x99, 0xc4, 0x63, 0x31, 0x9d, 0x4f, 0xdf, 0x00, 0x00, 0x00, 0xff,
0xff, 0xc3, 0x9d, 0x1a, 0x33, 0x81, 0x00, 0x00, 0x00,
var fileDescriptor3 = []byte{
// 148 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x29, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0xd1, 0x2f, 0xc8, 0x2f, 0x2a, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9,
0x17, 0x12, 0x85, 0xa9, 0x2a, 0x4a, 0xd5, 0x83, 0xa8, 0xd0, 0xcb, 0x4b, 0x2d, 0x51, 0xd2, 0xe7,
0xe2, 0x0c, 0xc8, 0x2f, 0x2a, 0x09, 0x4a, 0xcc, 0x4b, 0x4f, 0x15, 0x12, 0xe2, 0x62, 0x71, 0x2b,
0xca, 0xcf, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0d, 0x62, 0x49, 0x2b, 0xca, 0xcf, 0x15, 0xe2,
0xe3, 0x62, 0x0a, 0xc9, 0x97, 0x60, 0x02, 0x8b, 0x30, 0x95, 0xe4, 0x3b, 0x69, 0x73, 0x49, 0x26,
0xe7, 0xe7, 0xea, 0x61, 0x35, 0xcd, 0x09, 0x6c, 0x56, 0x00, 0xc8, 0xbe, 0x28, 0xe6, 0xbc, 0xd4,
0x92, 0x24, 0x36, 0xb0, 0xdd, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x28, 0x7b, 0x9b, 0xb3,
0xa3, 0x00, 0x00, 0x00,
}

View File

@@ -1,7 +1,9 @@
syntax = "proto3";
package com.v2ray.core.common.net;
package v2ray.core.common.net;
option go_package = "net";
option java_package = "com.v2ray.core.common.net";
option java_outer_classname = "PortProto";
// PortRange represents a range of ports.
message PortRange {

View File

@@ -19,13 +19,13 @@ func TestServerList(t *testing.T) {
assert.Uint32(list.Size()).Equals(2)
server := list.GetServer(1)
assert.Port(server.Destination().Port()).Equals(2)
assert.Port(server.Destination().Port).Equals(2)
time.Sleep(2 * time.Second)
server = list.GetServer(1)
assert.Pointer(server).IsNil()
server = list.GetServer(0)
assert.Port(server.Destination().Port()).Equals(1)
assert.Port(server.Destination().Port).Equals(1)
}
func TestServerPicker(t *testing.T) {
@@ -38,17 +38,17 @@ func TestServerPicker(t *testing.T) {
picker := NewRoundRobinServerPicker(list)
server := picker.PickServer()
assert.Port(server.Destination().Port()).Equals(1)
assert.Port(server.Destination().Port).Equals(1)
server = picker.PickServer()
assert.Port(server.Destination().Port()).Equals(2)
assert.Port(server.Destination().Port).Equals(2)
server = picker.PickServer()
assert.Port(server.Destination().Port()).Equals(3)
assert.Port(server.Destination().Port).Equals(3)
server = picker.PickServer()
assert.Port(server.Destination().Port()).Equals(1)
assert.Port(server.Destination().Port).Equals(1)
time.Sleep(2 * time.Second)
server = picker.PickServer()
assert.Port(server.Destination().Port()).Equals(1)
assert.Port(server.Destination().Port).Equals(1)
server = picker.PickServer()
assert.Port(server.Destination().Port()).Equals(1)
assert.Port(server.Destination().Port).Equals(1)
}

View File

@@ -62,7 +62,7 @@ func NewServerSpec(newAccount NewAccountFactory, dest v2net.Destination, valid V
func NewServerSpecFromPB(newAccount NewAccountFactory, spec ServerSpecPB) *ServerSpec {
dest := v2net.TCPDestination(spec.Address.AsAddress(), v2net.Port(spec.Port))
return NewServerSpec(newAccount, dest, AlwaysValid(), spec.Users...)
return NewServerSpec(newAccount, dest, AlwaysValid(), spec.User...)
}
func (this *ServerSpec) Destination() v2net.Destination {

View File

@@ -18,7 +18,7 @@ package protocol
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_common_net "v2ray.com/core/common/net"
import v2ray_core_common_net "v2ray.com/core/common/net"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -32,9 +32,9 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type ServerSpecPB struct {
Address *com_v2ray_core_common_net.AddressPB `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
Users []*User `protobuf:"bytes,3,rep,name=users" json:"users,omitempty"`
Address *v2ray_core_common_net.AddressPB `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
User []*User `protobuf:"bytes,3,rep,name=user" json:"user,omitempty"`
}
func (m *ServerSpecPB) Reset() { *m = ServerSpecPB{} }
@@ -42,40 +42,40 @@ func (m *ServerSpecPB) String() string { return proto.CompactTextStri
func (*ServerSpecPB) ProtoMessage() {}
func (*ServerSpecPB) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *ServerSpecPB) GetAddress() *com_v2ray_core_common_net.AddressPB {
func (m *ServerSpecPB) GetAddress() *v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
func (m *ServerSpecPB) GetUsers() []*User {
func (m *ServerSpecPB) GetUser() []*User {
if m != nil {
return m.Users
return m.User
}
return nil
}
func init() {
proto.RegisterType((*ServerSpecPB)(nil), "com.v2ray.core.common.protocol.ServerSpecPB")
proto.RegisterType((*ServerSpecPB)(nil), "v2ray.core.common.protocol.ServerSpecPB")
}
func init() { proto.RegisterFile("v2ray.com/core/common/protocol/server_spec.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 209 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x8e, 0x3f, 0x4b, 0xc5, 0x30,
0x14, 0xc5, 0x89, 0xf5, 0x1f, 0x51, 0x97, 0x4c, 0xa5, 0x83, 0x14, 0x11, 0xac, 0xcb, 0x8d, 0xd4,
0xcd, 0x41, 0xb0, 0x9f, 0xa0, 0xb4, 0xb8, 0xb8, 0x48, 0x4d, 0xef, 0x66, 0x7a, 0xc3, 0x4d, 0x2c,
0xf8, 0x65, 0xfc, 0xac, 0xf2, 0x92, 0x97, 0xad, 0xbc, 0xb7, 0x1d, 0x0e, 0xe7, 0x77, 0xce, 0x91,
0x4f, 0x6b, 0xcb, 0xd3, 0x2f, 0x18, 0xb2, 0xda, 0x10, 0xa3, 0x36, 0x64, 0x2d, 0x2d, 0xda, 0x31,
0x05, 0x32, 0xf4, 0xad, 0x3d, 0xf2, 0x8a, 0xfc, 0xe9, 0x1d, 0x1a, 0x88, 0xa6, 0xba, 0x35, 0x64,
0x21, 0x53, 0x8c, 0x90, 0x08, 0xc8, 0x44, 0xf5, 0xb0, 0xdd, 0xb8, 0x60, 0xd0, 0xd3, 0x3c, 0x33,
0x7a, 0x9f, 0xb2, 0xd5, 0xe3, 0x91, 0xe9, 0x1f, 0x8f, 0x9c, 0xa2, 0x77, 0x7f, 0x42, 0x5e, 0x8f,
0xf1, 0xc9, 0xe8, 0xd0, 0xf4, 0x9d, 0x7a, 0x95, 0x17, 0xfb, 0xb2, 0x52, 0xd4, 0xa2, 0xb9, 0x6a,
0xef, 0x61, 0xfb, 0xd6, 0x82, 0x01, 0xde, 0x52, 0xb2, 0xef, 0x86, 0x0c, 0x29, 0x25, 0x4f, 0x1d,
0x71, 0x28, 0x4f, 0x6a, 0xd1, 0xdc, 0x0c, 0x51, 0xab, 0x17, 0x79, 0xb6, 0x9b, 0xf4, 0x65, 0x51,
0x17, 0x07, 0x1a, 0xf3, 0x3f, 0x78, 0xf7, 0xc8, 0x43, 0x42, 0x3a, 0xf9, 0x71, 0x99, 0xfd, 0xaf,
0xf3, 0xa8, 0x9e, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xde, 0x92, 0x28, 0x40, 0x5b, 0x01, 0x00,
0x00,
// 216 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x8e, 0x3f, 0x4b, 0xc7, 0x30,
0x10, 0x86, 0x89, 0xbf, 0xa2, 0x12, 0x15, 0x21, 0x53, 0xe9, 0x20, 0xc1, 0xc5, 0xba, 0x24, 0x52,
0x9d, 0x74, 0x32, 0x9f, 0xa0, 0xb4, 0xb8, 0xb8, 0x48, 0x4d, 0x6f, 0x33, 0xbd, 0x70, 0x89, 0x05,
0xbf, 0x87, 0x1f, 0x58, 0x9a, 0x18, 0x10, 0xfc, 0xb7, 0x1d, 0x77, 0xcf, 0xbd, 0xef, 0xc3, 0xaf,
0xd6, 0x8e, 0xa6, 0x37, 0x65, 0xd1, 0x69, 0x8b, 0x04, 0xda, 0xa2, 0x73, 0xb8, 0x68, 0x4f, 0x18,
0xd1, 0xe2, 0x8b, 0x0e, 0x40, 0x2b, 0xd0, 0x53, 0xf0, 0x60, 0x55, 0x5a, 0x8a, 0xa6, 0x7c, 0x10,
0xa8, 0x4c, 0xab, 0x42, 0x37, 0x17, 0x3f, 0xa7, 0x2d, 0x10, 0xf5, 0x34, 0xcf, 0x04, 0x21, 0x64,
0xb6, 0xb9, 0xfc, 0xa7, 0xf6, 0x35, 0x00, 0x65, 0xf4, 0xfc, 0x9d, 0xf1, 0xe3, 0x31, 0x59, 0x8c,
0x1e, 0x6c, 0x6f, 0xc4, 0x2d, 0x3f, 0xf8, 0x0c, 0xab, 0x99, 0x64, 0xed, 0x51, 0x27, 0xd5, 0x77,
0xa5, 0x05, 0xa2, 0xba, 0xcf, 0x54, 0x6f, 0x86, 0xf2, 0x20, 0x04, 0xaf, 0x3c, 0x52, 0xac, 0xf7,
0x24, 0x6b, 0x4f, 0x86, 0x34, 0x8b, 0x1b, 0x5e, 0x6d, 0x75, 0xf5, 0x4e, 0xee, 0x7e, 0x09, 0x2b,
0x5a, 0xea, 0x21, 0x00, 0x0d, 0x89, 0x36, 0x77, 0xfc, 0xcc, 0xa2, 0xfb, 0x03, 0x36, 0xa7, 0x5f,
0xac, 0xb7, 0xdd, 0xe3, 0x61, 0x39, 0x3d, 0xef, 0xa7, 0xe9, 0xfa, 0x23, 0x00, 0x00, 0xff, 0xff,
0x30, 0xc6, 0x1e, 0xae, 0x7e, 0x01, 0x00, 0x00,
}

View File

@@ -1,13 +1,15 @@
syntax = "proto3";
package v2ray.core.common.protocol;
option go_package = "protocol";
option java_package = "com.v2ray.core.common.protocol";
option java_outer_classname = "ServerSpecProto";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/protocol/user.proto";
package com.v2ray.core.common.protocol;
option go_package = "protocol";
message ServerSpecPB {
com.v2ray.core.common.net.AddressPB address = 1;
v2ray.core.common.net.AddressPB address = 1;
uint32 port = 2;
repeated com.v2ray.core.common.protocol.User users = 3;
repeated v2ray.core.common.protocol.User user = 3;
}

View File

@@ -33,23 +33,23 @@ func (m *User) GetAccount() *google_protobuf.Any {
}
func init() {
proto.RegisterType((*User)(nil), "com.v2ray.core.common.protocol.User")
proto.RegisterType((*User)(nil), "v2ray.core.common.protocol.User")
}
func init() { proto.RegisterFile("v2ray.com/core/common/protocol/user.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 179 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x34, 0x8e, 0xcb, 0xaa, 0xc2, 0x30,
0x10, 0x86, 0xc9, 0x39, 0x5e, 0x23, 0x6e, 0x4a, 0x17, 0xd5, 0x85, 0x14, 0x57, 0x75, 0x33, 0x81,
0xfa, 0x04, 0xfa, 0x08, 0x05, 0x37, 0xee, 0xd2, 0x61, 0x2c, 0x42, 0x92, 0x91, 0xf4, 0x02, 0x79,
0x7b, 0xb1, 0x21, 0xbb, 0xf9, 0x66, 0xbe, 0xe1, 0xff, 0xe5, 0x65, 0xaa, 0xbd, 0x0e, 0x80, 0x6c,
0x15, 0xb2, 0x27, 0x85, 0x6c, 0x2d, 0x3b, 0xf5, 0xf1, 0x3c, 0x30, 0xb2, 0x51, 0x63, 0x4f, 0x1e,
0x66, 0xca, 0x4e, 0xc8, 0x16, 0x92, 0xee, 0x09, 0xa2, 0x0a, 0x49, 0x3d, 0x1e, 0x3a, 0xe6, 0xce,
0x50, 0xfc, 0x6d, 0xc7, 0x97, 0xd2, 0x2e, 0xc4, 0xeb, 0xb9, 0x95, 0x8b, 0x47, 0x4f, 0x3e, 0xcb,
0xe5, 0xd2, 0xd0, 0x44, 0xa6, 0x10, 0xa5, 0xa8, 0xf6, 0x4d, 0x84, 0xdf, 0x96, 0xac, 0x7e, 0x9b,
0xe2, 0xaf, 0x14, 0xd5, 0xb6, 0x89, 0x90, 0x81, 0x5c, 0x6b, 0x44, 0x1e, 0xdd, 0x50, 0xfc, 0x97,
0xa2, 0xda, 0xd5, 0x39, 0xc4, 0x00, 0x48, 0x01, 0x70, 0x73, 0xa1, 0x49, 0xd2, 0x5d, 0x3e, 0x37,
0xa9, 0x4a, 0xbb, 0x9a, 0xa7, 0xeb, 0x37, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x7e, 0xbf, 0xfa, 0xde,
0x00, 0x00, 0x00,
// 192 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x8e, 0xbd, 0xea, 0xc2, 0x30,
0x14, 0xc5, 0xc9, 0xff, 0x43, 0x6d, 0xc4, 0xa5, 0x74, 0xa8, 0x1d, 0xa4, 0x38, 0xd5, 0xe5, 0x06,
0x2a, 0x3e, 0x80, 0x7d, 0x02, 0x29, 0xb8, 0xb8, 0xa5, 0xe1, 0x5a, 0x84, 0x24, 0x57, 0xd2, 0x0f,
0xe8, 0xdb, 0x4b, 0x1b, 0x32, 0xba, 0xe5, 0x77, 0xf2, 0xbb, 0x9c, 0xc3, 0x4f, 0x63, 0xe9, 0xe4,
0x04, 0x8a, 0x8c, 0x50, 0xe4, 0x50, 0x28, 0x32, 0x86, 0xac, 0x78, 0x3b, 0xea, 0x49, 0x91, 0x16,
0x43, 0x87, 0x0e, 0x16, 0x8a, 0xb3, 0xa0, 0x3a, 0x04, 0xaf, 0x41, 0xd0, 0xb2, 0x7d, 0x4b, 0xd4,
0x6a, 0xf4, 0x77, 0xcd, 0xf0, 0x14, 0xd2, 0x4e, 0xfe, 0xf7, 0xd8, 0xf0, 0xbf, 0x7b, 0x87, 0x2e,
0x4e, 0xf8, 0xbf, 0xc6, 0x11, 0x75, 0xca, 0x72, 0x56, 0xec, 0x6a, 0x0f, 0x73, 0x8a, 0x46, 0xbe,
0x74, 0xfa, 0x93, 0xb3, 0x22, 0xaa, 0x3d, 0xc4, 0xc0, 0xd7, 0x52, 0x29, 0x1a, 0x6c, 0x9f, 0xfe,
0xe6, 0xac, 0xd8, 0x96, 0x09, 0xf8, 0x02, 0x08, 0x05, 0x70, 0xb5, 0x53, 0x1d, 0xa4, 0xea, 0xc2,
0x0f, 0x8a, 0x0c, 0x7c, 0x1f, 0x58, 0x45, 0xf3, 0x86, 0xdb, 0x4c, 0x8f, 0x4d, 0x08, 0x9b, 0xd5,
0xf2, 0x3a, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xd8, 0xfc, 0x46, 0xc6, 0x05, 0x01, 0x00, 0x00,
}

View File

@@ -1,9 +1,11 @@
syntax = "proto3";
import "google/protobuf/any.proto";
package com.v2ray.core.common.protocol;
package v2ray.core.common.protocol;
option go_package = "protocol";
option java_package = "com.v2ray.core.common.protocol";
option java_outer_classname = "UserProto";
import "google/protobuf/any.proto";
message User {
uint32 level = 1;

View File

@@ -8,7 +8,7 @@ import (
)
var (
version = "2.2"
version = "2.3"
build = "Custom"
codename = "One for all"
intro = "An unified platform for anti-censorship."

View File

@@ -6,21 +6,24 @@ import (
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/proxy/registry"
"v2ray.com/core/transport/internet"
"v2ray.com/core/transport/ray"
)
// BlackHole is an outbound connection that sliently swallow the entire payload.
type BlackHole struct {
meta *proxy.OutboundHandlerMeta
response Response
response ResponseConfig
}
func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) *BlackHole {
func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) (*BlackHole, error) {
response, err := config.Response.GetInternalResponse()
if err != nil {
return nil, err
}
return &BlackHole{
meta: meta,
response: config.Response,
}
response: response,
}, nil
}
func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
@@ -36,12 +39,14 @@ func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Bu
type Factory struct{}
func (this *Factory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
return NewBlackHole(space, config.(*Config), meta), nil
return NewBlackHole(space, config.(*Config), meta)
}
func init() {

View File

@@ -3,23 +3,14 @@ package blackhole
import (
"v2ray.com/core/common/alloc"
v2io "v2ray.com/core/common/io"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"strings"
"v2ray.com/core/common/loader"
)
type Config struct {
Response Response
}
type Response interface {
WriteTo(v2io.Writer)
}
type NoneResponse struct{}
func (this *NoneResponse) WriteTo(writer v2io.Writer) {}
type HTTPResponse struct {
}
const (
http403response = `HTTP/1.1 403 Forbidden
Connection: close
@@ -30,6 +21,51 @@ Content-Length: 0
`
)
type ResponseConfig interface {
AsAny() *any.Any
WriteTo(v2io.Writer)
}
func (this *NoneResponse) WriteTo(v2io.Writer) {}
func (this *NoneResponse) AsAny() *any.Any {
r, _ := ptypes.MarshalAny(this)
return r
}
func (this *HTTPResponse) WriteTo(writer v2io.Writer) {
writer.Write(alloc.NewLocalBuffer(512).Clear().AppendString(http403response))
}
func (this *HTTPResponse) AsAny() *any.Any {
r, _ := ptypes.MarshalAny(this)
return r
}
func (this *Response) GetInternalResponse() (ResponseConfig, error) {
if this == nil {
return new(NoneResponse), nil
}
var r ResponseConfig
switch this.Type {
case Response_None:
r = new(NoneResponse)
case Response_HTTP:
r = new(HTTPResponse)
}
err := ptypes.UnmarshalAny(this.Settings, r.(proto.Message))
if err != nil {
return nil, err
}
return r, nil
}
var (
cache = loader.ConfigCreatorCache{}
)
func init() {
cache.RegisterCreator(strings.ToLower(Response_Type_name[int32(Response_None)]), func() interface{} { return new(NoneResponse) })
cache.RegisterCreator(strings.ToLower(Response_Type_name[int32(Response_HTTP)]), func() interface{} { return new(HTTPResponse) })
}

View File

@@ -0,0 +1,134 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/blackhole/config.proto
// DO NOT EDIT!
/*
Package blackhole is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/blackhole/config.proto
It has these top-level messages:
NoneResponse
HTTPResponse
Response
Config
*/
package blackhole
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/ptypes/any"
// 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 Response_Type int32
const (
Response_None Response_Type = 0
Response_HTTP Response_Type = 1
)
var Response_Type_name = map[int32]string{
0: "None",
1: "HTTP",
}
var Response_Type_value = map[string]int32{
"None": 0,
"HTTP": 1,
}
func (x Response_Type) String() string {
return proto.EnumName(Response_Type_name, int32(x))
}
func (Response_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2, 0} }
type NoneResponse struct {
}
func (m *NoneResponse) Reset() { *m = NoneResponse{} }
func (m *NoneResponse) String() string { return proto.CompactTextString(m) }
func (*NoneResponse) ProtoMessage() {}
func (*NoneResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type HTTPResponse struct {
}
func (m *HTTPResponse) Reset() { *m = HTTPResponse{} }
func (m *HTTPResponse) String() string { return proto.CompactTextString(m) }
func (*HTTPResponse) ProtoMessage() {}
func (*HTTPResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type Response struct {
Type Response_Type `protobuf:"varint,1,opt,name=type,enum=v2ray.core.proxy.blackhole.Response_Type" json:"type,omitempty"`
Settings *google_protobuf.Any `protobuf:"bytes,2,opt,name=settings" json:"settings,omitempty"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (*Response) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *Response) GetSettings() *google_protobuf.Any {
if m != nil {
return m.Settings
}
return nil
}
type Config struct {
Response *Response `protobuf:"bytes,1,opt,name=response" json:"response,omitempty"`
}
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{3} }
func (m *Config) GetResponse() *Response {
if m != nil {
return m.Response
}
return nil
}
func init() {
proto.RegisterType((*NoneResponse)(nil), "v2ray.core.proxy.blackhole.NoneResponse")
proto.RegisterType((*HTTPResponse)(nil), "v2ray.core.proxy.blackhole.HTTPResponse")
proto.RegisterType((*Response)(nil), "v2ray.core.proxy.blackhole.Response")
proto.RegisterType((*Config)(nil), "v2ray.core.proxy.blackhole.Config")
proto.RegisterEnum("v2ray.core.proxy.blackhole.Response_Type", Response_Type_name, Response_Type_value)
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/blackhole/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 261 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x90, 0x41, 0x4b, 0xc3, 0x30,
0x18, 0x86, 0xad, 0x8c, 0x51, 0xbf, 0xca, 0x18, 0xc5, 0xc3, 0xec, 0x41, 0x46, 0xf1, 0x30, 0x11,
0xbe, 0x48, 0xbd, 0x78, 0x11, 0x74, 0x5e, 0xc4, 0x83, 0x8c, 0xd2, 0x93, 0xb7, 0x36, 0x64, 0x75,
0xd8, 0xe5, 0x0b, 0x69, 0x14, 0xf3, 0x4b, 0xfc, 0xbb, 0x92, 0xd4, 0xe6, 0xa6, 0x78, 0xcb, 0x1b,
0xde, 0x27, 0xef, 0x43, 0xe0, 0xf2, 0xa3, 0xd0, 0xb5, 0x45, 0x4e, 0x7b, 0xc6, 0x49, 0x0b, 0xa6,
0x34, 0x7d, 0x5a, 0xd6, 0x74, 0x35, 0x7f, 0x7b, 0xa5, 0x4e, 0x30, 0x4e, 0x72, 0xbb, 0x6b, 0x51,
0x69, 0x32, 0x94, 0x66, 0x63, 0x59, 0x0b, 0xf4, 0x45, 0x0c, 0xc5, 0xec, 0xb4, 0x25, 0x6a, 0x3b,
0xff, 0x80, 0xa1, 0xe6, 0x7d, 0xcb, 0x6a, 0x69, 0x07, 0x2c, 0x9f, 0xc1, 0xf1, 0x33, 0x49, 0x51,
0x8a, 0x5e, 0x91, 0xec, 0x85, 0xcb, 0x8f, 0x55, 0xb5, 0x09, 0xf9, 0x2b, 0x82, 0x78, 0x0c, 0xe9,
0x2d, 0x4c, 0x8c, 0x55, 0x62, 0x11, 0x2d, 0xa3, 0xd5, 0xac, 0xb8, 0xc0, 0xdf, 0x27, 0x71, 0x64,
0xb0, 0xb2, 0x4a, 0x94, 0x1e, 0x4b, 0xaf, 0x20, 0xee, 0x85, 0x31, 0x3b, 0xd9, 0xf6, 0x8b, 0xc3,
0x65, 0xb4, 0x4a, 0x8a, 0x13, 0x1c, 0xcc, 0x70, 0x34, 0xc3, 0x7b, 0x69, 0xcb, 0xd0, 0xca, 0x33,
0x98, 0x38, 0x3e, 0x8d, 0x61, 0xe2, 0x2c, 0xe7, 0x07, 0xee, 0xe4, 0xfc, 0xe6, 0x51, 0xfe, 0x04,
0xd3, 0x07, 0xff, 0x01, 0xe9, 0x1d, 0xc4, 0xfa, 0x67, 0xce, 0xab, 0x25, 0xc5, 0xf9, 0x7f, 0xd4,
0xca, 0x40, 0xad, 0x6f, 0xe0, 0x8c, 0xd3, 0xfe, 0x0f, 0x68, 0x9d, 0x0c, 0x5b, 0x1b, 0xe7, 0xf9,
0x72, 0x14, 0xee, 0x9b, 0xa9, 0x37, 0xbf, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x62, 0xb1, 0x35,
0x74, 0xac, 0x01, 0x00, 0x00,
}

View File

@@ -0,0 +1,29 @@
syntax = "proto3";
package v2ray.core.proxy.blackhole;
option go_package = "blackhole";
option java_package = "com.v2ray.core.proxy.blackhole";
option java_outer_classname = "ConfigProto";
import "google/protobuf/any.proto";
message NoneResponse {
}
message HTTPResponse {
}
message Response {
enum Type {
None = 0;
HTTP = 1;
}
Type type = 1;
google.protobuf.Any settings = 2;
}
message Config {
Response response = 1;
}

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"strings"
"v2ray.com/core/common/loader"
"v2ray.com/core/proxy/registry"
)
@@ -19,21 +20,28 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return errors.New("Blackhole: Failed to parse config: " + err.Error())
}
this.Response = new(NoneResponse)
if jsonConfig.Response != nil {
loader := loader.NewJSONConfigLoader("type", "")
loader.RegisterCreator("none", func() interface{} { return new(NoneResponse) })
loader.RegisterCreator("http", func() interface{} { return new(HTTPResponse) })
response, _, err := loader.Load(jsonConfig.Response)
response, rType, err := configLoader.Load(jsonConfig.Response)
if err != nil {
return errors.New("Blackhole: Failed to parse response config: " + err.Error())
}
this.Response = response.(Response)
this.Response = new(Response)
switch rType {
case strings.ToLower(Response_Type_name[int32(Response_None)]):
this.Response.Type = Response_None
case strings.ToLower(Response_Type_name[int32(Response_HTTP)]):
this.Response.Type = Response_HTTP
}
this.Response.Settings = response.(ResponseConfig).AsAny()
}
return nil
}
var (
configLoader = loader.NewJSONConfigLoader(cache, "type", "")
)
func init() {
registry.RegisterOutboundConfig("blackhole", func() interface{} { return new(Config) })
}

View File

@@ -22,6 +22,10 @@ func TestHTTPResponseJSON(t *testing.T) {
err := json.Unmarshal([]byte(rawJson), config)
assert.Error(err).IsNil()
_, ok := config.Response.(*HTTPResponse)
assert.Int(int(config.Response.Type)).Equals(int(Response_HTTP))
response, err := config.Response.GetInternalResponse()
assert.Error(err).IsNil()
_, ok := response.(*HTTPResponse)
assert.Bool(ok).IsTrue()
}

View File

@@ -4,10 +4,10 @@ import (
v2net "v2ray.com/core/common/net"
)
type Config struct {
FollowRedirect bool
Address v2net.Address
Port v2net.Port
Network *v2net.NetworkList
Timeout uint32
func (this *Config) GetPredefinedAddress() v2net.Address {
addr := this.Address.AsAddress()
if addr == nil {
return nil
}
return addr
}

View File

@@ -0,0 +1,85 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/dokodemo/config.proto
// DO NOT EDIT!
/*
Package dokodemo is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/dokodemo/config.proto
It has these top-level messages:
Config
*/
package dokodemo
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import v2ray_core_common_net "v2ray.com/core/common/net"
import v2ray_core_common_net1 "v2ray.com/core/common/net"
// 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 {
Address *v2ray_core_common_net.AddressPB `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
NetworkList *v2ray_core_common_net1.NetworkList `protobuf:"bytes,3,opt,name=network_list,json=networkList" json:"network_list,omitempty"`
Timeout uint32 `protobuf:"varint,4,opt,name=timeout" json:"timeout,omitempty"`
FollowRedirect bool `protobuf:"varint,5,opt,name=follow_redirect,json=followRedirect" json:"follow_redirect,omitempty"`
}
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 (m *Config) GetAddress() *v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
func (m *Config) GetNetworkList() *v2ray_core_common_net1.NetworkList {
if m != nil {
return m.NetworkList
}
return nil
}
func init() {
proto.RegisterType((*Config)(nil), "v2ray.core.proxy.dokodemo.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/dokodemo/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 269 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x90, 0x4d, 0x4b, 0xc3, 0x40,
0x10, 0x86, 0x89, 0xd6, 0xb6, 0x6c, 0xfd, 0x80, 0x3d, 0xad, 0x82, 0x10, 0x7a, 0x69, 0xf0, 0xb0,
0x0b, 0x15, 0x3c, 0x78, 0x33, 0xe2, 0x4d, 0xa4, 0xe4, 0xe8, 0xa5, 0xd4, 0xcd, 0x54, 0x42, 0xb3,
0x3b, 0x61, 0x32, 0x5a, 0xfb, 0x77, 0xfd, 0x25, 0xe2, 0x6e, 0x82, 0x22, 0xd4, 0xdb, 0xce, 0xcb,
0xb3, 0xcf, 0x0c, 0xaf, 0xb8, 0x7a, 0x9f, 0xd3, 0x6a, 0xa7, 0x2d, 0x3a, 0x63, 0x91, 0xc0, 0x34,
0x84, 0x1f, 0x3b, 0x53, 0xe2, 0x06, 0x4b, 0x70, 0x68, 0x2c, 0xfa, 0x75, 0xf5, 0xaa, 0x1b, 0x42,
0x46, 0x79, 0xde, 0xb3, 0x04, 0x3a, 0x70, 0xba, 0xe7, 0x2e, 0x66, 0x7f, 0x34, 0x16, 0x9d, 0x43,
0x6f, 0x3c, 0xb0, 0x59, 0x95, 0x25, 0x41, 0xdb, 0x46, 0xc7, 0x7f, 0xa0, 0x07, 0xde, 0x22, 0x6d,
0x22, 0x38, 0xfd, 0x4c, 0xc4, 0xf0, 0x3e, 0x6c, 0x97, 0xb7, 0x62, 0xd4, 0x49, 0x54, 0x92, 0x26,
0xd9, 0x64, 0x9e, 0xea, 0x5f, 0x97, 0x44, 0x83, 0xf6, 0xc0, 0xfa, 0x2e, 0x52, 0x8b, 0xbc, 0xe8,
0x3f, 0x48, 0x29, 0x06, 0x0d, 0x12, 0xab, 0x83, 0x34, 0xc9, 0x4e, 0x8a, 0xf0, 0x96, 0x0f, 0xe2,
0xb8, 0xdb, 0xb5, 0xac, 0xab, 0x96, 0xd5, 0x61, 0x90, 0x4e, 0xf7, 0x48, 0x9f, 0x22, 0xfa, 0x58,
0xb5, 0x5c, 0x4c, 0xfc, 0xcf, 0x20, 0x95, 0x18, 0x71, 0xe5, 0x00, 0xdf, 0x58, 0x0d, 0x82, 0xbd,
0x1f, 0xe5, 0x4c, 0x9c, 0xad, 0xb1, 0xae, 0x71, 0xbb, 0x24, 0x28, 0x2b, 0x02, 0xcb, 0xea, 0x28,
0x4d, 0xb2, 0x71, 0x71, 0x1a, 0xe3, 0xa2, 0x4b, 0xf3, 0x1b, 0x71, 0x69, 0xd1, 0xe9, 0xbd, 0xbd,
0xe6, 0x93, 0x58, 0xc1, 0xe2, 0xbb, 0x92, 0xe7, 0x71, 0x1f, 0xbf, 0x0c, 0x43, 0x47, 0xd7, 0x5f,
0x01, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xa7, 0xda, 0x7b, 0xbe, 0x01, 0x00, 0x00,
}

View File

@@ -0,0 +1,17 @@
syntax = "proto3";
package v2ray.core.proxy.dokodemo;
option go_package = "dokodemo";
option java_package = "com.v2ray.core.proxy.dokodemo";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/net/network.proto";
message Config {
v2ray.core.common.net.AddressPB address = 1;
uint32 port = 2;
v2ray.core.common.net.NetworkList network_list = 3;
uint32 timeout = 4;
bool follow_redirect = 5;
}

View File

@@ -23,10 +23,10 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return errors.New("Dokodemo: Failed to parse config: " + err.Error())
}
if rawConfig.Host != nil {
this.Address = rawConfig.Host.AsAddress()
this.Address = rawConfig.Host
}
this.Port = rawConfig.PortValue
this.Network = rawConfig.NetworkList
this.Port = uint32(rawConfig.PortValue)
this.NetworkList = rawConfig.NetworkList
this.Timeout = rawConfig.TimeoutValue
this.FollowRedirect = rawConfig.Redirect
return nil

View File

@@ -32,8 +32,8 @@ type DokodemoDoor struct {
func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) *DokodemoDoor {
d := &DokodemoDoor{
config: config,
address: config.Address,
port: config.Port,
address: config.GetPredefinedAddress(),
port: v2net.Port(config.Port),
meta: meta,
}
space.InitializeApplication(func() error {
@@ -73,13 +73,13 @@ func (this *DokodemoDoor) Start() error {
}
this.accepting = true
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
if this.config.NetworkList.HasNetwork(v2net.Network_TCP) {
err := this.ListenTCP()
if err != nil {
return err
}
}
if this.config.Network.HasNetwork(v2net.UDPNetwork) {
if this.config.NetworkList.HasNetwork(v2net.Network_UDP) {
err := this.ListenUDP()
if err != nil {
return err
@@ -106,10 +106,10 @@ func (this *DokodemoDoor) ListenUDP() error {
}
func (this *DokodemoDoor) handleUDPPackets(payload *alloc.Buffer, session *proxy.SessionInfo) {
if session.Destination == nil && this.address != nil && this.port > 0 {
if session.Destination.Network == v2net.Network_Unknown && this.address != nil && this.port > 0 {
session.Destination = v2net.UDPDestination(this.address, this.port)
}
if session.Destination == nil {
if session.Destination.Network == v2net.Network_Unknown {
log.Info("Dokodemo: Unknown destination, stop forwarding...")
return
}
@@ -144,16 +144,16 @@ func (this *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
var dest v2net.Destination
if this.config.FollowRedirect {
originalDest := GetOriginalDestination(conn)
if originalDest != nil {
if originalDest.Network != v2net.Network_Unknown {
log.Info("Dokodemo: Following redirect to: ", originalDest)
dest = originalDest
}
}
if dest == nil && this.address != nil && this.port > v2net.Port(0) {
if dest.Network == v2net.Network_Unknown && this.address != nil && this.port > v2net.Port(0) {
dest = v2net.TCPDestination(this.address, this.port)
}
if dest == nil {
if dest.Network == v2net.Network_Unknown {
log.Info("Dokodemo: Unknown destination, stop forwarding...")
return
}
@@ -194,8 +194,10 @@ func (this *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
type Factory struct{}
func (this *Factory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {

View File

@@ -44,8 +44,8 @@ func TestDokodemoTCP(t *testing.T) {
space,
&proxy.OutboundHandlerMeta{
Address: v2net.LocalHostIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
}))
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
@@ -54,15 +54,19 @@ func TestDokodemoTCP(t *testing.T) {
port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP,
Port: tcpServer.Port,
Network: v2net.TCPNetwork.AsList(),
Timeout: 600,
Address: &v2net.AddressPB{
Address: &v2net.AddressPB_Ip{
Ip: v2net.LocalHostIP.IP(),
},
},
Port: uint32(tcpServer.Port),
NetworkList: v2net.Network_TCP.AsList(),
Timeout: 600,
}, space, &proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP,
Port: port,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
}})
defer dokodemo.Close()
@@ -115,8 +119,8 @@ func TestDokodemoUDP(t *testing.T) {
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
}}))
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
@@ -124,15 +128,19 @@ func TestDokodemoUDP(t *testing.T) {
port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP,
Port: udpServer.Port,
Network: v2net.UDPNetwork.AsList(),
Timeout: 600,
Address: &v2net.AddressPB{
Address: &v2net.AddressPB_Ip{
Ip: v2net.LocalHostIP.IP(),
},
},
Port: uint32(udpServer.Port),
NetworkList: v2net.Network_UDP.AsList(),
Timeout: 600,
}, space, &proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP,
Port: port,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
}})
defer dokodemo.Close()

View File

@@ -16,18 +16,18 @@ func GetOriginalDestination(conn internet.Connection) v2net.Destination {
tcpConn, ok := conn.(internet.SysFd)
if !ok {
log.Info("Dokodemo: Failed to get sys fd.")
return nil
return v2net.Destination{}
}
fd, err := tcpConn.SysFd()
if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err)
return nil
return v2net.Destination{}
}
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
if err != nil {
log.Info("Dokodemo: Failed to call getsockopt: ", err)
return nil
return v2net.Destination{}
}
ip := v2net.IPAddress(addr.Multiaddr[4:8])
port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])

View File

@@ -8,5 +8,5 @@ import (
)
func GetOriginalDestination(conn internet.Connection) v2net.Destination {
return nil
return v2net.Destination{}
}

View File

@@ -50,7 +50,7 @@ func (x Config_DomainStrategy) String() string {
func (Config_DomainStrategy) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0, 0} }
type Config struct {
DomainStrategy Config_DomainStrategy `protobuf:"varint,1,opt,name=domainStrategy,enum=com.v2ray.core.proxy.freedom.Config_DomainStrategy" json:"domainStrategy,omitempty"`
DomainStrategy Config_DomainStrategy `protobuf:"varint,1,opt,name=domainStrategy,enum=v2ray.core.proxy.freedom.Config_DomainStrategy" json:"domainStrategy,omitempty"`
Timeout uint32 `protobuf:"varint,2,opt,name=timeout" json:"timeout,omitempty"`
}
@@ -60,24 +60,25 @@ func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.proxy.freedom.Config")
proto.RegisterEnum("com.v2ray.core.proxy.freedom.Config_DomainStrategy", Config_DomainStrategy_name, Config_DomainStrategy_value)
proto.RegisterType((*Config)(nil), "v2ray.core.proxy.freedom.Config")
proto.RegisterEnum("v2ray.core.proxy.freedom.Config_DomainStrategy", Config_DomainStrategy_name, Config_DomainStrategy_value)
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/freedom/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 188 bytes of a gzipped FileDescriptorProto
// 199 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x28, 0xca, 0xaf, 0xa8,
0xd4, 0x4f, 0x2b, 0x4a, 0x4d, 0x4d, 0x01, 0x0b, 0xe5, 0xa5, 0x65, 0xa6, 0xeb, 0x15, 0x14, 0xe5,
0x97, 0xe4, 0x0b, 0xc9, 0x24, 0xe7, 0xe7, 0xea, 0xc1, 0x94, 0x17, 0xa5, 0xea, 0x81, 0x95, 0xea,
0x41, 0x95, 0x2a, 0xad, 0x60, 0xe4, 0x62, 0x73, 0x06, 0x2b, 0x17, 0x8a, 0xe6, 0xe2, 0x4b, 0xc9,
0xcf, 0x4d, 0xcc, 0xcc, 0x0b, 0x2e, 0x29, 0x4a, 0x2c, 0x49, 0x4d, 0xaf, 0x94, 0x60, 0x54, 0x60,
0xd4, 0xe0, 0x33, 0x32, 0xd6, 0xc3, 0x67, 0x82, 0x1e, 0x44, 0xb7, 0x9e, 0x0b, 0x8a, 0xd6, 0x20,
0x34, 0xa3, 0x84, 0x24, 0xb8, 0xd8, 0x4b, 0x32, 0x73, 0x53, 0xf3, 0x4b, 0x4b, 0x24, 0x98, 0x14,
0x18, 0x35, 0x78, 0x83, 0x60, 0x5c, 0x25, 0x75, 0x2e, 0x3e, 0x54, 0xbd, 0x42, 0x9c, 0x5c, 0xac,
0x8e, 0xc1, 0xf1, 0x9e, 0xc1, 0x02, 0x0c, 0x42, 0x5c, 0x5c, 0x6c, 0xa1, 0xc1, 0xae, 0xf1, 0x9e,
0x01, 0x02, 0x8c, 0x4e, 0x9c, 0x51, 0xec, 0x50, 0x3b, 0x93, 0xd8, 0xc0, 0x5e, 0x33, 0x06, 0x04,
0x00, 0x00, 0xff, 0xff, 0x62, 0xf0, 0x2b, 0xbf, 0x07, 0x01, 0x00, 0x00,
0x97, 0xe4, 0x0b, 0x49, 0xc0, 0x94, 0x16, 0xa5, 0xea, 0x81, 0x95, 0xe9, 0x41, 0x95, 0x29, 0x2d,
0x61, 0xe4, 0x62, 0x73, 0x06, 0x2b, 0x15, 0x0a, 0xe7, 0xe2, 0x4b, 0xc9, 0xcf, 0x4d, 0xcc, 0xcc,
0x0b, 0x2e, 0x29, 0x4a, 0x2c, 0x49, 0x4d, 0xaf, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x33, 0xd2,
0xd7, 0xc3, 0xa5, 0x5b, 0x0f, 0xa2, 0x53, 0xcf, 0x05, 0x45, 0x5b, 0x10, 0x9a, 0x31, 0x42, 0x12,
0x5c, 0xec, 0x25, 0x99, 0xb9, 0xa9, 0xf9, 0xa5, 0x25, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xbc, 0x41,
0x30, 0xae, 0x92, 0x3a, 0x17, 0x1f, 0xaa, 0x5e, 0x21, 0x4e, 0x2e, 0x56, 0xc7, 0xe0, 0x78, 0xcf,
0x60, 0x01, 0x06, 0x21, 0x2e, 0x2e, 0xb6, 0xd0, 0x60, 0xd7, 0x78, 0xcf, 0x00, 0x01, 0x46, 0x27,
0x13, 0x2e, 0x99, 0xe4, 0xfc, 0x5c, 0x9c, 0x0e, 0x71, 0xe2, 0x86, 0xb8, 0x24, 0x00, 0xe4, 0xdb,
0x28, 0x76, 0xa8, 0x68, 0x12, 0x1b, 0xd8, 0xf7, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x36,
0x2d, 0x5d, 0x28, 0x2a, 0x01, 0x00, 0x00,
}

View File

@@ -1,7 +1,9 @@
syntax = "proto3";
package com.v2ray.core.proxy.freedom;
package v2ray.core.proxy.freedom;
option go_package = "freedom";
option java_package = "com.v2ray.core.proxy.freedom";
option java_outer_classname = "ConfigProto";
message Config {
enum DomainStrategy {

View File

@@ -46,11 +46,11 @@ func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundH
// Private: Visible for testing.
func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Destination {
if !destination.Address().Family().IsDomain() {
if !destination.Address.Family().IsDomain() {
return destination
}
ips := this.dns.Get(destination.Address().Domain())
ips := this.dns.Get(destination.Address.Domain())
if len(ips) == 0 {
log.Info("Freedom: DNS returns nil answer. Keep domain as is.")
return destination
@@ -58,10 +58,10 @@ func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.De
ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination
if destination.Network() == v2net.TCPNetwork {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port())
if destination.Network == v2net.Network_TCP {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port)
} else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port())
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port)
}
log.Info("Freedom: Changing destination from ", destination, " to ", newDest)
return newDest
@@ -75,7 +75,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
defer ray.OutboundOutput().Close()
var conn internet.Connection
if this.domainStrategy == Config_USE_IP && destination.Address().Family().IsDomain() {
if this.domainStrategy == Config_USE_IP && destination.Address.Family().IsDomain() {
destination = this.ResolveIP(destination)
}
err := retry.Timed(5, 100).On(func() error {
@@ -112,7 +112,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
var reader io.Reader = conn
timeout := this.timeout
if destination.Network() == v2net.UDPNetwork {
if destination.Network == v2net.Network_UDP {
timeout = 16
}
if timeout > 0 {
@@ -129,8 +129,10 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
type FreedomFactory struct{}
func (this *FreedomFactory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *FreedomFactory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *FreedomFactory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {

View File

@@ -1,7 +1,6 @@
package freedom_test
import (
"net"
"testing"
"v2ray.com/core/app"
@@ -41,8 +40,8 @@ func TestSinglePacket(t *testing.T) {
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
})
space.Initialize()
@@ -69,8 +68,8 @@ func TestUnreachableDestination(t *testing.T) {
app.NewSpace(),
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
})
traffic := ray.NewRay()
@@ -90,8 +89,12 @@ func TestIPResolution(t *testing.T) {
r, _ := router.CreateRouter("rules", &rules.RouterRuleConfig{}, space)
space.BindApp(router.APP_ID, r)
dnsServer := dns.NewCacheServer(space, &dns.Config{
Hosts: map[string]net.IP{
"v2ray.com": net.IP([]byte{127, 0, 0, 1}),
Hosts: map[string]*v2net.AddressPB{
"v2ray.com": &v2net.AddressPB{
Address: &v2net.AddressPB_Ip{
Ip: []byte{127, 0, 0, 1},
},
},
},
})
space.BindApp(dns.APP_ID, dnsServer)
@@ -101,8 +104,8 @@ func TestIPResolution(t *testing.T) {
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
})
@@ -110,5 +113,5 @@ func TestIPResolution(t *testing.T) {
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
assert.Destination(ipDest).IsTCP()
assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
assert.Address(ipDest.Address).Equals(v2net.LocalHostIP)
}

View File

@@ -49,21 +49,22 @@ func (*ClientConfig) ProtoMessage() {}
func (*ClientConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func init() {
proto.RegisterType((*ServerConfig)(nil), "com.v2ray.core.proxy.http.ServerConfig")
proto.RegisterType((*ClientConfig)(nil), "com.v2ray.core.proxy.http.ClientConfig")
proto.RegisterType((*ServerConfig)(nil), "v2ray.core.proxy.http.ServerConfig")
proto.RegisterType((*ClientConfig)(nil), "v2ray.core.proxy.http.ClientConfig")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/http/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 136 bytes of a gzipped FileDescriptorProto
// 147 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2b, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x28, 0xca, 0xaf, 0xa8,
0xd4, 0xcf, 0x28, 0x29, 0x29, 0xd0, 0x4f, 0xce, 0xcf, 0x4b, 0xcb, 0x4c, 0xd7, 0x2b, 0x28, 0xca,
0x2f, 0xc9, 0x17, 0x92, 0x4c, 0xce, 0xcf, 0xd5, 0x83, 0xa9, 0x2d, 0x4a, 0xd5, 0x03, 0xab, 0xd3,
0x03, 0xa9, 0x53, 0xd2, 0xe0, 0xe2, 0x09, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x72, 0x06, 0x6b, 0x10,
0x92, 0xe0, 0x62, 0x2f, 0xc9, 0xcc, 0x4d, 0xcd, 0x2f, 0x2d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0,
0x0d, 0x82, 0x71, 0x95, 0xf8, 0xb8, 0x78, 0x9c, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0x20, 0x2a, 0x9d,
0xd8, 0xa2, 0x58, 0x40, 0x26, 0x24, 0xb1, 0x81, 0xed, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff,
0x1e, 0x85, 0x9f, 0xf9, 0x8d, 0x00, 0x00, 0x00,
0x2f, 0xc9, 0x17, 0x12, 0x85, 0xa9, 0x2b, 0x4a, 0xd5, 0x03, 0xab, 0xd1, 0x03, 0xa9, 0x51, 0xd2,
0xe0, 0xe2, 0x09, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x72, 0x06, 0x2b, 0x16, 0x92, 0xe0, 0x62, 0x2f,
0xc9, 0xcc, 0x4d, 0xcd, 0x2f, 0x2d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0d, 0x82, 0x71, 0x95,
0xf8, 0xb8, 0x78, 0x9c, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0x20, 0x2a, 0x9d, 0xf4, 0xb8, 0x24, 0x93,
0xf3, 0x73, 0xf5, 0xb0, 0x1a, 0xeb, 0xc4, 0x0d, 0x51, 0x14, 0x00, 0xb2, 0x3a, 0x8a, 0x05, 0x24,
0x94, 0xc4, 0x06, 0x76, 0x87, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xc7, 0x71, 0x5d, 0x1f, 0xb1,
0x00, 0x00, 0x00,
}

View File

@@ -1,7 +1,9 @@
syntax = "proto3";
package com.v2ray.core.proxy.http;
package v2ray.core.proxy.http;
option go_package = "http";
option java_package = "com.v2ray.core.proxy.http";
option java_outer_classname = "ConfigProto";
// Config for HTTP proxy server.
message ServerConfig {

View File

@@ -77,12 +77,12 @@ func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
host = rawHost
} else {
return nil, err
return v2net.Destination{}, err
}
} else {
intPort, err := strconv.Atoi(rawPort)
if err != nil {
return nil, err
return v2net.Destination{}, err
}
port = v2net.Port(intPort)
}
@@ -264,8 +264,10 @@ func (this *Server) handlePlainHTTP(request *http.Request, session *proxy.Sessio
type ServerFactory struct{}
func (this *ServerFactory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *ServerFactory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {

View File

@@ -63,8 +63,8 @@ func TestNormalGetRequest(t *testing.T) {
&proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP,
Port: port,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
}})
defer httpProxy.Close()

View File

@@ -27,13 +27,13 @@ type InboundHandlerMeta struct {
Address v2net.Address
Port v2net.Port
AllowPassiveConnection bool
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
}
type OutboundHandlerMeta struct {
Tag string
Address v2net.Address
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
}
// An InboundHandler handles inbound network connections to V2Ray.

View File

@@ -3,16 +3,19 @@ package registry
import "v2ray.com/core/common/loader"
var (
inboundConfigCache loader.ConfigLoader
outboundConfigCache loader.ConfigLoader
inboundConfigCreatorCache = loader.ConfigCreatorCache{}
inboundConfigCache loader.ConfigLoader
outboundConfigCreatorCache = loader.ConfigCreatorCache{}
outboundConfigCache loader.ConfigLoader
)
func RegisterInboundConfig(protocol string, creator loader.ConfigCreator) error {
return inboundConfigCache.RegisterCreator(protocol, creator)
return inboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func RegisterOutboundConfig(protocol string, creator loader.ConfigCreator) error {
return outboundConfigCache.RegisterCreator(protocol, creator)
return outboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func CreateInboundConfig(protocol string, data []byte) (interface{}, error) {

View File

@@ -7,6 +7,6 @@ import (
)
func init() {
inboundConfigCache = loader.NewJSONConfigLoader("protocol", "settings")
outboundConfigCache = loader.NewJSONConfigLoader("protocol", "settings")
inboundConfigCache = loader.NewJSONConfigLoader(inboundConfigCreatorCache, "protocol", "settings")
outboundConfigCache = loader.NewJSONConfigLoader(outboundConfigCreatorCache, "protocol", "settings")
}

View File

@@ -2,16 +2,16 @@ package registry
import (
"v2ray.com/core/app"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet"
)
type InboundHandlerFactory interface {
StreamCapability() internet.StreamConnectionType
StreamCapability() v2net.NetworkList
Create(space app.Space, config interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error)
}
type OutboundHandlerFactory interface {
StreamCapability() internet.StreamConnectionType
StreamCapability() v2net.NetworkList
Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error)
}

View File

@@ -1,6 +1,8 @@
package registry
import (
"errors"
"v2ray.com/core/app"
"v2ray.com/core/common"
"v2ray.com/core/proxy"
@@ -46,11 +48,13 @@ func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *
return nil, common.ErrObjectNotFound
}
if meta.StreamSettings == nil {
meta.StreamSettings = &internet.StreamSettings{
Type: creator.StreamCapability(),
meta.StreamSettings = &internet.StreamConfig{
Network: creator.StreamCapability().Get(0),
}
} else {
meta.StreamSettings.Type &= creator.StreamCapability()
if !creator.StreamCapability().HasNetwork(meta.StreamSettings.Network) {
return nil, errors.New("Proxy|Registry: Invalid network: " + meta.StreamSettings.Network.String())
}
}
if len(rawConfig) > 0 {
@@ -69,11 +73,13 @@ func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta
return nil, common.ErrObjectNotFound
}
if meta.StreamSettings == nil {
meta.StreamSettings = &internet.StreamSettings{
Type: creator.StreamCapability(),
meta.StreamSettings = &internet.StreamConfig{
Network: creator.StreamCapability().Get(0),
}
} else {
meta.StreamSettings.Type &= creator.StreamCapability()
if !creator.StreamCapability().HasNetwork(meta.StreamSettings.Network) {
return nil, errors.New("Proxy|Registry: Invalid network: " + meta.StreamSettings.Network.String())
}
}
if len(rawConfig) > 0 {

View File

@@ -3,23 +3,25 @@ package shadowsocks
import (
"crypto/cipher"
"crypto/md5"
"errors"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/protocol"
)
func (this *Config) GetCipher() Cipher {
switch this.Cipher {
case Config_AES_128_CFB:
return &AesCfb{KeyBytes: 16}
case Config_AES_256_CFB:
return &AesCfb{KeyBytes: 32}
case Config_CHACHA20:
return &ChaCha20{IVBytes: 8}
case Config_CHACHA20_IEFT:
return &ChaCha20{IVBytes: 12}
func (this *Account) GetCipher() (Cipher, error) {
switch this.CipherType {
case CipherType_AES_128_CFB:
return &AesCfb{KeyBytes: 16}, nil
case CipherType_AES_256_CFB:
return &AesCfb{KeyBytes: 32}, nil
case CipherType_CHACHA20:
return &ChaCha20{IVBytes: 8}, nil
case CipherType_CHACHA20_IEFT:
return &ChaCha20{IVBytes: 12}, nil
default:
return nil, errors.New("Unsupported cipher.")
}
panic("Failed to create Cipher. Should not happen.")
}
func (this *Account) Equals(another protocol.Account) bool {
@@ -33,8 +35,12 @@ func (this *Account) AsAccount() (protocol.Account, error) {
return this, nil
}
func (this *Account) GetCipherKey(size int) []byte {
return PasswordToCipherKey(this.Password, size)
func (this *Account) GetCipherKey() []byte {
ct, err := this.GetCipher()
if err != nil {
return nil
}
return PasswordToCipherKey(this.Password, ct.KeySize())
}
type Cipher interface {

View File

@@ -10,14 +10,16 @@ It is generated from these files:
It has these top-level messages:
Account
Config
ServerConfig
ClientConfig
*/
package shadowsocks
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_common_protocol "v2ray.com/core/common/protocol"
import v2ray_core_common_protocol "v2ray.com/core/common/protocol"
import v2ray_core_common_protocol1 "v2ray.com/core/common/protocol"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -30,24 +32,24 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Config_Cipher int32
type CipherType int32
const (
Config_UNKNOWN Config_Cipher = 0
Config_AES_128_CFB Config_Cipher = 1
Config_AES_256_CFB Config_Cipher = 2
Config_CHACHA20 Config_Cipher = 3
Config_CHACHA20_IEFT Config_Cipher = 4
CipherType_UNKNOWN CipherType = 0
CipherType_AES_128_CFB CipherType = 1
CipherType_AES_256_CFB CipherType = 2
CipherType_CHACHA20 CipherType = 3
CipherType_CHACHA20_IEFT CipherType = 4
)
var Config_Cipher_name = map[int32]string{
var CipherType_name = map[int32]string{
0: "UNKNOWN",
1: "AES_128_CFB",
2: "AES_256_CFB",
3: "CHACHA20",
4: "CHACHA20_IEFT",
}
var Config_Cipher_value = map[string]int32{
var CipherType_value = map[string]int32{
"UNKNOWN": 0,
"AES_128_CFB": 1,
"AES_256_CFB": 2,
@@ -55,13 +57,14 @@ var Config_Cipher_value = map[string]int32{
"CHACHA20_IEFT": 4,
}
func (x Config_Cipher) String() string {
return proto.EnumName(Config_Cipher_name, int32(x))
func (x CipherType) String() string {
return proto.EnumName(CipherType_name, int32(x))
}
func (Config_Cipher) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1, 0} }
func (CipherType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type Account struct {
Password string `protobuf:"bytes,1,opt,name=password" json:"password,omitempty"`
Password string `protobuf:"bytes,1,opt,name=password" json:"password,omitempty"`
CipherType CipherType `protobuf:"varint,2,opt,name=cipher_type,json=cipherType,enum=v2ray.core.proxy.shadowsocks.CipherType" json:"cipher_type,omitempty"`
}
func (m *Account) Reset() { *m = Account{} }
@@ -69,52 +72,72 @@ func (m *Account) String() string { return proto.CompactTextString(m)
func (*Account) ProtoMessage() {}
func (*Account) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type Config struct {
Cipher Config_Cipher `protobuf:"varint,1,opt,name=cipher,enum=com.v2ray.core.proxy.shadowsocks.Config_Cipher" json:"cipher,omitempty"`
UdpEnabled bool `protobuf:"varint,2,opt,name=udp_enabled,json=udpEnabled" json:"udp_enabled,omitempty"`
User *com_v2ray_core_common_protocol.User `protobuf:"bytes,3,opt,name=user" json:"user,omitempty"`
type ServerConfig struct {
UdpEnabled bool `protobuf:"varint,1,opt,name=udp_enabled,json=udpEnabled" json:"udp_enabled,omitempty"`
User *v2ray_core_common_protocol.User `protobuf:"bytes,2,opt,name=user" json:"user,omitempty"`
}
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{1} }
func (m *ServerConfig) Reset() { *m = ServerConfig{} }
func (m *ServerConfig) String() string { return proto.CompactTextString(m) }
func (*ServerConfig) ProtoMessage() {}
func (*ServerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Config) GetUser() *com_v2ray_core_common_protocol.User {
func (m *ServerConfig) GetUser() *v2ray_core_common_protocol.User {
if m != nil {
return m.User
}
return nil
}
type ClientConfig struct {
Server []*v2ray_core_common_protocol1.ServerSpecPB `protobuf:"bytes,1,rep,name=server" json:"server,omitempty"`
}
func (m *ClientConfig) Reset() { *m = ClientConfig{} }
func (m *ClientConfig) String() string { return proto.CompactTextString(m) }
func (*ClientConfig) ProtoMessage() {}
func (*ClientConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *ClientConfig) GetServer() []*v2ray_core_common_protocol1.ServerSpecPB {
if m != nil {
return m.Server
}
return nil
}
func init() {
proto.RegisterType((*Account)(nil), "com.v2ray.core.proxy.shadowsocks.Account")
proto.RegisterType((*Config)(nil), "com.v2ray.core.proxy.shadowsocks.Config")
proto.RegisterEnum("com.v2ray.core.proxy.shadowsocks.Config_Cipher", Config_Cipher_name, Config_Cipher_value)
proto.RegisterType((*Account)(nil), "v2ray.core.proxy.shadowsocks.Account")
proto.RegisterType((*ServerConfig)(nil), "v2ray.core.proxy.shadowsocks.ServerConfig")
proto.RegisterType((*ClientConfig)(nil), "v2ray.core.proxy.shadowsocks.ClientConfig")
proto.RegisterEnum("v2ray.core.proxy.shadowsocks.CipherType", CipherType_name, CipherType_value)
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/shadowsocks/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 308 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x8f, 0x41, 0x4f, 0xc2, 0x40,
0x14, 0x84, 0x2d, 0x90, 0x82, 0xaf, 0xa2, 0x75, 0x4f, 0x84, 0x8b, 0x0d, 0xd1, 0x04, 0x0f, 0xee,
0x6a, 0x8d, 0x86, 0x6b, 0x69, 0x40, 0x8c, 0x09, 0x26, 0x55, 0xa2, 0xf1, 0xd2, 0x94, 0xed, 0x2a,
0x44, 0xda, 0xd7, 0xec, 0x52, 0x91, 0x3f, 0xe0, 0xef, 0x36, 0x6e, 0xad, 0x21, 0x5c, 0x3c, 0xbe,
0xc9, 0x7c, 0x6f, 0x66, 0xe0, 0xec, 0xc3, 0x95, 0xd1, 0x9a, 0x72, 0x4c, 0x18, 0x47, 0x29, 0x58,
0x26, 0xf1, 0x73, 0xcd, 0xd4, 0x2c, 0x8a, 0x71, 0xa5, 0x90, 0xbf, 0x2b, 0xc6, 0x31, 0x7d, 0x9d,
0xbf, 0xd1, 0x4c, 0xe2, 0x12, 0x89, 0xc3, 0x31, 0xa1, 0x25, 0x22, 0x05, 0xd5, 0x76, 0xba, 0x61,
0x6f, 0x9f, 0x6e, 0x3d, 0xe4, 0x98, 0x24, 0x98, 0x32, 0x8d, 0x73, 0x5c, 0xb0, 0x5c, 0x09, 0x59,
0x3c, 0xeb, 0x9c, 0x40, 0xdd, 0xe3, 0x1c, 0xf3, 0x74, 0x49, 0xda, 0xd0, 0xc8, 0x22, 0xa5, 0x56,
0x28, 0xe3, 0x96, 0xe1, 0x18, 0xdd, 0xdd, 0xe0, 0xef, 0xee, 0x7c, 0x55, 0xc0, 0xf4, 0x75, 0x09,
0x72, 0x03, 0x26, 0x9f, 0x67, 0x33, 0x21, 0xb5, 0x69, 0xdf, 0x65, 0xf4, 0xbf, 0x3e, 0xb4, 0x20,
0xa9, 0xaf, 0xb1, 0xe0, 0x17, 0x27, 0x47, 0x60, 0xe5, 0x71, 0x16, 0x8a, 0x34, 0x9a, 0x2e, 0x44,
0xdc, 0xaa, 0x38, 0x46, 0xb7, 0x11, 0x40, 0x1e, 0x67, 0x83, 0x42, 0x21, 0x3d, 0xa8, 0xfd, 0x34,
0x6d, 0x55, 0x1d, 0xa3, 0x6b, 0xb9, 0xc7, 0xdb, 0x39, 0xc5, 0x2a, 0x5a, 0xae, 0xa2, 0x13, 0x25,
0x64, 0xa0, 0x89, 0xce, 0x33, 0x98, 0x45, 0x18, 0xb1, 0xa0, 0x3e, 0x19, 0xdf, 0x8d, 0xef, 0x9f,
0xc6, 0xf6, 0x0e, 0x39, 0x00, 0xcb, 0x1b, 0x3c, 0x84, 0x17, 0x6e, 0x2f, 0xf4, 0x87, 0x7d, 0xdb,
0x28, 0x05, 0xf7, 0xea, 0x5a, 0x0b, 0x15, 0xb2, 0x07, 0x0d, 0x7f, 0xe4, 0xf9, 0x23, 0xcf, 0x3d,
0xb7, 0xab, 0xe4, 0x10, 0x9a, 0xe5, 0x15, 0xde, 0x0e, 0x86, 0x8f, 0x76, 0xad, 0xdf, 0x7c, 0xb1,
0x36, 0x96, 0x4d, 0x4d, 0x9d, 0x7e, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xee, 0x41, 0x94,
0xc3, 0x01, 0x00, 0x00,
// 370 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x50, 0xdd, 0xaf, 0xd2, 0x30,
0x14, 0x77, 0xf7, 0xde, 0x5c, 0xf0, 0x14, 0x75, 0xf6, 0x89, 0x10, 0x13, 0x17, 0x9e, 0xa6, 0x89,
0x1d, 0xce, 0x8f, 0xf8, 0xe0, 0x83, 0xdb, 0x02, 0x81, 0x98, 0x20, 0x19, 0x10, 0x13, 0x63, 0xb2,
0x8c, 0xae, 0x0a, 0x91, 0xad, 0x4d, 0xbb, 0x81, 0xfb, 0xef, 0x0d, 0x2d, 0x43, 0xe4, 0x01, 0xdf,
0x7a, 0x4e, 0x7f, 0x9f, 0x07, 0x5e, 0xed, 0x7c, 0x99, 0xd6, 0x84, 0xf2, 0xdc, 0xa3, 0x5c, 0x32,
0x4f, 0x48, 0xfe, 0xbb, 0xf6, 0xd4, 0x3a, 0xcd, 0xf8, 0x5e, 0x71, 0xfa, 0x4b, 0x79, 0x94, 0x17,
0x3f, 0x36, 0x3f, 0x89, 0x90, 0xbc, 0xe4, 0xf8, 0x59, 0x03, 0x97, 0x8c, 0x68, 0x28, 0x39, 0x83,
0xf6, 0x5e, 0x5c, 0x88, 0x51, 0x9e, 0xe7, 0xbc, 0xf0, 0x34, 0x95, 0xf2, 0xad, 0x57, 0x29, 0x26,
0x8d, 0x50, 0x6f, 0xf0, 0x1f, 0xa8, 0x62, 0x72, 0xc7, 0x64, 0xa2, 0x04, 0xa3, 0x86, 0xd1, 0x17,
0xd0, 0x0a, 0x28, 0xe5, 0x55, 0x51, 0xe2, 0x1e, 0xb4, 0x45, 0xaa, 0xd4, 0x9e, 0xcb, 0xac, 0x6b,
0x39, 0x96, 0xfb, 0x30, 0x3e, 0xcd, 0x78, 0x02, 0x88, 0x6e, 0xc4, 0x9a, 0xc9, 0xa4, 0xac, 0x05,
0xeb, 0xde, 0x38, 0x96, 0xfb, 0xd8, 0x77, 0xc9, 0xb5, 0xdc, 0x24, 0xd2, 0x84, 0x45, 0x2d, 0x58,
0x0c, 0xf4, 0xf4, 0xee, 0x33, 0xe8, 0xcc, 0x75, 0x8c, 0x48, 0x9f, 0x00, 0x3f, 0x07, 0x54, 0x65,
0x22, 0x61, 0x45, 0xba, 0xda, 0x32, 0xe3, 0xdc, 0x8e, 0xa1, 0xca, 0xc4, 0xd0, 0x6c, 0xf0, 0x5b,
0xb8, 0x3b, 0x54, 0xd4, 0xa6, 0xc8, 0x77, 0xce, 0x4d, 0x4d, 0x3f, 0xd2, 0xf4, 0x23, 0x4b, 0xc5,
0x64, 0xac, 0xd1, 0xfd, 0x19, 0x74, 0xa2, 0xed, 0x86, 0x15, 0xe5, 0xd1, 0xe6, 0x13, 0xdc, 0x9b,
0xf6, 0x5d, 0xcb, 0xb9, 0x75, 0xd1, 0xbf, 0xe1, 0x2f, 0x75, 0x4c, 0xc0, 0xb9, 0x60, 0x74, 0x16,
0xc6, 0x47, 0xde, 0xcb, 0xef, 0x00, 0x7f, 0x2b, 0x61, 0x04, 0xad, 0xe5, 0xf4, 0xf3, 0xf4, 0xcb,
0xd7, 0xa9, 0xfd, 0x00, 0x3f, 0x01, 0x14, 0x0c, 0xe7, 0xc9, 0x6b, 0xff, 0x43, 0x12, 0x8d, 0x42,
0xdb, 0x6a, 0x16, 0xfe, 0xbb, 0xf7, 0x7a, 0x71, 0x83, 0x3b, 0xd0, 0x8e, 0xc6, 0x41, 0x34, 0x0e,
0xfc, 0x81, 0x7d, 0x8b, 0x9f, 0xc2, 0xa3, 0x66, 0x4a, 0x26, 0xc3, 0xd1, 0xc2, 0xbe, 0x0b, 0x3f,
0x82, 0x43, 0x79, 0x7e, 0xf5, 0xa2, 0x21, 0x32, 0x5d, 0x66, 0x87, 0x98, 0xdf, 0xd0, 0xd9, 0xcf,
0xea, 0x5e, 0x47, 0x7f, 0xf3, 0x27, 0x00, 0x00, 0xff, 0xff, 0x62, 0xda, 0x5c, 0xcd, 0x79, 0x02,
0x00, 0x00,
}

View File

@@ -1,23 +1,31 @@
syntax = "proto3";
import "v2ray.com/core/common/protocol/user.proto";
package com.v2ray.core.proxy.shadowsocks;
package v2ray.core.proxy.shadowsocks;
option go_package = "shadowsocks";
option java_package = "com.v2ray.core.proxy.shadowsocks";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/protocol/user.proto";
import "v2ray.com/core/common/protocol/server_spec.proto";
message Account {
string password = 1;
CipherType cipher_type = 2;
}
message Config {
enum Cipher {
UNKNOWN = 0;
AES_128_CFB = 1;
AES_256_CFB = 2;
CHACHA20 = 3;
CHACHA20_IEFT = 4;
}
Cipher cipher = 1;
bool udp_enabled = 2;
com.v2ray.core.common.protocol.User user = 3;
enum CipherType {
UNKNOWN = 0;
AES_128_CFB = 1;
AES_256_CFB = 2;
CHACHA20 = 3;
CHACHA20_IEFT = 4;
}
message ServerConfig {
bool udp_enabled = 1;
v2ray.core.common.protocol.User user = 2;
}
message ClientConfig {
repeated v2ray.core.common.protocol.ServerSpecPB server = 1;
}

View File

@@ -15,7 +15,7 @@ import (
"github.com/golang/protobuf/ptypes"
)
func (this *Config) UnmarshalJSON(data []byte) error {
func (this *ServerConfig) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Cipher string `json:"method"`
Password string `json:"password"`
@@ -29,28 +29,30 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
this.UdpEnabled = jsonConfig.UDP
jsonConfig.Cipher = strings.ToLower(jsonConfig.Cipher)
switch jsonConfig.Cipher {
case "aes-256-cfb":
this.Cipher = Config_AES_256_CFB
case "aes-128-cfb":
this.Cipher = Config_AES_128_CFB
case "chacha20":
this.Cipher = Config_CHACHA20
case "chacha20-ietf":
this.Cipher = Config_CHACHA20_IEFT
default:
log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
return common.ErrBadConfiguration
}
if len(jsonConfig.Password) == 0 {
log.Error("Shadowsocks: Password is not specified.")
return common.ErrBadConfiguration
}
account, err := ptypes.MarshalAny(&Account{
account := &Account{
Password: jsonConfig.Password,
})
}
jsonConfig.Cipher = strings.ToLower(jsonConfig.Cipher)
switch jsonConfig.Cipher {
case "aes-256-cfb":
account.CipherType = CipherType_AES_256_CFB
case "aes-128-cfb":
account.CipherType = CipherType_AES_128_CFB
case "chacha20":
account.CipherType = CipherType_CHACHA20
case "chacha20-ietf":
account.CipherType = CipherType_CHACHA20_IEFT
default:
log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
return common.ErrBadConfiguration
}
anyAccount, err := ptypes.MarshalAny(account)
if err != nil {
log.Error("Shadowsocks: Failed to create account: ", err)
return common.ErrBadConfiguration
@@ -58,12 +60,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.User = &protocol.User{
Email: jsonConfig.Email,
Level: uint32(jsonConfig.Level),
Account: account,
Account: anyAccount,
}
return nil
}
func init() {
registry.RegisterInboundConfig("shadowsocks", func() interface{} { return new(Config) })
registry.RegisterInboundConfig("shadowsocks", func() interface{} { return new(ServerConfig) })
}

View File

@@ -17,12 +17,16 @@ func TestConfigParsing(t *testing.T) {
"password": "v2ray-password"
}`
config := new(Config)
config := new(ServerConfig)
err := json.Unmarshal([]byte(rawJson), config)
assert.Error(err).IsNil()
assert.Int(config.GetCipher().KeySize()).Equals(16)
account, err := config.User.GetTypedAccount(&Account{})
account := new(Account)
_, err = config.User.GetTypedAccount(account)
assert.Error(err).IsNil()
assert.Bytes(account.(*Account).GetCipherKey(config.GetCipher().KeySize())).Equals([]byte{160, 224, 26, 2, 22, 110, 9, 80, 65, 52, 80, 20, 38, 243, 224, 241})
cipher, err := account.GetCipher()
assert.Error(err).IsNil()
assert.Int(cipher.KeySize()).Equals(16)
assert.Bytes(account.GetCipherKey()).Equals([]byte{160, 224, 26, 2, 22, 110, 9, 80, 65, 52, 80, 20, 38, 243, 224, 241})
}

View File

@@ -23,7 +23,7 @@ import (
type Server struct {
packetDispatcher dispatcher.PacketDispatcher
config *Config
config *ServerConfig
cipher Cipher
cipherKey []byte
meta *proxy.InboundHandlerMeta
@@ -33,7 +33,7 @@ type Server struct {
udpServer *udp.UDPServer
}
func NewServer(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) (*Server, error) {
func NewServer(config *ServerConfig, space app.Space, meta *proxy.InboundHandlerMeta) (*Server, error) {
if config.GetUser() == nil {
return nil, protocol.ErrUserMissing
}
@@ -41,12 +41,15 @@ func NewServer(config *Config, space app.Space, meta *proxy.InboundHandlerMeta)
if _, err := config.GetUser().GetTypedAccount(account); err != nil {
return nil, err
}
cipher := config.GetCipher()
cipher, err := account.GetCipher()
if err != nil {
return nil, err
}
s := &Server{
config: config,
meta: meta,
cipher: cipher,
cipherKey: account.GetCipherKey(cipher.KeySize()),
cipherKey: account.GetCipherKey(),
}
space.InitializeApplication(func() error {
@@ -275,15 +278,17 @@ func (this *Server) handleConnection(conn internet.Connection) {
type ServerFactory struct{}
func (this *ServerFactory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *ServerFactory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
if !space.HasApp(dispatcher.APP_ID) {
return nil, common.ErrBadConfiguration
}
return NewServer(rawConfig.(*Config), space, meta)
return NewServer(rawConfig.(*ServerConfig), space, meta)
}
func init() {

View File

@@ -1,20 +0,0 @@
package socks
import (
"v2ray.com/core/common/protocol"
)
func (this *Account) Equals(another protocol.Account) bool {
if account, ok := another.(*Account); ok {
return this.Username == account.Username
}
return false
}
func (this *Account) AsAccount() (protocol.Account, error) {
return this, nil
}
func NewAccount() protocol.AsAccount {
return &Account{}
}

View File

@@ -1,28 +0,0 @@
package socks
import (
"v2ray.com/core/common/protocol"
"github.com/golang/protobuf/ptypes"
google_protobuf "github.com/golang/protobuf/ptypes/any"
)
func AccountEquals(a, b *google_protobuf.Any) bool {
accountA := new(Account)
if err := ptypes.UnmarshalAny(a, accountA); err != nil {
return false
}
accountB := new(Account)
if err := ptypes.UnmarshalAny(b, accountB); err != nil {
return false
}
return accountA.Equals(accountB)
}
func (this *Account) AsAny() (*google_protobuf.Any, error) {
return ptypes.MarshalAny(this)
}
type ClientConfig struct {
Servers []*protocol.ServerSpec
}

View File

@@ -1,61 +0,0 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/socks/client_config.proto
// DO NOT EDIT!
/*
Package socks is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/socks/client_config.proto
v2ray.com/core/proxy/socks/server_config.proto
It has these top-level messages:
Account
ServerConfig
*/
package socks
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 Account struct {
Username string `protobuf:"bytes,1,opt,name=username" json:"username,omitempty"`
Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"`
}
func (m *Account) Reset() { *m = Account{} }
func (m *Account) String() string { return proto.CompactTextString(m) }
func (*Account) ProtoMessage() {}
func (*Account) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*Account)(nil), "com.v2ray.core.proxy.socks.Account")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/socks/client_config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 146 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x2b, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x28, 0xca, 0xaf, 0xa8,
0xd4, 0x2f, 0xce, 0x4f, 0xce, 0x2e, 0xd6, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x89, 0x4f, 0xce,
0xcf, 0x4b, 0xcb, 0x4c, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4a, 0xce, 0xcf, 0x85,
0xeb, 0x29, 0x4a, 0xd5, 0x03, 0xab, 0xd7, 0x03, 0xab, 0x57, 0x72, 0xe4, 0x62, 0x77, 0x4c, 0x4e,
0xce, 0x2f, 0xcd, 0x2b, 0x11, 0x92, 0xe2, 0xe2, 0x28, 0x2d, 0x4e, 0x2d, 0xca, 0x4b, 0xcc, 0x4d,
0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0xf3, 0x41, 0x72, 0x05, 0x89, 0xc5, 0xc5, 0xe5,
0xf9, 0x45, 0x29, 0x12, 0x4c, 0x10, 0x39, 0x18, 0xdf, 0x89, 0x3d, 0x8a, 0x15, 0x6c, 0x56, 0x12,
0x1b, 0xd8, 0x3a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xf0, 0x36, 0x26, 0xa0, 0x00,
0x00, 0x00,
}

View File

@@ -1,9 +0,0 @@
syntax = "proto3";
package com.v2ray.core.proxy.socks;
option go_package = "socks";
message Account {
string username = 1;
string password = 2;
}

View File

@@ -1,5 +1,3 @@
// +build json
package socks
import (
@@ -9,9 +7,50 @@ import (
"v2ray.com/core/common"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/registry"
"github.com/golang/protobuf/ptypes"
google_protobuf "github.com/golang/protobuf/ptypes/any"
)
func (this *Account) Equals(another protocol.Account) bool {
if account, ok := another.(*Account); ok {
return this.Username == account.Username
}
return false
}
func (this *Account) AsAccount() (protocol.Account, error) {
return this, nil
}
func NewAccount() protocol.AsAccount {
return &Account{}
}
func (this *Account) AsAny() (*google_protobuf.Any, error) {
return ptypes.MarshalAny(this)
}
func (this *ServerConfig) HasAccount(username, password string) bool {
if this.Accounts == nil {
return false
}
storedPassed, found := this.Accounts[username]
if !found {
return false
}
return storedPassed == password
}
func (this *ServerConfig) GetNetAddress() v2net.Address {
if this.Address == nil {
return v2net.LocalHostIP
}
return this.Address.AsAddress()
}
const (
AuthMethodNoAuth = "noauth"
AuthMethodUserPass = "password"
@@ -31,9 +70,9 @@ func (this *ServerConfig) UnmarshalJSON(data []byte) error {
return errors.New("Socks: Failed to parse config: " + err.Error())
}
if rawConfig.AuthMethod == AuthMethodNoAuth {
this.AuthType = ServerConfig_NO_AUTH
this.AuthType = AuthType_NO_AUTH
} else if rawConfig.AuthMethod == AuthMethodUserPass {
this.AuthType = ServerConfig_PASSWORD
this.AuthType = AuthType_PASSWORD
} else {
log.Error("Socks: Unknown auth method: ", rawConfig.AuthMethod)
return common.ErrBadConfiguration

147
proxy/socks/config.pb.go Normal file
View File

@@ -0,0 +1,147 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/socks/config.proto
// DO NOT EDIT!
/*
Package socks is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/socks/config.proto
It has these top-level messages:
Account
ServerConfig
ClientConfig
*/
package socks
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import v2ray_core_common_net "v2ray.com/core/common/net"
import v2ray_core_common_protocol1 "v2ray.com/core/common/protocol"
// 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 AuthType int32
const (
AuthType_NO_AUTH AuthType = 0
AuthType_PASSWORD AuthType = 1
)
var AuthType_name = map[int32]string{
0: "NO_AUTH",
1: "PASSWORD",
}
var AuthType_value = map[string]int32{
"NO_AUTH": 0,
"PASSWORD": 1,
}
func (x AuthType) String() string {
return proto.EnumName(AuthType_name, int32(x))
}
func (AuthType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type Account struct {
Username string `protobuf:"bytes,1,opt,name=username" json:"username,omitempty"`
Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"`
}
func (m *Account) Reset() { *m = Account{} }
func (m *Account) String() string { return proto.CompactTextString(m) }
func (*Account) ProtoMessage() {}
func (*Account) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type ServerConfig struct {
AuthType AuthType `protobuf:"varint,1,opt,name=auth_type,json=authType,enum=v2ray.core.proxy.socks.AuthType" json:"auth_type,omitempty"`
Accounts map[string]string `protobuf:"bytes,2,rep,name=accounts" json:"accounts,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
Address *v2ray_core_common_net.AddressPB `protobuf:"bytes,3,opt,name=address" json:"address,omitempty"`
UdpEnabled bool `protobuf:"varint,4,opt,name=udp_enabled,json=udpEnabled" json:"udp_enabled,omitempty"`
Timeout uint32 `protobuf:"varint,5,opt,name=timeout" json:"timeout,omitempty"`
}
func (m *ServerConfig) Reset() { *m = ServerConfig{} }
func (m *ServerConfig) String() string { return proto.CompactTextString(m) }
func (*ServerConfig) ProtoMessage() {}
func (*ServerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *ServerConfig) GetAccounts() map[string]string {
if m != nil {
return m.Accounts
}
return nil
}
func (m *ServerConfig) GetAddress() *v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
type ClientConfig struct {
Server []*v2ray_core_common_protocol1.ServerSpecPB `protobuf:"bytes,1,rep,name=server" json:"server,omitempty"`
}
func (m *ClientConfig) Reset() { *m = ClientConfig{} }
func (m *ClientConfig) String() string { return proto.CompactTextString(m) }
func (*ClientConfig) ProtoMessage() {}
func (*ClientConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *ClientConfig) GetServer() []*v2ray_core_common_protocol1.ServerSpecPB {
if m != nil {
return m.Server
}
return nil
}
func init() {
proto.RegisterType((*Account)(nil), "v2ray.core.proxy.socks.Account")
proto.RegisterType((*ServerConfig)(nil), "v2ray.core.proxy.socks.ServerConfig")
proto.RegisterType((*ClientConfig)(nil), "v2ray.core.proxy.socks.ClientConfig")
proto.RegisterEnum("v2ray.core.proxy.socks.AuthType", AuthType_name, AuthType_value)
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/socks/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 428 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x91, 0x51, 0x6b, 0xdb, 0x30,
0x10, 0xc7, 0xe7, 0x64, 0x69, 0xdc, 0x73, 0x3a, 0x82, 0x18, 0xc3, 0xf8, 0x65, 0x26, 0x30, 0x66,
0xf6, 0x20, 0x97, 0xec, 0x65, 0x74, 0x0c, 0xe6, 0x74, 0x85, 0x3d, 0xb5, 0xc6, 0xe9, 0x18, 0xec,
0x25, 0xa8, 0xf2, 0x6d, 0x0d, 0xb5, 0x25, 0x21, 0xc9, 0xd9, 0xfc, 0x31, 0xf7, 0x8d, 0x46, 0x2c,
0xbb, 0xac, 0x25, 0x7d, 0xd3, 0xe9, 0xfe, 0xf7, 0xbf, 0xbb, 0xdf, 0xc1, 0xdb, 0xdd, 0x52, 0xb3,
0x96, 0x72, 0x59, 0xa7, 0x5c, 0x6a, 0x4c, 0x95, 0x96, 0x7f, 0xda, 0xd4, 0x48, 0x7e, 0x67, 0x52,
0x2e, 0xc5, 0xcf, 0xed, 0x2f, 0xaa, 0xb4, 0xb4, 0x92, 0xbc, 0x1a, 0x84, 0x1a, 0x69, 0x27, 0xa2,
0x9d, 0x28, 0x7a, 0x6c, 0xc0, 0x65, 0x5d, 0x4b, 0x91, 0x0a, 0xb4, 0x29, 0x2b, 0x4b, 0x8d, 0xc6,
0x38, 0x83, 0xe8, 0xf4, 0xb0, 0xb0, 0x4b, 0x72, 0x59, 0xa5, 0x06, 0xf5, 0x0e, 0xf5, 0xc6, 0x28,
0xe4, 0xae, 0x62, 0x91, 0xc1, 0x34, 0xe3, 0x5c, 0x36, 0xc2, 0x92, 0x08, 0xfc, 0xc6, 0xa0, 0x16,
0xac, 0xc6, 0xd0, 0x8b, 0xbd, 0xe4, 0xb8, 0xb8, 0x8f, 0xf7, 0x39, 0xc5, 0x8c, 0xf9, 0x2d, 0x75,
0x19, 0x8e, 0x5c, 0x6e, 0x88, 0x17, 0x7f, 0x47, 0x30, 0x5b, 0x77, 0xc6, 0xe7, 0xdd, 0x32, 0xe4,
0x13, 0x1c, 0xb3, 0xc6, 0xde, 0x6e, 0x6c, 0xab, 0x9c, 0xd3, 0x8b, 0x65, 0x4c, 0x0f, 0xaf, 0x46,
0xb3, 0xc6, 0xde, 0x5e, 0xb7, 0x0a, 0x0b, 0x9f, 0xf5, 0x2f, 0x72, 0x09, 0x3e, 0x73, 0x23, 0x99,
0x70, 0x14, 0x8f, 0x93, 0x60, 0xb9, 0x7c, 0xaa, 0xfa, 0xff, 0xb6, 0xb4, 0xdf, 0xc3, 0x5c, 0x08,
0xab, 0xdb, 0xe2, 0xde, 0x83, 0x9c, 0xc1, 0xb4, 0xa7, 0x14, 0x8e, 0x63, 0x2f, 0x09, 0x1e, 0x0e,
0xe3, 0x10, 0x51, 0x81, 0x96, 0x66, 0x4e, 0x95, 0xaf, 0x8a, 0xa1, 0x80, 0xbc, 0x86, 0xa0, 0x29,
0xd5, 0x06, 0x05, 0xbb, 0xa9, 0xb0, 0x0c, 0x9f, 0xc7, 0x5e, 0xe2, 0x17, 0xd0, 0x94, 0xea, 0xc2,
0xfd, 0x90, 0x10, 0xa6, 0x76, 0x5b, 0xa3, 0x6c, 0x6c, 0x38, 0x89, 0xbd, 0xe4, 0xa4, 0x18, 0xc2,
0xe8, 0x23, 0x9c, 0x3c, 0x98, 0x88, 0xcc, 0x61, 0x7c, 0x87, 0x6d, 0x8f, 0x76, 0xff, 0x24, 0x2f,
0x61, 0xb2, 0x63, 0x55, 0x83, 0x3d, 0x52, 0x17, 0x9c, 0x8d, 0x3e, 0x78, 0x8b, 0x1c, 0x66, 0xe7,
0xd5, 0x16, 0x85, 0xed, 0x91, 0x7e, 0x86, 0x23, 0x77, 0xbb, 0xd0, 0xeb, 0x88, 0x24, 0x07, 0x56,
0x18, 0xae, 0xdc, 0x53, 0x59, 0x2b, 0xe4, 0xf9, 0xaa, 0xe8, 0xeb, 0xde, 0xbd, 0x01, 0x7f, 0x60,
0x4d, 0x02, 0x98, 0x5e, 0x5e, 0x6d, 0xb2, 0x6f, 0xd7, 0x5f, 0xe7, 0xcf, 0xc8, 0x0c, 0xfc, 0x3c,
0x5b, 0xaf, 0xbf, 0x5f, 0x15, 0x5f, 0xe6, 0xde, 0xea, 0x14, 0x22, 0x2e, 0xeb, 0x27, 0x78, 0xaf,
0x02, 0x37, 0x4e, 0xbe, 0xef, 0xf4, 0x63, 0xd2, 0xfd, 0xdd, 0x1c, 0x75, 0x7d, 0xdf, 0xff, 0x0b,
0x00, 0x00, 0xff, 0xff, 0xb4, 0x25, 0x49, 0xd6, 0xe6, 0x02, 0x00, 0x00,
}

31
proxy/socks/config.proto Normal file
View File

@@ -0,0 +1,31 @@
syntax = "proto3";
package v2ray.core.proxy.socks;
option go_package = "socks";
option java_package = "com.v2ray.core.proxy.socks";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/protocol/server_spec.proto";
message Account {
string username = 1;
string password = 2;
}
enum AuthType {
NO_AUTH = 0;
PASSWORD = 1;
}
message ServerConfig {
AuthType auth_type = 1;
map<string, string> accounts = 2;
v2ray.core.common.net.AddressPB address = 3;
bool udp_enabled = 4;
uint32 timeout = 5;
}
message ClientConfig {
repeated v2ray.core.common.protocol.ServerSpecPB server = 1;
}

View File

@@ -38,9 +38,12 @@ func (this *ClientConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("Socks|Client: Failed to parse config: " + err.Error())
}
this.Servers = make([]*protocol.ServerSpec, len(jsonConfig.Servers))
this.Server = make([]*protocol.ServerSpecPB, len(jsonConfig.Servers))
for idx, serverConfig := range jsonConfig.Servers {
server := protocol.NewServerSpec(NewAccount, v2net.TCPDestination(serverConfig.Address.AsAddress(), serverConfig.Port), protocol.AlwaysValid())
server := &protocol.ServerSpecPB{
Address: serverConfig.Address,
Port: uint32(serverConfig.Port),
}
for _, rawUser := range serverConfig.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
@@ -55,9 +58,9 @@ func (this *ClientConfig) UnmarshalJSON(data []byte) error {
return err
}
user.Account = anyAccount
server.AddUser(user)
server.User = append(server.User, user)
}
this.Servers[idx] = server
this.Server[idx] = server
}
return nil
}

View File

@@ -129,7 +129,7 @@ func (this *Server) handleConnection(connection internet.Connection) {
func (this *Server) handleSocks5(clientAddr v2net.Destination, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error {
expectedAuthMethod := protocol.AuthNotRequired
if this.config.AuthType == ServerConfig_PASSWORD {
if this.config.AuthType == AuthType_PASSWORD {
expectedAuthMethod = protocol.AuthUserPass
}
@@ -152,7 +152,7 @@ func (this *Server) handleSocks5(clientAddr v2net.Destination, reader *v2io.Buff
log.Error("Socks: failed to write authentication: ", err)
return err
}
if this.config.AuthType == ServerConfig_PASSWORD {
if this.config.AuthType == AuthType_PASSWORD {
upRequest, err := protocol.ReadUserPassRequest(reader)
if err != nil {
log.Warning("Socks: failed to read username and password: ", err)
@@ -236,14 +236,14 @@ func (this *Server) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) err
udpAddr := this.udpAddress
response.Port = udpAddr.Port()
switch udpAddr.Address().Family() {
response.Port = udpAddr.Port
switch udpAddr.Address.Family() {
case v2net.AddressFamilyIPv4:
response.SetIPv4(udpAddr.Address().IP())
response.SetIPv4(udpAddr.Address.IP())
case v2net.AddressFamilyIPv6:
response.SetIPv6(udpAddr.Address().IP())
response.SetIPv6(udpAddr.Address.IP())
case v2net.AddressFamilyDomain:
response.SetDomain(udpAddr.Address().Domain())
response.SetDomain(udpAddr.Address.Domain())
}
response.Write(writer)
@@ -315,8 +315,10 @@ func (this *Server) transport(reader io.Reader, writer io.Writer, session *proxy
type ServerFactory struct{}
func (this *ServerFactory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP
func (this *ServerFactory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {

View File

@@ -1,23 +0,0 @@
package socks
import (
v2net "v2ray.com/core/common/net"
)
func (this *ServerConfig) HasAccount(username, password string) bool {
if this.Accounts == nil {
return false
}
storedPassed, found := this.Accounts[username]
if !found {
return false
}
return storedPassed == password
}
func (this *ServerConfig) GetNetAddress() v2net.Address {
if this.Address == nil {
return v2net.LocalHostIP
}
return this.Address.AsAddress()
}

View File

@@ -1,96 +0,0 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/socks/server_config.proto
// DO NOT EDIT!
package socks
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_common_net "v2ray.com/core/common/net"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type ServerConfig_AuthType int32
const (
ServerConfig_NO_AUTH ServerConfig_AuthType = 0
ServerConfig_PASSWORD ServerConfig_AuthType = 1
)
var ServerConfig_AuthType_name = map[int32]string{
0: "NO_AUTH",
1: "PASSWORD",
}
var ServerConfig_AuthType_value = map[string]int32{
"NO_AUTH": 0,
"PASSWORD": 1,
}
func (x ServerConfig_AuthType) String() string {
return proto.EnumName(ServerConfig_AuthType_name, int32(x))
}
func (ServerConfig_AuthType) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{0, 0} }
type ServerConfig struct {
AuthType ServerConfig_AuthType `protobuf:"varint,1,opt,name=auth_type,json=authType,enum=com.v2ray.core.proxy.socks.ServerConfig_AuthType" json:"auth_type,omitempty"`
Accounts map[string]string `protobuf:"bytes,2,rep,name=accounts" json:"accounts,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
Address *com_v2ray_core_common_net.AddressPB `protobuf:"bytes,3,opt,name=address" json:"address,omitempty"`
UdpEnabled bool `protobuf:"varint,4,opt,name=udp_enabled,json=udpEnabled" json:"udp_enabled,omitempty"`
Timeout uint32 `protobuf:"varint,5,opt,name=timeout" json:"timeout,omitempty"`
}
func (m *ServerConfig) Reset() { *m = ServerConfig{} }
func (m *ServerConfig) String() string { return proto.CompactTextString(m) }
func (*ServerConfig) ProtoMessage() {}
func (*ServerConfig) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (m *ServerConfig) GetAccounts() map[string]string {
if m != nil {
return m.Accounts
}
return nil
}
func (m *ServerConfig) GetAddress() *com_v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
func init() {
proto.RegisterType((*ServerConfig)(nil), "com.v2ray.core.proxy.socks.ServerConfig")
proto.RegisterEnum("com.v2ray.core.proxy.socks.ServerConfig_AuthType", ServerConfig_AuthType_name, ServerConfig_AuthType_value)
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/socks/server_config.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 345 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x91, 0xd1, 0x4b, 0xeb, 0x30,
0x14, 0xc6, 0x6f, 0xd7, 0xbb, 0xdb, 0x2e, 0xdd, 0x2e, 0x23, 0xf8, 0x50, 0xf6, 0x62, 0x19, 0x8a,
0x7d, 0x4a, 0xb1, 0x82, 0x88, 0x82, 0xd0, 0xe9, 0xc0, 0xa7, 0x6d, 0x64, 0x13, 0xc1, 0x97, 0xd2,
0xa5, 0x47, 0x37, 0xb6, 0x36, 0x25, 0x4d, 0x86, 0xfd, 0x33, 0xfc, 0x8f, 0xc5, 0x74, 0x1b, 0x3a,
0x10, 0x7c, 0x3b, 0xe7, 0xf0, 0x7d, 0xbf, 0xe4, 0x7c, 0x07, 0x91, 0x4d, 0x28, 0x92, 0x8a, 0x30,
0x9e, 0x05, 0x8c, 0x0b, 0x08, 0x0a, 0xc1, 0xdf, 0xaa, 0xa0, 0xe4, 0x6c, 0x55, 0x06, 0x25, 0x88,
0x0d, 0x88, 0x98, 0xf1, 0xfc, 0x65, 0xf9, 0x4a, 0x0a, 0xc1, 0x25, 0xc7, 0x3d, 0xc6, 0xb3, 0xbd,
0x47, 0x00, 0xd1, 0x7a, 0xa2, 0xf5, 0xbd, 0xb3, 0x03, 0x16, 0xe3, 0x59, 0xc6, 0xf3, 0x20, 0x07,
0x19, 0x24, 0x69, 0x2a, 0xa0, 0x2c, 0x6b, 0x48, 0xff, 0xdd, 0x44, 0xed, 0xa9, 0x86, 0xdf, 0x69,
0x36, 0x1e, 0xa1, 0x56, 0xa2, 0xe4, 0x22, 0x96, 0x55, 0x01, 0xae, 0xe1, 0x19, 0xfe, 0xff, 0xf0,
0x9c, 0xfc, 0xfc, 0x12, 0xf9, 0x6a, 0x26, 0x91, 0x92, 0x8b, 0x59, 0x55, 0x00, 0xb5, 0x93, 0x6d,
0x85, 0x29, 0xb2, 0x13, 0xc6, 0xb8, 0xca, 0x65, 0xe9, 0x36, 0x3c, 0xd3, 0x77, 0xc2, 0xcb, 0xdf,
0xe3, 0xb6, 0xc6, 0x61, 0x2e, 0x45, 0x45, 0xf7, 0x1c, 0x7c, 0x8b, 0xac, 0xed, 0x16, 0xae, 0xe9,
0x19, 0xbe, 0x13, 0x9e, 0x1c, 0x22, 0xeb, 0x7d, 0x49, 0x0e, 0x92, 0x44, 0xb5, 0x72, 0x32, 0xa0,
0x3b, 0x13, 0x3e, 0x46, 0x8e, 0x4a, 0x8b, 0x18, 0xf2, 0x64, 0xbe, 0x86, 0xd4, 0xfd, 0xeb, 0x19,
0xbe, 0x4d, 0x91, 0x4a, 0x8b, 0x61, 0x3d, 0xc1, 0x2e, 0xb2, 0xe4, 0x32, 0x03, 0xae, 0xa4, 0xdb,
0xf4, 0x0c, 0xbf, 0x43, 0x77, 0x6d, 0xef, 0x06, 0x75, 0xbe, 0xfd, 0x0a, 0x77, 0x91, 0xb9, 0x82,
0x4a, 0x27, 0xd5, 0xa2, 0x9f, 0x25, 0x3e, 0x42, 0xcd, 0x4d, 0xb2, 0x56, 0xe0, 0x36, 0xf4, 0xac,
0x6e, 0xae, 0x1b, 0x57, 0x46, 0xff, 0x14, 0xd9, 0xbb, 0x84, 0xb0, 0x83, 0xac, 0xd1, 0x38, 0x8e,
0x1e, 0x67, 0x0f, 0xdd, 0x3f, 0xb8, 0x8d, 0xec, 0x49, 0x34, 0x9d, 0x3e, 0x8d, 0xe9, 0x7d, 0xd7,
0x18, 0x58, 0xcf, 0x4d, 0x1d, 0xc6, 0xfc, 0x9f, 0xbe, 0xd1, 0xc5, 0x47, 0x00, 0x00, 0x00, 0xff,
0xff, 0x1f, 0xec, 0x2f, 0xc7, 0x1a, 0x02, 0x00, 0x00,
}

View File

@@ -1,18 +0,0 @@
syntax = "proto3";
package com.v2ray.core.proxy.socks;
option go_package = "socks";
import "v2ray.com/core/common/net/address.proto";
message ServerConfig {
enum AuthType {
NO_AUTH = 0;
PASSWORD = 1;
}
AuthType auth_type = 1;
map<string, string> accounts = 2;
com.v2ray.core.common.net.AddressPB address = 3;
bool udp_enabled = 4;
uint32 timeout = 5;
}

View File

@@ -49,8 +49,8 @@ func (this *Server) handleUDPPayload(payload *alloc.Buffer, session *proxy.Sessi
this.udpServer.Dispatch(&proxy.SessionInfo{Source: source, Destination: request.Destination()}, request.Data, func(destination v2net.Destination, payload *alloc.Buffer) {
response := &protocol.Socks5UDPRequest{
Fragment: 0,
Address: request.Destination().Address(),
Port: request.Destination().Port(),
Address: request.Destination().Address,
Port: request.Destination().Port,
Data: payload,
}
log.Info("Socks: Writing back UDP response with ", payload.Len(), " bytes to ", destination)

View File

@@ -30,7 +30,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type AccountPB struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
AlterId uint32 `protobuf:"varint,2,opt,name=alterId" json:"alterId,omitempty"`
AlterId uint32 `protobuf:"varint,2,opt,name=alter_id,json=alterId" json:"alter_id,omitempty"`
}
func (m *AccountPB) Reset() { *m = AccountPB{} }
@@ -39,20 +39,21 @@ func (*AccountPB) ProtoMessage() {}
func (*AccountPB) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*AccountPB)(nil), "com.v2ray.core.proxy.vmess.AccountPB")
proto.RegisterType((*AccountPB)(nil), "v2ray.core.proxy.vmess.AccountPB")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/vmess/account.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 138 bytes of a gzipped FileDescriptorProto
// 153 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x28, 0xca, 0xaf, 0xa8,
0xd4, 0x2f, 0xcb, 0x4d, 0x2d, 0x2e, 0xd6, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x2b,
0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4a, 0xce, 0xcf, 0xd5, 0x83, 0xa9, 0x2e, 0x4a, 0xd5, 0x03,
0xab, 0xd4, 0x03, 0xab, 0x54, 0x32, 0xe5, 0xe2, 0x74, 0x84, 0x28, 0x0e, 0x70, 0x12, 0xe2, 0xe3,
0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 0x11, 0x92, 0xe0,
0x62, 0x4f, 0xcc, 0x29, 0x49, 0x2d, 0xf2, 0x4c, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0d, 0x82,
0x71, 0x9d, 0xd8, 0xa3, 0x58, 0xc1, 0xfa, 0x93, 0xd8, 0xc0, 0x56, 0x18, 0x03, 0x02, 0x00, 0x00,
0xff, 0xff, 0xe4, 0xea, 0x97, 0xa3, 0x8e, 0x00, 0x00, 0x00,
0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x83, 0xa9, 0x2c, 0x4a, 0xd5, 0x03, 0xab, 0xd2, 0x03, 0xab,
0x52, 0x32, 0xe3, 0xe2, 0x74, 0x84, 0x28, 0x0c, 0x70, 0x12, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91,
0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 0x11, 0x92, 0xe4, 0xe2, 0x48, 0xcc, 0x29,
0x49, 0x2d, 0x8a, 0xcf, 0x4c, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0d, 0x62, 0x07, 0xf3, 0x3d,
0x53, 0x9c, 0x0c, 0xb9, 0xa4, 0x92, 0xf3, 0x73, 0xf5, 0xb0, 0x9b, 0xea, 0xc4, 0x03, 0x33, 0x13,
0x64, 0x77, 0x14, 0x2b, 0x58, 0x30, 0x89, 0x0d, 0xec, 0x12, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff,
0xff, 0xe2, 0x1e, 0x29, 0x36, 0xb5, 0x00, 0x00, 0x00,
}

View File

@@ -1,9 +1,12 @@
syntax = "proto3";
package com.v2ray.core.proxy.vmess;
package v2ray.core.proxy.vmess;
option go_package = "vmess";
option java_package = "com.v2ray.core.proxy.vmess";
option java_outer_classname = "AccountProto";
message AccountPB {
string id = 1;
uint32 alterId = 2;
uint32 alter_id = 2;
}

View File

@@ -8,7 +8,7 @@ import (
func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
if this.detours != nil {
tag := this.detours.ToTag
tag := this.detours.To
if this.inboundHandlerManager != nil {
handler, availableMin := this.inboundHandlerManager.GetHandler(tag)
inboundHandler, ok := handler.(*VMessInboundHandler)

View File

@@ -1,25 +1,3 @@
package inbound
import (
"v2ray.com/core/common/protocol"
)
type DetourConfig struct {
ToTag string
}
type FeaturesConfig struct {
Detour *DetourConfig
}
type DefaultConfig struct {
AlterIDs uint16
Level uint32
}
type Config struct {
AllowedUsers []*protocol.User
Features *FeaturesConfig
Defaults *DefaultConfig
DetourConfig *DetourConfig
}
import ()

View File

@@ -0,0 +1,113 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/vmess/inbound/config.proto
// DO NOT EDIT!
/*
Package inbound is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/vmess/inbound/config.proto
It has these top-level messages:
DetourConfig
DefaultConfig
Config
*/
package inbound
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import v2ray_core_common_protocol "v2ray.com/core/common/protocol"
// 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 DetourConfig struct {
To string `protobuf:"bytes,1,opt,name=to" json:"to,omitempty"`
}
func (m *DetourConfig) Reset() { *m = DetourConfig{} }
func (m *DetourConfig) String() string { return proto.CompactTextString(m) }
func (*DetourConfig) ProtoMessage() {}
func (*DetourConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type DefaultConfig struct {
AlterId uint32 `protobuf:"varint,1,opt,name=alter_id,json=alterId" json:"alter_id,omitempty"`
Level uint32 `protobuf:"varint,2,opt,name=level" json:"level,omitempty"`
}
func (m *DefaultConfig) Reset() { *m = DefaultConfig{} }
func (m *DefaultConfig) String() string { return proto.CompactTextString(m) }
func (*DefaultConfig) ProtoMessage() {}
func (*DefaultConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type Config struct {
User []*v2ray_core_common_protocol.User `protobuf:"bytes,1,rep,name=user" json:"user,omitempty"`
Default *DefaultConfig `protobuf:"bytes,2,opt,name=default" json:"default,omitempty"`
Detour *DetourConfig `protobuf:"bytes,3,opt,name=detour" json:"detour,omitempty"`
}
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{2} }
func (m *Config) GetUser() []*v2ray_core_common_protocol.User {
if m != nil {
return m.User
}
return nil
}
func (m *Config) GetDefault() *DefaultConfig {
if m != nil {
return m.Default
}
return nil
}
func (m *Config) GetDetour() *DetourConfig {
if m != nil {
return m.Detour
}
return nil
}
func init() {
proto.RegisterType((*DetourConfig)(nil), "v2ray.core.proxy.vmess.inbound.DetourConfig")
proto.RegisterType((*DefaultConfig)(nil), "v2ray.core.proxy.vmess.inbound.DefaultConfig")
proto.RegisterType((*Config)(nil), "v2ray.core.proxy.vmess.inbound.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/vmess/inbound/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 283 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x90, 0x4f, 0x4b, 0xc3, 0x40,
0x10, 0xc5, 0x49, 0xab, 0x89, 0x4e, 0xac, 0x87, 0xe0, 0x21, 0x7a, 0x28, 0x21, 0xa7, 0x0a, 0xba,
0x0b, 0xd1, 0x93, 0x27, 0xa9, 0x01, 0xf1, 0x26, 0x01, 0x2f, 0x5e, 0x24, 0xdd, 0x4c, 0x25, 0x90,
0x64, 0xca, 0x66, 0x13, 0xec, 0x87, 0xf4, 0x3b, 0x49, 0x27, 0x1b, 0xfc, 0x73, 0xb0, 0xc7, 0x19,
0xde, 0xef, 0xcd, 0x7b, 0x03, 0xb2, 0x4f, 0x74, 0xbe, 0x15, 0x8a, 0x6a, 0xa9, 0x48, 0xa3, 0xdc,
0x68, 0xfa, 0xd8, 0xca, 0xbe, 0xc6, 0xb6, 0x95, 0x65, 0xb3, 0xa2, 0xae, 0x29, 0xa4, 0xa2, 0x66,
0x5d, 0xbe, 0x8b, 0x8d, 0x26, 0x43, 0xc1, 0x7c, 0x04, 0x34, 0x0a, 0x16, 0x0b, 0x16, 0x0b, 0x2b,
0xbe, 0xb8, 0xfc, 0x63, 0xa8, 0xa8, 0xae, 0xa9, 0x91, 0x0c, 0x2b, 0xaa, 0x64, 0xd7, 0xa2, 0x1e,
0xac, 0xe2, 0x39, 0x9c, 0xa4, 0x68, 0xa8, 0xd3, 0x0f, 0x7c, 0x20, 0x38, 0x85, 0x89, 0xa1, 0xd0,
0x89, 0x9c, 0xc5, 0x71, 0x36, 0x31, 0x14, 0xdf, 0xc3, 0x2c, 0xc5, 0x75, 0xde, 0x55, 0xc6, 0x0a,
0xce, 0xe1, 0x28, 0xaf, 0x0c, 0xea, 0xb7, 0xb2, 0x60, 0xd9, 0x2c, 0xf3, 0x78, 0x7e, 0x2a, 0x82,
0x33, 0x38, 0xac, 0xb0, 0xc7, 0x2a, 0x9c, 0xf0, 0x7e, 0x18, 0xe2, 0x4f, 0x07, 0x5c, 0xcb, 0xde,
0xc2, 0xc1, 0xee, 0x74, 0xe8, 0x44, 0xd3, 0x85, 0x9f, 0x44, 0xe2, 0x47, 0x8d, 0x21, 0xa2, 0x18,
0x23, 0x8a, 0x97, 0x16, 0x75, 0xc6, 0xea, 0xe0, 0x11, 0xbc, 0x62, 0x88, 0xc0, 0xc6, 0x7e, 0x72,
0x2d, 0xfe, 0xef, 0x2f, 0x7e, 0x25, 0xce, 0x46, 0x3a, 0x48, 0xc1, 0x2d, 0xb8, 0x6b, 0x38, 0x65,
0x9f, 0xab, 0xfd, 0x3e, 0xdf, 0x9f, 0xc9, 0x2c, 0xbb, 0xbc, 0x83, 0x58, 0x51, 0xbd, 0x07, 0x5d,
0xfa, 0x03, 0xf5, 0xbc, 0xeb, 0xf3, 0xea, 0xd9, 0xed, 0xca, 0xe5, 0x7e, 0x37, 0x5f, 0x01, 0x00,
0x00, 0xff, 0xff, 0xf7, 0x79, 0xbc, 0x25, 0xf2, 0x01, 0x00, 0x00,
}

View File

@@ -0,0 +1,23 @@
syntax = "proto3";
package v2ray.core.proxy.vmess.inbound;
option go_package = "inbound";
option java_package = "com.v2ray.core.proxy.vmess.inbound";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/protocol/user.proto";
message DetourConfig {
string to = 1;
}
message DefaultConfig {
uint32 alter_id = 1;
uint32 level = 2;
}
message Config {
repeated v2ray.core.common.protocol.User user = 1;
DefaultConfig default = 2;
DetourConfig detour = 3;
}

View File

@@ -23,20 +23,12 @@ func (this *DetourConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("VMess|Inbound: Failed to parse detour config: " + err.Error())
}
this.ToTag = jsonConfig.ToTag
this.To = jsonConfig.ToTag
return nil
}
func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
type JsonFeaturesConfig struct {
Detour *DetourConfig `json:"detour"`
}
jsonConfig := new(JsonFeaturesConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("VMess|Inbound: Failed to parse features config: " + err.Error())
}
this.Detour = jsonConfig.Detour
return nil
type FeaturesConfig struct {
Detour *DetourConfig `json:"detour"`
}
func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
@@ -48,9 +40,9 @@ func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("VMess|Inbound: Failed to parse default config: " + err.Error())
}
this.AlterIDs = jsonConfig.AlterIDs
if this.AlterIDs == 0 {
this.AlterIDs = 32
this.AlterId = uint32(jsonConfig.AlterIDs)
if this.AlterId == 0 {
this.AlterId = 32
}
this.Level = uint32(jsonConfig.Level)
return nil
@@ -67,20 +59,19 @@ func (this *Config) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, jsonConfig); err != nil {
return errors.New("VMess|Inbound: Failed to parse config: " + err.Error())
}
this.Features = jsonConfig.Features // Backward compatibility
this.Defaults = jsonConfig.Defaults
if this.Defaults == nil {
this.Defaults = &DefaultConfig{
Level: 0,
AlterIDs: 32,
this.Default = jsonConfig.Defaults
if this.Default == nil {
this.Default = &DefaultConfig{
Level: 0,
AlterId: 32,
}
}
this.DetourConfig = jsonConfig.DetourConfig
this.Detour = jsonConfig.DetourConfig
// Backward compatibility
if this.Features != nil && this.DetourConfig == nil {
this.DetourConfig = this.Features.Detour
if jsonConfig.Features != nil && jsonConfig.DetourConfig == nil {
this.Detour = jsonConfig.Features.Detour
}
this.AllowedUsers = make([]*protocol.User, len(jsonConfig.Users))
this.User = make([]*protocol.User, len(jsonConfig.Users))
for idx, rawData := range jsonConfig.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawData, user); err != nil {
@@ -96,7 +87,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return common.ErrBadConfiguration
}
user.Account = anyAccount
this.AllowedUsers[idx] = user
this.User[idx] = user
}
return nil

View File

@@ -39,7 +39,7 @@ func NewUserByEmail(users []*protocol.User, config *DefaultConfig) *userByEmail
return &userByEmail{
cache: cache,
defaultLevel: config.Level,
defaultAlterIDs: config.AlterIDs,
defaultAlterIDs: uint16(config.AlterId),
}
}
@@ -249,8 +249,10 @@ func (this *VMessInboundHandler) HandleConnection(connection internet.Connection
type Factory struct{}
func (this *Factory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP | internet.StreamConnectionTypeTCP | internet.StreamConnectionTypeKCP | internet.StreamConnectionTypeWebSocket
func (this *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP, v2net.Network_KCP, v2net.Network_WebSocket},
}
}
func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
@@ -260,15 +262,15 @@ func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.
config := rawConfig.(*Config)
allowedClients := vmess.NewTimedUserValidator(protocol.DefaultIDHash)
for _, user := range config.AllowedUsers {
for _, user := range config.User {
allowedClients.Add(user)
}
handler := &VMessInboundHandler{
packetDispatcher: space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher),
clients: allowedClients,
detours: config.DetourConfig,
usersByEmail: NewUserByEmail(config.AllowedUsers, config.Defaults),
detours: config.Detour,
usersByEmail: NewUserByEmail(config.User, config.Default),
meta: meta,
}

View File

@@ -30,7 +30,7 @@ func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd prot
switch typedCommand := cmd.(type) {
case *protocol.CommandSwitchAccount:
if typedCommand.Host == nil {
typedCommand.Host = dest.Address()
typedCommand.Host = dest.Address
}
this.handleSwitchAccount(typedCommand)
default:

View File

@@ -1,9 +1,3 @@
package outbound
import (
"v2ray.com/core/common/protocol"
)
type Config struct {
Receivers []*protocol.ServerSpec
}
import ()

View File

@@ -0,0 +1,69 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/vmess/outbound/config.proto
// DO NOT EDIT!
/*
Package outbound is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/vmess/outbound/config.proto
It has these top-level messages:
Config
*/
package outbound
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import v2ray_core_common_protocol1 "v2ray.com/core/common/protocol"
// 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 {
Receiver []*v2ray_core_common_protocol1.ServerSpecPB `protobuf:"bytes,1,rep,name=Receiver,json=receiver" json:"Receiver,omitempty"`
}
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 (m *Config) GetReceiver() []*v2ray_core_common_protocol1.ServerSpecPB {
if m != nil {
return m.Receiver
}
return nil
}
func init() {
proto.RegisterType((*Config)(nil), "v2ray.core.proxy.vmess.outbound.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/vmess/outbound/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 193 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0xce, 0x31, 0x6b, 0xc3, 0x30,
0x10, 0x05, 0x60, 0x4a, 0xc1, 0x18, 0x79, 0xf3, 0x54, 0xba, 0xb4, 0xb4, 0x8b, 0xa7, 0x53, 0x71,
0xd7, 0x4e, 0x6e, 0xe6, 0x60, 0xec, 0x2d, 0x4b, 0x88, 0x2f, 0x97, 0x60, 0x88, 0x7c, 0xe2, 0x64,
0x8b, 0xf8, 0xdf, 0x87, 0xc8, 0x11, 0x84, 0x2c, 0x59, 0x8f, 0xf7, 0xbe, 0x77, 0xea, 0xc7, 0x97,
0xb2, 0x9b, 0x01, 0xd9, 0x68, 0x64, 0x21, 0x6d, 0x85, 0xcf, 0xb3, 0xf6, 0x86, 0x9c, 0xd3, 0x3c,
0x8d, 0x1d, 0x4f, 0xc3, 0x5e, 0x23, 0x0f, 0x87, 0xfe, 0x08, 0x56, 0x78, 0xe4, 0xfc, 0x23, 0x36,
0x84, 0x20, 0xa4, 0x21, 0xa4, 0x21, 0xa6, 0xdf, 0x1f, 0x49, 0x64, 0x63, 0x78, 0xd0, 0xa1, 0x8d,
0x7c, 0xd2, 0x8e, 0xc4, 0x93, 0x6c, 0x9d, 0x25, 0x5c, 0xc8, 0xaf, 0xb5, 0x4a, 0xfe, 0xc3, 0x44,
0xbe, 0x52, 0x69, 0x43, 0x48, 0xbd, 0x27, 0x79, 0x7b, 0xf9, 0x7c, 0x2d, 0xb2, 0xb2, 0x80, 0xbb,
0xbd, 0x85, 0x82, 0x48, 0x41, 0x1b, 0xa8, 0xd6, 0x12, 0xd6, 0x55, 0x93, 0xca, 0xad, 0x59, 0xfd,
0xa9, 0x6f, 0x64, 0x03, 0x4f, 0x1e, 0xad, 0xb2, 0x65, 0xb4, 0xbe, 0x6a, 0x9b, 0x34, 0x9e, 0xbb,
0x24, 0xf0, 0xbf, 0x97, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x86, 0x34, 0xb5, 0x1b, 0x01, 0x00,
0x00,
}

View File

@@ -0,0 +1,12 @@
syntax = "proto3";
package v2ray.core.proxy.vmess.outbound;
option go_package = "outbound";
option java_package = "com.v2ray.core.proxy.vmess.outbound";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/protocol/server_spec.proto";
message Config {
repeated v2ray.core.common.protocol.ServerSpecPB Receiver = 1;
}

View File

@@ -35,7 +35,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
log.Error("VMessOut: 0 VMess receiver configured.")
return common.ErrBadConfiguration
}
serverSpecs := make([]*protocol.ServerSpec, len(rawOutbound.Receivers))
serverSpecs := make([]*protocol.ServerSpecPB, len(rawOutbound.Receivers))
for idx, rec := range rawOutbound.Receivers {
if len(rec.Users) == 0 {
log.Error("VMess: 0 user configured for VMess outbound.")
@@ -50,7 +50,10 @@ func (this *Config) UnmarshalJSON(data []byte) error {
Ip: serial.Uint32ToBytes(757086633, nil),
}
}
spec := protocol.NewServerSpec(vmess.NewAccount, v2net.TCPDestination(rec.Address.AsAddress(), rec.Port), protocol.AlwaysValid())
spec := &protocol.ServerSpecPB{
Address: rec.Address,
Port: uint32(rec.Port),
}
for _, rawUser := range rec.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
@@ -68,12 +71,11 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return common.ErrBadConfiguration
}
user.Account = anyAccount
spec.AddUser(user)
spec.User = append(spec.User, user)
}
serverSpecs[idx] = spec
}
this.Receivers = serverSpecs
this.Receiver = serverSpecs
return nil
}

View File

@@ -6,7 +6,8 @@ import (
"encoding/json"
"testing"
//"v2ray.com/core/common/protocol"
"v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/vmess"
. "v2ray.com/core/proxy/vmess/outbound"
"v2ray.com/core/testing/assert"
)
@@ -31,5 +32,7 @@ func TestConfigTargetParsing(t *testing.T) {
config := new(Config)
err := json.Unmarshal([]byte(rawJson), &config)
assert.Error(err).IsNil()
assert.Destination(config.Receivers[0].Destination()).EqualsString("tcp:127.0.0.1:80")
specPB := config.Receiver[0]
spec := protocol.NewServerSpecFromPB(vmess.NewAccount, *specPB)
assert.Destination(spec.Destination()).EqualsString("tcp:127.0.0.1:80")
}

View File

@@ -13,6 +13,7 @@ import (
"v2ray.com/core/common/retry"
"v2ray.com/core/proxy"
"v2ray.com/core/proxy/registry"
"v2ray.com/core/proxy/vmess"
"v2ray.com/core/proxy/vmess/encoding"
vmessio "v2ray.com/core/proxy/vmess/io"
"v2ray.com/core/transport/internet"
@@ -49,15 +50,15 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())
command := protocol.RequestCommandTCP
if target.Network() == v2net.UDPNetwork {
if target.Network == v2net.Network_UDP {
command = protocol.RequestCommandUDP
}
request := &protocol.RequestHeader{
Version: encoding.Version,
User: rec.PickUser(),
Command: command,
Address: target.Address(),
Port: target.Port(),
Address: target.Address,
Port: target.Port,
Option: protocol.RequestOptionChunkStream,
}
@@ -159,16 +160,18 @@ func (this *VMessOutboundHandler) handleResponse(session *encoding.ClientSession
type Factory struct{}
func (this *Factory) StreamCapability() internet.StreamConnectionType {
return internet.StreamConnectionTypeRawTCP | internet.StreamConnectionTypeTCP | internet.StreamConnectionTypeKCP | internet.StreamConnectionTypeWebSocket
func (this *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP, v2net.Network_KCP, v2net.Network_WebSocket},
}
}
func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
vOutConfig := rawConfig.(*Config)
serverList := protocol.NewServerList()
for _, rec := range vOutConfig.Receivers {
serverList.AddServer(rec)
for _, rec := range vOutConfig.Receiver {
serverList.AddServer(protocol.NewServerSpecFromPB(vmess.NewAccount, *rec))
}
handler := &VMessOutboundHandler{
serverList: serverList,

View File

@@ -1,6 +1,8 @@
package point
import (
"io"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/router"
"v2ray.com/core/common"
@@ -13,7 +15,7 @@ import (
type InboundConnectionConfig struct {
Port v2net.Port
ListenOn v2net.Address
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
Protocol string
Settings []byte
AllowPassiveConnection bool
@@ -22,7 +24,7 @@ type InboundConnectionConfig struct {
type OutboundConnectionConfig struct {
Protocol string
SendThrough v2net.Address
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
Settings []byte
}
@@ -50,7 +52,7 @@ type InboundDetourConfig struct {
ListenOn v2net.Address
Tag string
Allocation *InboundDetourAllocationConfig
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
Settings []byte
AllowPassiveConnection bool
}
@@ -58,7 +60,7 @@ type InboundDetourConfig struct {
type OutboundDetourConfig struct {
Protocol string
SendThrough v2net.Address
StreamSettings *internet.StreamSettings
StreamSettings *internet.StreamConfig
Tag string
Settings []byte
}
@@ -75,15 +77,15 @@ type Config struct {
TransportConfig *transport.Config
}
type ConfigLoader func(init string) (*Config, error)
type ConfigLoader func(input io.Reader) (*Config, error)
var (
configLoader ConfigLoader
)
func LoadConfig(init string) (*Config, error) {
func LoadConfig(input io.Reader) (*Config, error) {
if configLoader == nil {
return nil, common.ErrBadConfiguration
}
return configLoader(init)
return configLoader(input)
}

View File

@@ -5,8 +5,7 @@ package point
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"io"
"strings"
"v2ray.com/core/app/dns"
@@ -55,9 +54,15 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.OutboundDetours = jsonConfig.OutboundDetours
if jsonConfig.DNSConfig == nil {
jsonConfig.DNSConfig = &dns.Config{
NameServers: []v2net.Destination{
v2net.UDPDestination(v2net.DomainAddress("localhost"), v2net.Port(53)),
},
NameServers: []*v2net.DestinationPB{{
Network: v2net.Network_UDP,
Address: &v2net.AddressPB{
Address: &v2net.AddressPB_Domain{
Domain: "localhost",
},
},
Port: 53,
}},
}
}
this.DNSConfig = jsonConfig.DNSConfig
@@ -67,12 +72,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
func (this *InboundConnectionConfig) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Port uint16 `json:"port"`
Listen *v2net.AddressPB `json:"listen"`
Protocol string `json:"protocol"`
StreamSetting *internet.StreamSettings `json:"streamSettings"`
Settings json.RawMessage `json:"settings"`
AllowPassive bool `json:"allowPassive"`
Port uint16 `json:"port"`
Listen *v2net.AddressPB `json:"listen"`
Protocol string `json:"protocol"`
StreamSetting *internet.StreamConfig `json:"streamSettings"`
Settings json.RawMessage `json:"settings"`
AllowPassive bool `json:"allowPassive"`
}
jsonConfig := new(JsonConfig)
@@ -99,10 +104,10 @@ func (this *InboundConnectionConfig) UnmarshalJSON(data []byte) error {
func (this *OutboundConnectionConfig) UnmarshalJSON(data []byte) error {
type JsonConnectionConfig struct {
Protocol string `json:"protocol"`
SendThrough *v2net.AddressPB `json:"sendThrough"`
StreamSetting *internet.StreamSettings `json:"streamSettings"`
Settings json.RawMessage `json:"settings"`
Protocol string `json:"protocol"`
SendThrough *v2net.AddressPB `json:"sendThrough"`
StreamSetting *internet.StreamConfig `json:"streamSettings"`
Settings json.RawMessage `json:"settings"`
}
jsonConfig := new(JsonConnectionConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@@ -188,7 +193,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
Settings json.RawMessage `json:"settings"`
Tag string `json:"tag"`
Allocation *InboundDetourAllocationConfig `json:"allocate"`
StreamSetting *internet.StreamSettings `json:"streamSettings"`
StreamSetting *internet.StreamConfig `json:"streamSettings"`
AllowPassive bool `json:"allowPassive"`
}
jsonConfig := new(JsonInboundDetourConfig)
@@ -226,11 +231,11 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
func (this *OutboundDetourConfig) UnmarshalJSON(data []byte) error {
type JsonOutboundDetourConfig struct {
Protocol string `json:"protocol"`
SendThrough *v2net.AddressPB `json:"sendThrough"`
Tag string `json:"tag"`
Settings json.RawMessage `json:"settings"`
StreamSetting *internet.StreamSettings `json:"streamSettings"`
Protocol string `json:"protocol"`
SendThrough *v2net.AddressPB `json:"sendThrough"`
Tag string `json:"tag"`
Settings json.RawMessage `json:"settings"`
StreamSetting *internet.StreamConfig `json:"streamSettings"`
}
jsonConfig := new(JsonOutboundDetourConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@@ -254,16 +259,10 @@ func (this *OutboundDetourConfig) UnmarshalJSON(data []byte) error {
return nil
}
func JsonLoadConfig(file string) (*Config, error) {
fixedFile := os.ExpandEnv(file)
rawConfig, err := ioutil.ReadFile(fixedFile)
if err != nil {
log.Error("Point: Failed to read server config file (", file, "): ", file, err)
return nil, err
}
func JsonLoadConfig(input io.Reader) (*Config, error) {
jsonConfig := &Config{}
err = json.Unmarshal(rawConfig, jsonConfig)
decoder := json.NewDecoder(input)
err := decoder.Decode(jsonConfig)
if err != nil {
log.Error("Point: Failed to load server config: ", err)
return nil, err

View File

@@ -4,6 +4,7 @@ package point_test
import (
"encoding/json"
"io"
"os"
"path/filepath"
"testing"
@@ -14,13 +15,19 @@ import (
"v2ray.com/core/testing/assert"
)
func OpenFile(file string, assert *assert.Assert) io.Reader {
input, err := os.Open(file)
assert.Error(err).IsNil()
return input
}
func TestClientSampleConfig(t *testing.T) {
assert := assert.On(t)
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_socks_vmess.json"), assert))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
@@ -40,7 +47,7 @@ func TestServerSampleConfig(t *testing.T) {
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_vmess_freedom.json"), assert))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()

Some files were not shown because too many files have changed in this diff Show More