sessdata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const BandwidthPeriodSec = 2 // 流量速率统计周期(秒)
View Source
const MaxMtu = 1460

Variables

View Source
var (
	IpPool = &ipPoolConfig{}
)

Functions

func AcquireIp

func AcquireIp(username, macAddr string) net.IP

获取动态ip

func CloseCSess added in v0.1.0

func CloseCSess(token string)

func CloseSess

func CloseSess(token string)

func CopyStruct

func CopyStruct(a interface{}, b interface{}, fields ...string) (err error)

用b的所有字段覆盖a的 如果fields不为空, 表示用b的特定字段覆盖a的 a应该为结构体指针

func DelSess

func DelSess(token string)

func DelSessByStoken

func DelSessByStoken(stoken string)

func GenToken

func GenToken() string

func LimitClient

func LimitClient(user string, close bool) bool

func ReleaseIp

func ReleaseIp(ip net.IP, macAddr string)

回收ip

func Start

func Start()

Types

type ConnSession

type ConnSession struct {
	Sess                *Session
	MasterSecret        string // dtls协议的 master_secret
	IpAddr              net.IP // 分配的ip地址
	LocalIp             net.IP
	MacHw               net.HardwareAddr // 客户端mac地址,从Session取出
	RemoteAddr          string
	Mtu                 int
	TunName             string
	Client              string // 客户端  mobile pc
	CstpDpd             int
	Group               *dbdata.Group
	Limit               *LimitRater
	BandwidthUp         uint32 // 使用上行带宽 Byte
	BandwidthDown       uint32 // 使用下行带宽 Byte
	BandwidthUpPeriod   uint32 // 前一周期的总量
	BandwidthDownPeriod uint32
	BandwidthUpAll      uint32 // 使用上行带宽总量
	BandwidthDownAll    uint32 // 使用下行带宽总量

	CloseChan  chan struct{}
	PayloadIn  chan *Payload
	PayloadOut chan *Payload
	// contains filtered or unexported fields
}

连接sess

func (*ConnSession) Close

func (cs *ConnSession) Close()

func (*ConnSession) RateLimit

func (cs *ConnSession) RateLimit(byt int, isUp bool) error

func (*ConnSession) SetMtu

func (cs *ConnSession) SetMtu(mtu string)

func (*ConnSession) SetTunName

func (cs *ConnSession) SetTunName(name string)

type LType

type LType int8
const (
	LTypeEthernet LType = 1
	LTypeIPData   LType = 2
)

type LimitRater

type LimitRater struct {
	// contains filtered or unexported fields
}

func NewLimitRater

func NewLimitRater(lim, burst int) *LimitRater

lim: 令牌产生速率 burst: 允许的最大爆发速率

func (*LimitRater) Wait

func (l *LimitRater) Wait(bt int) error

bt 不能超过burst大小

type Online

type Online struct {
	Token            string    `json:"token"`
	Username         string    `json:"username"`
	Group            string    `json:"group"`
	MacAddr          string    `json:"mac_addr"`
	Ip               net.IP    `json:"ip"`
	RemoteAddr       string    `json:"remote_addr"`
	TunName          string    `json:"tun_name"`
	Mtu              int       `json:"mtu"`
	Client           string    `json:"client"`
	BandwidthUp      string    `json:"bandwidth_up"`
	BandwidthDown    string    `json:"bandwidth_down"`
	BandwidthUpAll   string    `json:"bandwidth_up_all"`
	BandwidthDownAll string    `json:"bandwidth_down_all"`
	LastLogin        time.Time `json:"last_login"`
}

func OnlineSess

func OnlineSess() []Online

type Onlines

type Onlines []Online

func (Onlines) Len

func (o Onlines) Len() int

func (Onlines) Less

func (o Onlines) Less(i, j int) bool

func (Onlines) Swap

func (o Onlines) Swap(i, j int)

type Payload

type Payload struct {
	PType byte  // payload types
	LType LType // LinkType
	Data  []byte
}

type Session

type Session struct {
	Sid            string // auth返回的 session-id
	Token          string // session信息的唯一token
	DtlsSid        string // dtls协议的 session_id
	MacAddr        string // 客户端mac地址
	UniqueIdGlobal string // 客户端唯一标示
	Username       string // 用户名
	Group          string
	AuthStep       string
	AuthPass       string

	LastLogin time.Time
	IsActive  bool

	// 开启link需要设置的参数
	CSess *ConnSession
	// contains filtered or unexported fields
}

func Dtls2Sess

func Dtls2Sess(dtlsid []byte) *Session

func NewSession

func NewSession(token string) *Session

func SToken2Sess

func SToken2Sess(stoken string) *Session

func Token2Sess

func Token2Sess(token string) *Session

func (*Session) NewConn

func (s *Session) NewConn() *ConnSession

Jump to

Keyboard shortcuts

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