1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
This commit is contained in:
Darien Raymond 2018-04-03 22:34:59 +02:00
parent 074dfbb78c
commit 27ccc9d726
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
13 changed files with 19 additions and 13 deletions

View File

@ -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 //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg buf -path Buf

View File

@ -1,4 +1,3 @@
// Package buf provides a light-weight memory allocation mechanism.
package buf package buf
import ( import (

View File

@ -1,4 +1,4 @@
// Package crypto provides common crypto libraries for V2Ray. // 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 //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg crypto -path Crypto

View File

@ -1,6 +1,6 @@
// Package dice contains common functions to generate random number. // Package dice contains common functions to generate random number.
// It also initialize math/rand with the time in seconds at launch time. // It also initialize math/rand with the time in seconds at launch time.
package dice package dice // import "v2ray.com/core/common/dice"
import ( import (
"math/rand" "math/rand"

View File

@ -1,5 +1,5 @@
// Package errors is a drop-in replacement for Golang lib 'errors'. // Package errors is a drop-in replacement for Golang lib 'errors'.
package errors package errors // import "v2ray.com/core/common/errors"
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package log package log // import "v2ray.com/core/common/log"
import ( import (
"sync" "sync"

View File

@ -1,4 +1,4 @@
// Package net is a drop-in replacement to Golang's net package, with some more functionalities. // 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 //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg net -path Net

View File

@ -1,4 +1,4 @@
package platform package platform // import "v2ray.com/core/common/platform"
import ( import (
"os" "os"

View File

@ -1,4 +1,4 @@
package predicate package predicate // import "v2ray.com/core/common/predicate"
type Predicate func() bool type Predicate func() bool

View File

@ -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 //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg protocol -path Protocol

View File

@ -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 //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg retry -path Retry

View File

@ -1,12 +1,16 @@
package session // Package session provides functions for sessions of incoming requests.
package session // import "v2ray.com/core/common/session"
import ( import (
"context" "context"
"math/rand" "math/rand"
) )
// ID of a session.
type ID uint32 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 { func NewID() ID {
for { for {
id := ID(rand.Uint32()) id := ID(rand.Uint32())
@ -22,10 +26,12 @@ const (
idSessionKey sessionKey = iota idSessionKey sessionKey = iota
) )
// ContextWithID returns a new context with the given ID.
func ContextWithID(ctx context.Context, id ID) context.Context { func ContextWithID(ctx context.Context, id ID) context.Context {
return context.WithValue(ctx, idSessionKey, id) return context.WithValue(ctx, idSessionKey, id)
} }
// IDFromContext returns ID in this context, or 0 if not contained.
func IDFromContext(ctx context.Context) ID { func IDFromContext(ctx context.Context) ID {
if id, ok := ctx.Value(idSessionKey).(ID); ok { if id, ok := ctx.Value(idSessionKey).(ID); ok {
return id return id

View File

@ -1,4 +1,4 @@
package uuid package uuid // import "v2ray.com/core/common/uuid"
import ( import (
"bytes" "bytes"