@alteriom/painlessmesh 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,14 @@ class StationScan {
62
62
  // The station got an address: its link is up. Cleared once the drop
63
63
  // callbacks have judged a disconnect, so they can tell a link that was
64
64
  // up and went away from an attempt that never got that far.
65
- void stationUp() { stationLinkUp = true; }
65
+ void stationUp() {
66
+ stationLinkUp = true;
67
+ // A link again, so the immediate-rescan allowance is restored now
68
+ // rather than at the next scan. Without this a node that dropped
69
+ // twice inside one scan interval paid the full fifteen seconds for
70
+ // the second drop (#459).
71
+ rejoinScanned = false;
72
+ }
66
73
  void stationDown() { stationLinkUp = false; }
67
74
  bool stationLinkUp = false;
68
75
  // The station link was closed by this node's own channel move a moment
@@ -147,6 +154,11 @@ class StationScan {
147
154
  // channel re-detection runs, and consuming those results here found them
148
155
  // already deleted, reported "wifi scan failed", and rescanned at once.
149
156
  bool scanRequested = false;
157
+ // Whether this node has already scanned at once on losing its last
158
+ // connection. Cleared the moment it has one again, so the immediate
159
+ // rescan is one per outage and not a scan loop: a node that is out of
160
+ // the mesh and finds nothing still falls back to the interval below.
161
+ bool rejoinScanned = false;
150
162
  // Set when the next station scan must cover every channel: the empty
151
163
  // scans have piled up and the node is looking for the channel the mesh
152
164
  // moved to. The re-detection is this task's ordinary asynchronous scan
@@ -206,12 +206,17 @@ class SentBuffer {
206
206
  size_t requestLength(size_t buffer_length) {
207
207
  // Use highest priority message available
208
208
  auto* msg = getNextMessage();
209
- if (!msg)
210
- return 0;
211
- else
212
- // String.toCharArray automatically turns the last character into
213
- // a \0, we need the extra space to deal with that annoyance
214
- return (std::min)(buffer_length - 1, msg->length() + 1);
209
+ if (!msg) return 0;
210
+ // A caller with no room is owed nothing. The subtraction below leaves
211
+ // space for the terminator toCharArray() always writes; on an unsigned
212
+ // zero it wraps to SIZE_MAX instead, min() then picks the message, and
213
+ // the answer comes back *larger* than was asked for -- which the
214
+ // documented contract above forbids and read() then acts on, writing
215
+ // length + 1 bytes into a buffer the caller said had none.
216
+ if (buffer_length == 0) return 0;
217
+ // String.toCharArray automatically turns the last character into
218
+ // a \0, we need the extra space to deal with that annoyance
219
+ return (std::min)(buffer_length - 1, msg->length() + 1);
215
220
  }
216
221
 
217
222
  /**