Skip to content

Commit

Permalink
Return simple responses immediatly
Browse files Browse the repository at this point in the history
This commit rearranges the poll handler to immediatly accept
updates and notify its peers and return, not travel down the
function for a bit. This reduces the DB calls and other
holdups that isnt necessary to send a "lite response", a
map response without peers, or accepting an endpoint update.

Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Sep 19, 2023
1 parent 217ccd6 commit c957f89
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 139 deletions.
2 changes: 0 additions & 2 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ type Headscale struct {

shutdownChan chan struct{}
pollNetMapStreamWG sync.WaitGroup

pollStreamOpenMu sync.Mutex
}

func NewHeadscale(cfg *types.Config) (*Headscale, error) {
Expand Down
14 changes: 8 additions & 6 deletions hscontrol/db/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,15 @@ func (hsdb *HSDatabase) deleteMachine(machine *types.Machine) error {
return nil
}

func (hsdb *HSDatabase) TouchMachine(machine *types.Machine) error {
hsdb.mu.Lock()
defer hsdb.mu.Unlock()

// UpdateLastSeen sets a machine's last seen field indicating that we
// have recently communicating with this machine.
// This is mostly used to indicate if a machine is online and is not
// extremely important to make sure is fully correct and to avoid
// holding up the hot path, does not contain any locks and isnt
// concurrency safe. But that should be ok.
func (hsdb *HSDatabase) UpdateLastSeen(machine *types.Machine) error {
return hsdb.db.Model(machine).Updates(types.Machine{
LastSeen: machine.LastSeen,
LastSuccessfulUpdate: machine.LastSuccessfulUpdate,
LastSeen: machine.LastSeen,
}).Error
}

Expand Down
Loading

0 comments on commit c957f89

Please sign in to comment.