apply mux in inbound handler

This commit is contained in:
Darien Raymond committed 2017-04-02 14:06:20 +02:00
1 parent 3161c56aba
commit 1e06cf34d9
4 files changed
+28 -38

No files matched your search

+22 -1
View File
@@ -5,9 +5,11 @@ import (
"sync"
"time"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/net"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
@@ -194,13 +196,32 @@ type Server struct {
dispatcher dispatcher.Interface
}
func NewServer(ctx context.Context) *Server {
s := &Server{}
space := app.SpaceFromContext(ctx)
space.OnInitialize(func() error {
d := dispatcher.FromSpace(space)
if d == nil {
return errors.New("Proxyman|Mux: No dispatcher in space.")
}
s.dispatcher = d
return nil
})
return s
}
func (s *Server) Dispatch(ctx context.Context, dest net.Destination) (ray.InboundRay, error) {
if dest != muxCoolDestination {
return s.dispatcher.Dispatch(ctx, dest)
}
ray := ray.NewRay(ctx)
worker := &ServerWorker{
dispatcher: s.dispatcher,
outboundRay: ray,
sessions: make(map[uint16]*session),
}
go worker.run(ctx)
return ray, nil
}