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

Method handleRequest

tailnet/coordinator.go:237–301  ·  view source on GitHub ↗
(ctx context.Context, p *peer, req *proto.CoordinateRequest)

Source from the content-addressed store, hash-verified

235}
236
237func (c *core) handleRequest(ctx context.Context, p *peer, req *proto.CoordinateRequest) error {
238 c.mutex.Lock()
239 defer c.mutex.Unlock()
240 if c.closed {
241 return ErrClosed
242 }
243 pr, ok := c.peers[p.id]
244 if !ok || pr != p {
245 return ErrAlreadyRemoved
246 }
247
248 if err := pr.auth.Authorize(ctx, req); err != nil {
249 return AuthorizationError{Wrapped: err}
250 }
251
252 if req.UpdateSelf != nil {
253 err := c.nodeUpdateLocked(p, req.UpdateSelf.Node)
254 if xerrors.Is(err, ErrAlreadyRemoved) || xerrors.Is(err, ErrClosed) {
255 return nil
256 }
257 if err != nil {
258 return xerrors.Errorf("node update failed: %w", err)
259 }
260 }
261 if req.AddTunnel != nil {
262 dstID, err := uuid.FromBytes(req.AddTunnel.Id)
263 if err != nil {
264 // this shouldn't happen unless there is a client error. Close the connection so the client
265 // doesn't just happily continue thinking everything is fine.
266 return xerrors.Errorf("unable to convert bytes to UUID: %w", err)
267 }
268 err = c.addTunnelLocked(p, dstID)
269 if xerrors.Is(err, ErrAlreadyRemoved) || xerrors.Is(err, ErrClosed) {
270 return nil
271 }
272 if err != nil {
273 return xerrors.Errorf("add tunnel failed: %w", err)
274 }
275 }
276 if req.RemoveTunnel != nil {
277 dstID, err := uuid.FromBytes(req.RemoveTunnel.Id)
278 if err != nil {
279 // this shouldn't happen unless there is a client error. Close the connection so the client
280 // doesn't just happily continue thinking everything is fine.
281 return xerrors.Errorf("unable to convert bytes to UUID: %w", err)
282 }
283 err = c.removeTunnelLocked(p, dstID)
284 if xerrors.Is(err, ErrAlreadyRemoved) || xerrors.Is(err, ErrClosed) {
285 return nil
286 }
287 if err != nil {
288 return xerrors.Errorf("remove tunnel failed: %w", err)
289 }
290 }
291 if req.Disconnect != nil {
292 c.removePeerLocked(p.id, proto.CoordinateResponse_PeerUpdate_DISCONNECTED, "graceful disconnect", "")
293 }
294 if rfhs := req.ReadyForHandshake; rfhs != nil {

Callers

nothing calls this directly

Calls 10

nodeUpdateLockedMethod · 0.95
addTunnelLockedMethod · 0.95
removeTunnelLockedMethod · 0.95
removePeerLockedMethod · 0.95
AuthorizeMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected