feat: 授权延长——同事一键申请,管理员批准时决定时长;时长支持 30 分钟与自定义
同事端 - 用过邀请链接的设备再次打开链接时显示自己的授权状态:有效时可申请延长, 访问结束(到期或通道关闭)后 2 小时内也可以;超过 2 小时或被撤销则提示重新获取邀请 - 「申请延长」只有一个按钮,提交后复用审批状态页,批准后显示新的到期时间 - 用过链接的设备不再自动重新放通,统一走申请延长 网关 - 授权结束后保留 2 小时的记录(通道关闭后仍保留,随状态文件持久化);撤销的不能延长, 删除通道 / 解散组时一并清除(unregister 带 deleted 标记) - 新增 extend_lease:有效授权从原到期时间顺延,已结束的从现在起算,不受通道最长开启时长截断, 并批准该设备的延长申请;指标里带上全部可延长设备与申请(包括已关闭的通道) - 授权时长支持分钟数("30m"、"90m",5 分钟到 30 天) Agent / App / 网页面板 - POST .../leases/extend:通道已关闭时先自动开启(组则全组开启),并让通道至少开到授权结束 - 授权管理新增「申请延长」「最近结束 · 2 小时内可延长」,已授权设备可直接「延长」; 卡片、菜单栏和系统通知提示延长申请,菜单栏可直接选时长批准 - 邀请的可访问时长、通道最长开启时长增加 30 分钟与自定义;网页面板弹窗层级高于侧边抽屉 - 邀请分享文案提示「授权结束后 2 小时内可重新打开此链接申请延长」
This commit is contained in:
1 parent
9a675ba96e
commit
dceb59c0ca
16 files changed
+1707
-75
No files matched your search
+353
-19
@@ -25,10 +25,17 @@ const (
|
||||
leaseStartWindow = 24 * time.Hour
|
||||
)
|
||||
|
||||
// renewWindow 访问结束(授权到期或通道关闭)后多久内还能申请延长;之后清除记录,需要重新邀请
|
||||
var renewWindow = 2 * time.Hour
|
||||
|
||||
var (
|
||||
errInviteNotFound = errors.New("邀请链接无效或已过期")
|
||||
errInviteUsedUp = errors.New("该邀请链接的可用设备数已用完,请向管理员索取新的链接")
|
||||
errRequestGone = errors.New("申请不存在或已过期")
|
||||
errAlreadyUsed = errors.New("这台设备已经用过该邀请链接,请重新打开链接申请延长")
|
||||
errNothingToRenew = errors.New("访问已结束超过 2 小时,请联系管理员获取新的邀请链接")
|
||||
errRevoked = errors.New("授权已被管理员撤销,如需继续使用请联系管理员")
|
||||
errNotStarted = errors.New("授权尚未开始计时(首次连接后才开始),无需延长")
|
||||
)
|
||||
|
||||
type leaseInfo struct {
|
||||
@@ -89,10 +96,27 @@ func (s *stateStore) lease(scope, ip string) (leaseInfo, bool) {
|
||||
return leaseInfo{}, false
|
||||
}
|
||||
|
||||
// leaseRecord remembers a device whose access ended, so it can ask for an extension
|
||||
type leaseRecord struct {
|
||||
EndedAt time.Time `json:"ended_at"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Invite string `json:"invite,omitempty"`
|
||||
// Revoked 为 true 表示被管理员撤销,不能申请延长
|
||||
Revoked bool `json:"revoked,omitempty"`
|
||||
}
|
||||
|
||||
func (r leaseRecord) renewable(now time.Time) bool {
|
||||
return !r.Revoked && now.Before(r.EndedAt.Add(renewWindow))
|
||||
}
|
||||
|
||||
type tunnelState struct {
|
||||
Leases map[string]leaseInfo `json:"leases,omitempty"` // ip -> lease
|
||||
Invites map[string]*protocol.Invite `json:"invites,omitempty"` // code -> invite
|
||||
Requests map[string]*protocol.AccessRequest `json:"requests,omitempty"` // id -> request
|
||||
// Ended 访问已结束的设备(ip -> 记录),结束后 renewWindow 内可申请延长;通道关闭后仍保留
|
||||
Ended map[string]leaseRecord `json:"ended,omitempty"`
|
||||
// Name 通道或组最近的名称,通道关闭后用于申请延长页面
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// 授权状态的作用范围:单个通道(键为通道 ID,与旧数据兼容)或整个通道组(键为 "group:<组ID>")
|
||||
@@ -177,7 +201,7 @@ func (m *Manager) EnableLeasePersistence(path string) error {
|
||||
// looksLikeState distinguishes the new format from the legacy one (both are JSON objects of objects)
|
||||
func looksLikeState(d map[string]*tunnelState) bool {
|
||||
for _, st := range d {
|
||||
if st == nil || (st.Leases == nil && st.Invites == nil && st.Requests == nil) {
|
||||
if st == nil || (st.Leases == nil && st.Invites == nil && st.Requests == nil && st.Ended == nil) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -199,9 +223,21 @@ func (s *stateStore) scopeLocked(id string) *tunnelState {
|
||||
if st.Requests == nil {
|
||||
st.Requests = make(map[string]*protocol.AccessRequest)
|
||||
}
|
||||
if st.Ended == nil {
|
||||
st.Ended = make(map[string]leaseRecord)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
// endLeaseLocked turns a lease into an ended record (renewable unless revoked)
|
||||
func endLeaseLocked(st *tunnelState, ip string, l leaseInfo, at time.Time, revoked bool) {
|
||||
if st.Ended == nil {
|
||||
st.Ended = make(map[string]leaseRecord)
|
||||
}
|
||||
st.Ended[ip] = leaseRecord{EndedAt: at, Name: l.Name, Invite: l.Invite, Revoked: revoked}
|
||||
delete(st.Leases, ip)
|
||||
}
|
||||
|
||||
func randomCode(n int) string {
|
||||
const chars = "23456789abcdefghjkmnpqrstuvwxyz"
|
||||
b := make([]byte, n)
|
||||
@@ -225,13 +261,25 @@ func (s *stateStore) removeLease(scope, ip string) int {
|
||||
if st == nil {
|
||||
return 0
|
||||
}
|
||||
// 被撤销的授权不能再申请延长
|
||||
now := time.Now()
|
||||
n := 0
|
||||
if ip == "" {
|
||||
n = len(st.Leases)
|
||||
st.Leases = make(map[string]leaseInfo)
|
||||
} else if _, ok := st.Leases[ip]; ok {
|
||||
n = 1
|
||||
delete(st.Leases, ip)
|
||||
for lip, l := range st.Leases {
|
||||
if ip == "" || lip == ip {
|
||||
endLeaseLocked(st, lip, l, now, true)
|
||||
n++
|
||||
}
|
||||
}
|
||||
for lip, r := range st.Ended {
|
||||
if ip == "" || lip == ip {
|
||||
r.Revoked = true
|
||||
st.Ended[lip] = r
|
||||
}
|
||||
}
|
||||
for id, r := range st.Requests {
|
||||
if r.Renewal && r.Status == "pending" && (ip == "" || r.IP == ip) {
|
||||
delete(st.Requests, id)
|
||||
}
|
||||
}
|
||||
s.saveLocked()
|
||||
return n
|
||||
@@ -271,8 +319,54 @@ func (s *stateStore) leaseList(scope string) []protocol.DynamicLease {
|
||||
return out
|
||||
}
|
||||
|
||||
// forgetScope drops all access state of a tunnel or group (explicitly closed, deleted or dissolved)
|
||||
func (s *stateStore) forgetScope(scope string) {
|
||||
// closeScope runs when a tunnel, or the last open tunnel of a group, is closed: invites and
|
||||
// first-time requests become invalid, running leases end — but ended devices are remembered for
|
||||
// renewWindow so they can still ask for an extension.
|
||||
func (s *stateStore) closeScope(scope string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
st := s.data[scope]
|
||||
if st == nil {
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
for ip, l := range st.Leases {
|
||||
end := now
|
||||
if l.ExpiresAt.Before(now) {
|
||||
end = l.ExpiresAt
|
||||
}
|
||||
endLeaseLocked(st, ip, l, end, false)
|
||||
}
|
||||
st.Invites = nil
|
||||
for id, r := range st.Requests {
|
||||
if !r.Renewal && r.Status == "pending" {
|
||||
delete(st.Requests, id)
|
||||
}
|
||||
}
|
||||
s.saveLocked()
|
||||
}
|
||||
|
||||
// scopeDisplayName is the last known name of a scope (for pages shown after it closed)
|
||||
func (s *stateStore) scopeDisplayName(scope string) string {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if st := s.data[scope]; st != nil {
|
||||
return st.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setName records the display name of a scope that has access state
|
||||
func (s *stateStore) setName(scope, name string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if st := s.data[scope]; st != nil && name != "" && st.Name != name {
|
||||
st.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
// dropScope drops all access state of a deleted tunnel or a dissolved group, renewal records included
|
||||
func (s *stateStore) dropScope(scope string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if _, ok := s.data[scope]; ok {
|
||||
@@ -379,6 +473,13 @@ func (s *stateStore) useInviteAndGrant(scope, code, name, ip string, scopeExpire
|
||||
if !ok || !time.Now().Before(inv.ExpiresAt) {
|
||||
return leaseInfo{}, errInviteNotFound
|
||||
}
|
||||
// 已授权的设备再次提交不重新计时;用过链接、授权已结束的设备要申请延长
|
||||
if l, ok := st.Leases[ip]; ok && time.Now().Before(l.ExpiresAt) {
|
||||
return l, nil
|
||||
}
|
||||
if usedByLocked(inv, ip) {
|
||||
return leaseInfo{}, errAlreadyUsed
|
||||
}
|
||||
if !capacityOKLocked(st, inv, ip) {
|
||||
return leaseInfo{}, errInviteUsedUp
|
||||
}
|
||||
@@ -386,10 +487,20 @@ func (s *stateStore) useInviteAndGrant(scope, code, name, ip string, scopeExpire
|
||||
s.recordUseLocked(st, code, name, ip)
|
||||
l := newLease(name, code, inv.LeaseDuration, scopeExpires, time.Now())
|
||||
st.Leases[ip] = l
|
||||
delete(st.Ended, ip)
|
||||
s.saveLocked()
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func usedByLocked(inv *protocol.Invite, ip string) bool {
|
||||
for _, u := range inv.Uses {
|
||||
if u.IP == ip {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// revokeInvite removes the invite and the leases it granted; returns the affected IPs
|
||||
func (s *stateStore) revokeInvite(scope, code string) []string {
|
||||
s.mu.Lock()
|
||||
@@ -400,10 +511,17 @@ func (s *stateStore) revokeInvite(scope, code string) []string {
|
||||
}
|
||||
delete(st.Invites, code)
|
||||
var ips []string
|
||||
now := time.Now()
|
||||
for ip, l := range st.Leases {
|
||||
if l.Invite == code {
|
||||
ips = append(ips, ip)
|
||||
delete(st.Leases, ip)
|
||||
endLeaseLocked(st, ip, l, now, true)
|
||||
}
|
||||
}
|
||||
for ip, r := range st.Ended {
|
||||
if r.Invite == code {
|
||||
r.Revoked = true
|
||||
st.Ended[ip] = r
|
||||
}
|
||||
}
|
||||
for id, r := range st.Requests {
|
||||
@@ -449,12 +567,15 @@ func (s *stateStore) addRequest(scope, code, name, ip string) (protocol.AccessRe
|
||||
}
|
||||
st = s.scopeLocked(scope)
|
||||
for _, r := range st.Requests {
|
||||
if r.IP == ip && r.Status == "pending" {
|
||||
if r.IP == ip && r.Status == "pending" && !r.Renewal {
|
||||
r.Name = name
|
||||
s.saveLocked()
|
||||
return *r, nil
|
||||
}
|
||||
}
|
||||
if usedByLocked(inv, ip) {
|
||||
return protocol.AccessRequest{}, errAlreadyUsed
|
||||
}
|
||||
if !capacityOKLocked(st, inv, ip) {
|
||||
return protocol.AccessRequest{}, errInviteUsedUp
|
||||
}
|
||||
@@ -507,6 +628,24 @@ func (s *stateStore) decide(scope, id string, approve bool, scopeExpires *time.T
|
||||
if inv, ok := st.Invites[r.Invite]; ok {
|
||||
duration = inv.LeaseDuration
|
||||
}
|
||||
if r.Renewal {
|
||||
// 延长申请通常由 extendLease 按管理员选择的时长批准;这里按邀请的时长(默认 2 小时)处理
|
||||
if !approve {
|
||||
r.Status, r.At = "rejected", time.Now()
|
||||
s.saveLocked()
|
||||
return *r, time.Time{}, nil
|
||||
}
|
||||
minutes, ok := protocol.LeaseMinutes(duration)
|
||||
if !ok {
|
||||
minutes = 120
|
||||
}
|
||||
exp, err := s.extendLocked(st, r.IP, minutes, time.Now())
|
||||
if err != nil {
|
||||
return protocol.AccessRequest{}, time.Time{}, err
|
||||
}
|
||||
s.saveLocked()
|
||||
return *r, exp, nil
|
||||
}
|
||||
l := newLease(r.Name, r.Invite, duration, scopeExpires, time.Now())
|
||||
exp := l.ExpiresAt
|
||||
r.At = time.Now()
|
||||
@@ -514,6 +653,7 @@ func (s *stateStore) decide(scope, id string, approve bool, scopeExpires *time.T
|
||||
r.Status = "approved"
|
||||
s.recordUseLocked(st, r.Invite, r.Name, r.IP)
|
||||
st.Leases[r.IP] = l
|
||||
delete(st.Ended, r.IP)
|
||||
} else {
|
||||
r.Status = "rejected"
|
||||
}
|
||||
@@ -528,7 +668,7 @@ func (s *stateStore) pendingList(scope string) []protocol.AccessRequest {
|
||||
var out []protocol.AccessRequest
|
||||
if st := s.data[scope]; st != nil {
|
||||
for _, r := range st.Requests {
|
||||
if r.Status == "pending" {
|
||||
if r.Status == "pending" && !r.Renewal {
|
||||
out = append(out, *r)
|
||||
}
|
||||
}
|
||||
@@ -537,6 +677,195 @@ func (s *stateStore) pendingList(scope string) []protocol.AccessRequest {
|
||||
return out
|
||||
}
|
||||
|
||||
// ---- renewals ----
|
||||
|
||||
// deviceAccess is what a device that opens an invite link already has in the invite's scope
|
||||
type deviceAccess struct {
|
||||
scope string
|
||||
name string // 通道或组的名称(通道关闭后为最近一次的名称)
|
||||
lease *leaseInfo
|
||||
ended *leaseRecord
|
||||
pending *protocol.AccessRequest // 待处理的延长申请
|
||||
// usedBefore 用过该链接,但访问已结束超过 renewWindow
|
||||
usedBefore bool
|
||||
}
|
||||
|
||||
// deviceAccess looks up ip's access in the scope of invite code, also after the invite or the
|
||||
// tunnel is gone; false when the device never used this invite (a new visitor)
|
||||
func (s *stateStore) deviceAccess(code, ip string) (deviceAccess, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.pruneLocked()
|
||||
now := time.Now()
|
||||
for scope, st := range s.data {
|
||||
inv := st.Invites[code]
|
||||
l, hasLease := st.Leases[ip]
|
||||
rec, hasRec := st.Ended[ip]
|
||||
mine := (inv != nil && usedByLocked(inv, ip)) || (hasLease && l.Invite == code) || (hasRec && rec.Invite == code)
|
||||
if !mine {
|
||||
continue
|
||||
}
|
||||
da := deviceAccess{scope: scope, name: st.Name}
|
||||
switch {
|
||||
case hasLease && now.Before(l.ExpiresAt):
|
||||
da.lease = &l
|
||||
case hasRec && (rec.Revoked || rec.renewable(now)):
|
||||
da.ended = &rec
|
||||
default:
|
||||
da.usedBefore = true
|
||||
}
|
||||
for _, r := range st.Requests {
|
||||
if r.IP == ip && r.Renewal && r.Status == "pending" {
|
||||
c := *r
|
||||
da.pending = &c
|
||||
}
|
||||
}
|
||||
return da, true
|
||||
}
|
||||
return deviceAccess{}, false
|
||||
}
|
||||
|
||||
// addRenewal files (or re-uses) a renewal request for ip: its lease must be running, or have
|
||||
// ended less than renewWindow ago without being revoked
|
||||
func (s *stateStore) addRenewal(scope, ip string) (protocol.AccessRequest, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.pruneLocked()
|
||||
st := s.data[scope]
|
||||
if st == nil {
|
||||
return protocol.AccessRequest{}, errNothingToRenew
|
||||
}
|
||||
now := time.Now()
|
||||
var name, invite string
|
||||
if l, ok := st.Leases[ip]; ok && now.Before(l.ExpiresAt) {
|
||||
if l.Deferred {
|
||||
return protocol.AccessRequest{}, errNotStarted
|
||||
}
|
||||
name, invite = l.Name, l.Invite
|
||||
} else if rec, ok := st.Ended[ip]; ok && rec.Revoked {
|
||||
return protocol.AccessRequest{}, errRevoked
|
||||
} else if ok && rec.renewable(now) {
|
||||
name, invite = rec.Name, rec.Invite
|
||||
} else {
|
||||
return protocol.AccessRequest{}, errNothingToRenew
|
||||
}
|
||||
st = s.scopeLocked(scope)
|
||||
for _, r := range st.Requests {
|
||||
if r.IP == ip && r.Renewal && r.Status == "pending" {
|
||||
return *r, nil
|
||||
}
|
||||
}
|
||||
r := &protocol.AccessRequest{ID: randomCode(16), Name: name, IP: ip, Invite: invite, At: now, Status: "pending", Renewal: true}
|
||||
if id, isGroup := splitScope(scope); isGroup {
|
||||
r.GroupID = id
|
||||
} else {
|
||||
r.TunnelID = id
|
||||
}
|
||||
st.Requests[r.ID] = r
|
||||
s.saveLocked()
|
||||
return *r, nil
|
||||
}
|
||||
|
||||
// extendLease extends ip's access in scope by minutes and approves its pending renewal requests.
|
||||
// 不受通道最长开启时长限制:管理员批准的时长优先。
|
||||
func (s *stateStore) extendLease(scope, ip string, minutes int) (time.Time, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.pruneLocked()
|
||||
st := s.data[scope]
|
||||
if st == nil {
|
||||
return time.Time{}, errNothingToRenew
|
||||
}
|
||||
exp, err := s.extendLocked(s.scopeLocked(scope), ip, minutes, time.Now())
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
s.saveLocked()
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
// extendLocked: a running lease is extended from its expiry (one not yet started starts now),
|
||||
// an ended one is restored from now. Caller must hold s.mu and save.
|
||||
func (s *stateStore) extendLocked(st *tunnelState, ip string, minutes int, now time.Time) (time.Time, error) {
|
||||
d := time.Duration(minutes) * time.Minute
|
||||
if l, ok := st.Leases[ip]; ok && now.Before(l.ExpiresAt) {
|
||||
if l.Deferred {
|
||||
l.Deferred, l.StartedAt, l.ExpiresAt = false, &now, now.Add(d)
|
||||
} else {
|
||||
l.ExpiresAt = l.ExpiresAt.Add(d)
|
||||
}
|
||||
st.Leases[ip] = l
|
||||
} else if rec, ok := st.Ended[ip]; ok && rec.Revoked {
|
||||
return time.Time{}, errRevoked
|
||||
} else if ok && rec.renewable(now) {
|
||||
st.Leases[ip] = leaseInfo{Name: rec.Name, Invite: rec.Invite, Duration: protocol.LeaseDurationOf(minutes), StartedAt: &now, ExpiresAt: now.Add(d)}
|
||||
delete(st.Ended, ip)
|
||||
} else {
|
||||
return time.Time{}, errNothingToRenew
|
||||
}
|
||||
for _, r := range st.Requests {
|
||||
if r.IP == ip && r.Renewal && r.Status == "pending" {
|
||||
r.Status, r.At = "approved", now
|
||||
}
|
||||
}
|
||||
return st.Leases[ip].ExpiresAt, nil
|
||||
}
|
||||
|
||||
// renewalList reports, across all scopes (closed ones included), the devices that can still be
|
||||
// extended and the pending renewal requests
|
||||
func (s *stateStore) renewalList() []protocol.RenewalInfo {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.pruneLocked()
|
||||
now := time.Now()
|
||||
var out []protocol.RenewalInfo
|
||||
for scope, st := range s.data {
|
||||
id, isGroup := splitScope(scope)
|
||||
base := protocol.RenewalInfo{TunnelID: id}
|
||||
if isGroup {
|
||||
base = protocol.RenewalInfo{GroupID: id}
|
||||
}
|
||||
byIP := make(map[string]int)
|
||||
for ip, rec := range st.Ended {
|
||||
if !rec.renewable(now) {
|
||||
continue
|
||||
}
|
||||
info := base
|
||||
end, before := rec.EndedAt, rec.EndedAt.Add(renewWindow)
|
||||
info.IP, info.Name, info.Invite, info.EndedAt, info.RenewBefore = ip, rec.Name, rec.Invite, &end, &before
|
||||
byIP[ip] = len(out)
|
||||
out = append(out, info)
|
||||
}
|
||||
for _, r := range st.Requests {
|
||||
if !r.Renewal || r.Status != "pending" {
|
||||
continue
|
||||
}
|
||||
c := *r
|
||||
if i, ok := byIP[r.IP]; ok {
|
||||
out[i].Request = &c
|
||||
continue
|
||||
}
|
||||
info := base
|
||||
info.IP, info.Name, info.Invite, info.Request = r.IP, r.Name, r.Invite, &c
|
||||
out = append(out, info)
|
||||
}
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
if (out[i].Request != nil) != (out[j].Request != nil) {
|
||||
return out[i].Request != nil
|
||||
}
|
||||
ti, tj := now, now
|
||||
if out[i].EndedAt != nil {
|
||||
ti = *out[i].EndedAt
|
||||
}
|
||||
if out[j].EndedAt != nil {
|
||||
tj = *out[j].EndedAt
|
||||
}
|
||||
return ti.After(tj)
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
// ---- housekeeping ----
|
||||
|
||||
func (s *stateStore) pruneRequestsLocked() {
|
||||
@@ -560,7 +889,12 @@ func (s *stateStore) pruneLocked() {
|
||||
}
|
||||
for ip, l := range st.Leases {
|
||||
if !now.Before(l.ExpiresAt) {
|
||||
delete(st.Leases, ip)
|
||||
endLeaseLocked(st, ip, l, l.ExpiresAt, false)
|
||||
}
|
||||
}
|
||||
for ip, r := range st.Ended {
|
||||
if !now.Before(r.EndedAt.Add(renewWindow)) {
|
||||
delete(st.Ended, ip)
|
||||
}
|
||||
}
|
||||
for code, inv := range st.Invites {
|
||||
@@ -568,7 +902,7 @@ func (s *stateStore) pruneLocked() {
|
||||
delete(st.Invites, code)
|
||||
}
|
||||
}
|
||||
if len(st.Leases) == 0 && len(st.Invites) == 0 && len(st.Requests) == 0 {
|
||||
if len(st.Leases) == 0 && len(st.Invites) == 0 && len(st.Requests) == 0 && len(st.Ended) == 0 {
|
||||
delete(s.data, id)
|
||||
}
|
||||
}
|
||||
@@ -607,10 +941,6 @@ func (s *stateStore) saveLocked() {
|
||||
func leaseExpiry(duration string, scopeExpires *time.Time, now time.Time) time.Time {
|
||||
var exp time.Time
|
||||
switch duration {
|
||||
case protocol.LeaseDuration1h:
|
||||
exp = now.Add(time.Hour)
|
||||
case protocol.LeaseDuration8h:
|
||||
exp = now.Add(8 * time.Hour)
|
||||
case protocol.LeaseDurationToday:
|
||||
y, mo, d := now.Date()
|
||||
exp = time.Date(y, mo, d, 23, 59, 59, 0, now.Location())
|
||||
@@ -618,7 +948,11 @@ func leaseExpiry(duration string, scopeExpires *time.Time, now time.Time) time.T
|
||||
// 通道开启期间有效:通道被主动关闭时放通会被清除;设一个上限避免永久放通
|
||||
exp = now.Add(30 * 24 * time.Hour)
|
||||
default:
|
||||
exp = now.Add(2 * time.Hour)
|
||||
minutes, ok := protocol.LeaseMinutes(duration)
|
||||
if !ok {
|
||||
minutes = 120
|
||||
}
|
||||
exp = now.Add(time.Duration(minutes) * time.Minute)
|
||||
}
|
||||
if scopeExpires != nil && scopeExpires.After(now) && scopeExpires.Before(exp) {
|
||||
exp = *scopeExpires
|
||||
|
||||
Reference in new issue
Block a user