unix.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package inbound
  2. import (
  3. "context"
  4. "v2ray.com/core/app/proxyman"
  5. "v2ray.com/core/app/proxyman/mux"
  6. "v2ray.com/core/common"
  7. "v2ray.com/core/common/net"
  8. "v2ray.com/core/proxy"
  9. "v2ray.com/core/transport/internet/domainsocket"
  10. )
  11. type UnixInboundHandler struct {
  12. tag string
  13. listenerHolder *domainsocket.Listener
  14. ctx context.Context
  15. path string
  16. proxy proxy.Inbound
  17. mux *mux.Server
  18. }
  19. func (uih *UnixInboundHandler) Start() {
  20. var err error
  21. uih.listenerHolder, err = domainsocket.ListenDS(uih.ctx, uih.path)
  22. newError(err).AtError().WriteToLog()
  23. }
  24. func (uih *UnixInboundHandler) Close() {
  25. if uih.listenerHolder != nil {
  26. uih.listenerHolder.Down()
  27. } else {
  28. newError("Called UnixInboundHandler.Close while listenerHolder is nil").AtDebug().WriteToLog()
  29. }
  30. }
  31. func (uih *UnixInboundHandler) Tag() string {
  32. return uih.tag
  33. }
  34. func (uih *UnixInboundHandler) GetRandomInboundProxy() (interface{}, net.Port, int) {
  35. //It makes bo sense to support it
  36. return nil, 0, 0
  37. }
  38. func NewUnixInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.UnixReceiverConfig, proxyConfig interface{}) (*UnixInboundHandler, error) {
  39. rawProxy, err := common.CreateObject(ctx, proxyConfig)
  40. if err != nil {
  41. return nil, err
  42. }
  43. p, ok := rawProxy.(proxy.Inbound)
  44. if !ok {
  45. return nil, newError("not an inbound proxy.")
  46. }
  47. h := &UnixInboundHandler{
  48. proxy: p,
  49. mux: mux.NewServer(ctx),
  50. tag: tag,
  51. ctx: ctx,
  52. path: receiverConfig.DomainSockSettings.GetPath(),
  53. }
  54. return h, nil
  55. }