Skip to content

Commit

Permalink
Merge pull request #47 from juanfont/handle-ephemeral-reconnect
Browse files Browse the repository at this point in the history
Added HTTP responses on map errors
  • Loading branch information
juanfont committed Jul 11, 2021
2 parents f66c283 + bff3d2d commit ad7f03c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,21 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
mKey, err := wgkey.ParseHex(mKeyStr)
if err != nil {
log.Printf("Cannot parse client key: %s", err)
c.String(http.StatusBadRequest, "")
return
}
req := tailcfg.MapRequest{}
err = decode(body, &req, &mKey, h.privateKey)
if err != nil {
log.Printf("Cannot decode message: %s", err)
c.String(http.StatusBadRequest, "")
return
}

var m Machine
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
c.String(http.StatusUnauthorized, "")
return
}

Expand Down Expand Up @@ -287,7 +290,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
log.Printf("[%s] Sending data (%d bytes)", m.Name, len(data))
_, err := w.Write(data)
if err != nil {
log.Printf("[%s] 🤮 Cannot write data: %s", m.Name, err)
log.Printf("[%s] Cannot write data: %s", m.Name, err)
}
now := time.Now().UTC()
m.LastSeen = &now
Expand Down

0 comments on commit ad7f03c

Please sign in to comment.