| 1 | package outboundscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/ |
| 2 | |
| 3 | //go:generate go run v2ray.com/core/common/errors/errorgen |
| 4 | |
| 5 | import ( |
| 6 | "contextscip-go gomod github.com/golang/go/src go1.15 context/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.15 strings/" |
| 8 | "syncscip-go gomod github.com/golang/go/src go1.15 sync/" |
| 9 | |
| 10 | "v2ray.com/corescip-go gomod v2ray.com/core . `v2ray.com/core`/" |
| 11 | "v2ray.com/core/app/proxymanscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/" |
| 12 | "v2ray.com/core/commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/" |
| 13 | "v2ray.com/core/common/errorsscip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/" |
| 14 | "v2ray.com/core/features/outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/" |
| 15 | ) |
| 16 | |
| 17 | // Manager is to manage all outbound handlers. |
| 18 | type Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager# struct { |
| 19 | accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access. syncscip-go gomod github.com/golang/go/src go1.15 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex# |
| 20 | defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler# |
| 21 | taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler. map[string]outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler# |
| 22 | untaggedHandlersscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#untaggedHandlers. []outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler# |
| 23 | runningscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#running. bool |
| 24 | } |
| 25 | |
| 26 | // New creates a new Manager. |
| 27 | func Newscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/New().(ctx contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/golang/go/src go1.15 context/Context#, config *proxymanscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/.OutboundConfigscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/OutboundConfig#) (*Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#, error) { |
| 28 | m := &Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#{ |
| 29 | taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler.: make(map[string]outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler#), |
| 30 | } |
| 31 | return m, nil |
| 32 | } |
| 33 | |
| 34 | // Type implements common.HasType. |
| 35 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) Typescip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#Type().() interface{} { |
| 36 | return outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.ManagerTypescip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/ManagerType().() |
| 37 | } |
| 38 | |
| 39 | // Start implements core.Feature |
| 40 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) Startscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#Start().() error { |
| 41 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Lockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Lock().() |
| 42 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Unlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Unlock().() |
| 43 | |
| 44 | m.runningscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#running. = true |
| 45 | |
| 46 | for _, h := range m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler. { |
| 47 | if err := h.Startscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Runnable#Start.(); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | for _, h := range m.untaggedHandlersscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#untaggedHandlers. { |
| 53 | if err := h.Startscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Runnable#Start.(); err != nil { |
| 54 | return err |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | // Close implements core.Feature |
| 62 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) Closescip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#Close().() error { |
| 63 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Lockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Lock().() |
| 64 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Unlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Unlock().() |
| 65 | |
| 66 | m.runningscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#running. = false |
| 67 | |
| 68 | var errs []error |
| 69 | for _, h := range m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler. { |
| 70 | errs = append(errs, h.Closescip-go gomod v2ray.com/core . `v2ray.com/core/common`/Closable#Close.()) |
| 71 | } |
| 72 | |
| 73 | for _, h := range m.untaggedHandlersscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#untaggedHandlers. { |
| 74 | errs = append(errs, h.Closescip-go gomod v2ray.com/core . `v2ray.com/core/common`/Closable#Close.()) |
| 75 | } |
| 76 | |
| 77 | return errorsscip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/.Combinescip-go gomod v2ray.com/core . `v2ray.com/core/common/errors`/Combine().(errs...) |
| 78 | } |
| 79 | |
| 80 | // GetDefaultHandler implements outbound.Manager. |
| 81 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) GetDefaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#GetDefaultHandler().() outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler# { |
| 82 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RLockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RLock().() |
| 83 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RUnlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RUnlock().() |
| 84 | |
| 85 | if m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. == nil { |
| 86 | return nil |
| 87 | } |
| 88 | return m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. |
| 89 | } |
| 90 | |
| 91 | // GetHandler implements outbound.Manager. |
| 92 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) GetHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#GetHandler().(tag string) outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler# { |
| 93 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RLockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RLock().() |
| 94 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RUnlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RUnlock().() |
| 95 | if handler, found := m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler.[tag]; found { |
| 96 | return handler |
| 97 | } |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | // AddHandler implements outbound.Manager. |
| 102 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) AddHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#AddHandler().(ctx contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/golang/go/src go1.15 context/Context#, handler outboundscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/.Handlerscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler#) error { |
| 103 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Lockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Lock().() |
| 104 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Unlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Unlock().() |
| 105 | |
| 106 | if m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. == nil { |
| 107 | m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. = handler |
| 108 | } |
| 109 | |
| 110 | tag := handler.Tagscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler#Tag.() |
| 111 | if len(tag) > 0 { |
| 112 | m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler.[tag] = handler |
| 113 | } else { |
| 114 | m.untaggedHandlersscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#untaggedHandlers. = append(m.untaggedHandlersscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#untaggedHandlers., handler) |
| 115 | } |
| 116 | |
| 117 | if m.runningscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#running. { |
| 118 | return handler.Startscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Runnable#Start.() |
| 119 | } |
| 120 | |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | // RemoveHandler implements outbound.Manager. |
| 125 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) RemoveHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#RemoveHandler().(ctx contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/golang/go/src go1.15 context/Context#, tag string) error { |
| 126 | if tag == "" { |
| 127 | return commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.ErrNoCluescip-go gomod v2ray.com/core . `v2ray.com/core/common`/ErrNoClue. |
| 128 | } |
| 129 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Lockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Lock().() |
| 130 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..Unlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Unlock().() |
| 131 | |
| 132 | delete(m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler., tag) |
| 133 | if m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. != nil && m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler..Tagscip-go gomod v2ray.com/core . `v2ray.com/core/features/outbound`/Handler#Tag.() == tag { |
| 134 | m.defaultHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#defaultHandler. = nil |
| 135 | } |
| 136 | |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | // Select implements outbound.HandlerSelector. |
| 141 | func (m *Managerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#) Selectscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#Select().(selectors []string) []string { |
| 142 | m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RLockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RLock().() |
| 143 | defer m.accessscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#access..RUnlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RUnlock().() |
| 144 | |
| 145 | tags := make([]string, 0, len(selectors)) |
| 146 | |
| 147 | for tag := range m.taggedHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/Manager#taggedHandler. { |
| 148 | match := false |
| 149 | for _, selector := range selectors { |
| 150 | if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(tag, selector) { |
| 151 | match = true |
| 152 | break |
| 153 | } |
| 154 | } |
| 155 | if match { |
| 156 | tags = append(tags, tag) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return tags |
| 161 | } |
| 162 | |
| 163 | func initscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/init().() { |
| 164 | commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.Mustscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Must().(commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.RegisterConfigscip-go gomod v2ray.com/core . `v2ray.com/core/common`/RegisterConfig().((*proxymanscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/.OutboundConfigscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/OutboundConfig#)(nil), func(ctx contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/golang/go/src go1.15 context/Context#, config interface{}) (interface{}, error) { |
| 165 | return Newscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/New().(ctx, config.(*proxymanscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/.OutboundConfigscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman`/OutboundConfig#)) |
| 166 | })) |
| 167 | commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.Mustscip-go gomod v2ray.com/core . `v2ray.com/core/common`/Must().(commonscip-go gomod v2ray.com/core . `v2ray.com/core/common`/.RegisterConfigscip-go gomod v2ray.com/core . `v2ray.com/core/common`/RegisterConfig().((*corescip-go gomod v2ray.com/core . `v2ray.com/core`/.OutboundHandlerConfigscip-go gomod v2ray.com/core . `v2ray.com/core`/OutboundHandlerConfig#)(nil), func(ctx contextscip-go gomod github.com/golang/go/src go1.15 context/.Contextscip-go gomod github.com/golang/go/src go1.15 context/Context#, config interface{}) (interface{}, error) { |
| 168 | return NewHandlerscip-go gomod v2ray.com/core . `v2ray.com/core/app/proxyman/outbound`/NewHandler().(ctx, config.(*corescip-go gomod v2ray.com/core . `v2ray.com/core`/.OutboundHandlerConfigscip-go gomod v2ray.com/core . `v2ray.com/core`/OutboundHandlerConfig#)) |
| 169 | })) |
| 170 | } |