Skip to content

Commit effcc3a

Browse files
committed
- Make everything const by default.
- Remove setMeshInstance method from RequestData class. - Remove delay(50) and WiFi.disconnect() from setup() in the examples since those statements do not seem to have an effect any longer. - Improve documentation.
1 parent a24b8d2 commit effcc3a

40 files changed

+607
-518
lines changed

libraries/ESP8266WiFiMesh/examples/HelloEspnow/HelloEspnow.ino

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,6 @@ void setup() {
233233
WiFi.persistent(false);
234234

235235
Serial.begin(115200);
236-
delay(50); // Wait for Serial.
237-
238-
//yield(); // Use this if you don't want to wait for Serial, but not with the ESP-NOW backend (yield() causes crashes with ESP-NOW).
239-
240-
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
241-
// those WiFi connections will take a long time to make or sometimes will not work at all.
242-
WiFi.disconnect();
243236

244237
Serial.println();
245238
Serial.println();

libraries/ESP8266WiFiMesh/examples/HelloMesh/HelloMesh.ino

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ void setup() {
122122
WiFi.persistent(false);
123123

124124
Serial.begin(115200);
125-
delay(50); // Wait for Serial.
126-
127-
//yield(); // Use this if you don't want to wait for Serial, but not with the ESP-NOW backend (yield() causes crashes with ESP-NOW).
128-
129-
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
130-
// those WiFi connections will take a long time to make or sometimes will not work at all.
131-
WiFi.disconnect();
132125

133126
Serial.println();
134127
Serial.println();

libraries/ESP8266WiFiMesh/examples/HelloTcpIp/HelloTcpIp.ino

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ void setup() {
160160
WiFi.persistent(false);
161161

162162
Serial.begin(115200);
163-
delay(50); // Wait for Serial.
164-
165-
//yield(); // Use this if you don't want to wait for Serial.
166-
167-
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
168-
// those WiFi connections will take a long time to make or sometimes will not work at all.
169-
WiFi.disconnect();
170163

171164
Serial.println();
172165
Serial.println();

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
using EspnowProtocolInterpreter::espnowHashKeyLength;
3232
namespace TypeCast = MeshTypeConversionFunctions;
3333

34-
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
34+
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
3535
: _peerSessionKey(peerSessionKey), _ownSessionKey(ownSessionKey)
3636
{
3737
std::copy_n(peerStaMac, 6, _peerStaMac);
3838
std::copy_n(peerApMac, 6, _peerApMac);
3939
std::copy_n(hashKey, espnowHashKeyLength, _hashKey);
4040
}
4141

42-
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
42+
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
4343
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
4444
{
4545
setRemainingDuration(duration);
@@ -119,13 +119,13 @@ uint8_t *EncryptedConnectionData::getHashKey(uint8_t *resultArray) const
119119
return resultArray;
120120
}
121121

122-
void EncryptedConnectionData::setPeerSessionKey(uint64_t sessionKey) { _peerSessionKey = sessionKey; }
122+
void EncryptedConnectionData::setPeerSessionKey(const uint64_t sessionKey) { _peerSessionKey = sessionKey; }
123123
uint64_t EncryptedConnectionData::getPeerSessionKey() const { return _peerSessionKey; }
124124

125-
void EncryptedConnectionData::setOwnSessionKey(uint64_t sessionKey) { _ownSessionKey = sessionKey; }
125+
void EncryptedConnectionData::setOwnSessionKey(const uint64_t sessionKey) { _ownSessionKey = sessionKey; }
126126
uint64_t EncryptedConnectionData::getOwnSessionKey() const { return _ownSessionKey; }
127127

128-
uint64_t EncryptedConnectionData::incrementSessionKey(uint64_t sessionKey, const uint8_t *hashKey, uint8_t hashKeyLength)
128+
uint64_t EncryptedConnectionData::incrementSessionKey(const uint64_t sessionKey, const uint8_t *hashKey, const uint8_t hashKeyLength)
129129
{
130130
uint8_t inputArray[8] {0};
131131
uint8_t hmacArray[CryptoInterface::SHA256_NATURAL_LENGTH] {0};
@@ -149,7 +149,7 @@ void EncryptedConnectionData::incrementOwnSessionKey()
149149
setOwnSessionKey(incrementSessionKey(getOwnSessionKey(), _hashKey, EspnowProtocolInterpreter::espnowHashKeyLength));
150150
}
151151

152-
void EncryptedConnectionData::setDesync(bool desync) { _desync = desync; }
152+
void EncryptedConnectionData::setDesync(const bool desync) { _desync = desync; }
153153
bool EncryptedConnectionData::desync() const { return _desync; }
154154

155155
String EncryptedConnectionData::serialize() const
@@ -171,7 +171,7 @@ const ExpiringTimeTracker *EncryptedConnectionData::temporary() const
171171
return _timeTracker.get();
172172
}
173173

174-
void EncryptedConnectionData::setRemainingDuration(uint32_t remainingDuration)
174+
void EncryptedConnectionData::setRemainingDuration(const uint32_t remainingDuration)
175175
{
176176
if(!_timeTracker)
177177
{

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class EncryptedConnectionData {
3636

3737
virtual ~EncryptedConnectionData() = default;
3838

39-
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
39+
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
4040
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
41-
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
42-
uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
41+
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
42+
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
4343

4444
EncryptedConnectionData(const EncryptedConnectionData &other);
4545

@@ -65,23 +65,23 @@ class EncryptedConnectionData {
6565
// @param resultArray At least size espnowHashKeyLength.
6666
uint8_t *getHashKey(uint8_t *resultArray) const;
6767

68-
void setPeerSessionKey(uint64_t sessionKey);
68+
void setPeerSessionKey(const uint64_t sessionKey);
6969
uint64_t getPeerSessionKey() const;
70-
void setOwnSessionKey(uint64_t sessionKey);
70+
void setOwnSessionKey(const uint64_t sessionKey);
7171
uint64_t getOwnSessionKey() const;
7272

73-
static uint64_t incrementSessionKey(uint64_t sessionKey, const uint8_t *hashKey, uint8_t hashKeyLength);
73+
static uint64_t incrementSessionKey(const uint64_t sessionKey, const uint8_t *hashKey, const uint8_t hashKeyLength);
7474
void incrementOwnSessionKey();
7575

76-
void setDesync(bool desync);
76+
void setDesync(const bool desync);
7777
bool desync() const;
7878

7979
// Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
8080
// These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
8181
String serialize() const;
8282

8383
const ExpiringTimeTracker *temporary() const;
84-
virtual void setRemainingDuration(uint32_t remainingDuration);
84+
virtual void setRemainingDuration(const uint32_t remainingDuration);
8585
virtual void removeDuration();
8686

8787
private:

libraries/ESP8266WiFiMesh/src/EncryptedConnectionLog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626

2727
using EspnowProtocolInterpreter::espnowHashKeyLength;
2828

29-
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
29+
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
3030
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
3131
{ }
3232

33-
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
33+
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
3434
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, duration, hashKey)
3535
{ }
3636

3737
std::unique_ptr<ExpiringTimeTracker> EncryptedConnectionLog::_soonestExpiringConnectionTracker = nullptr;
3838

3939
bool EncryptedConnectionLog::_newRemovalsScheduled = false;
4040

41-
void EncryptedConnectionLog::setRemainingDuration(uint32_t remainingDuration)
41+
void EncryptedConnectionLog::setRemainingDuration(const uint32_t remainingDuration)
4242
{
4343
EncryptedConnectionData::setRemainingDuration(remainingDuration);
4444

@@ -61,7 +61,7 @@ void EncryptedConnectionLog::scheduleForRemoval()
6161
setScheduledForRemoval(true);
6262
}
6363

64-
void EncryptedConnectionLog::setScheduledForRemoval(bool scheduledForRemoval)
64+
void EncryptedConnectionLog::setScheduledForRemoval(const bool scheduledForRemoval)
6565
{
6666
_scheduledForRemoval = scheduledForRemoval;
6767

@@ -70,15 +70,15 @@ void EncryptedConnectionLog::setScheduledForRemoval(bool scheduledForRemoval)
7070
}
7171
bool EncryptedConnectionLog::removalScheduled() const { return _scheduledForRemoval; }
7272

73-
void EncryptedConnectionLog::setNewRemovalsScheduled(bool newRemovalsScheduled) { _newRemovalsScheduled = newRemovalsScheduled; }
74-
bool EncryptedConnectionLog::newRemovalsScheduled( ){ return _newRemovalsScheduled; }
73+
void EncryptedConnectionLog::setNewRemovalsScheduled(const bool newRemovalsScheduled) { _newRemovalsScheduled = newRemovalsScheduled; }
74+
bool EncryptedConnectionLog::newRemovalsScheduled( ) { return _newRemovalsScheduled; }
7575

7676
const ExpiringTimeTracker *EncryptedConnectionLog::getSoonestExpiringConnectionTracker()
7777
{
7878
return _soonestExpiringConnectionTracker.get();
7979
}
8080

81-
void EncryptedConnectionLog::updateSoonestExpiringConnectionTracker(uint32_t remainingDuration)
81+
void EncryptedConnectionLog::updateSoonestExpiringConnectionTracker(const uint32_t remainingDuration)
8282
{
8383
if(!getSoonestExpiringConnectionTracker() || remainingDuration < getSoonestExpiringConnectionTracker()->remainingDuration())
8484
{

libraries/ESP8266WiFiMesh/src/EncryptedConnectionLog.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class EncryptedConnectionLog : public EncryptedConnectionData {
3232

3333
public:
3434

35-
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
35+
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
3636
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
37-
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
38-
uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
37+
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
38+
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
3939

4040
// Only guaranteed to expire at the latest when the soonestExpiringConnection does. Can expire before the soonestExpiringConnection since it is not updated on connection removal.
4141
// Needs to be a copy to avoid invalidation during operations on temporaryEncryptedConnections.
@@ -46,23 +46,23 @@ class EncryptedConnectionLog : public EncryptedConnectionData {
4646
static bool _newRemovalsScheduled;
4747

4848
// Can be used to set a duration both for temporary and permanent encrypted connections (transforming the latter into a temporary connection in the process).
49-
void setRemainingDuration(uint32_t remainingDuration) override;
49+
void setRemainingDuration(const uint32_t remainingDuration) override;
5050
void removeDuration() override;
5151

5252
void scheduleForRemoval();
5353
bool removalScheduled() const;
5454

55-
static void setNewRemovalsScheduled(bool newRemovalsScheduled);
55+
static void setNewRemovalsScheduled(const bool newRemovalsScheduled);
5656
static bool newRemovalsScheduled();
5757

5858
static const ExpiringTimeTracker *getSoonestExpiringConnectionTracker();
59-
static void updateSoonestExpiringConnectionTracker(uint32_t remainingDuration);
59+
static void updateSoonestExpiringConnectionTracker(const uint32_t remainingDuration);
6060
static void clearSoonestExpiringConnectionTracker();
6161

6262
private:
6363

6464
bool _scheduledForRemoval = false;
65-
void setScheduledForRemoval(bool scheduledForRemoval);
65+
void setScheduledForRemoval(const bool scheduledForRemoval);
6666
};
6767

6868
#endif

0 commit comments

Comments
 (0)