MCPcopy Index your code
hub / github.com/0xUnixIO/pulse / handleNodeSpeedTest

Method handleNodeSpeedTest

internal/serverapi/api.go:659–683  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, nodeID string)

Source from the content-addressed store, hash-verified

657}
658
659func (a *API) handleNodeSpeedTest(w http.ResponseWriter, r *http.Request, nodeID string) {
660 if r.Method != http.MethodPost {
661 writeMethodNotAllowed(w, http.MethodPost)
662 return
663 }
664 client, err := a.clientFor(nodeID)
665 if err != nil {
666 writeNodeError(w, err)
667 return
668 }
669 ctx, cancel := context.WithTimeout(r.Context(), 70*time.Second)
670 defer cancel()
671 resp, err := client.SpeedTest(ctx)
672 if err != nil {
673 writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": err.Error()})
674 return
675 }
676 result := nodes.SpeedTestResult{
677 DownBps: resp.DownBps,
678 UpBps: resp.UpBps,
679 TestedAt: time.Now().UTC(),
680 }
681 _ = a.store.UpsertNodeSpeedTest(nodeID, result)
682 writeJSON(w, http.StatusOK, result)
683}
684
685func (a *API) handleNodeCheck(w http.ResponseWriter, r *http.Request, nodeID string) {
686 if r.Method != http.MethodPost {

Callers 1

handleNodeRoutesMethod · 0.95

Calls 7

clientForMethod · 0.95
writeMethodNotAllowedFunction · 0.85
writeNodeErrorFunction · 0.85
SpeedTestMethod · 0.80
writeJSONFunction · 0.70
UpsertNodeSpeedTestMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected