This commit is contained in:
Pascal Fischer
2024-04-25 15:44:06 +02:00
parent e50ed290d9
commit fbb1181b64
2 changed files with 29 additions and 0 deletions

View File

@@ -462,6 +462,12 @@ func (a *Account) GetExpiredPeers() []*nbpeer.Peer {
// If there is no peer that expires this function returns false and a duration of 0.
// This function only considers peers that haven't been expired yet and that are connected.
func (a *Account) GetNextPeerExpiration() (time.Duration, bool) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetNextPeerExpiration took %s", duration)
}()
peersWithExpiry := a.GetPeersWithExpiration()
if len(peersWithExpiry) == 0 {
return 0, false
@@ -518,6 +524,11 @@ func (a *Account) UpdateSettings(update *Settings) *Account {
// UpdatePeer saves new or replaces existing peer
func (a *Account) UpdatePeer(update *nbpeer.Peer) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("UpdatePeer took %s", duration)
}()
a.Peers[update.ID] = update
}
@@ -547,6 +558,12 @@ func (a *Account) DeletePeer(peerID string) {
// FindPeerByPubKey looks for a Peer by provided WireGuard public key in the Account or returns error if it wasn't found.
// It will return an object copy of the peer.
func (a *Account) FindPeerByPubKey(peerPubKey string) (*nbpeer.Peer, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("FindPeerByPubKey took %s", duration)
}()
for _, peer := range a.Peers {
if peer.Key == peerPubKey {
return peer.Copy(), nil
@@ -1042,6 +1059,12 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(accountID string) func()
}
func (am *DefaultAccountManager) checkAndSchedulePeerLoginExpiration(account *Account) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("checkAndSchedulePeerLoginExpiration took %s", duration)
}()
am.peerLoginExpiry.Cancel([]string{account.Id})
if nextRun, ok := account.GetNextPeerExpiration(); ok {
go am.peerLoginExpiry.Schedule(nextRun, account.Id, am.peerLoginExpirationJob(account.Id))

View File

@@ -106,6 +106,12 @@ func openDB(mmdbPath string) (*maxminddb.Reader, error) {
}
func (gl *Geolocation) Lookup(ip net.IP) (*Record, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("(GeoLocation) Lookup took %s", duration)
}()
gl.mux.RLock()
defer gl.mux.RUnlock()