@@ -148,11 +148,12 @@ func (t *Tunnel) handleRPC(req *ManagerMessage, msgID uint64) *TunnelMessage {
148
148
state ,err := t .conn .CurrentWorkspaceState ()
149
149
if err != nil {
150
150
t .logger .Critical (t .ctx ,"failed to get current workspace state" ,slog .Error (err ))
151
+ resp .Msg = & TunnelMessage_PeerUpdate {
152
+ PeerUpdate :nil ,
153
+ }
154
+ return resp
151
155
}
152
- update ,err := t .createPeerUpdate (state )
153
- if err != nil {
154
- t .logger .Error (t .ctx ,"failed to populate agent network info" ,slog .Error (err ))
155
- }
156
+ update := t .createPeerUpdate (state )
156
157
resp .Msg = & TunnelMessage_PeerUpdate {
157
158
PeerUpdate :update ,
158
159
}
@@ -241,10 +242,7 @@ func (t *Tunnel) ApplyNetworkSettings(ctx context.Context, ns *NetworkSettingsRe
241
242
}
242
243
243
244
func (t * Tunnel )Update (update tailnet.WorkspaceUpdate )error {
244
- peerUpdate ,err := t .createPeerUpdate (update )
245
- if err != nil {
246
- t .logger .Error (t .ctx ,"failed to populate agent network info" ,slog .Error (err ))
247
- }
245
+ peerUpdate := t .createPeerUpdate (update )
248
246
msg := & TunnelMessage {
249
247
Msg :& TunnelMessage_PeerUpdate {
250
248
PeerUpdate :peerUpdate ,
@@ -346,7 +344,7 @@ func sinkEntryToPb(e slog.SinkEntry) *Log {
346
344
347
345
// createPeerUpdate creates a PeerUpdate message from a workspace update, populating
348
346
// the network status of the agents.
349
- func (t * Tunnel )createPeerUpdate (update tailnet.WorkspaceUpdate )( * PeerUpdate , error ) {
347
+ func (t * Tunnel )createPeerUpdate (update tailnet.WorkspaceUpdate )* PeerUpdate {
350
348
out := & PeerUpdate {
351
349
UpsertedWorkspaces :make ([]* Workspace ,len (update .UpsertedWorkspaces )),
352
350
UpsertedAgents :make ([]* Agent ,len (update .UpsertedAgents )),
@@ -363,10 +361,7 @@ func (t *Tunnel) createPeerUpdate(update tailnet.WorkspaceUpdate) (*PeerUpdate,
363
361
Status :Workspace_Status (ws .Status ),
364
362
}
365
363
}
366
- upsertedAgents ,err := t .populateAgents (update .UpsertedAgents )
367
- if err != nil {
368
- return nil ,xerrors .Errorf ("failed to populate agent network info: %w" ,err )
369
- }
364
+ upsertedAgents := t .convertAgents (update .UpsertedAgents )
370
365
out .UpsertedAgents = upsertedAgents
371
366
for i ,ws := range update .DeletedWorkspaces {
372
367
out .DeletedWorkspaces [i ]= & Workspace {
@@ -389,15 +384,12 @@ func (t *Tunnel) createPeerUpdate(update tailnet.WorkspaceUpdate) (*PeerUpdate,
389
384
LastHandshake :nil ,
390
385
}
391
386
}
392
- return out , nil
387
+ return out
393
388
}
394
389
395
- // Given a list of `tailnet.Agent`, populate their network info, and convert them to proto agents.
396
- func (t * Tunnel )populateAgents (agents []* tailnet.Agent ) ([]* Agent ,error ) {
397
- if t .conn == nil {
398
- return nil ,xerrors .New ("no active connection" )
399
- }
400
-
390
+ // convertAgents takes a list of `tailnet.Agent` and converts them to proto agents.
391
+ // If there is an active connection, the last handshake time is populated.
392
+ func (t * Tunnel )convertAgents (agents []* tailnet.Agent ) []* Agent {
401
393
out := make ([]* Agent ,0 ,len (agents ))
402
394
403
395
for _ ,agent := range agents {
@@ -412,12 +404,14 @@ func (t *Tunnel) populateAgents(agents []*tailnet.Agent) ([]*Agent, error) {
412
404
Fqdn :fqdn ,
413
405
IpAddrs :hostsToIPStrings (agent .Hosts ),
414
406
}
415
- diags := t .conn .GetPeerDiagnostics (agent .ID )
416
- protoAgent .LastHandshake = timestamppb .New (diags .LastWireguardHandshake )
407
+ if t .conn != nil {
408
+ diags := t .conn .GetPeerDiagnostics (agent .ID )
409
+ protoAgent .LastHandshake = timestamppb .New (diags .LastWireguardHandshake )
410
+ }
417
411
out = append (out ,protoAgent )
418
412
}
419
413
420
- return out , nil
414
+ return out
421
415
}
422
416
423
417
// saveUpdate saves the workspace update to the tunnel's state, such that it can
@@ -442,12 +436,7 @@ func (t *Tunnel) sendAgentUpdate() {
442
436
t .mu .Lock ()
443
437
defer t .mu .Unlock ()
444
438
445
- upsertedAgents ,err := t .populateAgents (maps .Values (t .agents ))
446
- if err != nil {
447
- t .logger .Error (t .ctx ,"failed to produce agent network status update" ,slog .Error (err ))
448
- return
449
- }
450
-
439
+ upsertedAgents := t .convertAgents (maps .Values (t .agents ))
451
440
if len (upsertedAgents )== 0 {
452
441
return
453
442
}
@@ -525,6 +514,8 @@ func quote(key string) string {
525
514
return quoted
526
515
}
527
516
517
+ // hostsToIPStrings returns a slice of all unique IP addresses in the values
518
+ // of the given map.
528
519
func hostsToIPStrings (hosts map [dnsname.FQDN ][]netip.Addr ) []string {
529
520
seen := make (map [netip.Addr ]struct {})
530
521
var result []string