mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Add hook to init and listen observatory statuses
This commit is contained in:
parent
390a76ff61
commit
5bf2b31883
@ -32,6 +32,8 @@ type Observer struct {
|
||||
finished *done.Instance
|
||||
|
||||
ohm outbound.Manager
|
||||
|
||||
StatusUpdate func(result *OutboundStatus)
|
||||
}
|
||||
|
||||
func (o *Observer) GetObservation(ctx context.Context) (proto.Message, error) {
|
||||
@ -183,6 +185,10 @@ func (o *Observer) updateStatusForResult(outbound string, result *ProbeResult) {
|
||||
status.LastErrorReason = result.LastErrorReason
|
||||
status.Delay = 99999999
|
||||
}
|
||||
|
||||
if o.StatusUpdate != nil {
|
||||
o.StatusUpdate(status)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Observer) findStatusLocationLockHolderOnly(outbound string) int {
|
||||
|
12
app/observatory/persist.go
Normal file
12
app/observatory/persist.go
Normal file
@ -0,0 +1,12 @@
|
||||
package observatory
|
||||
|
||||
func (o *Observer) UpdateStatus(result *OutboundStatus) {
|
||||
o.statusLock.Lock()
|
||||
defer o.statusLock.Unlock()
|
||||
|
||||
if location := o.findStatusLocationLockHolderOnly(result.OutboundTag); location != -1 {
|
||||
o.status[location] = result
|
||||
} else {
|
||||
o.status = append(o.status, result)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user