mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-27 02:51:36 +00:00
24 lines
407 B
Go
24 lines
407 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
|
|
"github.com/sagernet/sing/common/random"
|
|
)
|
|
|
|
func init() {
|
|
random.InitializeSeed()
|
|
}
|
|
|
|
type idKey struct{}
|
|
|
|
func ContextWithNewID(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, (*idKey)(nil), rand.Uint32())
|
|
}
|
|
|
|
func IDFromContext(ctx context.Context) (uint32, bool) {
|
|
id, loaded := ctx.Value((*idKey)(nil)).(uint32)
|
|
return id, loaded
|
|
}
|