1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/session/session.go

57 lines
1.5 KiB
Go
Raw Normal View History

2018-04-03 16:34:59 -04:00
// Package session provides functions for sessions of incoming requests.
package session // import "v2ray.com/core/common/session"
2018-02-22 09:26:00 -05:00
import (
"context"
"math/rand"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/net"
2018-10-15 02:36:50 -04:00
"v2ray.com/core/common/protocol"
2018-02-22 09:26:00 -05:00
)
2018-04-03 16:34:59 -04:00
// ID of a session.
2018-02-22 09:26:00 -05:00
type ID uint32
2018-04-03 16:34:59 -04:00
// 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.
2018-02-22 09:26:00 -05:00
func NewID() ID {
for {
id := ID(rand.Uint32())
if id != 0 {
return id
}
}
}
2018-10-15 02:51:24 -04:00
// 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)
}
}
2018-10-15 02:51:24 -04:00
// Inbound is the metadata of an inbound connection.
type Inbound struct {
2018-10-15 02:51:24 -04:00
// Source address of the inbound connection.
Source net.Destination
// Getaway address
Gateway net.Destination
2018-10-15 02:51:24 -04:00
// Tag of the inbound proxy that handles the connection.
Tag string
2018-10-15 02:36:50 -04:00
// User is the user that authencates for the inbound. May be nil if the protocol allows anounymous traffic.
User *protocol.MemoryUser
}
2018-10-15 02:51:24 -04:00
// Outbound is the metadata of an outbound connection.
type Outbound struct {
2018-10-15 02:51:24 -04:00
// 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
}