session

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package session provides functions for sessions of incoming requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithID added in v1.0.2

func ContextWithID(ctx context.Context, id uint32) context.Context

func ContextWithInfo

func ContextWithInfo(ctx context.Context, info *Info) context.Context

func GetCtx added in v1.0.2

func GetCtx(ctx context.Context) context.Context

func IDFromContext added in v1.0.2

func IDFromContext(ctx context.Context) (uint32, bool)

Types

type DownCounter

type DownCounter interface {
	DownTraffic(uint64)
}

type DownCounters

type DownCounters []DownCounter

func (DownCounters) DownTraffic

func (c DownCounters) DownTraffic(n uint64)

type ID

type ID uint32

ID of a session. For debugging purpose.

func NewID

func NewID() ID

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 (ID) String

func (id ID) String() string

type Info

type Info struct {
	ID      ID
	Source  net.Destination
	Gateway net.Destination
	// if not nil, this is the original target address and it is an ip in fake dns pool
	FakeIP          net.IP
	Target          net.Destination
	InboundTag      string
	InboundProtocol string
	UdpUuid         uuid.UUID
	Sockopt         *Sockopt
	User            string

	Sniffed       bool
	Protocol      string
	SniffedDomain string

	AppId       string
	MatchedRule string

	ActivityChecker *signal.ActivityChecker
	// all up traffic should be added to the counter. It typically contains user traffic meter,
	// session traffic meter, and outbound link traffic meter.
	UpCounter   UpCounters
	DownCounter DownCounters
	// for debug purpose
	SessionUpCounter   atomic.Uint64
	SessionDownCounter atomic.Uint64
	// the selector being used initially
	UsedSelector string
}

func Copy

func Copy(old *Info) *Info

func InfoFromContext

func InfoFromContext(ctx context.Context) *Info

func NewInfo

func NewInfo(options ...Option) *Info

func NewInfoInbound

func NewInfoInbound(options ...Option) (*Info, context.Context, context.CancelCauseFunc)

func (*Info) GetAppId

func (c *Info) GetAppId() string

func (*Info) GetFakeIP

func (c *Info) GetFakeIP() net.IP

func (*Info) GetInboundTag

func (c *Info) GetInboundTag() string

func (*Info) GetNetwork

func (c *Info) GetNetwork() net.Network

func (*Info) GetSourceAddr

func (c *Info) GetSourceAddr() net.Destination

func (*Info) GetSourceIPs

func (c *Info) GetSourceIPs() net.IP

func (*Info) GetSourcePort

func (c *Info) GetSourcePort() net.Port

func (*Info) GetTargetAddr

func (c *Info) GetTargetAddr() net.Destination

func (*Info) GetTargetDomain

func (c *Info) GetTargetDomain() string

func (*Info) GetTargetIP

func (c *Info) GetTargetIP() net.IP

func (*Info) GetTargetPort

func (c *Info) GetTargetPort() net.Port

func (*Info) GetUser

func (c *Info) GetUser() string

type Option

type Option func(*Info)

func WithAppId

func WithAppId(appId string) Option

func WithGateway

func WithGateway(gtw net.Destination) Option

func WithInboundProtocol

func WithInboundProtocol(s string) Option

func WithInboundTag

func WithInboundTag(tag string) Option

func WithSource

func WithSource(src net.Destination) Option

func WithTarget

func WithTarget(tgt net.Destination) Option

func WithUdpUuid

func WithUdpUuid(uuid uuid.UUID) Option

func WithUser

func WithUser(user string) Option

type SessionCtxKey added in v1.0.2

type SessionCtxKey int
const (
	IDKey SessionCtxKey = iota
)

type Sockopt

type Sockopt struct {
	// Mark of the socket connection.
	Mark           uint32
	InterfaceName4 string
	InterfaceName6 string
}

Sockopt is the settings for socket connection.

func SockoptFromContext

func SockoptFromContext(ctx context.Context) *Sockopt

// SockoptFromContext returns Socket configs in this context, or nil if not contained.

type UpCounter

type UpCounter interface {
	UpTraffic(uint64)
}

type UpCounters

type UpCounters []UpCounter

func (UpCounters) UpTraffic

func (c UpCounters) UpTraffic(n uint64)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL