mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
Merge pull request #31 from juanfont/improving-client-startup
Improving how headscale handles the client startup process
This commit is contained in:
commit
094fde36d1
1 changed files with 36 additions and 16 deletions
32
api.go
32
api.go
|
@ -215,17 +215,37 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[%s] sending initial map", m.Name)
|
|
||||||
pollData <- *data
|
|
||||||
|
|
||||||
// We update our peers if the client is not sending ReadOnly in the MapRequest
|
// We update our peers if the client is not sending ReadOnly in the MapRequest
|
||||||
// so we don't distribute its initial request (it comes with
|
// so we don't distribute its initial request (it comes with
|
||||||
// empty endpoints to peers)
|
// empty endpoints to peers)
|
||||||
if !req.ReadOnly {
|
|
||||||
|
// Details on the protocol can be found in https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L696
|
||||||
|
log.Printf("[%s] ReadOnly=%t OmitPeers=%t Stream=%t", m.Name, req.ReadOnly, req.OmitPeers, req.Stream)
|
||||||
|
|
||||||
|
if req.ReadOnly {
|
||||||
|
log.Printf("[%s] Client is starting up. Asking for DERP map", m.Name)
|
||||||
|
c.Data(200, "application/json; charset=utf-8", *data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.OmitPeers && !req.Stream {
|
||||||
|
log.Printf("[%s] Client sent endpoint update and is ok with a response without peer list", m.Name)
|
||||||
|
c.Data(200, "application/json; charset=utf-8", *data)
|
||||||
|
return
|
||||||
|
} else if req.OmitPeers && req.Stream {
|
||||||
|
log.Printf("[%s] Warning, ignoring request, don't know how to handle it", m.Name)
|
||||||
|
c.String(http.StatusBadRequest, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[%s] Client is ready to access the tailnet", m.Name)
|
||||||
|
log.Printf("[%s] Sending initial map", m.Name)
|
||||||
|
pollData <- *data
|
||||||
|
|
||||||
|
log.Printf("[%s] Notifying peers", m.Name)
|
||||||
peers, _ := h.getPeers(m)
|
peers, _ := h.getPeers(m)
|
||||||
h.pollMu.Lock()
|
h.pollMu.Lock()
|
||||||
for _, p := range *peers {
|
for _, p := range *peers {
|
||||||
log.Printf("[%s] notifying peer %s (%s)", m.Name, p.Name, p.Addresses[0])
|
log.Printf("[%s] Notifying peer %s (%s)", m.Name, p.Name, p.Addresses[0])
|
||||||
if pUp, ok := h.clientsPolling[uint64(p.ID)]; ok {
|
if pUp, ok := h.clientsPolling[uint64(p.ID)]; ok {
|
||||||
pUp <- []byte{}
|
pUp <- []byte{}
|
||||||
} else {
|
} else {
|
||||||
|
@ -233,7 +253,6 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.pollMu.Unlock()
|
h.pollMu.Unlock()
|
||||||
}
|
|
||||||
|
|
||||||
go h.keepAlive(cancelKeepAlive, pollData, mKey, req, m)
|
go h.keepAlive(cancelKeepAlive, pollData, mKey, req, m)
|
||||||
|
|
||||||
|
@ -290,6 +309,7 @@ func (h *Headscale) keepAlive(cancel chan []byte, pollData chan []byte, mKey wgc
|
||||||
log.Printf("Error generating the keep alive msg: %s", err)
|
log.Printf("Error generating the keep alive msg: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("[%s] Sending keepalive", m.Name)
|
||||||
pollData <- *data
|
pollData <- *data
|
||||||
h.pollMu.Unlock()
|
h.pollMu.Unlock()
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(60 * time.Second)
|
||||||
|
|
Loading…
Reference in a new issue