MCPcopy Create free account
hub / github.com/coder/coder / handleRequest

Method handleRequest

enterprise/tailnet/connio.go:129–230  ·  view source on GitHub ↗
(req *proto.CoordinateRequest)

Source from the content-addressed store, hash-verified

127var errDisconnect = xerrors.New("graceful disconnect")
128
129func (c *connIO) handleRequest(req *proto.CoordinateRequest) error {
130 c.logger.Debug(c.peerCtx, "got request")
131 err := c.auth.Authorize(c.peerCtx, req)
132 if err != nil {
133 c.logger.Warn(c.peerCtx, "unauthorized request", slog.Error(err))
134 return agpl.AuthorizationError{Wrapped: err}
135 }
136
137 if req.UpdateSelf != nil {
138 c.logger.Debug(c.peerCtx, "got node update", slog.F("node", req.UpdateSelf))
139 b := binding{
140 bKey: bKey(c.UniqueID()),
141 node: req.UpdateSelf.Node,
142 kind: proto.CoordinateResponse_PeerUpdate_NODE,
143 }
144 if err := agpl.SendCtx(c.coordCtx, c.bindings, b); err != nil {
145 c.logger.Debug(c.peerCtx, "failed to send binding", slog.Error(err))
146 return err
147 }
148 }
149 if req.AddTunnel != nil {
150 c.logger.Debug(c.peerCtx, "got add tunnel", slog.F("tunnel", req.AddTunnel))
151 dst, err := uuid.FromBytes(req.AddTunnel.Id)
152 if err != nil {
153 c.logger.Error(c.peerCtx, "unable to convert bytes to UUID", slog.Error(err))
154 // this shouldn't happen unless there is a client error. Close the connection so the client
155 // doesn't just happily continue thinking everything is fine.
156 return err
157 }
158 t := tunnel{
159 tKey: tKey{
160 src: c.UniqueID(),
161 dst: dst,
162 },
163 active: true,
164 }
165 if err := agpl.SendCtx(c.coordCtx, c.tunnels, t); err != nil {
166 c.logger.Debug(c.peerCtx, "failed to send add tunnel", slog.Error(err))
167 return err
168 }
169 }
170 if req.RemoveTunnel != nil {
171 c.logger.Debug(c.peerCtx, "got remove tunnel", slog.F("tunnel", req.RemoveTunnel))
172 dst, err := uuid.FromBytes(req.RemoveTunnel.Id)
173 if err != nil {
174 c.logger.Error(c.peerCtx, "unable to convert bytes to UUID", slog.Error(err))
175 // this shouldn't happen unless there is a client error. Close the connection so the client
176 // doesn't just happily continue thinking everything is fine.
177 return err
178 }
179 t := tunnel{
180 tKey: tKey{
181 src: c.UniqueID(),
182 dst: dst,
183 },
184 active: false,
185 }
186 if err := agpl.SendCtx(c.coordCtx, c.tunnels, t); err != nil {

Callers 1

recvLoopMethod · 0.95

Calls 7

UniqueIDMethod · 0.95
getLatestMappingMethod · 0.95
EnqueueMethod · 0.95
bKeyTypeAlias · 0.85
AuthorizeMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected