mux.go 664 B

123456789101112131415161718192021222324252627282930313233
  1. package inbound
  2. import (
  3. "context"
  4. "errors"
  5. "v2ray.com/core/app"
  6. "v2ray.com/core/app/dispatcher"
  7. "v2ray.com/core/common/net"
  8. "v2ray.com/core/transport/ray"
  9. )
  10. type mux struct {
  11. dispatcher dispatcher.Interface
  12. }
  13. func newMux(ctx context.Context) *mux {
  14. m := &mux{}
  15. space := app.SpaceFromContext(ctx)
  16. space.OnInitialize(func() error {
  17. d := dispatcher.FromSpace(space)
  18. if d == nil {
  19. return errors.New("Proxyman|DefaultInboundHandler: No dispatcher in space.")
  20. }
  21. m.dispatcher = d
  22. return nil
  23. })
  24. return m
  25. }
  26. func (m *mux) Dispatch(ctx context.Context, dest net.Destination) (ray.InboundRay, error) {
  27. return m.dispatcher.Dispatch(ctx, dest)
  28. }