chore: release v0.27.12
This commit is contained in:
+31
-5
@@ -140,8 +140,17 @@ func New(cfg Config) *Watcher {
|
||||
// same measurement is 0.2 to 1.2 — the load follows distance, which is what the
|
||||
// feed is actually about, and it is the same for every operator.
|
||||
func (w *Watcher) topics() []string {
|
||||
bands := w.cfg.Bands
|
||||
// One subscription per band per square multiplies, and past a point the
|
||||
// cheaper trade is to take every band from those squares and drop the
|
||||
// unwanted ones here: four bands over six hundred squares is 2400
|
||||
// subscriptions, where "+" is 600 for maybe three times the messages —
|
||||
// which are then filtered locally, as they already are for everything else.
|
||||
if len(bands) > 1 && len(bands)*len(w.cfg.RxGrids) > 1000 {
|
||||
bands = []string{"+"}
|
||||
}
|
||||
out := []string{}
|
||||
for _, b := range w.cfg.Bands {
|
||||
for _, b := range bands {
|
||||
if len(w.cfg.RxGrids) == 0 {
|
||||
out = append(out, "pskr/filter/v2/"+b+"/#")
|
||||
continue
|
||||
@@ -181,13 +190,30 @@ func (w *Watcher) Start() error {
|
||||
|
||||
opts.OnConnect = func(c mqtt.Client) {
|
||||
w.cfg.Logf("pskr: connected to %s", w.cfg.Broker)
|
||||
for _, topic := range w.topics() {
|
||||
if tok := c.Subscribe(topic, 0, w.handle); tok.Wait() && tok.Error() != nil {
|
||||
w.cfg.Logf("pskr: subscribe %s failed: %v", topic, tok.Error())
|
||||
topics := w.topics()
|
||||
// In batches, not one at a time. Each Subscribe waits for its own
|
||||
// acknowledgement, which is fine for the nine squares this started with
|
||||
// and is minutes of waiting for the six hundred a 2000 km radius asks
|
||||
// for — during which the feed is only partly subscribed and the panel
|
||||
// looks broken.
|
||||
const batch = 100
|
||||
subbed := 0
|
||||
for i := 0; i < len(topics); i += batch {
|
||||
end := i + batch
|
||||
if end > len(topics) {
|
||||
end = len(topics)
|
||||
}
|
||||
filters := make(map[string]byte, end-i)
|
||||
for _, t := range topics[i:end] {
|
||||
filters[t] = 0
|
||||
}
|
||||
if tok := c.SubscribeMultiple(filters, w.handle); tok.Wait() && tok.Error() != nil {
|
||||
w.cfg.Logf("pskr: subscribing to %d topics failed: %v", len(filters), tok.Error())
|
||||
continue
|
||||
}
|
||||
w.cfg.Logf("pskr: watching %s", topic)
|
||||
subbed += len(filters)
|
||||
}
|
||||
w.cfg.Logf("pskr: watching %d topics (%d bands × %d receiver squares)", subbed, len(w.cfg.Bands), max(len(w.cfg.RxGrids), 1))
|
||||
}
|
||||
opts.OnConnectionLost = func(_ mqtt.Client, err error) {
|
||||
w.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user