1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

replace same tag default outbound handler (#1437)

* replace old default handler with same tag

Signed-off-by: Guofan Xu <xuguofan@live.com>

* add warning log when replace outbound

* fix lint

Signed-off-by: Guofan Xu <xuguofan@live.com>
This commit is contained in:
XGFan 2021-12-11 11:22:38 +08:00 committed by GitHub
parent 1a04abc820
commit e3610870d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,13 +102,18 @@ func (m *Manager) GetHandler(tag string) outbound.Handler {
func (m *Manager) AddHandler(ctx context.Context, handler outbound.Handler) error {
m.access.Lock()
defer m.access.Unlock()
tag := handler.Tag()
if m.defaultHandler == nil {
if m.defaultHandler == nil ||
(len(tag) > 0 && tag == m.defaultHandler.Tag()) {
m.defaultHandler = handler
}
tag := handler.Tag()
if len(tag) > 0 {
if oldHandler, found := m.taggedHandler[tag]; found {
errors.New("will replace the existed outbound with the tag: " + tag).AtWarning().WriteToLog()
_ = oldHandler.Close()
}
m.taggedHandler[tag] = handler
} else {
m.untaggedHandlers = append(m.untaggedHandlers, handler)