mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 01:27:03 -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:
parent
1a04abc820
commit
e3610870d1
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user