Browse Source

prototype for payload inspector

Darien Raymond 8 years ago
parent
commit
3ddacbb9c9

+ 44 - 6
app/dispatcher/config.pb.go

@@ -28,7 +28,32 @@ var _ = math.Inf
 // proto package needs to be updated.
 // proto package needs to be updated.
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
 
+type Config_FixDestination int32
+
+const (
+	Config_Auto     Config_FixDestination = 0
+	Config_Enabled  Config_FixDestination = 1
+	Config_Disabled Config_FixDestination = 2
+)
+
+var Config_FixDestination_name = map[int32]string{
+	0: "Auto",
+	1: "Enabled",
+	2: "Disabled",
+}
+var Config_FixDestination_value = map[string]int32{
+	"Auto":     0,
+	"Enabled":  1,
+	"Disabled": 2,
+}
+
+func (x Config_FixDestination) String() string {
+	return proto.EnumName(Config_FixDestination_name, int32(x))
+}
+func (Config_FixDestination) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0, 0} }
+
 type Config struct {
 type Config struct {
+	FixDestination Config_FixDestination `protobuf:"varint,1,opt,name=fix_destination,json=fixDestination,enum=v2ray.core.app.dispatcher.Config_FixDestination" json:"fix_destination,omitempty"`
 }
 }
 
 
 func (m *Config) Reset()                    { *m = Config{} }
 func (m *Config) Reset()                    { *m = Config{} }
