mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-04 01:06:30 -05:00
comments
This commit is contained in:
parent
074dfbb78c
commit
27ccc9d726
@ -1,3 +1,4 @@
|
||||
package buf
|
||||
// Package buf provides a light-weight memory allocation mechanism.
|
||||
package buf // import "v2ray.com/core/common/buf"
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg buf -path Buf
|
||||
|
@ -1,4 +1,3 @@
|
||||
// Package buf provides a light-weight memory allocation mechanism.
|
||||
package buf
|
||||
|
||||
import (
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Package crypto provides common crypto libraries for V2Ray.
|
||||
package crypto
|
||||
package crypto // import "v2ray.com/core/common/crypto"
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg crypto -path Crypto
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Package dice contains common functions to generate random number.
|
||||
// It also initialize math/rand with the time in seconds at launch time.
|
||||
package dice
|
||||
package dice // import "v2ray.com/core/common/dice"
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Package errors is a drop-in replacement for Golang lib 'errors'.
|
||||
package errors
|
||||
package errors // import "v2ray.com/core/common/errors"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package log
|
||||
package log // import "v2ray.com/core/common/log"
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Package net is a drop-in replacement to Golang's net package, with some more functionalities.
|
||||
package net
|
||||
package net // import "v2ray.com/core/common/net"
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg net -path Net
|
||||
|
@ -1,4 +1,4 @@
|
||||
package platform
|
||||
package platform // import "v2ray.com/core/common/platform"
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package predicate
|
||||
package predicate // import "v2ray.com/core/common/predicate"
|
||||
|
||||
type Predicate func() bool
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
package protocol
|
||||
package protocol // import "v2ray.com/core/common/protocol"
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg protocol -path Protocol
|
||||
|
@ -1,4 +1,4 @@
|
||||
package retry
|
||||
package retry // import "v2ray.com/core/common/retry"
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg retry -path Retry
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
package session
|
||||
// Package session provides functions for sessions of incoming requests.
|
||||
package session // import "v2ray.com/core/common/session"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// ID of a session.
|
||||
type ID uint32
|
||||
|
||||
// NewID generates a new ID. The generated ID is high likely to be unique, but not cryptographically secure.
|
||||
// The generated ID will never be 0.
|
||||
func NewID() ID {
|
||||
for {
|
||||
id := ID(rand.Uint32())
|
||||
@ -22,10 +26,12 @@ const (
|
||||
idSessionKey sessionKey = iota
|
||||
)
|
||||
|
||||
// ContextWithID returns a new context with the given ID.
|
||||
func ContextWithID(ctx context.Context, id ID) context.Context {
|
||||
return context.WithValue(ctx, idSessionKey, id)
|
||||
}
|
||||
|
||||
// IDFromContext returns ID in this context, or 0 if not contained.
|
||||
func IDFromContext(ctx context.Context) ID {
|
||||
if id, ok := ctx.Value(idSessionKey).(ID); ok {
|
||||
return id
|
||||
|
@ -1,4 +1,4 @@
|
||||
package uuid
|
||||
package uuid // import "v2ray.com/core/common/uuid"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
Loading…
Reference in New Issue
Block a user