You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/session/session.go

70 lines
1.8 KiB

7 years ago
// Package session provides functions for sessions of incoming requests.
package session // import "v2ray.com/core/common/session"
7 years ago
import (
"context"
"math/rand"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
7 years ago
)
7 years ago
// ID of a session.
7 years ago
type ID uint32
7 years ago
// 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.
7 years ago
func NewID() ID {
for {
id := ID(rand.Uint32())
if id != 0 {
return id
}
}
}
6 years ago
// ExportIDToError transfers session.ID into an error object, for logging purpose.
// This can be used with error.WriteToLog().
func ExportIDToError(ctx context.Context) errors.ExportOption {
id := IDFromContext(ctx)
return func(h *errors.ExportOptionHolder) {
h.SessionID = uint32(id)
}
}
6 years ago
// Inbound is the metadata of an inbound connection.
type Inbound struct {
6 years ago
// Source address of the inbound connection.
Source net.Destination
// Getaway address
Gateway net.Destination
6 years ago
// Tag of the inbound proxy that handles the connection.
Tag string
// User is the user that authencates for the inbound. May be nil if the protocol allows anounymous traffic.
User *protocol.MemoryUser
}
6 years ago
// Outbound is the metadata of an outbound connection.
type Outbound struct {
6 years ago
// Target address of the outbound connection.
Target net.Destination
// Gateway address
Gateway net.Address
// ResolvedIPs is the resolved IP addresses, if the Targe is a domain address.
ResolvedIPs []net.IP
}
type SniffingRequest struct {
OverrideDestinationForProtocol []string
Enabled bool
}
// Content is the metadata of the connection content.
type Content struct {
// Protocol of current content.
Protocol string
SniffingRequest SniffingRequest
}