@@ -36,21 +61,34 @@ func (m *Config) String() string            { return proto.CompactTextString(m)
 func (*Config) ProtoMessage()               {}
 func (*Config) ProtoMessage()               {}
 func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
 func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
 
 
+func (m *Config) GetFixDestination() Config_FixDestination {
+	if m != nil {
+		return m.FixDestination
+	}
+	return Config_Auto
+}
+
 func init() {
 func init() {
 	proto.RegisterType((*Config)(nil), "v2ray.core.app.dispatcher.Config")
 	proto.RegisterType((*Config)(nil), "v2ray.core.app.dispatcher.Config")
+	proto.RegisterEnum("v2ray.core.app.dispatcher.Config_FixDestination", Config_FixDestination_name, Config_FixDestination_value)
 }
 }
 
 
 func init() { proto.RegisterFile("v2ray.com/core/app/dispatcher/config.proto", fileDescriptor0) }
 func init() { proto.RegisterFile("v2ray.com/core/app/dispatcher/config.proto", fileDescriptor0) }
 
 
 var fileDescriptor0 = []byte{
 var fileDescriptor0 = []byte{
-	// 134 bytes of a gzipped FileDescriptorProto
+	// 218 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x2a, 0x33, 0x2a, 0x4a,
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xd2, 0x2a, 0x33, 0x2a, 0x4a,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x2c, 0x28, 0xd0, 0x4f,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x2c, 0x28, 0xd0, 0x4f,
 	0xc9, 0x2c, 0x2e, 0x48, 0x2c, 0x49, 0xce, 0x48, 0x2d, 0xd2, 0x4f, 0xce, 0xcf, 0x4b, 0xcb, 0x4c,
 	0xc9, 0x2c, 0x2e, 0x48, 0x2c, 0x49, 0xce, 0x48, 0x2d, 0xd2, 0x4f, 0xce, 0xcf, 0x4b, 0xcb, 0x4c,
 	0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x84, 0xa9, 0x2d, 0x4a, 0xd5, 0x4b, 0x2c, 0x28,
 	0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x84, 0xa9, 0x2d, 0x4a, 0xd5, 0x4b, 0x2c, 0x28,
-	0xd0, 0x43, 0xa8, 0x53, 0xe2, 0xe0, 0x62, 0x73, 0x06, 0x2b, 0x75, 0x0a, 0xe1, 0x92, 0x4d, 0xce,
-	0xcf, 0xd5, 0xc3, 0xa9, 0xd4, 0x89, 0x1b, 0xa2, 0x30, 0x00, 0x64, 0x64, 0x14, 0x17, 0x42, 0x62,
-	0x15, 0x93, 0x64, 0x98, 0x51, 0x50, 0x62, 0xa5, 0x9e, 0x33, 0x48, 0x93, 0x63, 0x41, 0x81, 0x9e,
-	0x0b, 0x5c, 0x2e, 0x89, 0x0d, 0xec, 0x02, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0xf8,
-	0x2f, 0x3b, 0xaf, 0x00, 0x00, 0x00,
+	0xd0, 0x43, 0xa8, 0x53, 0x9a, 0xc5, 0xc8, 0xc5, 0xe6, 0x0c, 0x56, 0x2b, 0x14, 0xc9, 0xc5, 0x9f,
+	0x96, 0x59, 0x11, 0x9f, 0x92, 0x5a, 0x5c, 0x92, 0x99, 0x97, 0x58, 0x92, 0x99, 0x9f, 0x27, 0xc1,
+	0xa8, 0xc0, 0xa8, 0xc1, 0x67, 0x64, 0xa0, 0x87, 0x53, 0xbf, 0x1e, 0x44, 0xaf, 0x9e, 0x5b, 0x66,
+	0x85, 0x0b, 0x42, 0x5f, 0x10, 0x5f, 0x1a, 0x0a, 0x5f, 0xc9, 0x94, 0x8b, 0x0f, 0x55, 0x85, 0x10,
+	0x07, 0x17, 0x8b, 0x63, 0x69, 0x49, 0xbe, 0x00, 0x83, 0x10, 0x37, 0x17, 0xbb, 0x6b, 0x5e, 0x62,
+	0x52, 0x4e, 0x6a, 0x8a, 0x00, 0xa3, 0x10, 0x0f, 0x17, 0x87, 0x4b, 0x66, 0x31, 0x84, 0xc7, 0xe4,
+	0x14, 0xc2, 0x25, 0x9b, 0x9c, 0x9f, 0x8b, 0xdb, 0x76, 0x27, 0x6e, 0x88, 0xf5, 0x01, 0x20, 0x5f,
+	0x46, 0x71, 0x21, 0x24, 0x56, 0x31, 0x49, 0x86, 0x19, 0x05, 0x25, 0x56, 0xea, 0x39, 0x83, 0x34,
+	0x39, 0x16, 0x14, 0xe8, 0xb9, 0xc0, 0xe5, 0x92, 0xd8, 0xc0, 0x81, 0x62, 0x0c, 0x08, 0x00, 0x00,
+	0xff, 0xff, 0x63, 0xfd, 0xa7, 0xdb, 0x42, 0x01, 0x00, 0x00,
 }
 }

+ 8 - 2
app/dispatcher/config.proto

@@ -7,5 +7,11 @@ option java_package = "com.v2ray.core.app.dispatcher";
 option java_outer_classname = "ConfigProto";
 option java_outer_classname = "ConfigProto";
 
 
 message Config {
 message Config {
-  
-}
+  enum FixDestination {
+    Auto = 0;
+    Enabled = 1;
+    Disabled = 2;
+  }
+
+  FixDestination fix_destination = 1;
+}

+ 15 - 0
app/dispatcher/impl/default.go

@@ -85,6 +85,21 @@ func (v *DefaultDispatcher) FilterPacketAndDispatch(destination v2net.Destinatio
 	dispatcher.Dispatch(destination, payload, link)
 	dispatcher.Dispatch(destination, payload, link)
 }
 }
 
 
+func (v *DefaultDispatcher) FixDestination(payload *buf.Buffer, dest v2net.Destination) v2net.Destination {
+	if dest.Address.Family().IsDomain() || dest.Network != v2net.Network_TCP {
+		return dest
+	}
+
+	switch dest.Port {
+	case 80:
+		addr := DetectHTTPHost(payload)
+		if addr != nil {
+			dest.Address = addr
+		}
+	}
+	return dest
+}
+
 type DefaultDispatcherFactory struct{}
 type DefaultDispatcherFactory struct{}
 
 
 func (v DefaultDispatcherFactory) Create(space app.Space, config interface{}) (app.Application, error) {
 func (v DefaultDispatcherFactory) Create(space app.Space, config interface{}) (app.Application, error) {

+ 10 - 0
app/dispatcher/impl/http.go

@@ -0,0 +1,10 @@
+package impl
+
+import (
+	"v2ray.com/core/common/buf"
+	v2net "v2ray.com/core/common/net"
+)
+
+func DetectHTTPHost(payload *buf.Buffer) v2net.Address {
+	return nil
+}