1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 09:57:04 -04:00
v2fly/app/observatory/observer.go

54 lines
990 B
Go
Raw Normal View History

2021-03-06 08:33:20 -05:00
package observatory
import (
"context"
"github.com/v2fly/v2ray-core/v4/common/signal/done"
"github.com/v2fly/v2ray-core/v4/features/extension"
"github.com/v2fly/v2ray-core/v4/features/outbound"
"sync"
)
type Observer struct {
config *Config
ctx context.Context
statusLock sync.Mutex
status []OutboundStatus
finished *done.Instance
ohm outbound.Manager
}
func (o *Observer) Type() interface{} {
return extension.ObservatoryType()
}
func (o *Observer) Start() error {
o.finished = done.New()
go o.background()
return nil
}
func (o *Observer) Close() error {
return o.finished.Close()
}
func (o *Observer) background() {
for !o.finished.Done() {
hs, ok := o.ohm.(outbound.HandlerSelector)
if !ok {
newError("outbound.Manager is not a HandlerSelector").WriteToLog()
return
}
outbounds := hs.Select(o.config.SubjectSelector)
}
}
func (o *Observer) updateStatus(outbounds []string) {
o.statusLock.Lock()
defer o.statusLock.Unlock()
o.status
}