mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-28 23:06:14 -04:00
54 lines
990 B
Go
54 lines
990 B
Go
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
|
|
}
|