diff --git a/all.go b/all.go index 529c659a5..77444fac9 100644 --- a/all.go +++ b/all.go @@ -2,6 +2,7 @@ package core import ( // The following are necessary as they register handlers in their init functions. + _ "v2ray.com/core/app/dispatcher/impl" _ "v2ray.com/core/app/dns" _ "v2ray.com/core/app/proxy" _ "v2ray.com/core/app/router" diff --git a/app/dispatcher/config.pb.go b/app/dispatcher/config.pb.go new file mode 100644 index 000000000..db22b31f5 --- /dev/null +++ b/app/dispatcher/config.pb.go @@ -0,0 +1,55 @@ +// Code generated by protoc-gen-go. +// source: v2ray.com/core/app/dispatcher/config.proto +// DO NOT EDIT! + +/* +Package dispatcher is a generated protocol buffer package. + +It is generated from these files: + v2ray.com/core/app/dispatcher/config.proto + +It has these top-level messages: + Config +*/ +package dispatcher + +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 Config struct { +} + +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 init() { + proto.RegisterType((*Config)(nil), "v2ray.core.app.dispatcher.Config") +} + +func init() { proto.RegisterFile("v2ray.com/core/app/dispatcher/config.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 114 bytes of a gzipped FileDescriptorProto + 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, + 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, + 0xd0, 0x43, 0xa8, 0x53, 0xe2, 0xe0, 0x62, 0x73, 0x06, 0x2b, 0x75, 0xb2, 0xe0, 0x92, 0x4d, 0xce, + 0xcf, 0xd5, 0xc3, 0xa9, 0xd4, 0x89, 0x1b, 0xa2, 0x30, 0x00, 0x64, 0x64, 0x14, 0x17, 0x42, 0x22, + 0x89, 0x0d, 0x6c, 0x8b, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xc1, 0x99, 0x9d, 0x93, 0x00, + 0x00, 0x00, +} diff --git a/app/dispatcher/config.proto b/app/dispatcher/config.proto new file mode 100644 index 000000000..9550ed413 --- /dev/null +++ b/app/dispatcher/config.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package v2ray.core.app.dispatcher; +option go_package = "dispatcher"; +option java_package = "com.v2ray.core.app.dispatcher"; +option java_outer_classname = "ConfigProto"; + +message Config { + +} \ No newline at end of file diff --git a/app/dispatcher/impl/default.go b/app/dispatcher/impl/default.go index 5ae2f6475..61dca9235 100644 --- a/app/dispatcher/impl/default.go +++ b/app/dispatcher/impl/default.go @@ -2,12 +2,14 @@ package impl import ( "v2ray.com/core/app" + "v2ray.com/core/app/dispatcher" "v2ray.com/core/app/proxyman" "v2ray.com/core/app/router" "v2ray.com/core/common/buf" "v2ray.com/core/common/errors" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/serial" "v2ray.com/core/proxy" "v2ray.com/core/transport/ray" ) @@ -81,3 +83,17 @@ func (v *DefaultDispatcher) FilterPacketAndDispatch(destination v2net.Destinatio } dispatcher.Dispatch(destination, payload, link) } + +type DefaultDispatcherFactory struct{} + +func (v DefaultDispatcherFactory) Create(space app.Space, config interface{}) (app.Application, error) { + return NewDefaultDispatcher(space), nil +} + +func (v DefaultDispatcherFactory) AppId() app.ID { + return dispatcher.APP_ID +} + +func init() { + app.RegisterApplicationFactory(serial.GetMessageType(new(dispatcher.Config)), DefaultDispatcherFactory{}) +} diff --git a/v2ray.go b/v2ray.go index afcaca38b..14327fc19 100644 --- a/v2ray.go +++ b/v2ray.go @@ -3,13 +3,13 @@ package core import ( "v2ray.com/core/app" "v2ray.com/core/app/dispatcher" - dispatchers "v2ray.com/core/app/dispatcher/impl" "v2ray.com/core/app/dns" proxydialer "v2ray.com/core/app/proxy" "v2ray.com/core/app/proxyman" "v2ray.com/core/common" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" + "v2ray.com/core/common/serial" "v2ray.com/core/proxy" ) @@ -69,7 +69,10 @@ func NewPoint(pConfig *Config) (*Point, error) { space.BindApp(dns.APP_ID, dnsServer) } - vpoint.space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(vpoint.space)) + dispatcherConfig := new(dispatcher.Config) + if err := vpoint.space.BindFromConfig(serial.GetMessageType(dispatcherConfig), dispatcherConfig); err != nil { + return nil, err + } vpoint.inboundHandlers = make([]InboundDetourHandler, 0, 8) vpoint.taggedInboundHandlers = make(map[string]InboundDetourHandler)