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

Method bindingsToMappings

enterprise/tailnet/pgcoord.go:1162–1185  ·  view source on GitHub ↗

bindingsToMappings converts binding rows to mappings.

(bindings []database.GetTailnetTunnelPeerBindingsBatchRow)

Source from the content-addressed store, hash-verified

1160
1161// bindingsToMappings converts binding rows to mappings.
1162func (q *querier) bindingsToMappings(bindings []database.GetTailnetTunnelPeerBindingsBatchRow) ([]mapping, error) {
1163 slog.Helper()
1164 mappings := make([]mapping, 0, len(bindings))
1165 for _, binding := range bindings {
1166 node := new(proto.Node)
1167 err := gProto.Unmarshal(binding.Node, node)
1168 if err != nil {
1169 q.logger.Error(q.ctx, "failed to unmarshal node", slog.Error(err))
1170 return nil, backoff.Permanent(err)
1171 }
1172 kind := proto.CoordinateResponse_PeerUpdate_NODE
1173 if binding.Status == database.TailnetStatusLost {
1174 kind = proto.CoordinateResponse_PeerUpdate_LOST
1175 }
1176 mappings = append(mappings, mapping{
1177 peer: binding.PeerID,
1178 coordinator: binding.CoordinatorID,
1179 updatedAt: binding.UpdatedAt,
1180 node: node,
1181 kind: kind,
1182 })
1183 }
1184 return mappings, nil
1185}
1186
1187// subscribe starts our subscriptions to peer and tunnnel updates in a new goroutine, and returns once we are subscribed
1188// or the querier context is canceled.

Callers 1

mappingQueryMethod · 0.95

Calls 3

HelperMethod · 0.65
UnmarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected