@@ -394,48 +394,12 @@ func (u *updater) sendUpdateResponse(req *request[*TunnelMessage, *ManagerMessag
394
394
return nil
395
395
}
396
396
397
- // processFreshState handles the logic for when a fresh state update is received.
398
- func (u * updater ) processFreshState (update * tailnet.WorkspaceUpdate ) {
399
- // ignoredWorkspaces is initially populated with the workspaces that are
400
- // in the current update. Later on we populate it with the deleted workspaces too
401
- // so that we don't send duplicate updates. Same applies to ignoredAgents.
402
- ignoredWorkspaces := make (map [uuid.UUID ]struct {}, len (update .UpsertedWorkspaces ))
403
- ignoredAgents := make (map [uuid.UUID ]struct {}, len (update .UpsertedAgents ))
404
-
405
- for _ , workspace := range update .UpsertedWorkspaces {
406
- ignoredWorkspaces [workspace .ID ] = struct {}{}
407
- }
408
- for _ , agent := range update .UpsertedAgents {
409
- ignoredAgents [agent .ID ] = struct {}{}
410
- }
411
- for _ , agent := range u .agents {
412
- if _ , ok := ignoredAgents [agent .ID ]; ! ok {
413
- // delete any current agents that are not in the new update
414
- update .DeletedAgents = append (update .DeletedAgents , & tailnet.Agent {
415
- ID : agent .ID ,
416
- Name : agent .Name ,
417
- WorkspaceID : agent .WorkspaceID ,
418
- })
419
- // if the workspace connected to an agent we're deleting,
420
- // is not present in the fresh state, add it to the deleted workspaces
421
- if _ , ok := ignoredWorkspaces [agent .WorkspaceID ]; ! ok {
422
- update .DeletedWorkspaces = append (update .DeletedWorkspaces , & tailnet.Workspace {
423
- // other fields cannot be populated because the tunnel
424
- // only stores agents and corresponding workspaceIDs
425
- ID : agent .WorkspaceID ,
426
- })
427
- ignoredWorkspaces [agent .WorkspaceID ] = struct {}{}
428
- }
429
- }
430
- }
431
- }
432
-
433
397
// createPeerUpdateLocked creates a PeerUpdate message from a workspace update, populating
434
398
// the network status of the agents.
435
399
func (u * updater ) createPeerUpdateLocked (update tailnet.WorkspaceUpdate ) * PeerUpdate {
436
400
// this flag is true on the first update after a reconnect
437
401
if update .FreshState {
438
- u . processFreshState (& update )
402
+ processFreshState (& update , u . agents )
439
403
}
440
404
441
405
out := & PeerUpdate {
@@ -590,6 +554,42 @@ func (u *updater) netStatusLoop() {
590
554
}
591
555
}
592
556
557
+ // processFreshState handles the logic for when a fresh state update is received.
558
+ func processFreshState (update * tailnet.WorkspaceUpdate , agents map [uuid.UUID ]tailnet.Agent ) {
559
+ // ignoredWorkspaces is initially populated with the workspaces that are
560
+ // in the current update. Later on we populate it with the deleted workspaces too
561
+ // so that we don't send duplicate updates. Same applies to ignoredAgents.
562
+ ignoredWorkspaces := make (map [uuid.UUID ]struct {}, len (update .UpsertedWorkspaces ))
563
+ ignoredAgents := make (map [uuid.UUID ]struct {}, len (update .UpsertedAgents ))
564
+
565
+ for _ , workspace := range update .UpsertedWorkspaces {
566
+ ignoredWorkspaces [workspace .ID ] = struct {}{}
567
+ }
568
+ for _ , agent := range update .UpsertedAgents {
569
+ ignoredAgents [agent .ID ] = struct {}{}
570
+ }
571
+ for _ , agent := range agents {
572
+ if _ , ok := ignoredAgents [agent .ID ]; ! ok {
573
+ // delete any current agents that are not in the new update
574
+ update .DeletedAgents = append (update .DeletedAgents , & tailnet.Agent {
575
+ ID : agent .ID ,
576
+ Name : agent .Name ,
577
+ WorkspaceID : agent .WorkspaceID ,
578
+ })
579
+ // if the workspace connected to an agent we're deleting,
580
+ // is not present in the fresh state, add it to the deleted workspaces
581
+ if _ , ok := ignoredWorkspaces [agent .WorkspaceID ]; ! ok {
582
+ update .DeletedWorkspaces = append (update .DeletedWorkspaces , & tailnet.Workspace {
583
+ // other fields cannot be populated because the tunnel
584
+ // only stores agents and corresponding workspaceIDs
585
+ ID : agent .WorkspaceID ,
586
+ })
587
+ ignoredWorkspaces [agent .WorkspaceID ] = struct {}{}
588
+ }
589
+ }
590
+ }
591
+ }
592
+
593
593
// hostsToIPStrings returns a slice of all unique IP addresses in the values
594
594
// of the given map.
595
595
func hostsToIPStrings (hosts map [dnsname.FQDN ][]netip.Addr ) []string {
0 commit comments