mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-13 20:09:36 +03:00
API: Add user online stats (#3637)
* add statsUserOnline bool to policy * add OnlineMap struct to stats * apply UserOnline functionality to dispatcher * add statsonline api command * fix comments * Update app/stats/online_map.go Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com> * improve AddIP * regenerate pb --------- Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>
This commit is contained in:
@ -181,6 +181,18 @@ func (d *DefaultDispatcher) getLink(ctx context.Context) (*transport.Link, *tran
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if p.Stats.UserOnline {
|
||||
name := "user>>>" + user.Email + ">>>online"
|
||||
if om, _ := stats.GetOrRegisterOnlineMap(d.stats, name); om != nil {
|
||||
sessionInbounds := session.InboundFromContext(ctx)
|
||||
userIP := sessionInbounds.Source.Address.String()
|
||||
om.AddIP(userIP)
|
||||
// log Online user with ips
|
||||
// errors.LogDebug(ctx, "user>>>" + user.Email + ">>>online", om.Count(), om.List())
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return inboundLink, outboundLink
|
||||
|
Reference in New Issue
Block a user