-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmesh.go
40 lines (31 loc) · 883 Bytes
/
dmesh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
"net/http"
"github.com/eoscanada/dmesh"
"go.uber.org/zap"
)
func (r *Diagnose) searchPeers(w http.ResponseWriter, req *http.Request) {
zlog.Info("diagnose - Search Peers")
ctx, cancel := context.WithCancel(req.Context())
conn, err := r.upgrader.Upgrade(w, req, nil)
if err != nil {
return
}
defer conn.Close()
go readWebsocket(conn, cancel)
servicePrefix := fmt.Sprintf("%s/search", r.DmeshServiceVersion)
zlog.Info("observing dmesh", zap.String("namespace", r.Namespace), zap.String("service_prefix", servicePrefix))
eventChan := dmesh.Observe(ctx, r.dmeshStore, r.Namespace, servicePrefix)
for {
select {
case <-ctx.Done():
zlog.Debug("context canceled")
return
case peer := <-eventChan:
maybeSendWebsocket(conn, WebsocketTypePeerEvent, peer)
}
}
zlog.Info("diagnose - Search Peers - Complete")
}