MCPcopy Index your code
hub / github.com/coder/coder / addTunnelLocked

Method addTunnelLocked

tailnet/coordinator.go:371–399  ·  view source on GitHub ↗
(src *peer, dstID uuid.UUID)

Source from the content-addressed store, hash-verified

369}
370
371func (c *core) addTunnelLocked(src *peer, dstID uuid.UUID) error {
372 c.tunnels.add(src.id, dstID)
373 c.logger.Debug(context.Background(), "adding tunnel",
374 slog.F("src_id", src.id),
375 slog.F("dst_id", dstID))
376 dst, ok := c.peers[dstID]
377 if ok {
378 if dst.node != nil {
379 err := src.updateMappingLocked(dstID, dst.node, proto.CoordinateResponse_PeerUpdate_NODE, "add tunnel")
380 if err != nil {
381 src.logger.Error(context.Background(), "failed update of tunnel src", slog.Error(err))
382 c.removePeerLocked(src.id, proto.CoordinateResponse_PeerUpdate_DISCONNECTED, "failed update",
383 "failed to update tunnel dest mapping")
384 // if the source fails, then the tunnel is also removed and there is no reason to continue
385 // processing.
386 return err
387 }
388 }
389 if src.node != nil {
390 err := dst.updateMappingLocked(src.id, src.node, proto.CoordinateResponse_PeerUpdate_NODE, "add tunnel")
391 if err != nil {
392 dst.logger.Error(context.Background(), "failed update of tunnel dst", slog.Error(err))
393 c.removePeerLocked(dst.id, proto.CoordinateResponse_PeerUpdate_DISCONNECTED, "failed update",
394 "failed to update tunnel src mapping")
395 }
396 }
397 }
398 return nil
399}
400
401func (c *core) removeTunnelLocked(src *peer, dstID uuid.UUID) error {
402 err := src.updateMappingLocked(dstID, nil, proto.CoordinateResponse_PeerUpdate_DISCONNECTED, "remove tunnel")

Callers 1

handleRequestMethod · 0.95

Calls 4

removePeerLockedMethod · 0.95
updateMappingLockedMethod · 0.80
addMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected