Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
save expiry timestamp in reservations
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 4, 2021
1 parent 6fe8142 commit eff0cbe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions v2/relay/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,27 @@ func (c *constraints) AddReservation(p peer.ID, a ma.Multiaddr) error {
}
}

c.total.PushBack(listEntry{t: now})
expiry := now.Add(validity)
c.total.PushBack(listEntry{t: expiry})

if peerReservations == nil {
peerReservations = list.New()
c.peers[p] = peerReservations
}
peerReservations.PushBack(listEntry{t: now})
peerReservations.PushBack(listEntry{t: expiry})

if ipReservations == nil {
ipReservations = list.New()
c.ips[ip.String()] = ipReservations
}
ipReservations.PushBack(listEntry{t: now})
ipReservations.PushBack(listEntry{t: expiry})

if asn != "" {
if asnReservations == nil {
asnReservations = list.New()
c.asns[asn] = asnReservations
}
asnReservations.PushBack(listEntry{t: now})
asnReservations.PushBack(listEntry{t: expiry})
}

return nil
Expand All @@ -129,7 +130,7 @@ func (c *constraints) AddReservation(p peer.ID, a ma.Multiaddr) error {
func (c *constraints) cleanupList(l *list.List, now time.Time) {
for el := l.Front(); el != nil; {
entry := el.Value.(listEntry)
if entry.t.Add(validity).After(now) {
if entry.t.After(now) {
return
}
nextEl := el.Next()
Expand Down

0 comments on commit eff0cbe

Please sign in to comment.