mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-06 09:15:37 -05:00
simplify app design
This commit is contained in:
@@ -38,11 +38,11 @@ func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandler
|
||||
port: v2net.Port(config.Port),
|
||||
meta: meta,
|
||||
}
|
||||
space.InitializeApplication(func() error {
|
||||
if !space.HasApp(dispatcher.APP_ID) {
|
||||
space.OnInitialize(func() error {
|
||||
d.packetDispatcher = dispatcher.FromSpace(space)
|
||||
if d.packetDispatcher == nil {
|
||||
return errors.New("Dokodemo: Dispatcher is not found in the space.")
|
||||
}
|
||||
d.packetDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
|
||||
return nil
|
||||
})
|
||||
return d
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
dispatchers "v2ray.com/core/app/dispatcher/impl"
|
||||
_ "v2ray.com/core/app/dispatcher/impl"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/outbound"
|
||||
_ "v2ray.com/core/app/proxyman/outbound"
|
||||
"v2ray.com/core/common/dice"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
@@ -38,8 +38,10 @@ func TestDokodemoTCP(t *testing.T) {
|
||||
defer tcpServer.Close()
|
||||
|
||||
space := app.NewSpace()
|
||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||
ohm := outbound.New()
|
||||
space.AddApp(new(dispatcher.Config))
|
||||
space.AddApp(new(proxyman.OutboundConfig))
|
||||
|
||||
ohm := proxyman.OutboundHandlerManagerFromSpace(space)
|
||||
ohm.SetDefaultHandler(
|
||||
freedom.New(
|
||||
&freedom.Config{},
|
||||
@@ -50,7 +52,6 @@ func TestDokodemoTCP(t *testing.T) {
|
||||
Network: v2net.Network_TCP,
|
||||
},
|
||||
}))
|
||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
||||
|
||||
data2Send := "Data to be sent to remote."
|
||||
|
||||
@@ -109,8 +110,10 @@ func TestDokodemoUDP(t *testing.T) {
|
||||
defer udpServer.Close()
|
||||
|
||||
space := app.NewSpace()
|
||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||
ohm := outbound.New()
|
||||
space.AddApp(new(dispatcher.Config))
|
||||
space.AddApp(new(proxyman.OutboundConfig))
|
||||
|
||||
ohm := proxyman.OutboundHandlerManagerFromSpace(space)
|
||||
ohm.SetDefaultHandler(
|
||||
freedom.New(
|
||||
&freedom.Config{},
|
||||
@@ -120,7 +123,6 @@ func TestDokodemoUDP(t *testing.T) {
|
||||
StreamSettings: &internet.StreamConfig{
|
||||
Network: v2net.Network_TCP,
|
||||
}}))
|
||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm)
|
||||
|
||||
data2Send := "Data to be sent to remote."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user