mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
- 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.
This commit is contained in:
parent
a24b8d23f0
commit
effcc3a2d0
@ -233,13 +233,6 @@ void setup() {
|
|||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(50); // Wait for Serial.
|
|
||||||
|
|
||||||
//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).
|
|
||||||
|
|
||||||
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
|
|
||||||
// those WiFi connections will take a long time to make or sometimes will not work at all.
|
|
||||||
WiFi.disconnect();
|
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -122,13 +122,6 @@ void setup() {
|
|||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(50); // Wait for Serial.
|
|
||||||
|
|
||||||
//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).
|
|
||||||
|
|
||||||
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
|
|
||||||
// those WiFi connections will take a long time to make or sometimes will not work at all.
|
|
||||||
WiFi.disconnect();
|
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -160,13 +160,6 @@ void setup() {
|
|||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(50); // Wait for Serial.
|
|
||||||
|
|
||||||
//yield(); // Use this if you don't want to wait for Serial.
|
|
||||||
|
|
||||||
// The WiFi.disconnect() ensures that the WiFi is working correctly. If this is not done before receiving WiFi connections,
|
|
||||||
// those WiFi connections will take a long time to make or sometimes will not work at all.
|
|
||||||
WiFi.disconnect();
|
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
||||||
namespace TypeCast = MeshTypeConversionFunctions;
|
namespace TypeCast = MeshTypeConversionFunctions;
|
||||||
|
|
||||||
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
|
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])
|
||||||
: _peerSessionKey(peerSessionKey), _ownSessionKey(ownSessionKey)
|
: _peerSessionKey(peerSessionKey), _ownSessionKey(ownSessionKey)
|
||||||
{
|
{
|
||||||
std::copy_n(peerStaMac, 6, _peerStaMac);
|
std::copy_n(peerStaMac, 6, _peerStaMac);
|
||||||
@ -39,7 +39,7 @@ EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], co
|
|||||||
std::copy_n(hashKey, espnowHashKeyLength, _hashKey);
|
std::copy_n(hashKey, espnowHashKeyLength, _hashKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
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])
|
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])
|
||||||
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
|
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
|
||||||
{
|
{
|
||||||
setRemainingDuration(duration);
|
setRemainingDuration(duration);
|
||||||
@ -119,13 +119,13 @@ uint8_t *EncryptedConnectionData::getHashKey(uint8_t *resultArray) const
|
|||||||
return resultArray;
|
return resultArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptedConnectionData::setPeerSessionKey(uint64_t sessionKey) { _peerSessionKey = sessionKey; }
|
void EncryptedConnectionData::setPeerSessionKey(const uint64_t sessionKey) { _peerSessionKey = sessionKey; }
|
||||||
uint64_t EncryptedConnectionData::getPeerSessionKey() const { return _peerSessionKey; }
|
uint64_t EncryptedConnectionData::getPeerSessionKey() const { return _peerSessionKey; }
|
||||||
|
|
||||||
void EncryptedConnectionData::setOwnSessionKey(uint64_t sessionKey) { _ownSessionKey = sessionKey; }
|
void EncryptedConnectionData::setOwnSessionKey(const uint64_t sessionKey) { _ownSessionKey = sessionKey; }
|
||||||
uint64_t EncryptedConnectionData::getOwnSessionKey() const { return _ownSessionKey; }
|
uint64_t EncryptedConnectionData::getOwnSessionKey() const { return _ownSessionKey; }
|
||||||
|
|
||||||
uint64_t EncryptedConnectionData::incrementSessionKey(uint64_t sessionKey, const uint8_t *hashKey, uint8_t hashKeyLength)
|
uint64_t EncryptedConnectionData::incrementSessionKey(const uint64_t sessionKey, const uint8_t *hashKey, const uint8_t hashKeyLength)
|
||||||
{
|
{
|
||||||
uint8_t inputArray[8] {0};
|
uint8_t inputArray[8] {0};
|
||||||
uint8_t hmacArray[CryptoInterface::SHA256_NATURAL_LENGTH] {0};
|
uint8_t hmacArray[CryptoInterface::SHA256_NATURAL_LENGTH] {0};
|
||||||
@ -149,7 +149,7 @@ void EncryptedConnectionData::incrementOwnSessionKey()
|
|||||||
setOwnSessionKey(incrementSessionKey(getOwnSessionKey(), _hashKey, EspnowProtocolInterpreter::espnowHashKeyLength));
|
setOwnSessionKey(incrementSessionKey(getOwnSessionKey(), _hashKey, EspnowProtocolInterpreter::espnowHashKeyLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptedConnectionData::setDesync(bool desync) { _desync = desync; }
|
void EncryptedConnectionData::setDesync(const bool desync) { _desync = desync; }
|
||||||
bool EncryptedConnectionData::desync() const { return _desync; }
|
bool EncryptedConnectionData::desync() const { return _desync; }
|
||||||
|
|
||||||
String EncryptedConnectionData::serialize() const
|
String EncryptedConnectionData::serialize() const
|
||||||
@ -171,7 +171,7 @@ const ExpiringTimeTracker *EncryptedConnectionData::temporary() const
|
|||||||
return _timeTracker.get();
|
return _timeTracker.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptedConnectionData::setRemainingDuration(uint32_t remainingDuration)
|
void EncryptedConnectionData::setRemainingDuration(const uint32_t remainingDuration)
|
||||||
{
|
{
|
||||||
if(!_timeTracker)
|
if(!_timeTracker)
|
||||||
{
|
{
|
||||||
|
@ -36,10 +36,10 @@ public:
|
|||||||
|
|
||||||
virtual ~EncryptedConnectionData() = default;
|
virtual ~EncryptedConnectionData() = default;
|
||||||
|
|
||||||
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
|
||||||
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
|
||||||
uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
|
|
||||||
EncryptedConnectionData(const EncryptedConnectionData &other);
|
EncryptedConnectionData(const EncryptedConnectionData &other);
|
||||||
|
|
||||||
@ -65,15 +65,15 @@ public:
|
|||||||
// @param resultArray At least size espnowHashKeyLength.
|
// @param resultArray At least size espnowHashKeyLength.
|
||||||
uint8_t *getHashKey(uint8_t *resultArray) const;
|
uint8_t *getHashKey(uint8_t *resultArray) const;
|
||||||
|
|
||||||
void setPeerSessionKey(uint64_t sessionKey);
|
void setPeerSessionKey(const uint64_t sessionKey);
|
||||||
uint64_t getPeerSessionKey() const;
|
uint64_t getPeerSessionKey() const;
|
||||||
void setOwnSessionKey(uint64_t sessionKey);
|
void setOwnSessionKey(const uint64_t sessionKey);
|
||||||
uint64_t getOwnSessionKey() const;
|
uint64_t getOwnSessionKey() const;
|
||||||
|
|
||||||
static uint64_t incrementSessionKey(uint64_t sessionKey, const uint8_t *hashKey, uint8_t hashKeyLength);
|
static uint64_t incrementSessionKey(const uint64_t sessionKey, const uint8_t *hashKey, const uint8_t hashKeyLength);
|
||||||
void incrementOwnSessionKey();
|
void incrementOwnSessionKey();
|
||||||
|
|
||||||
void setDesync(bool desync);
|
void setDesync(const bool desync);
|
||||||
bool desync() const;
|
bool desync() const;
|
||||||
|
|
||||||
// Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
// Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
String serialize() const;
|
String serialize() const;
|
||||||
|
|
||||||
const ExpiringTimeTracker *temporary() const;
|
const ExpiringTimeTracker *temporary() const;
|
||||||
virtual void setRemainingDuration(uint32_t remainingDuration);
|
virtual void setRemainingDuration(const uint32_t remainingDuration);
|
||||||
virtual void removeDuration();
|
virtual void removeDuration();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -26,11 +26,11 @@
|
|||||||
|
|
||||||
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
||||||
|
|
||||||
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
|
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])
|
||||||
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
|
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
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])
|
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])
|
||||||
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, duration, hashKey)
|
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, duration, hashKey)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ std::unique_ptr<ExpiringTimeTracker> EncryptedConnectionLog::_soonestExpiringCon
|
|||||||
|
|
||||||
bool EncryptedConnectionLog::_newRemovalsScheduled = false;
|
bool EncryptedConnectionLog::_newRemovalsScheduled = false;
|
||||||
|
|
||||||
void EncryptedConnectionLog::setRemainingDuration(uint32_t remainingDuration)
|
void EncryptedConnectionLog::setRemainingDuration(const uint32_t remainingDuration)
|
||||||
{
|
{
|
||||||
EncryptedConnectionData::setRemainingDuration(remainingDuration);
|
EncryptedConnectionData::setRemainingDuration(remainingDuration);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ void EncryptedConnectionLog::scheduleForRemoval()
|
|||||||
setScheduledForRemoval(true);
|
setScheduledForRemoval(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptedConnectionLog::setScheduledForRemoval(bool scheduledForRemoval)
|
void EncryptedConnectionLog::setScheduledForRemoval(const bool scheduledForRemoval)
|
||||||
{
|
{
|
||||||
_scheduledForRemoval = scheduledForRemoval;
|
_scheduledForRemoval = scheduledForRemoval;
|
||||||
|
|
||||||
@ -70,15 +70,15 @@ void EncryptedConnectionLog::setScheduledForRemoval(bool scheduledForRemoval)
|
|||||||
}
|
}
|
||||||
bool EncryptedConnectionLog::removalScheduled() const { return _scheduledForRemoval; }
|
bool EncryptedConnectionLog::removalScheduled() const { return _scheduledForRemoval; }
|
||||||
|
|
||||||
void EncryptedConnectionLog::setNewRemovalsScheduled(bool newRemovalsScheduled) { _newRemovalsScheduled = newRemovalsScheduled; }
|
void EncryptedConnectionLog::setNewRemovalsScheduled(const bool newRemovalsScheduled) { _newRemovalsScheduled = newRemovalsScheduled; }
|
||||||
bool EncryptedConnectionLog::newRemovalsScheduled( ){ return _newRemovalsScheduled; }
|
bool EncryptedConnectionLog::newRemovalsScheduled( ) { return _newRemovalsScheduled; }
|
||||||
|
|
||||||
const ExpiringTimeTracker *EncryptedConnectionLog::getSoonestExpiringConnectionTracker()
|
const ExpiringTimeTracker *EncryptedConnectionLog::getSoonestExpiringConnectionTracker()
|
||||||
{
|
{
|
||||||
return _soonestExpiringConnectionTracker.get();
|
return _soonestExpiringConnectionTracker.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncryptedConnectionLog::updateSoonestExpiringConnectionTracker(uint32_t remainingDuration)
|
void EncryptedConnectionLog::updateSoonestExpiringConnectionTracker(const uint32_t remainingDuration)
|
||||||
{
|
{
|
||||||
if(!getSoonestExpiringConnectionTracker() || remainingDuration < getSoonestExpiringConnectionTracker()->remainingDuration())
|
if(!getSoonestExpiringConnectionTracker() || remainingDuration < getSoonestExpiringConnectionTracker()->remainingDuration())
|
||||||
{
|
{
|
||||||
|
@ -32,10 +32,10 @@ class EncryptedConnectionLog : public EncryptedConnectionData {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
|
||||||
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
|
||||||
uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
|
|
||||||
// Only guaranteed to expire at the latest when the soonestExpiringConnection does. Can expire before the soonestExpiringConnection since it is not updated on connection removal.
|
// Only guaranteed to expire at the latest when the soonestExpiringConnection does. Can expire before the soonestExpiringConnection since it is not updated on connection removal.
|
||||||
// Needs to be a copy to avoid invalidation during operations on temporaryEncryptedConnections.
|
// Needs to be a copy to avoid invalidation during operations on temporaryEncryptedConnections.
|
||||||
@ -46,23 +46,23 @@ public:
|
|||||||
static bool _newRemovalsScheduled;
|
static bool _newRemovalsScheduled;
|
||||||
|
|
||||||
// Can be used to set a duration both for temporary and permanent encrypted connections (transforming the latter into a temporary connection in the process).
|
// Can be used to set a duration both for temporary and permanent encrypted connections (transforming the latter into a temporary connection in the process).
|
||||||
void setRemainingDuration(uint32_t remainingDuration) override;
|
void setRemainingDuration(const uint32_t remainingDuration) override;
|
||||||
void removeDuration() override;
|
void removeDuration() override;
|
||||||
|
|
||||||
void scheduleForRemoval();
|
void scheduleForRemoval();
|
||||||
bool removalScheduled() const;
|
bool removalScheduled() const;
|
||||||
|
|
||||||
static void setNewRemovalsScheduled(bool newRemovalsScheduled);
|
static void setNewRemovalsScheduled(const bool newRemovalsScheduled);
|
||||||
static bool newRemovalsScheduled();
|
static bool newRemovalsScheduled();
|
||||||
|
|
||||||
static const ExpiringTimeTracker *getSoonestExpiringConnectionTracker();
|
static const ExpiringTimeTracker *getSoonestExpiringConnectionTracker();
|
||||||
static void updateSoonestExpiringConnectionTracker(uint32_t remainingDuration);
|
static void updateSoonestExpiringConnectionTracker(const uint32_t remainingDuration);
|
||||||
static void clearSoonestExpiringConnectionTracker();
|
static void clearSoonestExpiringConnectionTracker();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool _scheduledForRemoval = false;
|
bool _scheduledForRemoval = false;
|
||||||
void setScheduledForRemoval(bool scheduledForRemoval);
|
void setScheduledForRemoval(const bool scheduledForRemoval);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -112,9 +112,9 @@ void espnowDelay(uint32_t durationMs)
|
|||||||
while(!timeout);
|
while(!timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
EspnowMeshBackend::EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
|
EspnowMeshBackend::EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter,
|
||||||
broadcastFilterType broadcastFilter, const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, bool verboseMode,
|
const broadcastFilterType broadcastFilter, const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode,
|
||||||
uint8 meshWiFiChannel)
|
const uint8 meshWiFiChannel)
|
||||||
: MeshBackendBase(requestHandler, responseHandler, networkFilter, MeshBackendType::ESP_NOW)
|
: MeshBackendBase(requestHandler, responseHandler, networkFilter, MeshBackendType::ESP_NOW)
|
||||||
{
|
{
|
||||||
// Reserve the maximum possible usage early on to prevent heap fragmentation later.
|
// Reserve the maximum possible usage early on to prevent heap fragmentation later.
|
||||||
@ -127,20 +127,20 @@ EspnowMeshBackend::EspnowMeshBackend(requestHandlerType requestHandler, response
|
|||||||
setWiFiChannel(meshWiFiChannel);
|
setWiFiChannel(meshWiFiChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
EspnowMeshBackend::EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
|
EspnowMeshBackend::EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter,
|
||||||
broadcastFilterType broadcastFilter, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[espnowEncryptedConnectionKeyLength],
|
const broadcastFilterType broadcastFilter, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[espnowHashKeyLength], const String &ssidPrefix, const String &ssidSuffix, bool verboseMode,
|
const uint8_t espnowHashKey[espnowHashKeyLength], const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode,
|
||||||
uint8 meshWiFiChannel)
|
const uint8 meshWiFiChannel)
|
||||||
: EspnowMeshBackend(requestHandler, responseHandler, networkFilter, broadcastFilter, meshPassword, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
: EspnowMeshBackend(requestHandler, responseHandler, networkFilter, broadcastFilter, meshPassword, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
||||||
{
|
{
|
||||||
setEspnowEncryptedConnectionKey(espnowEncryptedConnectionKey);
|
setEspnowEncryptedConnectionKey(espnowEncryptedConnectionKey);
|
||||||
setEspnowHashKey(espnowHashKey);
|
setEspnowHashKey(espnowHashKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
EspnowMeshBackend::EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
|
EspnowMeshBackend::EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter,
|
||||||
broadcastFilterType broadcastFilter, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed,
|
const broadcastFilterType broadcastFilter, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed,
|
||||||
const String &espnowHashKeySeed, const String &ssidPrefix, const String &ssidSuffix, bool verboseMode,
|
const String &espnowHashKeySeed, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode,
|
||||||
uint8 meshWiFiChannel)
|
const uint8 meshWiFiChannel)
|
||||||
: EspnowMeshBackend(requestHandler, responseHandler, networkFilter, broadcastFilter, meshPassword, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
: EspnowMeshBackend(requestHandler, responseHandler, networkFilter, broadcastFilter, meshPassword, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
||||||
{
|
{
|
||||||
setEspnowEncryptedConnectionKey(espnowEncryptedConnectionKeySeed);
|
setEspnowEncryptedConnectionKey(espnowEncryptedConnectionKeySeed);
|
||||||
@ -250,7 +250,7 @@ bool EspnowMeshBackend::latestTransmissionSuccessful()
|
|||||||
return latestTransmissionSuccessfulBase(latestTransmissionOutcomes());
|
return latestTransmissionSuccessfulBase(latestTransmissionOutcomes());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::performEspnowMaintenance(uint32_t estimatedMaxDuration)
|
void EspnowMeshBackend::performEspnowMaintenance(const uint32_t estimatedMaxDuration)
|
||||||
{
|
{
|
||||||
ExpiringTimeTracker estimatedMaxDurationTracker = ExpiringTimeTracker(estimatedMaxDuration);
|
ExpiringTimeTracker estimatedMaxDurationTracker = ExpiringTimeTracker(estimatedMaxDuration);
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ void EspnowMeshBackend::performEspnowMaintenance(uint32_t estimatedMaxDuration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::updateTemporaryEncryptedConnections(bool scheduledRemovalOnly)
|
void EspnowMeshBackend::updateTemporaryEncryptedConnections(const bool scheduledRemovalOnly)
|
||||||
{
|
{
|
||||||
EncryptedConnectionLog::clearSoonestExpiringConnectionTracker();
|
EncryptedConnectionLog::clearSoonestExpiringConnectionTracker();
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ void EspnowMeshBackend::updateTemporaryEncryptedConnections(bool scheduledRemova
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, T> &logEntries, uint32_t maxEntryLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, T> &logEntries, const uint32_t maxEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::map<std::pair<U, uint64_t>, T>::iterator entryIterator = logEntries.begin();
|
for(typename std::map<std::pair<U, uint64_t>, T>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -327,7 +327,7 @@ void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, TimeTracker> &logEntries, uint32_t maxEntryLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, TimeTracker> &logEntries, const uint32_t maxEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::map<std::pair<U, uint64_t>, TimeTracker>::iterator entryIterator = logEntries.begin();
|
for(typename std::map<std::pair<U, uint64_t>, TimeTracker>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -341,7 +341,7 @@ void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<peerMac_td, messageID_td>, RequestData> &logEntries, uint32_t requestLifetimeMs, uint32_t broadcastLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<peerMac_td, messageID_td>, RequestData> &logEntries, const uint32_t requestLifetimeMs, const uint32_t broadcastLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::map<std::pair<peerMac_td, messageID_td>, RequestData>::iterator entryIterator = logEntries.begin();
|
for(typename std::map<std::pair<peerMac_td, messageID_td>, RequestData>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -360,7 +360,7 @@ void EspnowMeshBackend::deleteExpiredLogEntries(std::map<std::pair<peerMac_td, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<T> &logEntries, uint32_t maxEntryLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<T> &logEntries, const uint32_t maxEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::list<T>::iterator entryIterator = logEntries.begin();
|
for(typename std::list<T>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -375,7 +375,7 @@ void EspnowMeshBackend::deleteExpiredLogEntries(std::list<T> &logEntries, uint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<EncryptedConnectionLog> &logEntries, uint32_t maxEntryLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<EncryptedConnectionLog> &logEntries, const uint32_t maxEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::list<EncryptedConnectionLog>::iterator entryIterator = logEntries.begin();
|
for(typename std::list<EncryptedConnectionLog>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -391,7 +391,7 @@ void EspnowMeshBackend::deleteExpiredLogEntries(std::list<EncryptedConnectionLog
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<PeerRequestLog> &logEntries, uint32_t maxEntryLifetimeMs)
|
void EspnowMeshBackend::deleteExpiredLogEntries(std::list<PeerRequestLog> &logEntries, const uint32_t maxEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
for(typename std::list<PeerRequestLog>::iterator entryIterator = logEntries.begin();
|
for(typename std::list<PeerRequestLog>::iterator entryIterator = logEntries.begin();
|
||||||
entryIterator != logEntries.end(); )
|
entryIterator != logEntries.end(); )
|
||||||
@ -421,7 +421,7 @@ void EspnowMeshBackend::clearOldLogEntries()
|
|||||||
deleteExpiredLogEntries(peerRequestConfirmationsToSend, getEncryptionRequestTimeout());
|
deleteExpiredLogEntries(peerRequestConfirmationsToSend, getEncryptionRequestTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *dataArray, uint8_t len)
|
void EspnowMeshBackend::espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *dataArray, const uint8_t len)
|
||||||
{
|
{
|
||||||
using namespace EspnowProtocolInterpreter;
|
using namespace EspnowProtocolInterpreter;
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ void EspnowMeshBackend::espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::handlePeerRequest(uint8_t *macaddr, uint8_t *dataArray, uint8_t len, uint64_t uint64StationMac, uint64_t receivedMessageID)
|
void EspnowMeshBackend::handlePeerRequest(const uint8_t *macaddr, uint8_t *dataArray, const uint8_t len, const uint64_t uint64StationMac, const uint64_t receivedMessageID)
|
||||||
{
|
{
|
||||||
// Pairing process ends when encryptedConnectionVerificationHeader is received, maxConnectionsReachedHeader is sent or timeout is reached.
|
// Pairing process ends when encryptedConnectionVerificationHeader is received, maxConnectionsReachedHeader is sent or timeout is reached.
|
||||||
// Pairing process stages for request receiver:
|
// Pairing process stages for request receiver:
|
||||||
@ -657,7 +657,7 @@ void EspnowMeshBackend::handlePeerRequest(uint8_t *macaddr, uint8_t *dataArray,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::handlePeerRequestConfirmation(uint8_t *macaddr, uint8_t *dataArray, uint8_t len)
|
void EspnowMeshBackend::handlePeerRequestConfirmation(uint8_t *macaddr, uint8_t *dataArray, const uint8_t len)
|
||||||
{
|
{
|
||||||
// Pairing process ends when _ongoingPeerRequestNonce == "" or timeout is reached.
|
// Pairing process ends when _ongoingPeerRequestNonce == "" or timeout is reached.
|
||||||
// Pairing process stages for request sender:
|
// Pairing process stages for request sender:
|
||||||
@ -764,7 +764,7 @@ void EspnowMeshBackend::handlePeerRequestConfirmation(uint8_t *macaddr, uint8_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::espnowReceiveCallback(uint8_t *macaddr, uint8_t *dataArray, uint8_t len)
|
void EspnowMeshBackend::espnowReceiveCallback(const uint8_t *macaddr, uint8_t *dataArray, const uint8_t len)
|
||||||
{
|
{
|
||||||
using namespace EspnowProtocolInterpreter;
|
using namespace EspnowProtocolInterpreter;
|
||||||
|
|
||||||
@ -924,29 +924,29 @@ void EspnowMeshBackend::setEspnowRequestManager(EspnowMeshBackend *espnowMeshIns
|
|||||||
|
|
||||||
EspnowMeshBackend *EspnowMeshBackend::getEspnowRequestManager() {return _espnowRequestManager;}
|
EspnowMeshBackend *EspnowMeshBackend::getEspnowRequestManager() {return _espnowRequestManager;}
|
||||||
|
|
||||||
bool EspnowMeshBackend::isEspnowRequestManager()
|
bool EspnowMeshBackend::isEspnowRequestManager() const
|
||||||
{
|
{
|
||||||
return (this == getEspnowRequestManager());
|
return (this == getEspnowRequestManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::encryptedConnectionEstablished(EncryptedConnectionStatus connectionStatus)
|
bool EspnowMeshBackend::encryptedConnectionEstablished(const EncryptedConnectionStatus connectionStatus)
|
||||||
{
|
{
|
||||||
return static_cast<int>(connectionStatus) > 0;
|
return static_cast<int>(connectionStatus) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setLogEntryLifetimeMs(uint32_t logEntryLifetimeMs)
|
void EspnowMeshBackend::setLogEntryLifetimeMs(const uint32_t logEntryLifetimeMs)
|
||||||
{
|
{
|
||||||
_logEntryLifetimeMs = logEntryLifetimeMs;
|
_logEntryLifetimeMs = logEntryLifetimeMs;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::logEntryLifetimeMs() { return _logEntryLifetimeMs; }
|
uint32_t EspnowMeshBackend::logEntryLifetimeMs() { return _logEntryLifetimeMs; }
|
||||||
|
|
||||||
void EspnowMeshBackend::setBroadcastResponseTimeoutMs(uint32_t broadcastResponseTimeoutMs)
|
void EspnowMeshBackend::setBroadcastResponseTimeoutMs(const uint32_t broadcastResponseTimeoutMs)
|
||||||
{
|
{
|
||||||
_broadcastResponseTimeoutMs = broadcastResponseTimeoutMs;
|
_broadcastResponseTimeoutMs = broadcastResponseTimeoutMs;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::broadcastResponseTimeoutMs() { return _broadcastResponseTimeoutMs; }
|
uint32_t EspnowMeshBackend::broadcastResponseTimeoutMs() { return _broadcastResponseTimeoutMs; }
|
||||||
|
|
||||||
void EspnowMeshBackend::setCriticalHeapLevelBuffer(uint32_t bufferInBytes)
|
void EspnowMeshBackend::setCriticalHeapLevelBuffer(const uint32_t bufferInBytes)
|
||||||
{
|
{
|
||||||
_criticalHeapLevelBuffer = bufferInBytes;
|
_criticalHeapLevelBuffer = bufferInBytes;
|
||||||
}
|
}
|
||||||
@ -957,7 +957,7 @@ uint32_t EspnowMeshBackend::criticalHeapLevelBuffer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T *EspnowMeshBackend::getMapValue(std::map<uint64_t, T> &mapIn, uint64_t keyIn)
|
T *EspnowMeshBackend::getMapValue(std::map<uint64_t, T> &mapIn, const uint64_t keyIn)
|
||||||
{
|
{
|
||||||
typename std::map<uint64_t, T>::iterator mapIterator = mapIn.find(keyIn);
|
typename std::map<uint64_t, T>::iterator mapIterator = mapIn.find(keyIn);
|
||||||
|
|
||||||
@ -979,7 +979,7 @@ void EspnowMeshBackend::storeReceivedRequest(const uint64_t senderBSSID, const u
|
|||||||
receivedRequests.insert(std::make_pair(std::make_pair(senderBSSID, messageID), timeTracker));
|
receivedRequests.insert(std::make_pair(std::make_pair(senderBSSID, messageID), timeTracker));
|
||||||
}
|
}
|
||||||
|
|
||||||
EspnowMeshBackend *EspnowMeshBackend::getOwnerOfSentRequest(uint64_t requestMac, uint64_t requestID)
|
EspnowMeshBackend *EspnowMeshBackend::getOwnerOfSentRequest(const uint64_t requestMac, const uint64_t requestID)
|
||||||
{
|
{
|
||||||
std::map<std::pair<peerMac_td, messageID_td>, RequestData>::iterator sentRequest = sentRequests.find(std::make_pair(requestMac, requestID));
|
std::map<std::pair<peerMac_td, messageID_td>, RequestData>::iterator sentRequest = sentRequests.find(std::make_pair(requestMac, requestID));
|
||||||
|
|
||||||
@ -991,12 +991,12 @@ EspnowMeshBackend *EspnowMeshBackend::getOwnerOfSentRequest(uint64_t requestMac,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t EspnowMeshBackend::deleteSentRequest(uint64_t requestMac, uint64_t requestID)
|
size_t EspnowMeshBackend::deleteSentRequest(const uint64_t requestMac, const uint64_t requestID)
|
||||||
{
|
{
|
||||||
return sentRequests.erase(std::make_pair(requestMac, requestID));
|
return sentRequests.erase(std::make_pair(requestMac, requestID));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t EspnowMeshBackend::deleteSentRequestsByOwner(EspnowMeshBackend *instancePointer)
|
size_t EspnowMeshBackend::deleteSentRequestsByOwner(const EspnowMeshBackend *instancePointer)
|
||||||
{
|
{
|
||||||
size_t numberDeleted = 0;
|
size_t numberDeleted = 0;
|
||||||
|
|
||||||
@ -1015,7 +1015,7 @@ size_t EspnowMeshBackend::deleteSentRequestsByOwner(EspnowMeshBackend *instanceP
|
|||||||
return numberDeleted;
|
return numberDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::requestReceived(uint64_t requestMac, uint64_t requestID)
|
bool EspnowMeshBackend::requestReceived(const uint64_t requestMac, const uint64_t requestID)
|
||||||
{
|
{
|
||||||
return receivedRequests.count(std::make_pair(requestMac, requestID));
|
return receivedRequests.count(std::make_pair(requestMac, requestID));
|
||||||
}
|
}
|
||||||
@ -1025,7 +1025,7 @@ uint32_t EspnowMeshBackend::criticalHeapLevel()
|
|||||||
return _criticalHeapLevel;
|
return _criticalHeapLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t EspnowMeshBackend::generateMessageID(EncryptedConnectionLog *encryptedConnection)
|
uint64_t EspnowMeshBackend::generateMessageID(const EncryptedConnectionLog *encryptedConnection)
|
||||||
{
|
{
|
||||||
if(encryptedConnection)
|
if(encryptedConnection)
|
||||||
{
|
{
|
||||||
@ -1041,39 +1041,39 @@ uint64_t EspnowMeshBackend::createSessionKey()
|
|||||||
return EspnowProtocolInterpreter::usesEncryption(newSessionKey) ? newSessionKey : (newSessionKey | ((uint64_t)RANDOM_REG32) << 32 | uint64MSB);
|
return EspnowProtocolInterpreter::usesEncryption(newSessionKey) ? newSessionKey : (newSessionKey | ((uint64_t)RANDOM_REG32) << 32 | uint64MSB);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setEspnowTransmissionTimeout(uint32_t timeoutMs)
|
void EspnowMeshBackend::setEspnowTransmissionTimeout(const uint32_t timeoutMs)
|
||||||
{
|
{
|
||||||
_espnowTransmissionTimeoutMs = timeoutMs;
|
_espnowTransmissionTimeoutMs = timeoutMs;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::getEspnowTransmissionTimeout() {return _espnowTransmissionTimeoutMs;}
|
uint32_t EspnowMeshBackend::getEspnowTransmissionTimeout() {return _espnowTransmissionTimeoutMs;}
|
||||||
|
|
||||||
void EspnowMeshBackend::setEspnowRetransmissionInterval(uint32_t intervalMs)
|
void EspnowMeshBackend::setEspnowRetransmissionInterval(const uint32_t intervalMs)
|
||||||
{
|
{
|
||||||
_espnowRetransmissionIntervalMs = intervalMs;
|
_espnowRetransmissionIntervalMs = intervalMs;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::getEspnowRetransmissionInterval() {return _espnowRetransmissionIntervalMs;}
|
uint32_t EspnowMeshBackend::getEspnowRetransmissionInterval() {return _espnowRetransmissionIntervalMs;}
|
||||||
|
|
||||||
void EspnowMeshBackend::setEncryptionRequestTimeout(uint32_t timeoutMs)
|
void EspnowMeshBackend::setEncryptionRequestTimeout(const uint32_t timeoutMs)
|
||||||
{
|
{
|
||||||
_encryptionRequestTimeoutMs = timeoutMs;
|
_encryptionRequestTimeoutMs = timeoutMs;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::getEncryptionRequestTimeout() {return _encryptionRequestTimeoutMs;}
|
uint32_t EspnowMeshBackend::getEncryptionRequestTimeout() {return _encryptionRequestTimeoutMs;}
|
||||||
|
|
||||||
void EspnowMeshBackend::setAutoEncryptionDuration(uint32_t duration)
|
void EspnowMeshBackend::setAutoEncryptionDuration(const uint32_t duration)
|
||||||
{
|
{
|
||||||
_autoEncryptionDuration = duration;
|
_autoEncryptionDuration = duration;
|
||||||
}
|
}
|
||||||
uint32_t EspnowMeshBackend::getAutoEncryptionDuration() {return _autoEncryptionDuration;}
|
uint32_t EspnowMeshBackend::getAutoEncryptionDuration() const {return _autoEncryptionDuration;}
|
||||||
|
|
||||||
void EspnowMeshBackend::setBroadcastFilter(broadcastFilterType broadcastFilter) {_broadcastFilter = broadcastFilter;}
|
void EspnowMeshBackend::setBroadcastFilter(const broadcastFilterType broadcastFilter) {_broadcastFilter = broadcastFilter;}
|
||||||
EspnowMeshBackend::broadcastFilterType EspnowMeshBackend::getBroadcastFilter() {return _broadcastFilter;}
|
EspnowMeshBackend::broadcastFilterType EspnowMeshBackend::getBroadcastFilter() const {return _broadcastFilter;}
|
||||||
|
|
||||||
bool EspnowMeshBackend::usesConstantSessionKey(char messageType)
|
bool EspnowMeshBackend::usesConstantSessionKey(const char messageType)
|
||||||
{
|
{
|
||||||
return messageType == 'A' || messageType == 'C';
|
return messageType == 'A' || messageType == 'C';
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType EspnowMeshBackend::espnowSendToNode(const String &message, const uint8_t *targetBSSID, char messageType, EspnowMeshBackend *espnowInstance)
|
TransmissionStatusType EspnowMeshBackend::espnowSendToNode(const String &message, const uint8_t *targetBSSID, const char messageType, EspnowMeshBackend *espnowInstance)
|
||||||
{
|
{
|
||||||
using EspnowProtocolInterpreter::synchronizationRequestHeader;
|
using EspnowProtocolInterpreter::synchronizationRequestHeader;
|
||||||
|
|
||||||
@ -1102,7 +1102,7 @@ TransmissionStatusType EspnowMeshBackend::espnowSendToNode(const String &message
|
|||||||
return espnowSendToNodeUnsynchronized(message, targetBSSID, messageType, generateMessageID(encryptedConnection), espnowInstance);
|
return espnowSendToNodeUnsynchronized(message, targetBSSID, messageType, generateMessageID(encryptedConnection), espnowInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType EspnowMeshBackend::espnowSendToNodeUnsynchronized(const String message, const uint8_t *targetBSSID, char messageType, uint64_t messageID, EspnowMeshBackend *espnowInstance)
|
TransmissionStatusType EspnowMeshBackend::espnowSendToNodeUnsynchronized(const String message, const uint8_t *targetBSSID, const char messageType, const uint64_t messageID, EspnowMeshBackend *espnowInstance)
|
||||||
{
|
{
|
||||||
using namespace EspnowProtocolInterpreter;
|
using namespace EspnowProtocolInterpreter;
|
||||||
|
|
||||||
@ -1276,7 +1276,7 @@ TransmissionStatusType EspnowMeshBackend::sendRequest(const String &message, con
|
|||||||
return transmissionStatus;
|
return transmissionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType EspnowMeshBackend::sendResponse(const String &message, uint64_t requestID, const uint8_t *targetBSSID)
|
TransmissionStatusType EspnowMeshBackend::sendResponse(const String &message, const uint64_t requestID, const uint8_t *targetBSSID)
|
||||||
{
|
{
|
||||||
EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(targetBSSID);
|
EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(targetBSSID);
|
||||||
uint8_t encryptedMac[6] {0};
|
uint8_t encryptedMac[6] {0};
|
||||||
@ -1292,7 +1292,7 @@ TransmissionStatusType EspnowMeshBackend::sendResponse(const String &message, ui
|
|||||||
|
|
||||||
bool EspnowMeshBackend::transmissionInProgress(){return *_espnowTransmissionMutex;}
|
bool EspnowMeshBackend::transmissionInProgress(){return *_espnowTransmissionMutex;}
|
||||||
|
|
||||||
EspnowMeshBackend::macAndType_td EspnowMeshBackend::createMacAndTypeValue(uint64_t uint64Mac, char messageType)
|
EspnowMeshBackend::macAndType_td EspnowMeshBackend::createMacAndTypeValue(const uint64_t uint64Mac, const char messageType)
|
||||||
{
|
{
|
||||||
return static_cast<macAndType_td>(uint64Mac << 8 | (uint64_t)messageType);
|
return static_cast<macAndType_td>(uint64Mac << 8 | (uint64_t)messageType);
|
||||||
}
|
}
|
||||||
@ -1317,12 +1317,12 @@ void EspnowMeshBackend::setEspnowEncryptedConnectionKey(const String &espnowEncr
|
|||||||
MeshCryptoInterface::initializeKey(_espnowEncryptedConnectionKey, espnowEncryptedConnectionKeyLength, espnowEncryptedConnectionKeySeed);
|
MeshCryptoInterface::initializeKey(_espnowEncryptedConnectionKey, espnowEncryptedConnectionKeyLength, espnowEncryptedConnectionKeySeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EspnowMeshBackend::getEspnowEncryptedConnectionKey()
|
const uint8_t *EspnowMeshBackend::getEspnowEncryptedConnectionKey() const
|
||||||
{
|
{
|
||||||
return _espnowEncryptedConnectionKey;
|
return _espnowEncryptedConnectionKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *EspnowMeshBackend::getEspnowEncryptedConnectionKey(uint8_t resultArray[espnowEncryptedConnectionKeyLength])
|
uint8_t *EspnowMeshBackend::getEspnowEncryptedConnectionKey(uint8_t resultArray[espnowEncryptedConnectionKeyLength]) const
|
||||||
{
|
{
|
||||||
std::copy_n(_espnowEncryptedConnectionKey, espnowEncryptedConnectionKeyLength, resultArray);
|
std::copy_n(_espnowEncryptedConnectionKey, espnowEncryptedConnectionKeyLength, resultArray);
|
||||||
return resultArray;
|
return resultArray;
|
||||||
@ -1374,12 +1374,12 @@ void EspnowMeshBackend::setEspnowHashKey(const String &espnowHashKeySeed)
|
|||||||
MeshCryptoInterface::initializeKey(_espnowHashKey, espnowHashKeyLength, espnowHashKeySeed);
|
MeshCryptoInterface::initializeKey(_espnowHashKey, espnowHashKeyLength, espnowHashKeySeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EspnowMeshBackend::getEspnowHashKey()
|
const uint8_t *EspnowMeshBackend::getEspnowHashKey() const
|
||||||
{
|
{
|
||||||
return _espnowHashKey;
|
return _espnowHashKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setEspnowMessageEncryptionKey(uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH])
|
void EspnowMeshBackend::setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH])
|
||||||
{
|
{
|
||||||
assert(espnowMessageEncryptionKey != nullptr);
|
assert(espnowMessageEncryptionKey != nullptr);
|
||||||
|
|
||||||
@ -1399,7 +1399,7 @@ const uint8_t *EspnowMeshBackend::getEspnowMessageEncryptionKey()
|
|||||||
return _espnowMessageEncryptionKey;
|
return _espnowMessageEncryptionKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setUseEncryptedMessages(bool useEncryptedMessages)
|
void EspnowMeshBackend::setUseEncryptedMessages(const bool useEncryptedMessages)
|
||||||
{
|
{
|
||||||
MutexTracker mutexTracker(_espnowSendToNodeMutex);
|
MutexTracker mutexTracker(_espnowSendToNodeMutex);
|
||||||
if(!mutexTracker.mutexCaptured())
|
if(!mutexTracker.mutexCaptured())
|
||||||
@ -1411,7 +1411,7 @@ void EspnowMeshBackend::setUseEncryptedMessages(bool useEncryptedMessages)
|
|||||||
}
|
}
|
||||||
bool EspnowMeshBackend::useEncryptedMessages() { return _useEncryptedMessages; }
|
bool EspnowMeshBackend::useEncryptedMessages() { return _useEncryptedMessages; }
|
||||||
|
|
||||||
bool EspnowMeshBackend::verifyPeerSessionKey(uint64_t sessionKey, const uint8_t *peerMac, char messageType)
|
bool EspnowMeshBackend::verifyPeerSessionKey(const uint64_t sessionKey, const uint8_t *peerMac, const char messageType)
|
||||||
{
|
{
|
||||||
if(EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(peerMac))
|
if(EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(peerMac))
|
||||||
{
|
{
|
||||||
@ -1421,7 +1421,7 @@ bool EspnowMeshBackend::verifyPeerSessionKey(uint64_t sessionKey, const uint8_t
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::verifyPeerSessionKey(uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection, uint64_t uint64PeerMac, char messageType)
|
bool EspnowMeshBackend::verifyPeerSessionKey(const uint64_t sessionKey, const EncryptedConnectionLog &encryptedConnection, const uint64_t uint64PeerMac, const char messageType)
|
||||||
{
|
{
|
||||||
if(EspnowProtocolInterpreter::usesEncryption(sessionKey))
|
if(EspnowProtocolInterpreter::usesEncryption(sessionKey))
|
||||||
{
|
{
|
||||||
@ -1437,7 +1437,7 @@ bool EspnowMeshBackend::verifyPeerSessionKey(uint64_t sessionKey, EncryptedConne
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::synchronizePeerSessionKey(uint64_t sessionKey, const uint8_t *peerMac)
|
bool EspnowMeshBackend::synchronizePeerSessionKey(const uint64_t sessionKey, const uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
if(EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(peerMac))
|
if(EncryptedConnectionLog *encryptedConnection = getEncryptedConnection(peerMac))
|
||||||
{
|
{
|
||||||
@ -1447,7 +1447,7 @@ bool EspnowMeshBackend::synchronizePeerSessionKey(uint64_t sessionKey, const uin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::synchronizePeerSessionKey(uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection)
|
bool EspnowMeshBackend::synchronizePeerSessionKey(const uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection)
|
||||||
{
|
{
|
||||||
if(EspnowProtocolInterpreter::usesEncryption(sessionKey))
|
if(EspnowProtocolInterpreter::usesEncryption(sessionKey))
|
||||||
{
|
{
|
||||||
@ -1462,7 +1462,7 @@ bool EspnowMeshBackend::synchronizePeerSessionKey(uint64_t sessionKey, Encrypted
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ResponseData>::const_iterator EspnowMeshBackend::getScheduledResponse(uint32_t responseIndex)
|
std::list<ResponseData>::const_iterator EspnowMeshBackend::getScheduledResponse(const uint32_t responseIndex)
|
||||||
{
|
{
|
||||||
assert(responseIndex < numberOfScheduledResponses());
|
assert(responseIndex < numberOfScheduledResponses());
|
||||||
|
|
||||||
@ -1479,12 +1479,12 @@ std::list<ResponseData>::const_iterator EspnowMeshBackend::getScheduledResponse(
|
|||||||
return responseIterator;
|
return responseIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
String EspnowMeshBackend::getScheduledResponseMessage(uint32_t responseIndex)
|
String EspnowMeshBackend::getScheduledResponseMessage(const uint32_t responseIndex)
|
||||||
{
|
{
|
||||||
return getScheduledResponse(responseIndex)->getMessage();
|
return getScheduledResponse(responseIndex)->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *EspnowMeshBackend::getScheduledResponseRecipient(uint32_t responseIndex)
|
const uint8_t *EspnowMeshBackend::getScheduledResponseRecipient(const uint32_t responseIndex)
|
||||||
{
|
{
|
||||||
return getScheduledResponse(responseIndex)->getRecipientMac();
|
return getScheduledResponse(responseIndex)->getRecipientMac();
|
||||||
}
|
}
|
||||||
@ -1502,7 +1502,7 @@ void EspnowMeshBackend::clearAllScheduledResponses()
|
|||||||
responsesToSend.clear();
|
responsesToSend.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::deleteScheduledResponsesByRecipient(const uint8_t *recipientMac, bool encryptedOnly)
|
void EspnowMeshBackend::deleteScheduledResponsesByRecipient(const uint8_t *recipientMac, const bool encryptedOnly)
|
||||||
{
|
{
|
||||||
MutexTracker responsesToSendMutexTracker(_responsesToSendMutex);
|
MutexTracker responsesToSendMutexTracker(_responsesToSendMutex);
|
||||||
if(!responsesToSendMutexTracker.mutexCaptured())
|
if(!responsesToSendMutexTracker.mutexCaptured())
|
||||||
@ -1522,39 +1522,39 @@ void EspnowMeshBackend::deleteScheduledResponsesByRecipient(const uint8_t *recip
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setSenderMac(uint8_t *macArray)
|
void EspnowMeshBackend::setSenderMac(const uint8_t *macArray)
|
||||||
{
|
{
|
||||||
std::copy_n(macArray, 6, _senderMac);
|
std::copy_n(macArray, 6, _senderMac);
|
||||||
}
|
}
|
||||||
|
|
||||||
String EspnowMeshBackend::getSenderMac() {return TypeCast::macToString(_senderMac);}
|
String EspnowMeshBackend::getSenderMac() const {return TypeCast::macToString(_senderMac);}
|
||||||
uint8_t *EspnowMeshBackend::getSenderMac(uint8_t *macArray)
|
uint8_t *EspnowMeshBackend::getSenderMac(uint8_t *macArray) const
|
||||||
{
|
{
|
||||||
std::copy_n(_senderMac, 6, macArray);
|
std::copy_n(_senderMac, 6, macArray);
|
||||||
return macArray;
|
return macArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setSenderAPMac(uint8_t *macArray)
|
void EspnowMeshBackend::setSenderAPMac(const uint8_t *macArray)
|
||||||
{
|
{
|
||||||
std::copy_n(macArray, 6, _senderAPMac);
|
std::copy_n(macArray, 6, _senderAPMac);
|
||||||
}
|
}
|
||||||
|
|
||||||
String EspnowMeshBackend::getSenderAPMac() {return TypeCast::macToString(_senderAPMac);}
|
String EspnowMeshBackend::getSenderAPMac() const {return TypeCast::macToString(_senderAPMac);}
|
||||||
uint8_t *EspnowMeshBackend::getSenderAPMac(uint8_t *macArray)
|
uint8_t *EspnowMeshBackend::getSenderAPMac(uint8_t *macArray) const
|
||||||
{
|
{
|
||||||
std::copy_n(_senderAPMac, 6, macArray);
|
std::copy_n(_senderAPMac, 6, macArray);
|
||||||
return macArray;
|
return macArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setReceivedEncryptedTransmission(bool receivedEncryptedTransmission) { _receivedEncryptedTransmission = receivedEncryptedTransmission; }
|
void EspnowMeshBackend::setReceivedEncryptedTransmission(const bool receivedEncryptedTransmission) { _receivedEncryptedTransmission = receivedEncryptedTransmission; }
|
||||||
bool EspnowMeshBackend::receivedEncryptedTransmission() {return _receivedEncryptedTransmission;}
|
bool EspnowMeshBackend::receivedEncryptedTransmission() const {return _receivedEncryptedTransmission;}
|
||||||
|
|
||||||
bool EspnowMeshBackend::addUnencryptedConnection(const String &serializedConnectionState)
|
bool EspnowMeshBackend::addUnencryptedConnection(const String &serializedConnectionState)
|
||||||
{
|
{
|
||||||
return JsonTranslator::getUnsynchronizedMessageID(serializedConnectionState, _unsynchronizedMessageID);
|
return JsonTranslator::getUnsynchronizedMessageID(serializedConnectionState, _unsynchronizedMessageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, uint64_t peerSessionKey, uint64_t ownSessionKey)
|
EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, const uint64_t peerSessionKey, const uint64_t ownSessionKey)
|
||||||
{
|
{
|
||||||
assert(encryptedConnections.size() <= maxEncryptedConnections); // If this is not the case, ESP-NOW is no longer in sync with the library
|
assert(encryptedConnections.size() <= maxEncryptedConnections); // If this is not the case, ESP-NOW is no longer in sync with the library
|
||||||
|
|
||||||
@ -1590,7 +1590,7 @@ EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(uint8_t *pee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(const String &serializedConnectionState, bool ignoreDuration)
|
EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(const String &serializedConnectionState, const bool ignoreDuration)
|
||||||
{
|
{
|
||||||
uint32_t duration = 0;
|
uint32_t duration = 0;
|
||||||
bool desync = false;
|
bool desync = false;
|
||||||
@ -1626,7 +1626,7 @@ EncryptedConnectionStatus EspnowMeshBackend::addEncryptedConnection(const String
|
|||||||
return EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED;
|
return EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::addTemporaryEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, uint64_t peerSessionKey, uint64_t ownSessionKey, uint32_t duration)
|
EncryptedConnectionStatus EspnowMeshBackend::addTemporaryEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration)
|
||||||
{
|
{
|
||||||
assert(encryptedConnections.size() <= maxEncryptedConnections); // If this is not the case, ESP-NOW is no longer in sync with the library
|
assert(encryptedConnections.size() <= maxEncryptedConnections); // If this is not the case, ESP-NOW is no longer in sync with the library
|
||||||
|
|
||||||
@ -1663,7 +1663,7 @@ EncryptedConnectionStatus EspnowMeshBackend::addTemporaryEncryptedConnection(uin
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::addTemporaryEncryptedConnection(const String &serializedConnectionState, uint32_t duration)
|
EncryptedConnectionStatus EspnowMeshBackend::addTemporaryEncryptedConnection(const String &serializedConnectionState, const uint32_t duration)
|
||||||
{
|
{
|
||||||
bool desync = false;
|
bool desync = false;
|
||||||
uint64_t ownSessionKey = 0;
|
uint64_t ownSessionKey = 0;
|
||||||
@ -1704,7 +1704,7 @@ void EspnowMeshBackend::handlePostponedRemovals()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::requestEncryptedConnectionKernel(uint8_t *peerMac, const encryptionRequestBuilderType &encryptionRequestBuilder)
|
EncryptedConnectionStatus EspnowMeshBackend::requestEncryptedConnectionKernel(const uint8_t *peerMac, const encryptionRequestBuilderType &encryptionRequestBuilder)
|
||||||
{
|
{
|
||||||
using namespace EspnowProtocolInterpreter;
|
using namespace EspnowProtocolInterpreter;
|
||||||
|
|
||||||
@ -1856,26 +1856,26 @@ String EspnowMeshBackend::flexibleEncryptionRequestBuilder(const uint32_t minDur
|
|||||||
return createEncryptionRequestHmacMessage(FPSTR(temporaryEncryptionRequestHeader), requestNonce, hashKey, espnowHashKeyLength, connectionDuration);
|
return createEncryptionRequestHmacMessage(FPSTR(temporaryEncryptionRequestHeader), requestNonce, hashKey, espnowHashKeyLength, connectionDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::requestEncryptedConnection(uint8_t *peerMac)
|
EncryptedConnectionStatus EspnowMeshBackend::requestEncryptedConnection(const uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
return requestEncryptedConnectionKernel(peerMac, std::bind(defaultEncryptionRequestBuilder, FPSTR(EspnowProtocolInterpreter::encryptionRequestHeader), 0, getEspnowHashKey(), _1, _2));
|
return requestEncryptedConnectionKernel(peerMac, std::bind(defaultEncryptionRequestBuilder, FPSTR(EspnowProtocolInterpreter::encryptionRequestHeader), 0, getEspnowHashKey(), _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::requestTemporaryEncryptedConnection(uint8_t *peerMac, uint32_t durationMs)
|
EncryptedConnectionStatus EspnowMeshBackend::requestTemporaryEncryptedConnection(const uint8_t *peerMac, const uint32_t durationMs)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
return requestEncryptedConnectionKernel(peerMac, std::bind(defaultEncryptionRequestBuilder, FPSTR(EspnowProtocolInterpreter::temporaryEncryptionRequestHeader),
|
return requestEncryptedConnectionKernel(peerMac, std::bind(defaultEncryptionRequestBuilder, FPSTR(EspnowProtocolInterpreter::temporaryEncryptionRequestHeader),
|
||||||
durationMs, getEspnowHashKey(), _1, _2));
|
durationMs, getEspnowHashKey(), _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::requestFlexibleTemporaryEncryptedConnection(uint8_t *peerMac, uint32_t minDurationMs)
|
EncryptedConnectionStatus EspnowMeshBackend::requestFlexibleTemporaryEncryptedConnection(const uint8_t *peerMac, const uint32_t minDurationMs)
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
return requestEncryptedConnectionKernel(peerMac, std::bind(flexibleEncryptionRequestBuilder, minDurationMs, getEspnowHashKey(), _1, _2));
|
return requestEncryptedConnectionKernel(peerMac, std::bind(flexibleEncryptionRequestBuilder, minDurationMs, getEspnowHashKey(), _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EspnowMeshBackend::temporaryEncryptedConnectionToPermanent(uint8_t *peerMac)
|
bool EspnowMeshBackend::temporaryEncryptedConnectionToPermanent(const uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
if(EncryptedConnectionLog *temporaryConnection = getTemporaryEncryptedConnection(peerMac))
|
if(EncryptedConnectionLog *temporaryConnection = getTemporaryEncryptedConnection(peerMac))
|
||||||
{
|
{
|
||||||
@ -1886,7 +1886,7 @@ bool EspnowMeshBackend::temporaryEncryptedConnectionToPermanent(uint8_t *peerMac
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionRemovalOutcome EspnowMeshBackend::removeEncryptedConnection(uint8_t *peerMac)
|
EncryptedConnectionRemovalOutcome EspnowMeshBackend::removeEncryptedConnection(const uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
auto connectionIterator = getEncryptedConnectionIterator(peerMac, encryptedConnections);
|
auto connectionIterator = getEncryptedConnectionIterator(peerMac, encryptedConnections);
|
||||||
if(connectionIterator != encryptedConnections.end())
|
if(connectionIterator != encryptedConnections.end())
|
||||||
@ -1962,7 +1962,7 @@ EncryptedConnectionRemovalOutcome EspnowMeshBackend::removeEncryptedConnectionUn
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<macAndType_td, uint64_t>, T> &logEntries, const uint8_t *peerMac, bool encryptedOnly)
|
void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<macAndType_td, uint64_t>, T> &logEntries, const uint8_t *peerMac, const bool encryptedOnly)
|
||||||
{
|
{
|
||||||
bool macFound = false;
|
bool macFound = false;
|
||||||
|
|
||||||
@ -1990,7 +1990,7 @@ void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<macAndType_td, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<uint64_t, uint64_t>, T> &logEntries, const uint8_t *peerMac, bool encryptedOnly)
|
void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<uint64_t, uint64_t>, T> &logEntries, const uint8_t *peerMac, const bool encryptedOnly)
|
||||||
{
|
{
|
||||||
bool macFound = false;
|
bool macFound = false;
|
||||||
|
|
||||||
@ -2017,7 +2017,7 @@ void EspnowMeshBackend::deleteEntriesByMac(std::map<std::pair<uint64_t, uint64_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionRemovalOutcome EspnowMeshBackend::requestEncryptedConnectionRemoval(uint8_t *peerMac)
|
EncryptedConnectionRemovalOutcome EspnowMeshBackend::requestEncryptedConnectionRemoval(const uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
using EspnowProtocolInterpreter::encryptedConnectionRemovalRequestHeader;
|
using EspnowProtocolInterpreter::encryptedConnectionRemovalRequestHeader;
|
||||||
|
|
||||||
@ -2049,16 +2049,16 @@ EncryptedConnectionRemovalOutcome EspnowMeshBackend::requestEncryptedConnectionR
|
|||||||
return EncryptedConnectionRemovalOutcome::REMOVAL_SUCCEEDED;
|
return EncryptedConnectionRemovalOutcome::REMOVAL_SUCCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setAcceptsUnverifiedRequests(bool acceptsUnverifiedRequests) { _acceptsUnverifiedRequests = acceptsUnverifiedRequests; }
|
void EspnowMeshBackend::setAcceptsUnverifiedRequests(const bool acceptsUnverifiedRequests) { _acceptsUnverifiedRequests = acceptsUnverifiedRequests; }
|
||||||
bool EspnowMeshBackend::acceptsUnverifiedRequests() { return _acceptsUnverifiedRequests; }
|
bool EspnowMeshBackend::acceptsUnverifiedRequests() const { return _acceptsUnverifiedRequests; }
|
||||||
|
|
||||||
void EspnowMeshBackend::setEncryptedConnectionsSoftLimit(uint8_t softLimit)
|
void EspnowMeshBackend::setEncryptedConnectionsSoftLimit(const uint8_t softLimit)
|
||||||
{
|
{
|
||||||
assert(softLimit <= 6); // Valid values are 0 to 6, but uint8_t is always at least 0.
|
assert(softLimit <= 6); // Valid values are 0 to 6, but uint8_t is always at least 0.
|
||||||
_encryptedConnectionsSoftLimit = softLimit;
|
_encryptedConnectionsSoftLimit = softLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EspnowMeshBackend::encryptedConnectionsSoftLimit() { return _encryptedConnectionsSoftLimit; }
|
uint8_t EspnowMeshBackend::encryptedConnectionsSoftLimit() const { return _encryptedConnectionsSoftLimit; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename T::iterator EspnowMeshBackend::getEncryptedConnectionIterator(const uint8_t *peerMac, T &connectionContainer)
|
typename T::iterator EspnowMeshBackend::getEncryptedConnectionIterator(const uint8_t *peerMac, T &connectionContainer)
|
||||||
@ -2140,7 +2140,7 @@ uint8_t *EspnowMeshBackend::getEncryptedMac(const uint8_t *peerMac, uint8_t *res
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::prepareForTransmission(const String &message, bool scan, bool scanAllWiFiChannels)
|
void EspnowMeshBackend::prepareForTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels)
|
||||||
{
|
{
|
||||||
setMessage(message);
|
setMessage(message);
|
||||||
|
|
||||||
@ -2189,7 +2189,7 @@ TransmissionStatusType EspnowMeshBackend::initiateTransmissionKernel(const Strin
|
|||||||
return transmissionResult;
|
return transmissionResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::printTransmissionStatistics()
|
void EspnowMeshBackend::printTransmissionStatistics() const
|
||||||
{
|
{
|
||||||
if(verboseMode() && successfulTransmissions_AT > 0) // Avoid calculations if not required
|
if(verboseMode() && successfulTransmissions_AT > 0) // Avoid calculations if not required
|
||||||
{
|
{
|
||||||
@ -2202,7 +2202,7 @@ void EspnowMeshBackend::printTransmissionStatistics()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::attemptTransmission(const String &message, bool scan, bool scanAllWiFiChannels)
|
void EspnowMeshBackend::attemptTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels)
|
||||||
{
|
{
|
||||||
MutexTracker mutexTracker(_espnowTransmissionMutex, handlePostponedRemovals);
|
MutexTracker mutexTracker(_espnowTransmissionMutex, handlePostponedRemovals);
|
||||||
if(!mutexTracker.mutexCaptured())
|
if(!mutexTracker.mutexCaptured())
|
||||||
@ -2246,7 +2246,7 @@ TransmissionStatusType EspnowMeshBackend::attemptTransmission(const String &mess
|
|||||||
return initiateTransmission(message, recipientInfo);
|
return initiateTransmission(message, recipientInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedConnectionStatus EspnowMeshBackend::initiateAutoEncryptingConnection(const EspnowNetworkInfo &recipientInfo, bool requestPermanentConnection, uint8_t *targetBSSID, EncryptedConnectionLog **existingEncryptedConnection)
|
EncryptedConnectionStatus EspnowMeshBackend::initiateAutoEncryptingConnection(const EspnowNetworkInfo &recipientInfo, const bool requestPermanentConnection, uint8_t *targetBSSID, EncryptedConnectionLog **existingEncryptedConnection)
|
||||||
{
|
{
|
||||||
assert(recipientInfo.BSSID() != nullptr); // We need at least the BSSID to connect
|
assert(recipientInfo.BSSID() != nullptr); // We need at least the BSSID to connect
|
||||||
recipientInfo.getBSSID(targetBSSID);
|
recipientInfo.getBSSID(targetBSSID);
|
||||||
@ -2268,7 +2268,7 @@ EncryptedConnectionStatus EspnowMeshBackend::initiateAutoEncryptingConnection(co
|
|||||||
return connectionStatus;
|
return connectionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType EspnowMeshBackend::initiateAutoEncryptingTransmission(const String &message, const uint8_t *targetBSSID, EncryptedConnectionStatus connectionStatus)
|
TransmissionStatusType EspnowMeshBackend::initiateAutoEncryptingTransmission(const String &message, uint8_t *targetBSSID, EncryptedConnectionStatus connectionStatus)
|
||||||
{
|
{
|
||||||
TransmissionStatusType transmissionResult = TransmissionStatusType::CONNECTION_FAILED;
|
TransmissionStatusType transmissionResult = TransmissionStatusType::CONNECTION_FAILED;
|
||||||
|
|
||||||
@ -2282,7 +2282,7 @@ TransmissionStatusType EspnowMeshBackend::initiateAutoEncryptingTransmission(con
|
|||||||
return transmissionResult;
|
return transmissionResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::finalizeAutoEncryptingConnection(const uint8_t *targetBSSID, const EncryptedConnectionLog *existingEncryptedConnection, bool requestPermanentConnection)
|
void EspnowMeshBackend::finalizeAutoEncryptingConnection(const uint8_t *targetBSSID, const EncryptedConnectionLog *existingEncryptedConnection, const bool requestPermanentConnection)
|
||||||
{
|
{
|
||||||
if(!existingEncryptedConnection && !requestPermanentConnection && !_reciprocalPeerRequestConfirmation)
|
if(!existingEncryptedConnection && !requestPermanentConnection && !_reciprocalPeerRequestConfirmation)
|
||||||
{
|
{
|
||||||
@ -2291,7 +2291,7 @@ void EspnowMeshBackend::finalizeAutoEncryptingConnection(const uint8_t *targetBS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::attemptAutoEncryptingTransmission(const String &message, bool requestPermanentConnections, bool scan, bool scanAllWiFiChannels)
|
void EspnowMeshBackend::attemptAutoEncryptingTransmission(const String &message, const bool requestPermanentConnections, const bool scan, const bool scanAllWiFiChannels)
|
||||||
{
|
{
|
||||||
MutexTracker outerMutexTracker(_espnowTransmissionMutex, handlePostponedRemovals);
|
MutexTracker outerMutexTracker(_espnowTransmissionMutex, handlePostponedRemovals);
|
||||||
if(!outerMutexTracker.mutexCaptured())
|
if(!outerMutexTracker.mutexCaptured())
|
||||||
@ -2338,7 +2338,7 @@ void EspnowMeshBackend::attemptAutoEncryptingTransmission(const String &message,
|
|||||||
printTransmissionStatistics();
|
printTransmissionStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType EspnowMeshBackend::attemptAutoEncryptingTransmission(const String &message, const EspnowNetworkInfo &recipientInfo, bool requestPermanentConnection)
|
TransmissionStatusType EspnowMeshBackend::attemptAutoEncryptingTransmission(const String &message, const EspnowNetworkInfo &recipientInfo, const bool requestPermanentConnection)
|
||||||
{
|
{
|
||||||
uint8_t targetBSSID[6] {0};
|
uint8_t targetBSSID[6] {0};
|
||||||
EncryptedConnectionLog *existingEncryptedConnection = nullptr;
|
EncryptedConnectionLog *existingEncryptedConnection = nullptr;
|
||||||
@ -2370,11 +2370,11 @@ void EspnowMeshBackend::broadcast(const String &message)
|
|||||||
espnowSendToNode(message, broadcastMac, 'B', this);
|
espnowSendToNode(message, broadcastMac, 'B', this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setBroadcastTransmissionRedundancy(uint8_t redundancy) { _broadcastTransmissionRedundancy = redundancy; }
|
void EspnowMeshBackend::setBroadcastTransmissionRedundancy(const uint8_t redundancy) { _broadcastTransmissionRedundancy = redundancy; }
|
||||||
uint8_t EspnowMeshBackend::getBroadcastTransmissionRedundancy() { return _broadcastTransmissionRedundancy; }
|
uint8_t EspnowMeshBackend::getBroadcastTransmissionRedundancy() const { return _broadcastTransmissionRedundancy; }
|
||||||
|
|
||||||
void EspnowMeshBackend::setResponseTransmittedHook(responseTransmittedHookType responseTransmittedHook) { _responseTransmittedHook = responseTransmittedHook; }
|
void EspnowMeshBackend::setResponseTransmittedHook(const responseTransmittedHookType responseTransmittedHook) { _responseTransmittedHook = responseTransmittedHook; }
|
||||||
EspnowMeshBackend::responseTransmittedHookType EspnowMeshBackend::getResponseTransmittedHook() { return _responseTransmittedHook; }
|
EspnowMeshBackend::responseTransmittedHookType EspnowMeshBackend::getResponseTransmittedHook() const { return _responseTransmittedHook; }
|
||||||
|
|
||||||
void EspnowMeshBackend::sendStoredEspnowMessages(const ExpiringTimeTracker *estimatedMaxDurationTracker)
|
void EspnowMeshBackend::sendStoredEspnowMessages(const ExpiringTimeTracker *estimatedMaxDurationTracker)
|
||||||
{
|
{
|
||||||
@ -2587,7 +2587,7 @@ uint32_t EspnowMeshBackend::getMaxMessageBytesPerTransmission()
|
|||||||
return getMaxBytesPerTransmission() - espnowMetadataSize();
|
return getMaxBytesPerTransmission() - espnowMetadataSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setMaxTransmissionsPerMessage(uint8_t maxTransmissionsPerMessage)
|
void EspnowMeshBackend::setMaxTransmissionsPerMessage(const uint8_t maxTransmissionsPerMessage)
|
||||||
{
|
{
|
||||||
assert(1 <= maxTransmissionsPerMessage && maxTransmissionsPerMessage <= 128);
|
assert(1 <= maxTransmissionsPerMessage && maxTransmissionsPerMessage <= 128);
|
||||||
|
|
||||||
@ -2646,7 +2646,7 @@ ConnectionType EspnowMeshBackend::getConnectionInfo(uint8_t *peerMac, uint32_t *
|
|||||||
return getConnectionInfoHelper(encryptedConnection, remainingDuration);
|
return getConnectionInfoHelper(encryptedConnection, remainingDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionType EspnowMeshBackend::getConnectionInfo(uint32_t connectionIndex, uint32_t *remainingDuration, uint8_t *peerMac)
|
ConnectionType EspnowMeshBackend::getConnectionInfo(const uint32_t connectionIndex, uint32_t *remainingDuration, uint8_t *peerMac)
|
||||||
{
|
{
|
||||||
EncryptedConnectionLog *encryptedConnection = nullptr;
|
EncryptedConnectionLog *encryptedConnection = nullptr;
|
||||||
|
|
||||||
@ -2694,7 +2694,7 @@ String EspnowMeshBackend::serializeEncryptedConnection(const uint8_t *peerMac)
|
|||||||
return serializedConnection;
|
return serializedConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
String EspnowMeshBackend::serializeEncryptedConnection(uint32_t connectionIndex)
|
String EspnowMeshBackend::serializeEncryptedConnection(const uint32_t connectionIndex)
|
||||||
{
|
{
|
||||||
String serializedConnection(emptyString);
|
String serializedConnection(emptyString);
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ enum class EncryptedConnectionStatus
|
|||||||
MAX_CONNECTIONS_REACHED_PEER = -1,
|
MAX_CONNECTIONS_REACHED_PEER = -1,
|
||||||
API_CALL_FAILED = 0,
|
API_CALL_FAILED = 0,
|
||||||
CONNECTION_ESTABLISHED = 1,
|
CONNECTION_ESTABLISHED = 1,
|
||||||
SOFT_LIMIT_CONNECTION_ESTABLISHED = 2 // Only used if _encryptedConnectionsSoftLimit is less than 6.
|
SOFT_LIMIT_CONNECTION_ESTABLISHED = 2 // Only used if _encryptedConnectionsSoftLimit is less than 6. See the setEncryptedConnectionsSoftLimit method documentation for details.
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class EncryptedConnectionRemovalOutcome
|
enum class EncryptedConnectionRemovalOutcome
|
||||||
@ -128,7 +128,7 @@ enum class EncryptedConnectionRemovalOutcome
|
|||||||
*
|
*
|
||||||
* @param durationMs The shortest allowed delay duration, in milliseconds.
|
* @param durationMs The shortest allowed delay duration, in milliseconds.
|
||||||
*/
|
*/
|
||||||
void espnowDelay(uint32_t durationMs);
|
void espnowDelay(const uint32_t durationMs);
|
||||||
|
|
||||||
class RequestData;
|
class RequestData;
|
||||||
|
|
||||||
@ -166,10 +166,10 @@ public:
|
|||||||
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
|
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter, broadcastFilterType broadcastFilter,
|
EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter, const broadcastFilterType broadcastFilter,
|
||||||
const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ESP-NOW constructor method. Creates an ESP-NOW node, ready to be initialised.
|
* ESP-NOW constructor method. Creates an ESP-NOW node, ready to be initialised.
|
||||||
@ -194,9 +194,9 @@ public:
|
|||||||
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
|
* make it impossible for other stations to detect the APs whose WiFi channels have changed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter, broadcastFilterType broadcastFilter,
|
EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter, const broadcastFilterType broadcastFilter,
|
||||||
const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed, const String &ssidPrefix,
|
const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed, const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
~EspnowMeshBackend() override;
|
~EspnowMeshBackend() override;
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ public:
|
|||||||
* Note that setting the estimatedMaxDuration too low may result in missed ESP-NOW transmissions because of too little time for maintenance.
|
* Note that setting the estimatedMaxDuration too low may result in missed ESP-NOW transmissions because of too little time for maintenance.
|
||||||
* Also note that although the method will try to respect the max duration limit, there is no guarantee. Overshoots by tens of milliseconds are possible.
|
* Also note that although the method will try to respect the max duration limit, there is no guarantee. Overshoots by tens of milliseconds are possible.
|
||||||
*/
|
*/
|
||||||
static void performEspnowMaintenance(uint32_t estimatedMaxDuration = 0);
|
static void performEspnowMaintenance(const uint32_t estimatedMaxDuration = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* At critical heap level no more incoming requests are accepted.
|
* At critical heap level no more incoming requests are accepted.
|
||||||
@ -271,7 +271,7 @@ public:
|
|||||||
* If the buffer is set to 0 bytes a significant number of incoming requests are likely to be lost during intense transmission activity,
|
* If the buffer is set to 0 bytes a significant number of incoming requests are likely to be lost during intense transmission activity,
|
||||||
* and there is a greater risk of heap space completely running out before log clearing occurs (which may cause crashes or empty transmissions).
|
* and there is a greater risk of heap space completely running out before log clearing occurs (which may cause crashes or empty transmissions).
|
||||||
*/
|
*/
|
||||||
static void setCriticalHeapLevelBuffer(uint32_t bufferInBytes);
|
static void setCriticalHeapLevelBuffer(const uint32_t bufferInBytes);
|
||||||
static uint32_t criticalHeapLevelBuffer();
|
static uint32_t criticalHeapLevelBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,7 +281,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool deactivateEspnow();
|
static bool deactivateEspnow();
|
||||||
|
|
||||||
void attemptTransmission(const String &message, bool scan = true, bool scanAllWiFiChannels = false) override;
|
void attemptTransmission(const String &message, const bool scan = true, const bool scanAllWiFiChannels = false) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transmit message to a single recipient without changing the local transmission state.
|
* Transmit message to a single recipient without changing the local transmission state.
|
||||||
@ -315,13 +315,13 @@ public:
|
|||||||
* Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
|
* Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
|
||||||
* This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
|
* This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
|
||||||
*/
|
*/
|
||||||
void attemptAutoEncryptingTransmission(const String &message, bool requestPermanentConnections = false, bool scan = true, bool scanAllWiFiChannels = false);
|
void attemptAutoEncryptingTransmission(const String &message, const bool requestPermanentConnections = false, const bool scan = true, const bool scanAllWiFiChannels = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transmit message to a single recipient without changing the local transmission state (apart from encrypted connections).
|
* Transmit message to a single recipient without changing the local transmission state (apart from encrypted connections).
|
||||||
* Will not change connectionQueue, latestTransmissionOutcomes or stored message.
|
* Will not change connectionQueue, latestTransmissionOutcomes or stored message.
|
||||||
*/
|
*/
|
||||||
TransmissionStatusType attemptAutoEncryptingTransmission(const String &message, const EspnowNetworkInfo &recipientInfo, bool requestPermanentConnection = false);
|
TransmissionStatusType attemptAutoEncryptingTransmission(const String &message, const EspnowNetworkInfo &recipientInfo, const bool requestPermanentConnection = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message simultaneously to all nearby nodes which have ESP-NOW activated.
|
* Send a message simultaneously to all nearby nodes which have ESP-NOW activated.
|
||||||
@ -340,8 +340,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param redundancy The number of extra transmissions to make of each broadcast. Defaults to 1.
|
* @param redundancy The number of extra transmissions to make of each broadcast. Defaults to 1.
|
||||||
*/
|
*/
|
||||||
void setBroadcastTransmissionRedundancy(uint8_t redundancy);
|
void setBroadcastTransmissionRedundancy(const uint8_t redundancy);
|
||||||
uint8_t getBroadcastTransmissionRedundancy();
|
uint8_t getBroadcastTransmissionRedundancy() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the EspnowMeshBackend instance responsible for handling incoming requests. The requestHandler of the instance will be called upon receiving ESP-NOW requests.
|
* Set the EspnowMeshBackend instance responsible for handling incoming requests. The requestHandler of the instance will be called upon receiving ESP-NOW requests.
|
||||||
@ -358,7 +358,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return True if this EspnowMeshBackend is the espnowRequestManager. False otherwise.
|
* @return True if this EspnowMeshBackend is the espnowRequestManager. False otherwise.
|
||||||
*/
|
*/
|
||||||
bool isEspnowRequestManager();
|
bool isEspnowRequestManager() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the duration of most ESP-NOW log entries. Used for all ESP-NOW communication except for broadcasts and encrypted connection requests.
|
* Set the duration of most ESP-NOW log entries. Used for all ESP-NOW communication except for broadcasts and encrypted connection requests.
|
||||||
@ -369,7 +369,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param logEntryLifetimeMs The duration to use for most ESP-NOW log entries, in milliseconds.
|
* @param logEntryLifetimeMs The duration to use for most ESP-NOW log entries, in milliseconds.
|
||||||
*/
|
*/
|
||||||
static void setLogEntryLifetimeMs(uint32_t logEntryLifetimeMs);
|
static void setLogEntryLifetimeMs(const uint32_t logEntryLifetimeMs);
|
||||||
static uint32_t logEntryLifetimeMs();
|
static uint32_t logEntryLifetimeMs();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -383,7 +383,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param broadcastResponseTimeoutMs The duration sent ESP-NOW broadcasts will be stored in the log, in milliseconds.
|
* @param broadcastResponseTimeoutMs The duration sent ESP-NOW broadcasts will be stored in the log, in milliseconds.
|
||||||
*/
|
*/
|
||||||
static void setBroadcastResponseTimeoutMs(uint32_t broadcastResponseTimeoutMs);
|
static void setBroadcastResponseTimeoutMs(const uint32_t broadcastResponseTimeoutMs);
|
||||||
static uint32_t broadcastResponseTimeoutMs();
|
static uint32_t broadcastResponseTimeoutMs();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -420,8 +420,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @return The current espnowEncryptedConnectionKey for this EspnowMeshBackend instance.
|
* @return The current espnowEncryptedConnectionKey for this EspnowMeshBackend instance.
|
||||||
*/
|
*/
|
||||||
const uint8_t *getEspnowEncryptedConnectionKey();
|
const uint8_t *getEspnowEncryptedConnectionKey() const;
|
||||||
uint8_t *getEspnowEncryptedConnectionKey(uint8_t resultArray[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength]);
|
uint8_t *getEspnowEncryptedConnectionKey(uint8_t resultArray[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength]) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the key used to encrypt/decrypt the encrypted connection key when creating encrypted ESP-NOW connections. (Kok = key of keys, perhaps) If no Kok is provided by the user, a default Kok is used.
|
* Change the key used to encrypt/decrypt the encrypted connection key when creating encrypted ESP-NOW connections. (Kok = key of keys, perhaps) If no Kok is provided by the user, a default Kok is used.
|
||||||
@ -486,7 +486,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setEspnowHashKey(const String &espnowHashKeySeed);
|
void setEspnowHashKey(const String &espnowHashKeySeed);
|
||||||
|
|
||||||
const uint8_t *getEspnowHashKey();
|
const uint8_t *getEspnowHashKey() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the key used to encrypt/decrypt messages when using AEAD encryption.
|
* Change the key used to encrypt/decrypt messages when using AEAD encryption.
|
||||||
@ -496,7 +496,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param espnowMessageEncryptionKey An array containing the CryptoInterface::ENCRYPTION_KEY_LENGTH bytes that will be used as the message encryption key.
|
* @param espnowMessageEncryptionKey An array containing the CryptoInterface::ENCRYPTION_KEY_LENGTH bytes that will be used as the message encryption key.
|
||||||
*/
|
*/
|
||||||
static void setEspnowMessageEncryptionKey(uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH]);
|
static void setEspnowMessageEncryptionKey(const uint8_t espnowMessageEncryptionKey[CryptoInterface::ENCRYPTION_KEY_LENGTH]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the key used to encrypt/decrypt messages when using AEAD encryption.
|
* Change the key used to encrypt/decrypt messages when using AEAD encryption.
|
||||||
@ -532,7 +532,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param useEncryptedMessages If true, AEAD encryption/decryption is enabled. If false, AEAD encryption/decryption is disabled.
|
* @param useEncryptedMessages If true, AEAD encryption/decryption is enabled. If false, AEAD encryption/decryption is disabled.
|
||||||
*/
|
*/
|
||||||
static void setUseEncryptedMessages(bool useEncryptedMessages);
|
static void setUseEncryptedMessages(const bool useEncryptedMessages);
|
||||||
static bool useEncryptedMessages();
|
static bool useEncryptedMessages();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -556,7 +556,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param maxTransmissionsPerMessage The maximum acceptable message length, in terms of transmissions, when sending a message from this node. Valid values are 1 to 128. Defaults to 3.
|
* @param maxTransmissionsPerMessage The maximum acceptable message length, in terms of transmissions, when sending a message from this node. Valid values are 1 to 128. Defaults to 3.
|
||||||
*/
|
*/
|
||||||
static void setMaxTransmissionsPerMessage(uint8_t maxTransmissionsPerMessage);
|
static void setMaxTransmissionsPerMessage(const uint8_t maxTransmissionsPerMessage);
|
||||||
static uint8_t getMaxTransmissionsPerMessage();
|
static uint8_t getMaxTransmissionsPerMessage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -574,8 +574,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param enabled If true, library Serial prints are activated.
|
* @param enabled If true, library Serial prints are activated.
|
||||||
*/
|
*/
|
||||||
void setVerboseModeState(bool enabled) override;
|
void setVerboseModeState(const bool enabled) override;
|
||||||
bool verboseMode() override;
|
bool verboseMode() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only print stringToPrint if verboseMode() returns true.
|
* Only print stringToPrint if verboseMode() returns true.
|
||||||
@ -583,7 +583,7 @@ public:
|
|||||||
* @param stringToPrint String to print.
|
* @param stringToPrint String to print.
|
||||||
* @param newline If true, will end the print with a newline. True by default.
|
* @param newline If true, will end the print with a newline. True by default.
|
||||||
*/
|
*/
|
||||||
void verboseModePrint(const String &stringToPrint, bool newline = true) override;
|
void verboseModePrint(const String &stringToPrint, const bool newline = true) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as verboseMode(), but used for printing from static functions.
|
* Same as verboseMode(), but used for printing from static functions.
|
||||||
@ -598,7 +598,7 @@ public:
|
|||||||
* @param stringToPrint String to print.
|
* @param stringToPrint String to print.
|
||||||
* @param newline If true, will end the print with a newline. True by default.
|
* @param newline If true, will end the print with a newline. True by default.
|
||||||
*/
|
*/
|
||||||
static void staticVerboseModePrint(const String &stringToPrint, bool newline = true);
|
static void staticVerboseModePrint(const String &stringToPrint, const bool newline = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the message of the response at responseIndex among the responses that are scheduled for transmission from this node.
|
* Get the message of the response at responseIndex among the responses that are scheduled for transmission from this node.
|
||||||
@ -606,7 +606,7 @@ public:
|
|||||||
* @param responseIndex The index of the response. Must be lower than numberOfScheduledResponses().
|
* @param responseIndex The index of the response. Must be lower than numberOfScheduledResponses().
|
||||||
* @return A String containing the message of the response at responseIndex.
|
* @return A String containing the message of the response at responseIndex.
|
||||||
*/
|
*/
|
||||||
static String getScheduledResponseMessage(uint32_t responseIndex);
|
static String getScheduledResponseMessage(const uint32_t responseIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MAC address for the recipient of the response at responseIndex among the responses that are scheduled for transmission from this node.
|
* Get the MAC address for the recipient of the response at responseIndex among the responses that are scheduled for transmission from this node.
|
||||||
@ -614,7 +614,7 @@ public:
|
|||||||
* @param responseIndex The index of the response. Must be lower than numberOfScheduledResponses().
|
* @param responseIndex The index of the response. Must be lower than numberOfScheduledResponses().
|
||||||
* @return An array with six bytes containing the MAC address for the recipient of the response at responseIndex.
|
* @return An array with six bytes containing the MAC address for the recipient of the response at responseIndex.
|
||||||
*/
|
*/
|
||||||
static const uint8_t *getScheduledResponseRecipient(uint32_t responseIndex);
|
static const uint8_t *getScheduledResponseRecipient(const uint32_t responseIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of ESP-NOW responses that are scheduled for transmission from this node.
|
* Get the number of ESP-NOW responses that are scheduled for transmission from this node.
|
||||||
@ -637,7 +637,7 @@ public:
|
|||||||
* @param recipientMac The MAC address of the response recipient.
|
* @param recipientMac The MAC address of the response recipient.
|
||||||
* @param encryptedOnly If true, only responses to encrypted requests will be deleted.
|
* @param encryptedOnly If true, only responses to encrypted requests will be deleted.
|
||||||
*/
|
*/
|
||||||
static void deleteScheduledResponsesByRecipient(const uint8_t *recipientMac, bool encryptedOnly);
|
static void deleteScheduledResponsesByRecipient(const uint8_t *recipientMac, const bool encryptedOnly);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the timeout to use for each ESP-NOW transmission when transmitting.
|
* Set the timeout to use for each ESP-NOW transmission when transmitting.
|
||||||
@ -646,7 +646,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param timeoutMs The timeout that should be used for each ESP-NOW transmission, in milliseconds. Defaults to 40 ms.
|
* @param timeoutMs The timeout that should be used for each ESP-NOW transmission, in milliseconds. Defaults to 40 ms.
|
||||||
*/
|
*/
|
||||||
static void setEspnowTransmissionTimeout(uint32_t timeoutMs);
|
static void setEspnowTransmissionTimeout(const uint32_t timeoutMs);
|
||||||
static uint32_t getEspnowTransmissionTimeout();
|
static uint32_t getEspnowTransmissionTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -656,18 +656,18 @@ public:
|
|||||||
*
|
*
|
||||||
* @param intervalMs The time to wait for an ack after having made an ESP-NOW transmission, in milliseconds. Defaults to 15 ms.
|
* @param intervalMs The time to wait for an ack after having made an ESP-NOW transmission, in milliseconds. Defaults to 15 ms.
|
||||||
*/
|
*/
|
||||||
static void setEspnowRetransmissionInterval(uint32_t intervalMs);
|
static void setEspnowRetransmissionInterval(const uint32_t intervalMs);
|
||||||
static uint32_t getEspnowRetransmissionInterval();
|
static uint32_t getEspnowRetransmissionInterval();
|
||||||
|
|
||||||
// The maximum amount of time each of the two stages in an encrypted connection request may take.
|
// The maximum amount of time each of the two stages in an encrypted connection request may take.
|
||||||
static void setEncryptionRequestTimeout(uint32_t timeoutMs);
|
static void setEncryptionRequestTimeout(const uint32_t timeoutMs);
|
||||||
static uint32_t getEncryptionRequestTimeout();
|
static uint32_t getEncryptionRequestTimeout();
|
||||||
|
|
||||||
void setAutoEncryptionDuration(uint32_t duration);
|
void setAutoEncryptionDuration(const uint32_t duration);
|
||||||
uint32_t getAutoEncryptionDuration();
|
uint32_t getAutoEncryptionDuration() const;
|
||||||
|
|
||||||
void setBroadcastFilter(broadcastFilterType broadcastFilter);
|
void setBroadcastFilter(const broadcastFilterType broadcastFilter);
|
||||||
broadcastFilterType getBroadcastFilter();
|
broadcastFilterType getBroadcastFilter() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a function that should be called after each successful ESP-NOW response transmission, just before the response is removed from the waiting list.
|
* Set a function that should be called after each successful ESP-NOW response transmission, just before the response is removed from the waiting list.
|
||||||
@ -679,8 +679,8 @@ public:
|
|||||||
* If it is false, the response transmission process will stop after removing the just sent response from the waiting list.
|
* If it is false, the response transmission process will stop after removing the just sent response from the waiting list.
|
||||||
* The default responseTransmittedHook always returns true.
|
* The default responseTransmittedHook always returns true.
|
||||||
*/
|
*/
|
||||||
void setResponseTransmittedHook(responseTransmittedHookType responseTransmittedHook);
|
void setResponseTransmittedHook(const responseTransmittedHookType responseTransmittedHook);
|
||||||
responseTransmittedHookType getResponseTransmittedHook();
|
responseTransmittedHookType getResponseTransmittedHook() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
* Get the MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
||||||
@ -690,7 +690,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A String filled with a hexadecimal representation of the MAC, without delimiters.
|
* @return A String filled with a hexadecimal representation of the MAC, without delimiters.
|
||||||
*/
|
*/
|
||||||
String getSenderMac();
|
String getSenderMac() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
* Get the MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
||||||
@ -701,7 +701,7 @@ public:
|
|||||||
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
||||||
* @return macArray filled with the sender MAC.
|
* @return macArray filled with the sender MAC.
|
||||||
*/
|
*/
|
||||||
uint8_t *getSenderMac(uint8_t *macArray);
|
uint8_t *getSenderMac(uint8_t *macArray) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the AP MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
* Get the AP MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
||||||
@ -709,7 +709,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A String filled with a hexadecimal representation of the AP MAC, without delimiters.
|
* @return A String filled with a hexadecimal representation of the AP MAC, without delimiters.
|
||||||
*/
|
*/
|
||||||
String getSenderAPMac();
|
String getSenderAPMac() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the AP MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
* Get the AP MAC address of the sender of the most recently received ESP-NOW request, response or broadcast to this EspnowMeshBackend instance.
|
||||||
@ -718,14 +718,14 @@ public:
|
|||||||
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
||||||
* @return macArray filled with the sender AP MAC.
|
* @return macArray filled with the sender AP MAC.
|
||||||
*/
|
*/
|
||||||
uint8_t *getSenderAPMac(uint8_t *macArray);
|
uint8_t *getSenderAPMac(uint8_t *macArray) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the ESP-NOW request, response or broadcast which was most recently received by this EspnowMeshBackend instance was sent over an encrypted connection or not.
|
* Get whether the ESP-NOW request, response or broadcast which was most recently received by this EspnowMeshBackend instance was sent over an encrypted connection or not.
|
||||||
*
|
*
|
||||||
* @return If true, the request, response or broadcast was sent over an encrypted connection. If false, the connection was unencrypted.
|
* @return If true, the request, response or broadcast was sent over an encrypted connection. If false, the connection was unencrypted.
|
||||||
*/
|
*/
|
||||||
bool receivedEncryptedTransmission();
|
bool receivedEncryptedTransmission() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used together with serializeUnencryptedConnection() if the node sends unencrypted transmissions
|
* Should be used together with serializeUnencryptedConnection() if the node sends unencrypted transmissions
|
||||||
@ -738,34 +738,134 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool addUnencryptedConnection(const String &serializedConnectionState);
|
static bool addUnencryptedConnection(const String &serializedConnectionState);
|
||||||
|
|
||||||
// Updates connection with current stored encrypted connection key.
|
/**
|
||||||
// At least one of the leftmost 32 bits in each of the session keys should be 1, since the key otherwise indicates the connection is unencrypted.
|
* Adds a new permanent encrypted ESP-NOW connection, or makes the duration of an existing temporary connection permanent.
|
||||||
EncryptedConnectionStatus addEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, uint64_t peerSessionKey, uint64_t ownSessionKey);
|
* Note that this will not add an encrypted ESP-NOW connection automatically to the other node. Thus the same method will need to be called on the other node as well to establish an encrypted connection.
|
||||||
// Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
* Methods such as requestEncryptedConnection creates an encrypted connection automatically in both nodes, but requires information exchange between the nodes before the connection is established (and is thus much slower).
|
||||||
// These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
|
*
|
||||||
// @param ignoreDuration Ignores any stored duration serializedConnectionState, guaranteeing that the created connection will be permanent. Returns: EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED indicates malformed serializedConnectionState.
|
* When called, the method will update an existing encrypted ESP-NOW connection with the current stored encrypted connection key. (in case it has changed since the connection was established)
|
||||||
EncryptedConnectionStatus addEncryptedConnection(const String &serializedConnectionState, bool ignoreDuration = false);
|
*
|
||||||
|
* @param peerStaMac The station MAC of the other node.
|
||||||
|
* @param peerApMac The AP MAC of the other node.
|
||||||
|
* @param peerSessionKey The session key of the other node. At least one of the leftmost 32 bits should be 1, since the key otherwise indicates the connection is unencrypted.
|
||||||
|
* @param peerSessionKey The session key of this node. At least one of the leftmost 32 bits should be 1, since the key otherwise indicates the connection is unencrypted.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the connection was created. Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus addEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, const uint64_t peerSessionKey, const uint64_t ownSessionKey);
|
||||||
|
|
||||||
// Adds a new temporary encrypted connection, or changes the duration of an existing temporary connection (only updates keys, not duration, for existing permanent connections).
|
/**
|
||||||
// As with all these methods, changes will only take effect once the requester proves it has the ability to decrypt the session key.
|
* Create an encrypted ESP-NOW connection on this node based on the information stored in serializedConnectionState.
|
||||||
// At least one of the leftmost 32 bits in each of the session keys should be 1, since the key otherwise indicates the connection is unencrypted.
|
* Note that this will not add an encrypted ESP-NOW connection automatically to the other node. Thus the same method will need to be called on the other node as well to establish an encrypted connection.
|
||||||
EncryptedConnectionStatus addTemporaryEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, uint64_t peerSessionKey, uint64_t ownSessionKey, uint32_t duration);
|
* Methods such as requestEncryptedConnection creates an encrypted connection automatically in both nodes, but requires information exchange between the nodes before the connection is established (and is thus much slower).
|
||||||
// Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
*
|
||||||
// These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
|
* When called, the method will update an existing encrypted ESP-NOW connection with the current stored encrypted connection key. (in case it has changed since the connection was established)
|
||||||
// Uses duration argument instead of any stored duration in serializedConnectionState. Returns: EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED indicates malformed serializedConnectionState.
|
*
|
||||||
EncryptedConnectionStatus addTemporaryEncryptedConnection(const String &serializedConnectionState, uint32_t duration);
|
* Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
||||||
|
* These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
|
||||||
|
*
|
||||||
|
* @param serializedConnectionState A String containing the serialized connection state.
|
||||||
|
* @param ignoreDuration Ignores any stored duration in serializedConnectionState, guaranteeing that the created connection will be permanent.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the connection was created. Otherwise another status code based on the outcome. EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED indicates a malformed serializedConnectionState.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus addEncryptedConnection(const String &serializedConnectionState, const bool ignoreDuration = false);
|
||||||
|
|
||||||
// If an encrypted connection to peerMac already exists, only connection duration is updated. All other settings are kept as is. Use removeEncryptedConnection/requestEncryptedConnectionRemoval first if encryption keys should be updated.
|
/**
|
||||||
// Makes sure both nodes have an encrypted connection to each other that's permanent.
|
* Adds a new temporary encrypted ESP-NOW connection, or changes the duration of an existing temporary connection (only updates keys, not duration, for existing permanent connections).
|
||||||
EncryptedConnectionStatus requestEncryptedConnection(uint8_t *peerMac);
|
* Note that this will not add an encrypted ESP-NOW connection automatically to the other node. Thus the same method will need to be called on the other node as well to establish an encrypted connection.
|
||||||
// Makes sure both nodes have an encrypted connection to each other that's either permanent or has the duration specified.
|
* Methods such as requestEncryptedConnection creates an encrypted connection automatically in both nodes, but requires information exchange between the nodes before the connection is established (and is thus much slower).
|
||||||
EncryptedConnectionStatus requestTemporaryEncryptedConnection(uint8_t *peerMac, uint32_t durationMs);
|
*
|
||||||
// Makes sure both nodes have an encrypted connection to each other that's either permanent or has at least the duration specified.
|
* When called, the method will update an existing encrypted ESP-NOW connection with the current stored encrypted connection key. (in case it has changed since the connection was established)
|
||||||
// Note that if a temporary encrypted connection already exists to a target node, this method will slightly extend the connection duration
|
*
|
||||||
// depending on the time it takes to verify the connection to the node.
|
* As with all these methods, changes will only take effect once the requester proves it has the ability to decrypt the session key.
|
||||||
EncryptedConnectionStatus requestFlexibleTemporaryEncryptedConnection(uint8_t *peerMac, uint32_t minDurationMs);
|
*
|
||||||
static EncryptedConnectionRemovalOutcome removeEncryptedConnection(uint8_t *peerMac);
|
* @param peerStaMac The station MAC of the other node.
|
||||||
EncryptedConnectionRemovalOutcome requestEncryptedConnectionRemoval(uint8_t *peerMac);
|
* @param peerApMac The AP MAC of the other node.
|
||||||
|
* @param peerSessionKey The session key of the other node. At least one of the leftmost 32 bits should be 1, since the key otherwise indicates the connection is unencrypted.
|
||||||
|
* @param peerSessionKey The session key of this node. At least one of the leftmost 32 bits should be 1, since the key otherwise indicates the connection is unencrypted.
|
||||||
|
* @param duration The desired duration of the connection.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the connection was created. Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus addTemporaryEncryptedConnection(uint8_t *peerStaMac, uint8_t *peerApMac, const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a temporary encrypted ESP-NOW connection on this node based on the information stored in serializedConnectionState.
|
||||||
|
* Note that this will not add an encrypted ESP-NOW connection automatically to the other node. Thus the same method will need to be called on the other node as well to establish an encrypted connection.
|
||||||
|
* Methods such as requestEncryptedConnection creates an encrypted connection automatically in both nodes, but requires information exchange between the nodes before the connection is established (and is thus much slower).
|
||||||
|
*
|
||||||
|
* When called, the method will update an existing encrypted ESP-NOW connection with the current stored encrypted connection key. (in case it has changed since the connection was established)
|
||||||
|
*
|
||||||
|
* Note that the espnowEncryptedConnectionKey, espnowEncryptionKok, espnowHashKey and espnowMessageEncryptionKey are not serialized.
|
||||||
|
* These will be set to the values of the EspnowMeshBackend instance that is adding the serialized encrypted connection.
|
||||||
|
*
|
||||||
|
* @param serializedConnectionState A String containing the serialized connection state.
|
||||||
|
* @param ignoreDuration Ignores any stored duration in serializedConnectionState, guaranteeing that the created connection will be permanent.
|
||||||
|
* @param duration The desired duration of the connection. Overrides any stored duration in the serializedConnectionState.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the connection was created. Otherwise another status code based on the outcome. EncryptedConnectionStatus::REQUEST_TRANSMISSION_FAILED indicates a malformed serializedConnectionState.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus addTemporaryEncryptedConnection(const String &serializedConnectionState, const uint32_t duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request a permanent encrypted ESP-NOW connection with the node that uses peerMac.
|
||||||
|
* If an encrypted connection to peerMac already exists, only connection duration is updated. All other settings are kept as is. Use removeEncryptedConnection/requestEncryptedConnectionRemoval first if encryption keys should be updated.
|
||||||
|
* The method makes sure both nodes have an encrypted connection to each other that's permanent.
|
||||||
|
*
|
||||||
|
* @param peerMac The MAC of the other node to which the request should be sent.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the permanent connection was created. EncryptedConnectionStatus::SOFT_LIMIT_CONNECTION_ESTABLISHED if only a temporary soft limit connection could be established (see the setEncryptedConnectionsSoftLimit method documentation for details). Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus requestEncryptedConnection(const uint8_t *peerMac);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request a temporary encrypted ESP-NOW connection with the node that uses peerMac.
|
||||||
|
* If a temporary encrypted connection to peerMac already exists, only connection duration is updated. All other settings are kept as is. Permanent connections are not modified. Use removeEncryptedConnection/requestEncryptedConnectionRemoval first if encryption keys should be updated.
|
||||||
|
* The method makes sure both nodes have an encrypted connection to each other that's either permanent or has exactly the duration specified.
|
||||||
|
*
|
||||||
|
* @param peerMac The MAC of the other node to which the request should be sent.
|
||||||
|
* @param durationMs The desired duration of the connection.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the request was succesful. EncryptedConnectionStatus::SOFT_LIMIT_CONNECTION_ESTABLISHED if only a temporary soft limit connection could be established (see the setEncryptedConnectionsSoftLimit method documentation for details). Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus requestTemporaryEncryptedConnection(const uint8_t *peerMac, const uint32_t durationMs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request a flexible temporary encrypted ESP-NOW connection with the node that uses peerMac.
|
||||||
|
* If a temporary encrypted connection to peerMac with a shorter duration already exists, connection duration is updated. All other settings are kept as is. Permanent connections are not modified. Use removeEncryptedConnection/requestEncryptedConnectionRemoval first if encryption keys should be updated.
|
||||||
|
* The method makes sure both nodes have an encrypted connection to each other that's either permanent or has at least the duration specified.
|
||||||
|
*
|
||||||
|
* Note that if a temporary encrypted connection already exists to a target node, this method will slightly extend the connection duration
|
||||||
|
* depending on the time it takes to verify the connection to the node.
|
||||||
|
*
|
||||||
|
* @param peerMac The MAC of the other node to which the request should be sent.
|
||||||
|
* @param minDurationMs The desired minimum duration of the connection.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionStatus::CONNECTION_ESTABLISHED if the request was succesful. EncryptedConnectionStatus::SOFT_LIMIT_CONNECTION_ESTABLISHED if only a temporary soft limit connection could be established (see the setEncryptedConnectionsSoftLimit method documentation for details). Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
EncryptedConnectionStatus requestFlexibleTemporaryEncryptedConnection(const uint8_t *peerMac, const uint32_t minDurationMs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the encrypted ESP-NOW connection to peerMac from this node.
|
||||||
|
* Note that this will not remove the encrypted ESP-NOW connection automatically from the other node. Thus the same method will need to be called on the other node as well to complete the encrypted connection removal.
|
||||||
|
* The method requestEncryptedConnectionRemoval removes the encrypted connection automatically in both nodes, but requires extra information exchange between the nodes (and is thus much slower).
|
||||||
|
*
|
||||||
|
* @param peerMac The MAC of the other node.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionRemovalOutcome::REMOVAL_SUCCEEDED if the removal succeeded. EncryptedConnectionRemovalOutcome::REMOVAL_SCHEDULED if the removal is scheduled to occur as soon as it is safe to do so (generally as soon as an ongoing transmission is complete, or at the latest during the next performEspnowMaintenance call). Otherwise another status code based on the outcome.
|
||||||
|
*/
|
||||||
|
static EncryptedConnectionRemovalOutcome removeEncryptedConnection(const uint8_t *peerMac);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request the removal of the encrypted ESP-NOW connection between this node and the node that uses peerMac.
|
||||||
|
* The method makes sure both nodes remove the encrypted connection to each other.
|
||||||
|
*
|
||||||
|
* @param peerMac The MAC of the other node to which the request should be sent.
|
||||||
|
*
|
||||||
|
* @return EncryptedConnectionRemovalOutcome::REMOVAL_SUCCEEDED if the removal succeeded. Otherwise another status code based on the outcome (never REMOVAL_SCHEDULED).
|
||||||
|
*/
|
||||||
|
EncryptedConnectionRemovalOutcome requestEncryptedConnectionRemoval(const uint8_t *peerMac);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether this EspnowMeshBackend instance will accept ESP-NOW requests from unencrypted connections or not, when acting as EspnowRequestManager.
|
* Set whether this EspnowMeshBackend instance will accept ESP-NOW requests from unencrypted connections or not, when acting as EspnowRequestManager.
|
||||||
@ -777,8 +877,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param acceptsUnverifiedRequests If and only if true, requests from unencrypted connections will be processed when this EspnowMeshBackend instance is acting as EspnowRequestManager.
|
* @param acceptsUnverifiedRequests If and only if true, requests from unencrypted connections will be processed when this EspnowMeshBackend instance is acting as EspnowRequestManager.
|
||||||
*/
|
*/
|
||||||
void setAcceptsUnverifiedRequests(bool acceptsUnverifiedRequests);
|
void setAcceptsUnverifiedRequests(const bool acceptsUnverifiedRequests);
|
||||||
bool acceptsUnverifiedRequests();
|
bool acceptsUnverifiedRequests() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a soft upper limit on the number of encrypted connections this node can have when receiving encrypted connection requests.
|
* Set a soft upper limit on the number of encrypted connections this node can have when receiving encrypted connection requests.
|
||||||
@ -795,15 +895,17 @@ public:
|
|||||||
*
|
*
|
||||||
* @param softLimit The new soft limit. Valid values are 0 to 6.
|
* @param softLimit The new soft limit. Valid values are 0 to 6.
|
||||||
*/
|
*/
|
||||||
void setEncryptedConnectionsSoftLimit(uint8_t softLimit);
|
void setEncryptedConnectionsSoftLimit(const uint8_t softLimit);
|
||||||
uint8_t encryptedConnectionsSoftLimit();
|
uint8_t encryptedConnectionsSoftLimit() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The current number of encrypted ESP-NOW connections.
|
* @return The current number of encrypted ESP-NOW connections.
|
||||||
*/
|
*/
|
||||||
static uint8_t numberOfEncryptedConnections();
|
static uint8_t numberOfEncryptedConnections();
|
||||||
|
|
||||||
// @return resultArray filled with the MAC to the encrypted interface of the node, if an encrypted connection exists. nulltpr otherwise.
|
/**
|
||||||
|
* @return resultArray filled with the MAC to the encrypted interface of the node, if an encrypted connection exists. nulltpr otherwise.
|
||||||
|
*/
|
||||||
static uint8_t *getEncryptedMac(const uint8_t *peerMac, uint8_t *resultArray);
|
static uint8_t *getEncryptedMac(const uint8_t *peerMac, uint8_t *resultArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -815,12 +917,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static String serializeUnencryptedConnection();
|
static String serializeUnencryptedConnection();
|
||||||
|
|
||||||
// Create a string containing the current state of the encrypted connection for this node. The result can be used as input to addEncryptedConnection.
|
/**
|
||||||
// Note that transferring the serialized state over an unencrypted connection will compromise the security of the stored connection.
|
* Create a string containing the current state of the encrypted connection for this node. The result can be used as input to addEncryptedConnection.
|
||||||
// Also note that this saves the current state only, so if encrypted communication between the nodes happen after this, the stored state is invalid.
|
* Note that transferring the serialized state over an unencrypted connection will compromise the security of the stored connection.
|
||||||
// @return A String containing the serialized encrypted connection, or an empty String if there is no matching encrypted connection.
|
* Also note that this saves the current state only, so if encrypted communication between the nodes happen after this, the stored state is invalid.
|
||||||
|
* @return A String containing the serialized encrypted connection, or an empty String if there is no matching encrypted connection.
|
||||||
|
*/
|
||||||
static String serializeEncryptedConnection(const uint8_t *peerMac);
|
static String serializeEncryptedConnection(const uint8_t *peerMac);
|
||||||
static String serializeEncryptedConnection(uint32_t connectionIndex);
|
static String serializeEncryptedConnection(const uint32_t connectionIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about any current ESP-NOW connection with another node.
|
* Get information about any current ESP-NOW connection with another node.
|
||||||
@ -845,7 +949,7 @@ public:
|
|||||||
* Otherwise the array is not modified.
|
* Otherwise the array is not modified.
|
||||||
* @return The ConnectionType of the connection given by connectionIndex.
|
* @return The ConnectionType of the connection given by connectionIndex.
|
||||||
*/
|
*/
|
||||||
static ConnectionType getConnectionInfo(uint32_t connectionIndex, uint32_t *remainingDuration = nullptr, uint8_t *peerMac = nullptr);
|
static ConnectionType getConnectionInfo(const uint32_t connectionIndex, uint32_t *remainingDuration = nullptr, uint8_t *peerMac = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The proportion of ESP-NOW requests made by this node that have failed, since power on or latest reset.
|
* @return The proportion of ESP-NOW requests made by this node that have failed, since power on or latest reset.
|
||||||
@ -870,7 +974,7 @@ protected:
|
|||||||
|
|
||||||
bool activateEspnow();
|
bool activateEspnow();
|
||||||
|
|
||||||
static bool encryptedConnectionEstablished(EncryptedConnectionStatus connectionStatus);
|
static bool encryptedConnectionEstablished(const EncryptedConnectionStatus connectionStatus);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that ESP-NOW is not perfect and in rare cases messages may be dropped.
|
* Note that ESP-NOW is not perfect and in rare cases messages may be dropped.
|
||||||
@ -902,7 +1006,7 @@ protected:
|
|||||||
|
|
||||||
static uint32_t getMaxBytesPerTransmission();
|
static uint32_t getMaxBytesPerTransmission();
|
||||||
|
|
||||||
static std::list<ResponseData>::const_iterator getScheduledResponse(uint32_t responseIndex);
|
static std::list<ResponseData>::const_iterator getScheduledResponse(const uint32_t responseIndex);
|
||||||
|
|
||||||
// Note that removing an encrypted connection while there are encrypted responses scheduled for transmission to the encrypted peer will cause these encrypted responses to be removed without being sent.
|
// Note that removing an encrypted connection while there are encrypted responses scheduled for transmission to the encrypted peer will cause these encrypted responses to be removed without being sent.
|
||||||
// Also note that removing an encrypted connection while there is encrypted data to be received will make the node unable to decrypt that data (although an ack will still be sent to confirm data reception).
|
// Also note that removing an encrypted connection while there is encrypted data to be received will make the node unable to decrypt that data (although an ack will still be sent to confirm data reception).
|
||||||
@ -918,23 +1022,23 @@ protected:
|
|||||||
*
|
*
|
||||||
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
||||||
*/
|
*/
|
||||||
void setSenderMac(uint8_t *macArray);
|
void setSenderMac(const uint8_t *macArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MAC address considered to be the AP MAC of the sender of the most recently received ESP-NOW request, response or broadcast.
|
* Set the MAC address considered to be the AP MAC of the sender of the most recently received ESP-NOW request, response or broadcast.
|
||||||
*
|
*
|
||||||
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
||||||
*/
|
*/
|
||||||
void setSenderAPMac(uint8_t *macArray);
|
void setSenderAPMac(const uint8_t *macArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the most recently received ESP-NOW request, response or broadcast is presented as having been sent over an encrypted connection or not
|
* Set whether the most recently received ESP-NOW request, response or broadcast is presented as having been sent over an encrypted connection or not
|
||||||
*
|
*
|
||||||
* @param receivedEncryptedTransmission If true, the request, response or broadcast is presented as having been sent over an encrypted connection.
|
* @param receivedEncryptedTransmission If true, the request, response or broadcast is presented as having been sent over an encrypted connection.
|
||||||
*/
|
*/
|
||||||
void setReceivedEncryptedTransmission(bool receivedEncryptedTransmission);
|
void setReceivedEncryptedTransmission(const bool receivedEncryptedTransmission);
|
||||||
|
|
||||||
static bool temporaryEncryptedConnectionToPermanent(uint8_t *peerMac);
|
static bool temporaryEncryptedConnectionToPermanent(const uint8_t *peerMac);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will be true if a transmission initiated by a public method is in progress.
|
* Will be true if a transmission initiated by a public method is in progress.
|
||||||
@ -962,7 +1066,7 @@ protected:
|
|||||||
using messageID_td = uint64_t;
|
using messageID_td = uint64_t;
|
||||||
using peerMac_td = uint64_t;
|
using peerMac_td = uint64_t;
|
||||||
|
|
||||||
static macAndType_td createMacAndTypeValue(uint64_t uint64Mac, char messageType);
|
static macAndType_td createMacAndTypeValue(const uint64_t uint64Mac, const char messageType);
|
||||||
static uint64_t macAndTypeToUint64Mac(const macAndType_td &macAndTypeValue);
|
static uint64_t macAndTypeToUint64Mac(const macAndType_td &macAndTypeValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -974,12 +1078,12 @@ protected:
|
|||||||
* @param encryptedOnly If true, only entries sent/received by encrypted transmissions will be deleted.
|
* @param encryptedOnly If true, only entries sent/received by encrypted transmissions will be deleted.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void deleteEntriesByMac(std::map<std::pair<uint64_t, uint64_t>, T> &logEntries, const uint8_t *peerMac, bool encryptedOnly);
|
static void deleteEntriesByMac(std::map<std::pair<uint64_t, uint64_t>, T> &logEntries, const uint8_t *peerMac, const bool encryptedOnly);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void deleteEntriesByMac(std::map<std::pair<macAndType_td, uint64_t>, T> &logEntries, const uint8_t *peerMac, bool encryptedOnly);
|
static void deleteEntriesByMac(std::map<std::pair<macAndType_td, uint64_t>, T> &logEntries, const uint8_t *peerMac, const bool encryptedOnly);
|
||||||
|
|
||||||
static bool requestReceived(uint64_t requestMac, uint64_t requestID);
|
static bool requestReceived(const uint64_t requestMac, const uint64_t requestID);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an ESP-NOW message to the ESP8266 that has the MAC address specified in targetBSSID.
|
* Send an ESP-NOW message to the ESP8266 that has the MAC address specified in targetBSSID.
|
||||||
@ -989,17 +1093,17 @@ protected:
|
|||||||
* @return The transmission status for the transmission.
|
* @return The transmission status for the transmission.
|
||||||
*/
|
*/
|
||||||
// Send a message to the node having targetBSSID as mac, changing targetBSSID to the mac of the encrypted connection if it exists and ensuring such an encrypted connection is synchronized.
|
// Send a message to the node having targetBSSID as mac, changing targetBSSID to the mac of the encrypted connection if it exists and ensuring such an encrypted connection is synchronized.
|
||||||
static TransmissionStatusType espnowSendToNode(const String &message, const uint8_t *targetBSSID, char messageType, EspnowMeshBackend *espnowInstance = nullptr);
|
static TransmissionStatusType espnowSendToNode(const String &message, const uint8_t *targetBSSID, const char messageType, EspnowMeshBackend *espnowInstance = nullptr);
|
||||||
// Send a message using exactly the arguments given, without consideration for any encrypted connections.
|
// Send a message using exactly the arguments given, without consideration for any encrypted connections.
|
||||||
static TransmissionStatusType espnowSendToNodeUnsynchronized(const String message, const uint8_t *targetBSSID, char messageType, uint64_t messageID, EspnowMeshBackend *espnowInstance = nullptr);
|
static TransmissionStatusType espnowSendToNodeUnsynchronized(const String message, const uint8_t *targetBSSID, const char messageType, const uint64_t messageID, EspnowMeshBackend *espnowInstance = nullptr);
|
||||||
|
|
||||||
TransmissionStatusType sendRequest(const String &message, const uint8_t *targetBSSID);
|
TransmissionStatusType sendRequest(const String &message, const uint8_t *targetBSSID);
|
||||||
TransmissionStatusType sendResponse(const String &message, uint64_t requestID, const uint8_t *targetBSSID);
|
TransmissionStatusType sendResponse(const String &message, const uint64_t requestID, const uint8_t *targetBSSID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
EspnowMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter, broadcastFilterType broadcastFilter,
|
EspnowMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter, const broadcastFilterType broadcastFilter,
|
||||||
const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel);
|
const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel);
|
||||||
|
|
||||||
using encryptionRequestBuilderType = std::function<String(const String &, const ExpiringTimeTracker &)>;
|
using encryptionRequestBuilderType = std::function<String(const String &, const ExpiringTimeTracker &)>;
|
||||||
static String defaultEncryptionRequestBuilder(const String &requestHeader, const uint32_t durationMs, const uint8_t *hashKey, const String &requestNonce, const ExpiringTimeTracker &existingTimeTracker);
|
static String defaultEncryptionRequestBuilder(const String &requestHeader, const uint32_t durationMs, const uint8_t *hashKey, const String &requestNonce, const ExpiringTimeTracker &existingTimeTracker);
|
||||||
@ -1011,19 +1115,19 @@ private:
|
|||||||
* This method is very time critical so avoid Serial printing in it and in methods called from it (such as espnowReceiveCallback) as much as possible.
|
* This method is very time critical so avoid Serial printing in it and in methods called from it (such as espnowReceiveCallback) as much as possible.
|
||||||
* Otherwise transmission fail rate is likely to skyrocket.
|
* Otherwise transmission fail rate is likely to skyrocket.
|
||||||
*/
|
*/
|
||||||
static void espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *dataArray, uint8_t len);
|
static void espnowReceiveCallbackWrapper(uint8_t *macaddr, uint8_t *dataArray, const uint8_t len);
|
||||||
void espnowReceiveCallback(uint8_t *macaddr, uint8_t *data, uint8_t len);
|
void espnowReceiveCallback(const uint8_t *macaddr, uint8_t *data, const uint8_t len);
|
||||||
|
|
||||||
static void handlePeerRequest(uint8_t *macaddr, uint8_t *dataArray, uint8_t len, uint64_t uint64StationMac, uint64_t receivedMessageID);
|
static void handlePeerRequest(const uint8_t *macaddr, uint8_t *dataArray, const uint8_t len, const uint64_t uint64StationMac, const uint64_t receivedMessageID);
|
||||||
static void handlePeerRequestConfirmation(uint8_t *macaddr, uint8_t *dataArray, uint8_t len);
|
static void handlePeerRequestConfirmation(uint8_t *macaddr, uint8_t *dataArray, const uint8_t len);
|
||||||
|
|
||||||
static void handlePostponedRemovals();
|
static void handlePostponedRemovals();
|
||||||
|
|
||||||
static bool verifyPeerSessionKey(uint64_t sessionKey, const uint8_t *peerMac, char messageType);
|
static bool verifyPeerSessionKey(const uint64_t sessionKey, const uint8_t *peerMac, const char messageType);
|
||||||
static bool verifyPeerSessionKey(uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection, uint64_t uint64PeerMac, char messageType);
|
static bool verifyPeerSessionKey(const uint64_t sessionKey, const EncryptedConnectionLog &encryptedConnection, const uint64_t uint64PeerMac, const char messageType);
|
||||||
|
|
||||||
static bool synchronizePeerSessionKey(uint64_t sessionKey, const uint8_t *peerMac);
|
static bool synchronizePeerSessionKey(const uint64_t sessionKey, const uint8_t *peerMac);
|
||||||
static bool synchronizePeerSessionKey(uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection);
|
static bool synchronizePeerSessionKey(const uint64_t sessionKey, EncryptedConnectionLog &encryptedConnection);
|
||||||
|
|
||||||
static const uint32_t _maxBytesPerTransmission = 250;
|
static const uint32_t _maxBytesPerTransmission = 250;
|
||||||
static uint8_t _maxTransmissionsPerMessage;
|
static uint8_t _maxTransmissionsPerMessage;
|
||||||
@ -1071,18 +1175,18 @@ private:
|
|||||||
// Should only be used when there is no transmissions in progress, so it is safe to remove encrypted connections. In practice when _espnowTransmissionMutex is free.
|
// Should only be used when there is no transmissions in progress, so it is safe to remove encrypted connections. In practice when _espnowTransmissionMutex is free.
|
||||||
// @param scheduledRemovalOnly If true, only deletes encrypted connections where removalScheduled() is true. This means only connections which have been requested for removal will be deleted,
|
// @param scheduledRemovalOnly If true, only deletes encrypted connections where removalScheduled() is true. This means only connections which have been requested for removal will be deleted,
|
||||||
// not other connections which have expired.
|
// not other connections which have expired.
|
||||||
static void updateTemporaryEncryptedConnections(bool scheduledRemovalOnly = false);
|
static void updateTemporaryEncryptedConnections(const bool scheduledRemovalOnly = false);
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
static void deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, T> &logEntries, uint32_t maxEntryLifetimeMs);
|
static void deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, T> &logEntries, const uint32_t maxEntryLifetimeMs);
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static void deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, TimeTracker> &logEntries, uint32_t maxEntryLifetimeMs);
|
static void deleteExpiredLogEntries(std::map<std::pair<U, uint64_t>, TimeTracker> &logEntries, const uint32_t maxEntryLifetimeMs);
|
||||||
|
|
||||||
static void deleteExpiredLogEntries(std::map<std::pair<peerMac_td, messageID_td>, RequestData> &logEntries, uint32_t requestLifetimeMs, uint32_t broadcastLifetimeMs);
|
static void deleteExpiredLogEntries(std::map<std::pair<peerMac_td, messageID_td>, RequestData> &logEntries, const uint32_t requestLifetimeMs, const uint32_t broadcastLifetimeMs);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void deleteExpiredLogEntries(std::list<T> &logEntries, uint32_t maxEntryLifetimeMs);
|
static void deleteExpiredLogEntries(std::list<T> &logEntries, const uint32_t maxEntryLifetimeMs);
|
||||||
|
|
||||||
static uint32_t _logEntryLifetimeMs;
|
static uint32_t _logEntryLifetimeMs;
|
||||||
static uint32_t _broadcastResponseTimeoutMs;
|
static uint32_t _broadcastResponseTimeoutMs;
|
||||||
@ -1106,9 +1210,9 @@ private:
|
|||||||
static bool _reciprocalPeerRequestConfirmation;
|
static bool _reciprocalPeerRequestConfirmation;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T *getMapValue(std::map<uint64_t, T> &mapIn, uint64_t keyIn);
|
static T *getMapValue(std::map<uint64_t, T> &mapIn, const uint64_t keyIn);
|
||||||
|
|
||||||
static bool usesConstantSessionKey(char messageType);
|
static bool usesConstantSessionKey(const char messageType);
|
||||||
|
|
||||||
bool _acceptsUnverifiedRequests = true;
|
bool _acceptsUnverifiedRequests = true;
|
||||||
|
|
||||||
@ -1135,16 +1239,16 @@ private:
|
|||||||
*
|
*
|
||||||
* @return A valid EspnowMeshBackend pointer if a matching entry is found in the EspnowMeshBackend sentRequests container. nullptr otherwise.
|
* @return A valid EspnowMeshBackend pointer if a matching entry is found in the EspnowMeshBackend sentRequests container. nullptr otherwise.
|
||||||
*/
|
*/
|
||||||
static EspnowMeshBackend *getOwnerOfSentRequest(uint64_t requestMac, uint64_t requestID);
|
static EspnowMeshBackend *getOwnerOfSentRequest(const uint64_t requestMac, const uint64_t requestID);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all entries in the sentRequests container where requestMac is noted as having received requestID.
|
* Delete all entries in the sentRequests container where requestMac is noted as having received requestID.
|
||||||
*
|
*
|
||||||
* @return The number of entries deleted.
|
* @return The number of entries deleted.
|
||||||
*/
|
*/
|
||||||
static size_t deleteSentRequest(uint64_t requestMac, uint64_t requestID);
|
static size_t deleteSentRequest(const uint64_t requestMac, const uint64_t requestID);
|
||||||
|
|
||||||
static size_t deleteSentRequestsByOwner(EspnowMeshBackend *instancePointer);
|
static size_t deleteSentRequestsByOwner(const EspnowMeshBackend *instancePointer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the core logic used for requesting an encrypted connection to a peerMac.
|
* Contains the core logic used for requesting an encrypted connection to a peerMac.
|
||||||
@ -1155,7 +1259,7 @@ private:
|
|||||||
* The request message should typically be of the form: JsonTranslator::createEncryptionRequestIntro() + JsonTranslator::createEncryptionRequestEnding().
|
* The request message should typically be of the form: JsonTranslator::createEncryptionRequestIntro() + JsonTranslator::createEncryptionRequestEnding().
|
||||||
* @return The ultimate status of the requested encrypted connection, as EncryptedConnectionStatus.
|
* @return The ultimate status of the requested encrypted connection, as EncryptedConnectionStatus.
|
||||||
*/
|
*/
|
||||||
EncryptedConnectionStatus requestEncryptedConnectionKernel(uint8_t *peerMac, const encryptionRequestBuilderType &encryptionRequestBuilder);
|
EncryptedConnectionStatus requestEncryptedConnectionKernel(const uint8_t *peerMac, const encryptionRequestBuilderType &encryptionRequestBuilder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a new message ID to be used when making a data transmission. The generated ID will be different depending on whether an encrypted connection exists or not.
|
* Generate a new message ID to be used when making a data transmission. The generated ID will be different depending on whether an encrypted connection exists or not.
|
||||||
@ -1163,7 +1267,7 @@ private:
|
|||||||
* @param encryptedConnection A pointer to the EncryptedConnectionLog of the encrypted connection. Can be set to nullptr if the connection is unecrypted.
|
* @param encryptedConnection A pointer to the EncryptedConnectionLog of the encrypted connection. Can be set to nullptr if the connection is unecrypted.
|
||||||
* @return The generated message ID.
|
* @return The generated message ID.
|
||||||
*/
|
*/
|
||||||
static uint64_t generateMessageID(EncryptedConnectionLog *encryptedConnection);
|
static uint64_t generateMessageID(const EncryptedConnectionLog *encryptedConnection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new session key for an encrypted connection using the built in RANDOM_REG32 of the ESP8266.
|
* Create a new session key for an encrypted connection using the built in RANDOM_REG32 of the ESP8266.
|
||||||
@ -1174,14 +1278,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
static uint64_t createSessionKey();
|
static uint64_t createSessionKey();
|
||||||
|
|
||||||
void prepareForTransmission(const String &message, bool scan, bool scanAllWiFiChannels);
|
void prepareForTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels);
|
||||||
TransmissionStatusType initiateTransmission(const String &message, const EspnowNetworkInfo &recipientInfo);
|
TransmissionStatusType initiateTransmission(const String &message, const EspnowNetworkInfo &recipientInfo);
|
||||||
TransmissionStatusType initiateTransmissionKernel(const String &message, const uint8_t *targetBSSID);
|
TransmissionStatusType initiateTransmissionKernel(const String &message, const uint8_t *targetBSSID);
|
||||||
void printTransmissionStatistics();
|
void printTransmissionStatistics() const;
|
||||||
|
|
||||||
EncryptedConnectionStatus initiateAutoEncryptingConnection(const EspnowNetworkInfo &recipientInfo, bool requestPermanentConnection, uint8_t *targetBSSID, EncryptedConnectionLog **existingEncryptedConnection);
|
EncryptedConnectionStatus initiateAutoEncryptingConnection(const EspnowNetworkInfo &recipientInfo, const bool requestPermanentConnection, uint8_t *targetBSSID, EncryptedConnectionLog **existingEncryptedConnection);
|
||||||
TransmissionStatusType initiateAutoEncryptingTransmission(const String &message, const uint8_t *targetBSSID, EncryptedConnectionStatus connectionStatus);
|
TransmissionStatusType initiateAutoEncryptingTransmission(const String &message, uint8_t *targetBSSID, const EncryptedConnectionStatus connectionStatus);
|
||||||
void finalizeAutoEncryptingConnection(const uint8_t *targetBSSID, const EncryptedConnectionLog *existingEncryptedConnection, bool requestPermanentConnection);
|
void finalizeAutoEncryptingConnection(const uint8_t *targetBSSID, const EncryptedConnectionLog *existingEncryptedConnection, const bool requestPermanentConnection);
|
||||||
|
|
||||||
// Used for verboseMode printing in attemptTransmission, _AT suffix used to reduce namespace clutter
|
// Used for verboseMode printing in attemptTransmission, _AT suffix used to reduce namespace clutter
|
||||||
uint32_t totalDurationWhenSuccessful_AT = 0;
|
uint32_t totalDurationWhenSuccessful_AT = 0;
|
||||||
|
@ -25,14 +25,14 @@
|
|||||||
#include "EspnowNetworkInfo.h"
|
#include "EspnowNetworkInfo.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
EspnowNetworkInfo::EspnowNetworkInfo(int networkIndex) : NetworkInfoBase(networkIndex) { };
|
EspnowNetworkInfo::EspnowNetworkInfo(const int networkIndex) : NetworkInfoBase(networkIndex) { };
|
||||||
|
|
||||||
EspnowNetworkInfo::EspnowNetworkInfo(const NetworkInfoBase &originalNetworkInfo) : NetworkInfoBase(originalNetworkInfo)
|
EspnowNetworkInfo::EspnowNetworkInfo(const NetworkInfoBase &originalNetworkInfo) : NetworkInfoBase(originalNetworkInfo)
|
||||||
{
|
{
|
||||||
assert(BSSID() != defaultBSSID); // We need at least BSSID to be able to connect.
|
assert(BSSID() != defaultBSSID); // We need at least BSSID to be able to connect.
|
||||||
};
|
};
|
||||||
|
|
||||||
EspnowNetworkInfo::EspnowNetworkInfo(const uint8_t BSSID[6], const String &SSID, int32_t wifiChannel, uint8_t encryptionType, int32_t RSSI , bool isHidden)
|
EspnowNetworkInfo::EspnowNetworkInfo(const uint8_t BSSID[6], const String &SSID, const int32_t wifiChannel, const uint8_t encryptionType, const int32_t RSSI , const bool isHidden)
|
||||||
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden)
|
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
@ -34,12 +34,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
||||||
*/
|
*/
|
||||||
EspnowNetworkInfo(int networkIndex);
|
EspnowNetworkInfo(const int networkIndex);
|
||||||
|
|
||||||
EspnowNetworkInfo(const NetworkInfoBase &originalNetworkInfo);
|
EspnowNetworkInfo(const NetworkInfoBase &originalNetworkInfo);
|
||||||
|
|
||||||
EspnowNetworkInfo(const uint8_t BSSID[6], const String &SSID = defaultSSID, int32_t wifiChannel = defaultWifiChannel, uint8_t encryptionType = defaultEncryptionType,
|
EspnowNetworkInfo(const uint8_t BSSID[6], const String &SSID = defaultSSID, const int32_t wifiChannel = defaultWifiChannel, const uint8_t encryptionType = defaultEncryptionType,
|
||||||
int32_t RSSI = defaultRSSI, bool isHidden = defaultIsHidden);
|
const int32_t RSSI = defaultRSSI, const bool isHidden = defaultIsHidden);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,7 +36,7 @@ namespace EspnowProtocolInterpreter
|
|||||||
return espnowProtocolBytesSize + (EspnowMeshBackend::useEncryptedMessages() ? aeadMetadataSize : 0);
|
return espnowProtocolBytesSize + (EspnowMeshBackend::useEncryptedMessages() ? aeadMetadataSize : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
String espnowGetMessageContent(uint8_t *transmissionDataArray, uint8_t transmissionLength)
|
String espnowGetMessageContent(uint8_t *transmissionDataArray, const uint8_t transmissionLength)
|
||||||
{
|
{
|
||||||
String messageContent = emptyString;
|
String messageContent = emptyString;
|
||||||
|
|
||||||
@ -81,12 +81,12 @@ namespace EspnowProtocolInterpreter
|
|||||||
return TypeCast::uint8ArrayToUint64(transmissionDataArray + espnowMessageIDIndex);
|
return TypeCast::uint8ArrayToUint64(transmissionDataArray + espnowMessageIDIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *espnowSetMessageID(uint8_t *transmissionDataArray, uint64_t messageID)
|
uint8_t *espnowSetMessageID(uint8_t *transmissionDataArray, const uint64_t messageID)
|
||||||
{
|
{
|
||||||
return TypeCast::uint64ToUint8Array(messageID, transmissionDataArray + espnowMessageIDIndex);
|
return TypeCast::uint64ToUint8Array(messageID, transmissionDataArray + espnowMessageIDIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usesEncryption(uint64_t messageID)
|
bool usesEncryption(const uint64_t messageID)
|
||||||
{
|
{
|
||||||
// At least one of the leftmost half of bits in messageID is 1 if the transmission is encrypted.
|
// At least one of the leftmost half of bits in messageID is 1 if the transmission is encrypted.
|
||||||
return messageID & uint64LeftmostBits;
|
return messageID & uint64LeftmostBits;
|
||||||
|
@ -63,7 +63,7 @@ namespace EspnowProtocolInterpreter
|
|||||||
|
|
||||||
constexpr uint64_t uint64LeftmostBits = 0xFFFFFFFF00000000;
|
constexpr uint64_t uint64LeftmostBits = 0xFFFFFFFF00000000;
|
||||||
|
|
||||||
String espnowGetMessageContent(uint8_t *transmissionDataArray, uint8_t transmissionLength);
|
String espnowGetMessageContent(uint8_t *transmissionDataArray, const uint8_t transmissionLength);
|
||||||
char espnowGetMessageType(const uint8_t *transmissionDataArray);
|
char espnowGetMessageType(const uint8_t *transmissionDataArray);
|
||||||
uint8_t espnowGetTransmissionsRemaining(const uint8_t *transmissionDataArray);
|
uint8_t espnowGetTransmissionsRemaining(const uint8_t *transmissionDataArray);
|
||||||
bool espnowIsMessageStart(const uint8_t *transmissionDataArray);
|
bool espnowIsMessageStart(const uint8_t *transmissionDataArray);
|
||||||
@ -71,9 +71,9 @@ namespace EspnowProtocolInterpreter
|
|||||||
uint8_t *espnowGetTransmissionMac(const uint8_t *transmissionDataArray, uint8_t *resultArray);
|
uint8_t *espnowGetTransmissionMac(const uint8_t *transmissionDataArray, uint8_t *resultArray);
|
||||||
uint64_t espnowGetMessageID(const uint8_t *transmissionDataArray);
|
uint64_t espnowGetMessageID(const uint8_t *transmissionDataArray);
|
||||||
// @return a pointer to transmissionDataArray
|
// @return a pointer to transmissionDataArray
|
||||||
uint8_t *espnowSetMessageID(uint8_t *transmissionDataArray, uint64_t messageID);
|
uint8_t *espnowSetMessageID(uint8_t *transmissionDataArray, const uint64_t messageID);
|
||||||
|
|
||||||
bool usesEncryption(uint64_t messageID);
|
bool usesEncryption(const uint64_t messageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -38,7 +38,7 @@ std::set<FloodingMesh *> FloodingMesh::availableFloodingMeshes = {};
|
|||||||
|
|
||||||
char FloodingMesh::_metadataDelimiter = 23;
|
char FloodingMesh::_metadataDelimiter = 23;
|
||||||
|
|
||||||
void floodingMeshDelay(uint32_t durationMs)
|
void floodingMeshDelay(const uint32_t durationMs)
|
||||||
{
|
{
|
||||||
ExpiringTimeTracker timeout(durationMs);
|
ExpiringTimeTracker timeout(durationMs);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ void floodingMeshDelay(uint32_t durationMs)
|
|||||||
|
|
||||||
FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel)
|
const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel)
|
||||||
: _espnowBackend(
|
: _espnowBackend(
|
||||||
[this](const String &request, MeshBackendBase &meshInstance){ return _defaultRequestHandler(request, meshInstance); },
|
[this](const String &request, MeshBackendBase &meshInstance){ return _defaultRequestHandler(request, meshInstance); },
|
||||||
[this](const String &response, MeshBackendBase &meshInstance){ return _defaultResponseHandler(response, meshInstance); },
|
[this](const String &response, MeshBackendBase &meshInstance){ return _defaultResponseHandler(response, meshInstance); },
|
||||||
@ -68,7 +68,7 @@ FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &mesh
|
|||||||
}
|
}
|
||||||
|
|
||||||
FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed,
|
FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed,
|
||||||
const String &ssidPrefix, const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel)
|
const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel)
|
||||||
: FloodingMesh(messageHandler, meshPassword, (const uint8_t[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength]){0},
|
: FloodingMesh(messageHandler, meshPassword, (const uint8_t[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength]){0},
|
||||||
(const uint8_t[EspnowProtocolInterpreter::espnowHashKeyLength]){0}, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
(const uint8_t[EspnowProtocolInterpreter::espnowHashKeyLength]){0}, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ FloodingMesh::FloodingMesh(messageHandlerType messageHandler, const String &mesh
|
|||||||
FloodingMesh::FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
FloodingMesh::FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
||||||
const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel)
|
const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel)
|
||||||
: FloodingMesh(messageHandler, meshPassword, espnowEncryptedConnectionKey, espnowHashKey, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
: FloodingMesh(messageHandler, meshPassword, espnowEncryptedConnectionKey, espnowHashKey, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
||||||
{
|
{
|
||||||
loadMeshState(serializedMeshState);
|
loadMeshState(serializedMeshState);
|
||||||
@ -87,7 +87,7 @@ FloodingMesh::FloodingMesh(const String &serializedMeshState, messageHandlerType
|
|||||||
|
|
||||||
FloodingMesh::FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
FloodingMesh::FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
||||||
const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed, const String &ssidPrefix,
|
const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed, const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel)
|
const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel)
|
||||||
: FloodingMesh(messageHandler, meshPassword, espnowEncryptedConnectionKeySeed, espnowHashKeySeed, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
: FloodingMesh(messageHandler, meshPassword, espnowEncryptedConnectionKeySeed, espnowHashKeySeed, ssidPrefix, ssidSuffix, verboseMode, meshWiFiChannel)
|
||||||
{
|
{
|
||||||
loadMeshState(serializedMeshState);
|
loadMeshState(serializedMeshState);
|
||||||
@ -151,13 +151,13 @@ void FloodingMesh::performMeshInstanceMaintenance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String FloodingMesh::serializeMeshState()
|
String FloodingMesh::serializeMeshState() const
|
||||||
{
|
{
|
||||||
using namespace JsonTranslator;
|
using namespace JsonTranslator;
|
||||||
|
|
||||||
// Returns: {"meshState":{"connectionState":{"unsyncMsgID":"123"},"meshMsgCount":"123"}}
|
// Returns: {"meshState":{"connectionState":{"unsyncMsgID":"123"},"meshMsgCount":"123"}}
|
||||||
|
|
||||||
String connectionState = getEspnowMeshBackend().serializeUnencryptedConnection();
|
String connectionState = getEspnowMeshBackendConst().serializeUnencryptedConnection();
|
||||||
|
|
||||||
return
|
return
|
||||||
String(F("{\"meshState\":{"))
|
String(F("{\"meshState\":{"))
|
||||||
@ -204,12 +204,12 @@ void FloodingMesh::broadcastKernel(const String &message)
|
|||||||
getEspnowMeshBackend().broadcast(message);
|
getEspnowMeshBackend().broadcast(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloodingMesh::setBroadcastReceptionRedundancy(uint8_t redundancy)
|
void FloodingMesh::setBroadcastReceptionRedundancy(const uint8_t redundancy)
|
||||||
{
|
{
|
||||||
assert(redundancy < 255);
|
assert(redundancy < 255);
|
||||||
_broadcastReceptionRedundancy = redundancy;
|
_broadcastReceptionRedundancy = redundancy;
|
||||||
}
|
}
|
||||||
uint8_t FloodingMesh::getBroadcastReceptionRedundancy() { return _broadcastReceptionRedundancy; }
|
uint8_t FloodingMesh::getBroadcastReceptionRedundancy() const { return _broadcastReceptionRedundancy; }
|
||||||
|
|
||||||
void FloodingMesh::encryptedBroadcast(const String &message)
|
void FloodingMesh::encryptedBroadcast(const String &message)
|
||||||
{
|
{
|
||||||
@ -236,40 +236,40 @@ void FloodingMesh::clearForwardingBacklog()
|
|||||||
_forwardingBacklog.clear();
|
_forwardingBacklog.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloodingMesh::setMessageHandler(messageHandlerType messageHandler) { _messageHandler = messageHandler; }
|
void FloodingMesh::setMessageHandler(const messageHandlerType messageHandler) { _messageHandler = messageHandler; }
|
||||||
FloodingMesh::messageHandlerType FloodingMesh::getMessageHandler() { return _messageHandler; }
|
FloodingMesh::messageHandlerType FloodingMesh::getMessageHandler() const { return _messageHandler; }
|
||||||
|
|
||||||
void FloodingMesh::setOriginMac(uint8_t *macArray)
|
void FloodingMesh::setOriginMac(const uint8_t *macArray)
|
||||||
{
|
{
|
||||||
std::copy_n(macArray, 6, _originMac);
|
std::copy_n(macArray, 6, _originMac);
|
||||||
}
|
}
|
||||||
|
|
||||||
String FloodingMesh::getOriginMac() { return TypeCast::macToString(_originMac); }
|
String FloodingMesh::getOriginMac() const { return TypeCast::macToString(_originMac); }
|
||||||
uint8_t *FloodingMesh::getOriginMac(uint8_t *macArray)
|
uint8_t *FloodingMesh::getOriginMac(uint8_t *macArray) const
|
||||||
{
|
{
|
||||||
std::copy_n(_originMac, 6, macArray);
|
std::copy_n(_originMac, 6, macArray);
|
||||||
return macArray;
|
return macArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FloodingMesh::maxUnencryptedMessageLength()
|
uint32_t FloodingMesh::maxUnencryptedMessageLength() const
|
||||||
{
|
{
|
||||||
return getEspnowMeshBackend().getMaxMessageLength() - MESSAGE_ID_LENGTH - (getEspnowMeshBackend().getMeshName().length() + 1); // Need room for mesh name + delimiter
|
return getEspnowMeshBackendConst().getMaxMessageLength() - MESSAGE_ID_LENGTH - (getEspnowMeshBackendConst().getMeshName().length() + 1); // Need room for mesh name + delimiter
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FloodingMesh::maxEncryptedMessageLength()
|
uint32_t FloodingMesh::maxEncryptedMessageLength() const
|
||||||
{
|
{
|
||||||
// Need 1 extra delimiter character for maximum metadata efficiency (makes it possible to store exactly 18 MACs in metadata by adding an extra transmission)
|
// Need 1 extra delimiter character for maximum metadata efficiency (makes it possible to store exactly 18 MACs in metadata by adding an extra transmission)
|
||||||
return getEspnowMeshBackend().getMaxMessageLength() - MESSAGE_ID_LENGTH - 1;
|
return getEspnowMeshBackendConst().getMaxMessageLength() - MESSAGE_ID_LENGTH - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloodingMesh::setMessageLogSize(uint16_t messageLogSize)
|
void FloodingMesh::setMessageLogSize(const uint16_t messageLogSize)
|
||||||
{
|
{
|
||||||
assert(messageLogSize >= 1);
|
assert(messageLogSize >= 1);
|
||||||
_messageLogSize = messageLogSize;
|
_messageLogSize = messageLogSize;
|
||||||
}
|
}
|
||||||
uint16_t FloodingMesh::messageLogSize() { return _messageLogSize; }
|
uint16_t FloodingMesh::messageLogSize() const { return _messageLogSize; }
|
||||||
|
|
||||||
void FloodingMesh::setMetadataDelimiter(char metadataDelimiter)
|
void FloodingMesh::setMetadataDelimiter(const char metadataDelimiter)
|
||||||
{
|
{
|
||||||
// Using HEX number characters as a delimiter is a bad idea regardless of broadcast type, since they are always in the broadcast metadata.
|
// Using HEX number characters as a delimiter is a bad idea regardless of broadcast type, since they are always in the broadcast metadata.
|
||||||
// We therefore check for those characters below.
|
// We therefore check for those characters below.
|
||||||
@ -286,7 +286,12 @@ EspnowMeshBackend &FloodingMesh::getEspnowMeshBackend()
|
|||||||
return _espnowBackend;
|
return _espnowBackend;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloodingMesh::insertPreliminaryMessageID(uint64_t messageID)
|
const EspnowMeshBackend &FloodingMesh::getEspnowMeshBackendConst() const
|
||||||
|
{
|
||||||
|
return _espnowBackend;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FloodingMesh::insertPreliminaryMessageID(const uint64_t messageID)
|
||||||
{
|
{
|
||||||
uint8_t apMacArray[6] = { 0 };
|
uint8_t apMacArray[6] = { 0 };
|
||||||
if(messageID >> 16 == TypeCast::macToUint64(WiFi.softAPmacAddress(apMacArray)))
|
if(messageID >> 16 == TypeCast::macToUint64(WiFi.softAPmacAddress(apMacArray)))
|
||||||
@ -304,7 +309,7 @@ bool FloodingMesh::insertPreliminaryMessageID(uint64_t messageID)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloodingMesh::insertCompletedMessageID(uint64_t messageID)
|
bool FloodingMesh::insertCompletedMessageID(const uint64_t messageID)
|
||||||
{
|
{
|
||||||
uint8_t apMacArray[6] = { 0 };
|
uint8_t apMacArray[6] = { 0 };
|
||||||
if(messageID >> 16 == TypeCast::macToUint64(WiFi.softAPmacAddress(apMacArray)))
|
if(messageID >> 16 == TypeCast::macToUint64(WiFi.softAPmacAddress(apMacArray)))
|
||||||
@ -322,7 +327,7 @@ bool FloodingMesh::insertCompletedMessageID(uint64_t messageID)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloodingMesh::updateMessageQueue(messageQueueElementType messageIterator)
|
void FloodingMesh::updateMessageQueue(const messageQueueElementType messageIterator)
|
||||||
{
|
{
|
||||||
_messageIdOrder.emplace(messageIterator);
|
_messageIdOrder.emplace(messageIterator);
|
||||||
|
|
||||||
@ -449,7 +454,7 @@ TransmissionStatusType FloodingMesh::_defaultResponseHandler(const String &respo
|
|||||||
* @param numberOfNetworks The number of networks found in the WiFi scan.
|
* @param numberOfNetworks The number of networks found in the WiFi scan.
|
||||||
* @param meshInstance The MeshBackendBase instance that called the function.
|
* @param meshInstance The MeshBackendBase instance that called the function.
|
||||||
*/
|
*/
|
||||||
void FloodingMesh::_defaultNetworkFilter(int numberOfNetworks, MeshBackendBase &meshInstance)
|
void FloodingMesh::_defaultNetworkFilter(const int numberOfNetworks, MeshBackendBase &meshInstance)
|
||||||
{
|
{
|
||||||
// Note that the network index of a given node may change whenever a new scan is done.
|
// Note that the network index of a given node may change whenever a new scan is done.
|
||||||
for (int networkIndex = 0; networkIndex < numberOfNetworks; ++networkIndex)
|
for (int networkIndex = 0; networkIndex < numberOfNetworks; ++networkIndex)
|
||||||
@ -554,7 +559,7 @@ bool FloodingMesh::_defaultTransmissionOutcomesUpdateHook(MeshBackendBase &meshI
|
|||||||
* @return True if the response transmission process should continue with the next response in the waiting list.
|
* @return True if the response transmission process should continue with the next response in the waiting list.
|
||||||
* False if the response transmission process should stop after removing the just sent response from the waiting list.
|
* False if the response transmission process should stop after removing the just sent response from the waiting list.
|
||||||
*/
|
*/
|
||||||
bool FloodingMesh::_defaultResponseTransmittedHook(const String &response, const uint8_t *recipientMac, uint32_t responseIndex, EspnowMeshBackend &meshInstance)
|
bool FloodingMesh::_defaultResponseTransmittedHook(const String &response, const uint8_t *recipientMac, const uint32_t responseIndex, EspnowMeshBackend &meshInstance)
|
||||||
{
|
{
|
||||||
(void)response; // This is useful to remove a "unused parameter" compiler warning. Does nothing else.
|
(void)response; // This is useful to remove a "unused parameter" compiler warning. Does nothing else.
|
||||||
(void)recipientMac;
|
(void)recipientMac;
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
*
|
*
|
||||||
* @param durationMs The shortest allowed delay duration, in milliseconds.
|
* @param durationMs The shortest allowed delay duration, in milliseconds.
|
||||||
*/
|
*/
|
||||||
void floodingMeshDelay(uint32_t durationMs);
|
void floodingMeshDelay(const uint32_t durationMs);
|
||||||
|
|
||||||
class FloodingMesh {
|
class FloodingMesh {
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FloodingMesh constructor method. Creates a FloodingMesh node, ready to be initialised.
|
* FloodingMesh constructor method. Creates a FloodingMesh node, ready to be initialised.
|
||||||
@ -90,7 +90,7 @@ public:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed,
|
FloodingMesh(messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed, const String &espnowHashKeySeed,
|
||||||
const String &ssidPrefix, const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor should be used in combination with serializeMeshState() when the node has gone to sleep while other nodes stayed awake.
|
* This constructor should be used in combination with serializeMeshState() when the node has gone to sleep while other nodes stayed awake.
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword,
|
||||||
const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
const uint8_t espnowEncryptedConnectionKey[EspnowProtocolInterpreter::espnowEncryptedConnectionKeyLength],
|
||||||
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
const uint8_t espnowHashKey[EspnowProtocolInterpreter::espnowHashKeyLength], const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor should be used in combination with serializeMeshState() when the node has gone to sleep while other nodes stayed awake.
|
* This constructor should be used in combination with serializeMeshState() when the node has gone to sleep while other nodes stayed awake.
|
||||||
@ -110,7 +110,7 @@ public:
|
|||||||
* @param serializedMeshState A String with a serialized mesh node state that the node should use.
|
* @param serializedMeshState A String with a serialized mesh node state that the node should use.
|
||||||
*/
|
*/
|
||||||
FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed,
|
FloodingMesh(const String &serializedMeshState, messageHandlerType messageHandler, const String &meshPassword, const String &espnowEncryptedConnectionKeySeed,
|
||||||
const String &espnowHashKeySeed, const String &ssidPrefix, const String &ssidSuffix, bool verboseMode = false, uint8 meshWiFiChannel = 1);
|
const String &espnowHashKeySeed, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode = false, const uint8 meshWiFiChannel = 1);
|
||||||
|
|
||||||
virtual ~FloodingMesh();
|
virtual ~FloodingMesh();
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A string with the serialized current mesh node state.
|
* @return A string with the serialized current mesh node state.
|
||||||
*/
|
*/
|
||||||
String serializeMeshState();
|
String serializeMeshState() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an unencrypted broadcast to the entire mesh network.
|
* Make an unencrypted broadcast to the entire mesh network.
|
||||||
@ -173,8 +173,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param redundancy The maximum number of extra copies that will be accepted. Defaults to 2. Valid values are 0 to 254.
|
* @param redundancy The maximum number of extra copies that will be accepted. Defaults to 2. Valid values are 0 to 254.
|
||||||
*/
|
*/
|
||||||
void setBroadcastReceptionRedundancy(uint8_t redundancy);
|
void setBroadcastReceptionRedundancy(const uint8_t redundancy);
|
||||||
uint8_t getBroadcastReceptionRedundancy();
|
uint8_t getBroadcastReceptionRedundancy() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an encrypted broadcast to the entire mesh network.
|
* Make an encrypted broadcast to the entire mesh network.
|
||||||
@ -205,8 +205,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param messageHandler The message handler callback function to use.
|
* @param messageHandler The message handler callback function to use.
|
||||||
*/
|
*/
|
||||||
void setMessageHandler(messageHandlerType messageHandler);
|
void setMessageHandler(const messageHandlerType messageHandler);
|
||||||
messageHandlerType getMessageHandler();
|
messageHandlerType getMessageHandler() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the origin AP MAC address of the most recently received mesh message.
|
* Get the origin AP MAC address of the most recently received mesh message.
|
||||||
@ -214,7 +214,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A String filled with a hexadecimal representation of the MAC, without delimiters.
|
* @return A String filled with a hexadecimal representation of the MAC, without delimiters.
|
||||||
*/
|
*/
|
||||||
String getOriginMac();
|
String getOriginMac() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the origin AP MAC address of the most recently received mesh message.
|
* Get the origin AP MAC address of the most recently received mesh message.
|
||||||
@ -223,7 +223,7 @@ public:
|
|||||||
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
* @param macArray The array that should store the MAC address. Must be at least 6 bytes.
|
||||||
* @return macArray filled with the origin MAC.
|
* @return macArray filled with the origin MAC.
|
||||||
*/
|
*/
|
||||||
uint8_t *getOriginMac(uint8_t *macArray);
|
uint8_t *getOriginMac(uint8_t *macArray) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of received messageID:s that will be stored by the node. Used to remember which messages have been received.
|
* The number of received messageID:s that will be stored by the node. Used to remember which messages have been received.
|
||||||
@ -237,8 +237,8 @@ public:
|
|||||||
* If a value close to the maximum is chosen, there is a high risk the node will ignore transmissions on messageID rollover if they are sent only by one node
|
* If a value close to the maximum is chosen, there is a high risk the node will ignore transmissions on messageID rollover if they are sent only by one node
|
||||||
* (especially if some transmissions are missed), since the messageID also uses uint16_t.
|
* (especially if some transmissions are missed), since the messageID also uses uint16_t.
|
||||||
*/
|
*/
|
||||||
void setMessageLogSize(uint16_t messageLogSize);
|
void setMessageLogSize(const uint16_t messageLogSize);
|
||||||
uint16_t messageLogSize();
|
uint16_t messageLogSize() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hint: Use String.length() to get the ASCII length of a String.
|
* Hint: Use String.length() to get the ASCII length of a String.
|
||||||
@ -247,7 +247,7 @@ public:
|
|||||||
* Note that non-ASCII characters usually require at least two bytes each.
|
* Note that non-ASCII characters usually require at least two bytes each.
|
||||||
* Also note that for unencrypted messages the maximum size will depend on getEspnowMeshBackend().getMeshName().length()
|
* Also note that for unencrypted messages the maximum size will depend on getEspnowMeshBackend().getMeshName().length()
|
||||||
*/
|
*/
|
||||||
uint32_t maxUnencryptedMessageLength();
|
uint32_t maxUnencryptedMessageLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hint: Use String.length() to get the ASCII length of a String.
|
* Hint: Use String.length() to get the ASCII length of a String.
|
||||||
@ -255,7 +255,7 @@ public:
|
|||||||
* @return The maximum length in bytes an encrypted ASCII message is allowed to be when broadcasted by this node.
|
* @return The maximum length in bytes an encrypted ASCII message is allowed to be when broadcasted by this node.
|
||||||
* Note that non-ASCII characters usually require at least two bytes each.
|
* Note that non-ASCII characters usually require at least two bytes each.
|
||||||
*/
|
*/
|
||||||
uint32_t maxEncryptedMessageLength();
|
uint32_t maxEncryptedMessageLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the delimiter character used for metadata by every FloodingMesh instance.
|
* Set the delimiter character used for metadata by every FloodingMesh instance.
|
||||||
@ -264,7 +264,7 @@ public:
|
|||||||
* @param metadataDelimiter The metadata delimiter character to use.
|
* @param metadataDelimiter The metadata delimiter character to use.
|
||||||
* Defaults to 23 = End-of-Transmission-Block (ETB) control character in ASCII
|
* Defaults to 23 = End-of-Transmission-Block (ETB) control character in ASCII
|
||||||
*/
|
*/
|
||||||
static void setMetadataDelimiter(char metadataDelimiter);
|
static void setMetadataDelimiter(const char metadataDelimiter);
|
||||||
static char metadataDelimiter();
|
static char metadataDelimiter();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -274,6 +274,7 @@ public:
|
|||||||
* and so are discouraged for those who prefer it when things just work.
|
* and so are discouraged for those who prefer it when things just work.
|
||||||
*/
|
*/
|
||||||
EspnowMeshBackend &getEspnowMeshBackend();
|
EspnowMeshBackend &getEspnowMeshBackend();
|
||||||
|
const EspnowMeshBackend &getEspnowMeshBackendConst() const;
|
||||||
|
|
||||||
void restoreDefaultRequestHandler();
|
void restoreDefaultRequestHandler();
|
||||||
void restoreDefaultResponseHandler();
|
void restoreDefaultResponseHandler();
|
||||||
@ -292,9 +293,9 @@ protected:
|
|||||||
|
|
||||||
void encryptedBroadcastKernel(const String &message);
|
void encryptedBroadcastKernel(const String &message);
|
||||||
|
|
||||||
bool insertPreliminaryMessageID(uint64_t messageID);
|
bool insertPreliminaryMessageID(const uint64_t messageID);
|
||||||
bool insertCompletedMessageID(uint64_t messageID);
|
bool insertCompletedMessageID(const uint64_t messageID);
|
||||||
void updateMessageQueue(messageQueueElementType messageIterator);
|
void updateMessageQueue(const messageQueueElementType messageIterator);
|
||||||
|
|
||||||
void loadMeshState(const String &serializedMeshState);
|
void loadMeshState(const String &serializedMeshState);
|
||||||
|
|
||||||
@ -303,7 +304,7 @@ protected:
|
|||||||
*
|
*
|
||||||
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
* @param macArray An uint8_t array which contains the MAC address to store. The method will store the first 6 bytes of the array.
|
||||||
*/
|
*/
|
||||||
void setOriginMac(uint8_t *macArray);
|
void setOriginMac(const uint8_t *macArray);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -328,10 +329,10 @@ private:
|
|||||||
|
|
||||||
String _defaultRequestHandler(const String &request, MeshBackendBase &meshInstance);
|
String _defaultRequestHandler(const String &request, MeshBackendBase &meshInstance);
|
||||||
TransmissionStatusType _defaultResponseHandler(const String &response, MeshBackendBase &meshInstance);
|
TransmissionStatusType _defaultResponseHandler(const String &response, MeshBackendBase &meshInstance);
|
||||||
void _defaultNetworkFilter(int numberOfNetworks, MeshBackendBase &meshInstance);
|
void _defaultNetworkFilter(const int numberOfNetworks, MeshBackendBase &meshInstance);
|
||||||
bool _defaultBroadcastFilter(String &firstTransmission, EspnowMeshBackend &meshInstance);
|
bool _defaultBroadcastFilter(String &firstTransmission, EspnowMeshBackend &meshInstance);
|
||||||
bool _defaultTransmissionOutcomesUpdateHook(MeshBackendBase &meshInstance);
|
bool _defaultTransmissionOutcomesUpdateHook(MeshBackendBase &meshInstance);
|
||||||
bool _defaultResponseTransmittedHook(const String &response, const uint8_t *recipientMac, uint32_t responseIndex, EspnowMeshBackend &meshInstance);
|
bool _defaultResponseTransmittedHook(const String &response, const uint8_t *recipientMac, const uint32_t responseIndex, EspnowMeshBackend &meshInstance);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,7 @@ namespace JsonTranslator
|
|||||||
return valueIdentifier + '\"' + value + F("\"}}");
|
return valueIdentifier + '\"' + value + F("\"}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
String createEncryptedConnectionInfo(const String &infoHeader, const String &requestNonce, const String &authenticationPassword, uint64_t ownSessionKey, uint64_t peerSessionKey)
|
String createEncryptedConnectionInfo(const String &infoHeader, const String &requestNonce, const String &authenticationPassword, const uint64_t ownSessionKey, const uint64_t peerSessionKey)
|
||||||
{
|
{
|
||||||
// Returns: Encrypted connection info:{"arguments":{"nonce":"1F2","password":"abc","ownSK":"3B4","peerSK":"1A2"}}
|
// Returns: Encrypted connection info:{"arguments":{"nonce":"1F2","password":"abc","ownSK":"3B4","peerSK":"1A2"}}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ namespace JsonTranslator
|
|||||||
+ createJsonEndPair(FPSTR(jsonPeerSessionKey), TypeCast::uint64ToString(ownSessionKey));
|
+ createJsonEndPair(FPSTR(jsonPeerSessionKey), TypeCast::uint64ToString(ownSessionKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
String createEncryptionRequestIntro(const String &requestHeader, uint32_t duration)
|
String createEncryptionRequestIntro(const String &requestHeader, const uint32_t duration)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
requestHeader + String(F("{\"arguments\":{"))
|
requestHeader + String(F("{\"arguments\":{"))
|
||||||
@ -65,7 +65,7 @@ namespace JsonTranslator
|
|||||||
return createJsonEndPair(FPSTR(jsonNonce), requestNonce);
|
return createJsonEndPair(FPSTR(jsonNonce), requestNonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
String createEncryptionRequestHmacMessage(const String &requestHeader, const String &requestNonce, const uint8_t *hashKey, uint8_t hashKeyLength, uint32_t duration)
|
String createEncryptionRequestHmacMessage(const String &requestHeader, const String &requestNonce, const uint8_t *hashKey, const uint8_t hashKeyLength, const uint32_t duration)
|
||||||
{
|
{
|
||||||
String mainMessage = createEncryptionRequestIntro(requestHeader, duration) + createJsonPair(FPSTR(jsonNonce), requestNonce);
|
String mainMessage = createEncryptionRequestIntro(requestHeader, duration) + createJsonPair(FPSTR(jsonNonce), requestNonce);
|
||||||
uint8_t staMac[6] {0};
|
uint8_t staMac[6] {0};
|
||||||
@ -76,7 +76,7 @@ namespace JsonTranslator
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool verifyEncryptionRequestHmac(const String &encryptionRequestHmacMessage, const uint8_t *requesterStaMac, const uint8_t *requesterApMac,
|
bool verifyEncryptionRequestHmac(const String &encryptionRequestHmacMessage, const uint8_t *requesterStaMac, const uint8_t *requesterApMac,
|
||||||
const uint8_t *hashKey, uint8_t hashKeyLength)
|
const uint8_t *hashKey, const uint8_t hashKeyLength)
|
||||||
{
|
{
|
||||||
using MeshCryptoInterface::verifyMeshHmac;
|
using MeshCryptoInterface::verifyMeshHmac;
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ namespace JsonTranslator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getStartIndex(const String &jsonString, const String &valueIdentifier, int32_t searchStartIndex)
|
int32_t getStartIndex(const String &jsonString, const String &valueIdentifier, const int32_t searchStartIndex)
|
||||||
{
|
{
|
||||||
int32_t startIndex = jsonString.indexOf(valueIdentifier, searchStartIndex);
|
int32_t startIndex = jsonString.indexOf(valueIdentifier, searchStartIndex);
|
||||||
if(startIndex < 0)
|
if(startIndex < 0)
|
||||||
@ -107,7 +107,7 @@ namespace JsonTranslator
|
|||||||
return startIndex;
|
return startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getEndIndex(const String &jsonString, int32_t searchStartIndex)
|
int32_t getEndIndex(const String &jsonString, const int32_t searchStartIndex)
|
||||||
{
|
{
|
||||||
int32_t endIndex = jsonString.indexOf(',', searchStartIndex);
|
int32_t endIndex = jsonString.indexOf(',', searchStartIndex);
|
||||||
if(endIndex < 0)
|
if(endIndex < 0)
|
||||||
|
@ -45,12 +45,12 @@ namespace JsonTranslator
|
|||||||
String createJsonPair(const String &valueIdentifier, const String &value);
|
String createJsonPair(const String &valueIdentifier, const String &value);
|
||||||
String createJsonEndPair(const String &valueIdentifier, const String &value);
|
String createJsonEndPair(const String &valueIdentifier, const String &value);
|
||||||
|
|
||||||
String createEncryptedConnectionInfo(const String &infoHeader, const String &requestNonce, const String &authenticationPassword, uint64_t ownSessionKey, uint64_t peerSessionKey);
|
String createEncryptedConnectionInfo(const String &infoHeader, const String &requestNonce, const String &authenticationPassword, const uint64_t ownSessionKey, const uint64_t peerSessionKey);
|
||||||
String createEncryptionRequestIntro(const String &requestHeader, uint32_t duration = 0);
|
String createEncryptionRequestIntro(const String &requestHeader, const uint32_t duration = 0);
|
||||||
String createEncryptionRequestEnding(const String &requestNonce);
|
String createEncryptionRequestEnding(const String &requestNonce);
|
||||||
String createEncryptionRequestHmacMessage(const String &requestHeader, const String &requestNonce, const uint8_t *hashKey, uint8_t hashKeyLength, uint32_t duration = 0);
|
String createEncryptionRequestHmacMessage(const String &requestHeader, const String &requestNonce, const uint8_t *hashKey, const uint8_t hashKeyLength, const uint32_t duration = 0);
|
||||||
|
|
||||||
bool verifyEncryptionRequestHmac(const String &encryptionRequestHmacMessage, const uint8_t *requesterStaMac, const uint8_t *requesterApMac, const uint8_t *hashKey, uint8_t hashKeyLength);
|
bool verifyEncryptionRequestHmac(const String &encryptionRequestHmacMessage, const uint8_t *requesterStaMac, const uint8_t *requesterApMac, const uint8_t *hashKey, const uint8_t hashKeyLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the index within jsonString where the value of valueIdentifier starts.
|
* Provides the index within jsonString where the value of valueIdentifier starts.
|
||||||
@ -61,7 +61,7 @@ namespace JsonTranslator
|
|||||||
*
|
*
|
||||||
* @return An int32_t containing the index within jsonString where the value of valueIdentifier starts, or a negative value if valueIdentifier was not found.
|
* @return An int32_t containing the index within jsonString where the value of valueIdentifier starts, or a negative value if valueIdentifier was not found.
|
||||||
*/
|
*/
|
||||||
int32_t getStartIndex(const String &jsonString, const String &valueIdentifier, int32_t searchStartIndex = 0);
|
int32_t getStartIndex(const String &jsonString, const String &valueIdentifier, const int32_t searchStartIndex = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the index within jsonString where the next JSON termination character (',' or '}') is found, starting from searchStartIndex.
|
* Provides the index within jsonString where the next JSON termination character (',' or '}') is found, starting from searchStartIndex.
|
||||||
@ -71,7 +71,7 @@ namespace JsonTranslator
|
|||||||
*
|
*
|
||||||
* @return An int32_t containing the index within jsonString where the next JSON termination character is found, or a negative value if no such character was found.
|
* @return An int32_t containing the index within jsonString where the next JSON termination character is found, or a negative value if no such character was found.
|
||||||
*/
|
*/
|
||||||
int32_t getEndIndex(const String &jsonString, int32_t searchStartIndex);
|
int32_t getEndIndex(const String &jsonString, const int32_t searchStartIndex);
|
||||||
|
|
||||||
bool getConnectionState(const String &jsonString, String &result);
|
bool getConnectionState(const String &jsonString, String &result);
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ std::shared_ptr<bool> MeshBackendBase::_scanMutex = std::make_shared<bool>(false
|
|||||||
|
|
||||||
bool MeshBackendBase::_printWarnings = true;
|
bool MeshBackendBase::_printWarnings = true;
|
||||||
|
|
||||||
MeshBackendBase::MeshBackendBase(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter, MeshBackendType classType)
|
MeshBackendBase::MeshBackendBase(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter, const MeshBackendType classType)
|
||||||
{
|
{
|
||||||
setRequestHandler(requestHandler);
|
setRequestHandler(requestHandler);
|
||||||
setResponseHandler(responseHandler);
|
setResponseHandler(responseHandler);
|
||||||
@ -43,12 +43,12 @@ MeshBackendBase::~MeshBackendBase()
|
|||||||
deactivateControlledAP();
|
deactivateControlledAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshBackendBase::setClassType(MeshBackendType classType)
|
void MeshBackendBase::setClassType(const MeshBackendType classType)
|
||||||
{
|
{
|
||||||
_classType = classType;
|
_classType = classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshBackendType MeshBackendBase::getClassType() {return _classType;}
|
MeshBackendType MeshBackendBase::getClassType() const {return _classType;}
|
||||||
|
|
||||||
void MeshBackendBase::activateAP()
|
void MeshBackendBase::activateAP()
|
||||||
{
|
{
|
||||||
@ -108,12 +108,12 @@ MeshBackendBase *MeshBackendBase::getAPController()
|
|||||||
return apController;
|
return apController;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeshBackendBase::isAPController()
|
bool MeshBackendBase::isAPController() const
|
||||||
{
|
{
|
||||||
return (this == getAPController());
|
return (this == getAPController());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshBackendBase::setWiFiChannel(uint8 newWiFiChannel)
|
void MeshBackendBase::setWiFiChannel(const uint8 newWiFiChannel)
|
||||||
{
|
{
|
||||||
wifi_country_t wifiCountry;
|
wifi_country_t wifiCountry;
|
||||||
wifi_get_country(&wifiCountry); // Note: Should return 0 on success and -1 on failure, but always seems to return 1. Possibly broken API. Channels 1 to 13 are the default limits.
|
wifi_get_country(&wifiCountry); // Note: Should return 0 on success and -1 on failure, but always seems to return 1. Possibly broken API. Channels 1 to 13 are the default limits.
|
||||||
@ -188,14 +188,14 @@ void MeshBackendBase::setMeshName(const String &newMeshName)
|
|||||||
setSSIDPrefix(newMeshName);
|
setSSIDPrefix(newMeshName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String MeshBackendBase::getMeshName() {return getSSIDPrefix();}
|
String MeshBackendBase::getMeshName() const {return getSSIDPrefix();}
|
||||||
|
|
||||||
void MeshBackendBase::setNodeID(const String &newNodeID)
|
void MeshBackendBase::setNodeID(const String &newNodeID)
|
||||||
{
|
{
|
||||||
setSSIDSuffix(newNodeID);
|
setSSIDSuffix(newNodeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
String MeshBackendBase::getNodeID() {return getSSIDSuffix();}
|
String MeshBackendBase::getNodeID() const {return getSSIDSuffix();}
|
||||||
|
|
||||||
void MeshBackendBase::setMeshPassword(const String &newMeshPassword)
|
void MeshBackendBase::setMeshPassword(const String &newMeshPassword)
|
||||||
{
|
{
|
||||||
@ -213,26 +213,26 @@ String MeshBackendBase::getMeshPassword() const {return _meshPassword;}
|
|||||||
void MeshBackendBase::setMessage(const String &newMessage) {_message = newMessage;}
|
void MeshBackendBase::setMessage(const String &newMessage) {_message = newMessage;}
|
||||||
String MeshBackendBase::getMessage() const {return _message;}
|
String MeshBackendBase::getMessage() const {return _message;}
|
||||||
|
|
||||||
void MeshBackendBase::setRequestHandler(MeshBackendBase::requestHandlerType requestHandler) {_requestHandler = requestHandler;}
|
void MeshBackendBase::setRequestHandler(const MeshBackendBase::requestHandlerType requestHandler) {_requestHandler = requestHandler;}
|
||||||
MeshBackendBase::requestHandlerType MeshBackendBase::getRequestHandler() {return _requestHandler;}
|
MeshBackendBase::requestHandlerType MeshBackendBase::getRequestHandler() const {return _requestHandler;}
|
||||||
|
|
||||||
void MeshBackendBase::setResponseHandler(MeshBackendBase::responseHandlerType responseHandler) {_responseHandler = responseHandler;}
|
void MeshBackendBase::setResponseHandler(const MeshBackendBase::responseHandlerType responseHandler) {_responseHandler = responseHandler;}
|
||||||
MeshBackendBase::responseHandlerType MeshBackendBase::getResponseHandler() {return _responseHandler;}
|
MeshBackendBase::responseHandlerType MeshBackendBase::getResponseHandler() const {return _responseHandler;}
|
||||||
|
|
||||||
void MeshBackendBase::setNetworkFilter(MeshBackendBase::networkFilterType networkFilter) {_networkFilter = networkFilter;}
|
void MeshBackendBase::setNetworkFilter(const MeshBackendBase::networkFilterType networkFilter) {_networkFilter = networkFilter;}
|
||||||
MeshBackendBase::networkFilterType MeshBackendBase::getNetworkFilter() {return _networkFilter;}
|
MeshBackendBase::networkFilterType MeshBackendBase::getNetworkFilter() const {return _networkFilter;}
|
||||||
|
|
||||||
void MeshBackendBase::setTransmissionOutcomesUpdateHook(MeshBackendBase::transmissionOutcomesUpdateHookType transmissionOutcomesUpdateHook) {_transmissionOutcomesUpdateHook = transmissionOutcomesUpdateHook;}
|
void MeshBackendBase::setTransmissionOutcomesUpdateHook(const MeshBackendBase::transmissionOutcomesUpdateHookType transmissionOutcomesUpdateHook) {_transmissionOutcomesUpdateHook = transmissionOutcomesUpdateHook;}
|
||||||
MeshBackendBase::transmissionOutcomesUpdateHookType MeshBackendBase::getTransmissionOutcomesUpdateHook() {return _transmissionOutcomesUpdateHook;}
|
MeshBackendBase::transmissionOutcomesUpdateHookType MeshBackendBase::getTransmissionOutcomesUpdateHook() const {return _transmissionOutcomesUpdateHook;}
|
||||||
|
|
||||||
void MeshBackendBase::setScanHidden(bool scanHidden)
|
void MeshBackendBase::setScanHidden(const bool scanHidden)
|
||||||
{
|
{
|
||||||
_scanHidden = scanHidden;
|
_scanHidden = scanHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeshBackendBase::getScanHidden() const {return _scanHidden;}
|
bool MeshBackendBase::getScanHidden() const {return _scanHidden;}
|
||||||
|
|
||||||
void MeshBackendBase::setAPHidden(bool apHidden)
|
void MeshBackendBase::setAPHidden(const bool apHidden)
|
||||||
{
|
{
|
||||||
if(getAPHidden() != apHidden)
|
if(getAPHidden() != apHidden)
|
||||||
{
|
{
|
||||||
@ -258,7 +258,7 @@ bool MeshBackendBase::latestTransmissionSuccessfulBase(const std::vector<Transmi
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshBackendBase::scanForNetworks(bool scanAllWiFiChannels)
|
void MeshBackendBase::scanForNetworks(const bool scanAllWiFiChannels)
|
||||||
{
|
{
|
||||||
MutexTracker mutexTracker(_scanMutex);
|
MutexTracker mutexTracker(_scanMutex);
|
||||||
if(!mutexTracker.mutexCaptured())
|
if(!mutexTracker.mutexCaptured())
|
||||||
|
@ -40,7 +40,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MeshBackendBase(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter, MeshBackendType classType);
|
MeshBackendBase(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter, const MeshBackendType classType);
|
||||||
|
|
||||||
virtual ~MeshBackendBase();
|
virtual ~MeshBackendBase();
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return True if this MeshBackendBase instance is in control of the ESP8266 AP. False otherwise.
|
* @return True if this MeshBackendBase instance is in control of the ESP8266 AP. False otherwise.
|
||||||
*/
|
*/
|
||||||
bool isAPController();
|
bool isAPController() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the WiFi channel used by this MeshBackendBase instance.
|
* Change the WiFi channel used by this MeshBackendBase instance.
|
||||||
@ -118,7 +118,7 @@ public:
|
|||||||
* @param newWiFiChannel The WiFi channel to change to. Valid values are determined by wifi_get_country, usually integers from 1 to 11 or 1 to 13.
|
* @param newWiFiChannel The WiFi channel to change to. Valid values are determined by wifi_get_country, usually integers from 1 to 11 or 1 to 13.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void setWiFiChannel(uint8 newWiFiChannel);
|
void setWiFiChannel(const uint8 newWiFiChannel);
|
||||||
uint8 getWiFiChannel() const;
|
uint8 getWiFiChannel() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,7 +175,7 @@ public:
|
|||||||
* @param newMeshName The mesh name to change to.
|
* @param newMeshName The mesh name to change to.
|
||||||
*/
|
*/
|
||||||
virtual void setMeshName(const String &newMeshName);
|
virtual void setMeshName(const String &newMeshName);
|
||||||
virtual String getMeshName();
|
virtual String getMeshName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the node id used by this MeshBackendBase instance.
|
* Change the node id used by this MeshBackendBase instance.
|
||||||
@ -187,7 +187,7 @@ public:
|
|||||||
* @param newNodeID The node id to change to.
|
* @param newNodeID The node id to change to.
|
||||||
*/
|
*/
|
||||||
virtual void setNodeID(const String &newNodeID);
|
virtual void setNodeID(const String &newNodeID);
|
||||||
virtual String getNodeID();
|
virtual String getNodeID() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the password used when connecting to other AP:s and when other nodes connect to the AP of this node.
|
* Set the password used when connecting to other AP:s and when other nodes connect to the AP of this node.
|
||||||
@ -207,16 +207,16 @@ public:
|
|||||||
void setMessage(const String &newMessage);
|
void setMessage(const String &newMessage);
|
||||||
String getMessage() const;
|
String getMessage() const;
|
||||||
|
|
||||||
virtual void attemptTransmission(const String &message, bool scan = true, bool scanAllWiFiChannels = false) = 0;
|
virtual void attemptTransmission(const String &message, const bool scan = true, const bool scanAllWiFiChannels = false) = 0;
|
||||||
|
|
||||||
void setRequestHandler(requestHandlerType requestHandler);
|
void setRequestHandler(const requestHandlerType requestHandler);
|
||||||
requestHandlerType getRequestHandler();
|
requestHandlerType getRequestHandler() const;
|
||||||
|
|
||||||
void setResponseHandler(responseHandlerType responseHandler);
|
void setResponseHandler(const responseHandlerType responseHandler);
|
||||||
responseHandlerType getResponseHandler();
|
responseHandlerType getResponseHandler() const;
|
||||||
|
|
||||||
void setNetworkFilter(networkFilterType networkFilter);
|
void setNetworkFilter(const networkFilterType networkFilter);
|
||||||
networkFilterType getNetworkFilter();
|
networkFilterType getNetworkFilter() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a function that should be called after each update of the latestTransmissionOutcomes vector during attemptTransmission. (which happens after each individual transmission has finished)
|
* Set a function that should be called after each update of the latestTransmissionOutcomes vector during attemptTransmission. (which happens after each individual transmission has finished)
|
||||||
@ -225,8 +225,8 @@ public:
|
|||||||
*
|
*
|
||||||
* Example use cases is modifying getMessage() between transmissions, or aborting attemptTransmission before all nodes in the connectionQueue have been contacted.
|
* Example use cases is modifying getMessage() between transmissions, or aborting attemptTransmission before all nodes in the connectionQueue have been contacted.
|
||||||
*/
|
*/
|
||||||
void setTransmissionOutcomesUpdateHook(transmissionOutcomesUpdateHookType transmissionOutcomesUpdateHook);
|
void setTransmissionOutcomesUpdateHook(const transmissionOutcomesUpdateHookType transmissionOutcomesUpdateHook);
|
||||||
transmissionOutcomesUpdateHookType getTransmissionOutcomesUpdateHook();
|
transmissionOutcomesUpdateHookType getTransmissionOutcomesUpdateHook() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether scan results from this MeshBackendBase instance will include WiFi networks with hidden SSIDs.
|
* Set whether scan results from this MeshBackendBase instance will include WiFi networks with hidden SSIDs.
|
||||||
@ -236,7 +236,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param scanHidden If true, WiFi networks with hidden SSIDs will be included in scan results.
|
* @param scanHidden If true, WiFi networks with hidden SSIDs will be included in scan results.
|
||||||
*/
|
*/
|
||||||
void setScanHidden(bool scanHidden);
|
void setScanHidden(const bool scanHidden);
|
||||||
bool getScanHidden() const;
|
bool getScanHidden() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,7 +247,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param apHidden If true, the WiFi network created will have a hidden SSID.
|
* @param apHidden If true, the WiFi network created will have a hidden SSID.
|
||||||
*/
|
*/
|
||||||
void setAPHidden(bool apHidden);
|
void setAPHidden(const bool apHidden);
|
||||||
bool getAPHidden() const;
|
bool getAPHidden() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -256,8 +256,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param enabled If true, library Serial prints are activated.
|
* @param enabled If true, library Serial prints are activated.
|
||||||
*/
|
*/
|
||||||
virtual void setVerboseModeState(bool enabled);
|
virtual void setVerboseModeState(const bool enabled);
|
||||||
virtual bool verboseMode();
|
virtual bool verboseMode() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only print stringToPrint if verboseMode() returns true.
|
* Only print stringToPrint if verboseMode() returns true.
|
||||||
@ -265,7 +265,7 @@ public:
|
|||||||
* @param stringToPrint String to print.
|
* @param stringToPrint String to print.
|
||||||
* @param newline If true, will end the print with a newline. True by default.
|
* @param newline If true, will end the print with a newline. True by default.
|
||||||
*/
|
*/
|
||||||
virtual void verboseModePrint(const String &stringToPrint, bool newline = true);
|
virtual void verboseModePrint(const String &stringToPrint, const bool newline = true) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the warnings occurring in the library will be printed to Serial or not. On by default.
|
* Set whether the warnings occurring in the library will be printed to Serial or not. On by default.
|
||||||
@ -273,7 +273,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param printEnabled If true, warning Serial prints from the library are activated.
|
* @param printEnabled If true, warning Serial prints from the library are activated.
|
||||||
*/
|
*/
|
||||||
static void setPrintWarnings(bool printEnabled);
|
static void setPrintWarnings(const bool printEnabled);
|
||||||
static bool printWarnings();
|
static bool printWarnings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,9 +282,9 @@ public:
|
|||||||
* @param stringToPrint String to print.
|
* @param stringToPrint String to print.
|
||||||
* @param newline If true, will end the print with a newline. True by default.
|
* @param newline If true, will end the print with a newline. True by default.
|
||||||
*/
|
*/
|
||||||
static void warningPrint(const String &stringToPrint, bool newline = true);
|
static void warningPrint(const String &stringToPrint, const bool newline = true);
|
||||||
|
|
||||||
MeshBackendType getClassType();
|
MeshBackendType getClassType() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
static bool latestTransmissionSuccessfulBase(const std::vector<TransmissionOutcome> &latestTransmissionOutcomes);
|
static bool latestTransmissionSuccessfulBase(const std::vector<TransmissionOutcome> &latestTransmissionOutcomes);
|
||||||
|
|
||||||
virtual void scanForNetworks(bool scanAllWiFiChannels);
|
virtual void scanForNetworks(const bool scanAllWiFiChannels);
|
||||||
virtual void printAPInfo(const NetworkInfoBase &apNetworkInfo);
|
virtual void printAPInfo(const NetworkInfoBase &apNetworkInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,7 +310,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void deactivateAPHook();
|
virtual void deactivateAPHook();
|
||||||
|
|
||||||
void setClassType(MeshBackendType classType);
|
void setClassType(const MeshBackendType classType);
|
||||||
|
|
||||||
static std::shared_ptr<bool> _scanMutex;
|
static std::shared_ptr<bool> _scanMutex;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ namespace MeshCryptoInterface
|
|||||||
return CryptoInterface::sha256Hmac(message, hashKey, hashKeyLength, hmacLength);
|
return CryptoInterface::sha256Hmac(message, hashKey, hashKeyLength, hmacLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verifyMeshHmac(const String &message, const String &messageHmac, const uint8_t *hashKey, uint8_t hashKeyLength)
|
bool verifyMeshHmac(const String &message, const String &messageHmac, const uint8_t *hashKey, const uint8_t hashKeyLength)
|
||||||
{
|
{
|
||||||
String generatedHmac = createMeshHmac(message, hashKey, hashKeyLength, messageHmac.length()/2); // We know that each HMAC byte should become 2 String characters due to uint8ArrayToHexString.
|
String generatedHmac = createMeshHmac(message, hashKey, hashKeyLength, messageHmac.length()/2); // We know that each HMAC byte should become 2 String characters due to uint8ArrayToHexString.
|
||||||
if(generatedHmac == messageHmac)
|
if(generatedHmac == messageHmac)
|
||||||
@ -41,7 +41,7 @@ namespace MeshCryptoInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *initializeKey(uint8_t *key, uint8_t keyLength, const String &keySeed)
|
uint8_t *initializeKey(uint8_t *key, const uint8_t keyLength, const String &keySeed)
|
||||||
{
|
{
|
||||||
assert(keyLength <= CryptoInterface::SHA256_NATURAL_LENGTH);
|
assert(keyLength <= CryptoInterface::SHA256_NATURAL_LENGTH);
|
||||||
uint8_t hashArray[CryptoInterface::SHA256_NATURAL_LENGTH] {};
|
uint8_t hashArray[CryptoInterface::SHA256_NATURAL_LENGTH] {};
|
||||||
|
@ -66,7 +66,7 @@ namespace MeshCryptoInterface
|
|||||||
*
|
*
|
||||||
* @return True if the HMAC is correct. False otherwise.
|
* @return True if the HMAC is correct. False otherwise.
|
||||||
*/
|
*/
|
||||||
bool verifyMeshHmac(const String &message, const String &messageHmac, const uint8_t *hashKey, uint8_t hashKeyLength);
|
bool verifyMeshHmac(const String &message, const String &messageHmac, const uint8_t *hashKey, const uint8_t hashKeyLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize key with a SHA-256 hash of keySeed.
|
* Initialize key with a SHA-256 hash of keySeed.
|
||||||
@ -77,7 +77,7 @@ namespace MeshCryptoInterface
|
|||||||
*
|
*
|
||||||
* @return A pointer to the initialized key array.
|
* @return A pointer to the initialized key array.
|
||||||
*/
|
*/
|
||||||
uint8_t *initializeKey(uint8_t *key, uint8_t keyLength, const String &keySeed);
|
uint8_t *initializeKey(uint8_t *key, const uint8_t keyLength, const String &keySeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "EspnowMeshBackend.h"
|
#include "EspnowMeshBackend.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
MessageData::MessageData(String &message, uint8_t transmissionsRemaining, uint32_t creationTimeMs) :
|
MessageData::MessageData(const String &message, const uint8_t transmissionsRemaining, const uint32_t creationTimeMs) :
|
||||||
_timeTracker(creationTimeMs)
|
_timeTracker(creationTimeMs)
|
||||||
{
|
{
|
||||||
_transmissionsExpected = transmissionsRemaining + 1;
|
_transmissionsExpected = transmissionsRemaining + 1;
|
||||||
@ -35,14 +35,14 @@ MessageData::MessageData(String &message, uint8_t transmissionsRemaining, uint32
|
|||||||
++_transmissionsReceived;
|
++_transmissionsReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageData::MessageData(uint8_t *initialTransmission, uint8_t transmissionLength, uint32_t creationTimeMs) :
|
MessageData::MessageData(uint8_t *initialTransmission, const uint8_t transmissionLength, const uint32_t creationTimeMs) :
|
||||||
_timeTracker(creationTimeMs)
|
_timeTracker(creationTimeMs)
|
||||||
{
|
{
|
||||||
_transmissionsExpected = EspnowProtocolInterpreter::espnowGetTransmissionsRemaining(initialTransmission) + 1;
|
_transmissionsExpected = EspnowProtocolInterpreter::espnowGetTransmissionsRemaining(initialTransmission) + 1;
|
||||||
addToMessage(initialTransmission, transmissionLength);
|
addToMessage(initialTransmission, transmissionLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageData::addToMessage(uint8_t *transmission, uint8_t transmissionLength)
|
bool MessageData::addToMessage(uint8_t *transmission, const uint8_t transmissionLength)
|
||||||
{
|
{
|
||||||
if(EspnowProtocolInterpreter::espnowGetTransmissionsRemaining(transmission) == getTransmissionsRemaining() - 1)
|
if(EspnowProtocolInterpreter::espnowGetTransmissionsRemaining(transmission) == getTransmissionsRemaining() - 1)
|
||||||
{
|
{
|
||||||
@ -56,22 +56,22 @@ bool MessageData::addToMessage(uint8_t *transmission, uint8_t transmissionLength
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MessageData::getTransmissionsReceived()
|
uint8_t MessageData::getTransmissionsReceived() const
|
||||||
{
|
{
|
||||||
return _transmissionsReceived;
|
return _transmissionsReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MessageData::getTransmissionsExpected()
|
uint8_t MessageData::getTransmissionsExpected() const
|
||||||
{
|
{
|
||||||
return _transmissionsExpected;
|
return _transmissionsExpected;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MessageData::getTransmissionsRemaining()
|
uint8_t MessageData::getTransmissionsRemaining() const
|
||||||
{
|
{
|
||||||
return getTransmissionsExpected() - getTransmissionsReceived();
|
return getTransmissionsExpected() - getTransmissionsReceived();
|
||||||
}
|
}
|
||||||
|
|
||||||
String MessageData::getTotalMessage()
|
String MessageData::getTotalMessage() const
|
||||||
{
|
{
|
||||||
return _totalMessage;
|
return _totalMessage;
|
||||||
}
|
}
|
||||||
|
@ -32,17 +32,17 @@ class MessageData {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MessageData(String &message, uint8_t transmissionsRemaining, uint32_t creationTimeMs = millis());
|
MessageData(const String &message, const uint8_t transmissionsRemaining, const uint32_t creationTimeMs = millis());
|
||||||
MessageData(uint8_t *initialTransmission, uint8_t transmissionLength, uint32_t creationTimeMs = millis());
|
MessageData(uint8_t *initialTransmission, const uint8_t transmissionLength, const uint32_t creationTimeMs = millis());
|
||||||
/**
|
/**
|
||||||
* @transmission A string of characters, including initial protocol bytes.
|
* @transmission A string of characters, including initial protocol bytes. Not const since that would increase heap consumption during processing.
|
||||||
* @transmissionLength Length of transmission.
|
* @transmissionLength Length of transmission.
|
||||||
*/
|
*/
|
||||||
bool addToMessage(uint8_t *transmission, uint8_t transmissionLength);
|
bool addToMessage(uint8_t *transmission, const uint8_t transmissionLength);
|
||||||
uint8_t getTransmissionsReceived();
|
uint8_t getTransmissionsReceived() const;
|
||||||
uint8_t getTransmissionsExpected();
|
uint8_t getTransmissionsExpected() const;
|
||||||
uint8_t getTransmissionsRemaining();
|
uint8_t getTransmissionsRemaining() const;
|
||||||
String getTotalMessage();
|
String getTotalMessage() const;
|
||||||
const TimeTracker &getTimeTracker() const;
|
const TimeTracker &getTimeTracker() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -53,14 +53,14 @@ void NetworkInfoBase::storeBSSID(const uint8_t newBSSID[6])
|
|||||||
|
|
||||||
NetworkInfoBase::NetworkInfoBase() {};
|
NetworkInfoBase::NetworkInfoBase() {};
|
||||||
|
|
||||||
NetworkInfoBase::NetworkInfoBase(uint8_t networkIndex)
|
NetworkInfoBase::NetworkInfoBase(const uint8_t networkIndex)
|
||||||
{
|
{
|
||||||
uint8_t *bssidPtr = nullptr;
|
uint8_t *bssidPtr = nullptr;
|
||||||
WiFi.getNetworkInfo(networkIndex, _SSID, _encryptionType, _RSSI, bssidPtr, _wifiChannel, _isHidden);
|
WiFi.getNetworkInfo(networkIndex, _SSID, _encryptionType, _RSSI, bssidPtr, _wifiChannel, _isHidden);
|
||||||
storeBSSID(bssidPtr);
|
storeBSSID(bssidPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkInfoBase::NetworkInfoBase(const String &SSID, int32_t wifiChannel, const uint8_t BSSID[6], uint8_t encryptionType, int32_t RSSI, bool isHidden) :
|
NetworkInfoBase::NetworkInfoBase(const String &SSID, const int32_t wifiChannel, const uint8_t BSSID[6], const uint8_t encryptionType, const int32_t RSSI, const bool isHidden) :
|
||||||
_SSID(SSID), _wifiChannel(wifiChannel), _encryptionType(encryptionType), _RSSI(RSSI), _isHidden(isHidden)
|
_SSID(SSID), _wifiChannel(wifiChannel), _encryptionType(encryptionType), _RSSI(RSSI), _isHidden(isHidden)
|
||||||
{
|
{
|
||||||
storeBSSID(BSSID);
|
storeBSSID(BSSID);
|
||||||
@ -104,17 +104,17 @@ uint8_t *NetworkInfoBase::getBSSID(uint8_t resultArray[6]) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInfoBase::setSSID(String &SSID) { _SSID = SSID; }
|
void NetworkInfoBase::setSSID(const String &SSID) { _SSID = SSID; }
|
||||||
String NetworkInfoBase::SSID() const { return _SSID; }
|
String NetworkInfoBase::SSID() const { return _SSID; }
|
||||||
|
|
||||||
void NetworkInfoBase::setWifiChannel(int32_t wifiChannel) { _wifiChannel = wifiChannel; }
|
void NetworkInfoBase::setWifiChannel(const int32_t wifiChannel) { _wifiChannel = wifiChannel; }
|
||||||
int32_t NetworkInfoBase::wifiChannel() const { return _wifiChannel; }
|
int32_t NetworkInfoBase::wifiChannel() const { return _wifiChannel; }
|
||||||
|
|
||||||
void NetworkInfoBase::setEncryptionType(uint8_t encryptionType) { _encryptionType = encryptionType; }
|
void NetworkInfoBase::setEncryptionType(const uint8_t encryptionType) { _encryptionType = encryptionType; }
|
||||||
uint8_t NetworkInfoBase::encryptionType() const { return _encryptionType; }
|
uint8_t NetworkInfoBase::encryptionType() const { return _encryptionType; }
|
||||||
|
|
||||||
void NetworkInfoBase::setRSSI(int32_t RSSI) { _RSSI = RSSI; }
|
void NetworkInfoBase::setRSSI(const int32_t RSSI) { _RSSI = RSSI; }
|
||||||
int32_t NetworkInfoBase::RSSI() const { return _RSSI; }
|
int32_t NetworkInfoBase::RSSI() const { return _RSSI; }
|
||||||
|
|
||||||
void NetworkInfoBase::setIsHidden(bool isHidden) { _isHidden = isHidden; }
|
void NetworkInfoBase::setIsHidden(const bool isHidden) { _isHidden = isHidden; }
|
||||||
bool NetworkInfoBase::isHidden() const { return _isHidden; }
|
bool NetworkInfoBase::isHidden() const { return _isHidden; }
|
||||||
|
@ -36,12 +36,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
||||||
*/
|
*/
|
||||||
NetworkInfoBase(uint8_t networkIndex);
|
NetworkInfoBase(const uint8_t networkIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Without giving channel and BSSID, connection time is longer.
|
* Without giving channel and BSSID, connection time is longer.
|
||||||
*/
|
*/
|
||||||
NetworkInfoBase(const String &SSID, int32_t wifiChannel, const uint8_t BSSID[6], uint8_t encryptionType, int32_t RSSI, bool isHidden);
|
NetworkInfoBase(const String &SSID, const int32_t wifiChannel, const uint8_t BSSID[6], const uint8_t encryptionType, const int32_t RSSI, const bool isHidden);
|
||||||
|
|
||||||
NetworkInfoBase(const NetworkInfoBase &other);
|
NetworkInfoBase(const NetworkInfoBase &other);
|
||||||
|
|
||||||
@ -54,19 +54,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint8_t *getBSSID(uint8_t resultArray[6]) const;
|
uint8_t *getBSSID(uint8_t resultArray[6]) const;
|
||||||
|
|
||||||
void setSSID(String &SSID);
|
void setSSID(const String &SSID);
|
||||||
String SSID() const;
|
String SSID() const;
|
||||||
|
|
||||||
void setWifiChannel(int32_t wifiChannel);
|
void setWifiChannel(const int32_t wifiChannel);
|
||||||
int32_t wifiChannel() const;
|
int32_t wifiChannel() const;
|
||||||
|
|
||||||
void setEncryptionType(uint8_t encryptionType);
|
void setEncryptionType(const uint8_t encryptionType);
|
||||||
uint8_t encryptionType() const;
|
uint8_t encryptionType() const;
|
||||||
|
|
||||||
void setRSSI(int32_t RSSI);
|
void setRSSI(const int32_t RSSI);
|
||||||
int32_t RSSI() const;
|
int32_t RSSI() const;
|
||||||
|
|
||||||
void setIsHidden(bool isHidden);
|
void setIsHidden(const bool isHidden);
|
||||||
bool isHidden() const;
|
bool isHidden() const;
|
||||||
|
|
||||||
static uint8_t * const defaultBSSID;
|
static uint8_t * const defaultBSSID;
|
||||||
|
@ -27,31 +27,31 @@
|
|||||||
|
|
||||||
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
using EspnowProtocolInterpreter::espnowHashKeyLength;
|
||||||
|
|
||||||
PeerRequestLog::PeerRequestLog(uint64_t requestID, bool requestEncrypted, const String &authenticationPassword, uint8_t encryptedConnectionsSoftLimit,
|
PeerRequestLog::PeerRequestLog(const uint64_t requestID, const bool requestEncrypted, const String &authenticationPassword, const uint8_t encryptedConnectionsSoftLimit,
|
||||||
const String &peerRequestNonce, const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint8_t hashKey[espnowHashKeyLength])
|
const String &peerRequestNonce, const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint8_t hashKey[espnowHashKeyLength])
|
||||||
: EncryptedConnectionData(peerStaMac, peerApMac, 0, 0, EspnowMeshBackend::getEncryptionRequestTimeout(), hashKey),
|
: EncryptedConnectionData(peerStaMac, peerApMac, 0, 0, EspnowMeshBackend::getEncryptionRequestTimeout(), hashKey),
|
||||||
_requestID(requestID), _requestEncrypted(requestEncrypted), _authenticationPassword(authenticationPassword),
|
_requestID(requestID), _requestEncrypted(requestEncrypted), _authenticationPassword(authenticationPassword),
|
||||||
_encryptedConnectionsSoftLimit(encryptedConnectionsSoftLimit), _peerRequestNonce(peerRequestNonce)
|
_encryptedConnectionsSoftLimit(encryptedConnectionsSoftLimit), _peerRequestNonce(peerRequestNonce)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
PeerRequestLog::PeerRequestLog(uint64_t requestID, bool requestEncrypted, const String &authenticationPassword, uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
PeerRequestLog::PeerRequestLog(const uint64_t requestID, const bool requestEncrypted, const String &authenticationPassword, const uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
||||||
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
|
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
|
||||||
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, EspnowMeshBackend::getEncryptionRequestTimeout(), hashKey),
|
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, EspnowMeshBackend::getEncryptionRequestTimeout(), hashKey),
|
||||||
_requestID(requestID), _requestEncrypted(requestEncrypted), _authenticationPassword(authenticationPassword),
|
_requestID(requestID), _requestEncrypted(requestEncrypted), _authenticationPassword(authenticationPassword),
|
||||||
_encryptedConnectionsSoftLimit(encryptedConnectionsSoftLimit), _peerRequestNonce(peerRequestNonce)
|
_encryptedConnectionsSoftLimit(encryptedConnectionsSoftLimit), _peerRequestNonce(peerRequestNonce)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void PeerRequestLog::setRequestID(uint64_t requestID) { _requestID = requestID; }
|
void PeerRequestLog::setRequestID(const uint64_t requestID) { _requestID = requestID; }
|
||||||
uint64_t PeerRequestLog::getRequestID() { return _requestID; }
|
uint64_t PeerRequestLog::getRequestID() const { return _requestID; }
|
||||||
|
|
||||||
void PeerRequestLog::setRequestEncrypted(bool requestEncrypted) { _requestEncrypted = requestEncrypted; }
|
void PeerRequestLog::setRequestEncrypted(const bool requestEncrypted) { _requestEncrypted = requestEncrypted; }
|
||||||
bool PeerRequestLog::requestEncrypted() { return _requestEncrypted; }
|
bool PeerRequestLog::requestEncrypted() const { return _requestEncrypted; }
|
||||||
|
|
||||||
void PeerRequestLog::setAuthenticationPassword(const String &password) { _authenticationPassword = password; }
|
void PeerRequestLog::setAuthenticationPassword(const String &password) { _authenticationPassword = password; }
|
||||||
String PeerRequestLog::getAuthenticationPassword() { return _authenticationPassword; }
|
String PeerRequestLog::getAuthenticationPassword() const { return _authenticationPassword; }
|
||||||
|
|
||||||
void PeerRequestLog::setEncryptedConnectionsSoftLimit(uint8_t softLimit) { _encryptedConnectionsSoftLimit = softLimit; }
|
void PeerRequestLog::setEncryptedConnectionsSoftLimit(const uint8_t softLimit) { _encryptedConnectionsSoftLimit = softLimit; }
|
||||||
uint8_t PeerRequestLog::getEncryptedConnectionsSoftLimit() { return _encryptedConnectionsSoftLimit; }
|
uint8_t PeerRequestLog::getEncryptedConnectionsSoftLimit() const { return _encryptedConnectionsSoftLimit; }
|
||||||
|
|
||||||
void PeerRequestLog::setPeerRequestNonce(const String &nonce) { _peerRequestNonce = nonce; }
|
void PeerRequestLog::setPeerRequestNonce(const String &nonce) { _peerRequestNonce = nonce; }
|
||||||
String PeerRequestLog::getPeerRequestNonce() { return _peerRequestNonce; }
|
String PeerRequestLog::getPeerRequestNonce() const { return _peerRequestNonce; }
|
||||||
|
@ -32,26 +32,26 @@ class PeerRequestLog : public EncryptedConnectionData {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PeerRequestLog(uint64_t requestID, bool requestEncrypted, const String &authenticationPassword, uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
PeerRequestLog(const uint64_t requestID, const bool requestEncrypted, const String &authenticationPassword, const uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
||||||
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
PeerRequestLog(uint64_t requestID, bool requestEncrypted, const String &authenticationPassword, uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
PeerRequestLog(const uint64_t requestID, const bool requestEncrypted, const String &authenticationPassword, const uint8_t encryptedConnectionsSoftLimit, const String &peerRequestNonce,
|
||||||
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], uint64_t peerSessionKey, uint64_t ownSessionKey,
|
const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
|
||||||
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
|
||||||
|
|
||||||
void setRequestID(uint64_t requestID);
|
void setRequestID(const uint64_t requestID);
|
||||||
uint64_t getRequestID();
|
uint64_t getRequestID() const;
|
||||||
|
|
||||||
void setRequestEncrypted(bool requestEncrypted);
|
void setRequestEncrypted(const bool requestEncrypted);
|
||||||
bool requestEncrypted();
|
bool requestEncrypted() const;
|
||||||
|
|
||||||
void setAuthenticationPassword(const String &password);
|
void setAuthenticationPassword(const String &password);
|
||||||
String getAuthenticationPassword();
|
String getAuthenticationPassword() const;
|
||||||
|
|
||||||
void setEncryptedConnectionsSoftLimit(uint8_t softLimit);
|
void setEncryptedConnectionsSoftLimit(const uint8_t softLimit);
|
||||||
uint8_t getEncryptedConnectionsSoftLimit();
|
uint8_t getEncryptedConnectionsSoftLimit() const;
|
||||||
|
|
||||||
void setPeerRequestNonce(const String &nonce);
|
void setPeerRequestNonce(const String &nonce);
|
||||||
String getPeerRequestNonce();
|
String getPeerRequestNonce() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -24,10 +24,9 @@
|
|||||||
|
|
||||||
#include "RequestData.h"
|
#include "RequestData.h"
|
||||||
|
|
||||||
RequestData::RequestData(EspnowMeshBackend &meshInstance, uint32_t creationTimeMs) :
|
RequestData::RequestData(EspnowMeshBackend &meshInstance, const uint32_t creationTimeMs) :
|
||||||
_timeTracker(creationTimeMs), _meshInstance(meshInstance)
|
_timeTracker(creationTimeMs), _meshInstance(meshInstance)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void RequestData::setMeshInstance(const EspnowMeshBackend &meshInstance) { _meshInstance = meshInstance; }
|
|
||||||
EspnowMeshBackend &RequestData::getMeshInstance() const { return _meshInstance; }
|
EspnowMeshBackend &RequestData::getMeshInstance() const { return _meshInstance; }
|
||||||
const TimeTracker &RequestData::getTimeTracker() const { return _timeTracker; }
|
const TimeTracker &RequestData::getTimeTracker() const { return _timeTracker; }
|
||||||
|
@ -34,9 +34,8 @@ class RequestData {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RequestData(EspnowMeshBackend &meshInstance, uint32_t creationTimeMs = millis());
|
RequestData(EspnowMeshBackend &meshInstance, const uint32_t creationTimeMs = millis());
|
||||||
|
|
||||||
void setMeshInstance(const EspnowMeshBackend &meshInstance);
|
|
||||||
EspnowMeshBackend &getMeshInstance() const;
|
EspnowMeshBackend &getMeshInstance() const;
|
||||||
const TimeTracker &getTimeTracker() const;
|
const TimeTracker &getTimeTracker() const;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "ResponseData.h"
|
#include "ResponseData.h"
|
||||||
|
|
||||||
ResponseData::ResponseData(const String &message, const uint8_t recipientMac[6], uint64_t requestID, uint32_t creationTimeMs) :
|
ResponseData::ResponseData(const String &message, const uint8_t recipientMac[6], const uint64_t requestID, const uint32_t creationTimeMs) :
|
||||||
_timeTracker(creationTimeMs), _message(message), _requestID(requestID)
|
_timeTracker(creationTimeMs), _message(message), _requestID(requestID)
|
||||||
{
|
{
|
||||||
storeRecipientMac(recipientMac);
|
storeRecipientMac(recipientMac);
|
||||||
@ -71,10 +71,10 @@ void ResponseData::storeRecipientMac(const uint8_t newRecipientMac[6])
|
|||||||
void ResponseData::setRecipientMac(const uint8_t recipientMac[6]) { storeRecipientMac(recipientMac); }
|
void ResponseData::setRecipientMac(const uint8_t recipientMac[6]) { storeRecipientMac(recipientMac); }
|
||||||
const uint8_t *ResponseData::getRecipientMac() const { return _recipientMac; }
|
const uint8_t *ResponseData::getRecipientMac() const { return _recipientMac; }
|
||||||
|
|
||||||
void ResponseData::setMessage(String &message) { _message = message; }
|
void ResponseData::setMessage(const String &message) { _message = message; }
|
||||||
String ResponseData::getMessage() const { return _message; }
|
String ResponseData::getMessage() const { return _message; }
|
||||||
|
|
||||||
void ResponseData::setRequestID(uint64_t requestID) { _requestID = requestID; }
|
void ResponseData::setRequestID(const uint64_t requestID) { _requestID = requestID; }
|
||||||
uint64_t ResponseData::getRequestID() const { return _requestID; }
|
uint64_t ResponseData::getRequestID() const { return _requestID; }
|
||||||
|
|
||||||
const TimeTracker &ResponseData::getTimeTracker() const { return _timeTracker; }
|
const TimeTracker &ResponseData::getTimeTracker() const { return _timeTracker; }
|
||||||
|
@ -32,7 +32,7 @@ class ResponseData {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ResponseData(const String &message, const uint8_t recipientMac[6], uint64_t requestID, uint32_t creationTimeMs = millis());
|
ResponseData(const String &message, const uint8_t recipientMac[6], const uint64_t requestID, const uint32_t creationTimeMs = millis());
|
||||||
ResponseData(const ResponseData &other);
|
ResponseData(const ResponseData &other);
|
||||||
ResponseData & operator=(const ResponseData &other);
|
ResponseData & operator=(const ResponseData &other);
|
||||||
// No need for explicit destructor with current class design
|
// No need for explicit destructor with current class design
|
||||||
@ -40,10 +40,10 @@ public:
|
|||||||
void setRecipientMac(const uint8_t recipientMac[6]);
|
void setRecipientMac(const uint8_t recipientMac[6]);
|
||||||
const uint8_t *getRecipientMac() const;
|
const uint8_t *getRecipientMac() const;
|
||||||
|
|
||||||
void setMessage(String &message);
|
void setMessage(const String &message);
|
||||||
String getMessage() const;
|
String getMessage() const;
|
||||||
|
|
||||||
void setRequestID(uint64_t requestID);
|
void setRequestID(const uint64_t requestID);
|
||||||
uint64_t getRequestID() const;
|
uint64_t getRequestID() const;
|
||||||
|
|
||||||
const TimeTracker &getTimeTracker() const;
|
const TimeTracker &getTimeTracker() const;
|
||||||
|
@ -48,9 +48,9 @@ IPAddress TcpIpMeshBackend::subnetMask(255,255,255,0);
|
|||||||
std::vector<TcpIpNetworkInfo> TcpIpMeshBackend::_connectionQueue = {};
|
std::vector<TcpIpNetworkInfo> TcpIpMeshBackend::_connectionQueue = {};
|
||||||
std::vector<TransmissionOutcome> TcpIpMeshBackend::_latestTransmissionOutcomes = {};
|
std::vector<TransmissionOutcome> TcpIpMeshBackend::_latestTransmissionOutcomes = {};
|
||||||
|
|
||||||
TcpIpMeshBackend::TcpIpMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler,
|
TcpIpMeshBackend::TcpIpMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler,
|
||||||
networkFilterType networkFilter, const String &meshPassword, const String &ssidPrefix,
|
const networkFilterType networkFilter, const String &meshPassword, const String &ssidPrefix,
|
||||||
const String &ssidSuffix, bool verboseMode, uint8 meshWiFiChannel, uint16_t serverPort)
|
const String &ssidSuffix, const bool verboseMode, const uint8 meshWiFiChannel, const uint16_t serverPort)
|
||||||
: MeshBackendBase(requestHandler, responseHandler, networkFilter, MeshBackendType::TCP_IP), _server(serverPort)
|
: MeshBackendBase(requestHandler, responseHandler, networkFilter, MeshBackendType::TCP_IP), _server(serverPort)
|
||||||
{
|
{
|
||||||
setSSID(ssidPrefix, emptyString, ssidSuffix);
|
setSSID(ssidPrefix, emptyString, ssidSuffix);
|
||||||
@ -114,10 +114,10 @@ void TcpIpMeshBackend::deactivateAPHook()
|
|||||||
bool TcpIpMeshBackend::transmissionInProgress(){return *_tcpIpTransmissionMutex;}
|
bool TcpIpMeshBackend::transmissionInProgress(){return *_tcpIpTransmissionMutex;}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setTemporaryMessage(const String &newTemporaryMessage) {_temporaryMessage = newTemporaryMessage;}
|
void TcpIpMeshBackend::setTemporaryMessage(const String &newTemporaryMessage) {_temporaryMessage = newTemporaryMessage;}
|
||||||
String TcpIpMeshBackend::getTemporaryMessage() {return _temporaryMessage;}
|
String TcpIpMeshBackend::getTemporaryMessage() const {return _temporaryMessage;}
|
||||||
void TcpIpMeshBackend::clearTemporaryMessage() {_temporaryMessage.clear();}
|
void TcpIpMeshBackend::clearTemporaryMessage() {_temporaryMessage.clear();}
|
||||||
|
|
||||||
String TcpIpMeshBackend::getCurrentMessage()
|
String TcpIpMeshBackend::getCurrentMessage() const
|
||||||
{
|
{
|
||||||
String message = getTemporaryMessage();
|
String message = getTemporaryMessage();
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ void TcpIpMeshBackend::setStaticIP(const IPAddress &newIP)
|
|||||||
staticIP = newIP;
|
staticIP = newIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress TcpIpMeshBackend::getStaticIP()
|
IPAddress TcpIpMeshBackend::getStaticIP() const
|
||||||
{
|
{
|
||||||
if(staticIPActivated)
|
if(staticIPActivated)
|
||||||
return staticIP;
|
return staticIP;
|
||||||
@ -153,7 +153,7 @@ void TcpIpMeshBackend::disableStaticIP()
|
|||||||
staticIPActivated = false;
|
staticIPActivated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setServerPort(uint16_t serverPort)
|
void TcpIpMeshBackend::setServerPort(const uint16_t serverPort)
|
||||||
{
|
{
|
||||||
_serverPort = serverPort;
|
_serverPort = serverPort;
|
||||||
|
|
||||||
@ -162,9 +162,9 @@ void TcpIpMeshBackend::setServerPort(uint16_t serverPort)
|
|||||||
restartAP();
|
restartAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t TcpIpMeshBackend::getServerPort() {return _serverPort;}
|
uint16_t TcpIpMeshBackend::getServerPort() const {return _serverPort;}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setMaxAPStations(uint8_t maxAPStations)
|
void TcpIpMeshBackend::setMaxAPStations(const uint8_t maxAPStations)
|
||||||
{
|
{
|
||||||
assert(maxAPStations <= 8); // Valid values are 0 to 8, but uint8_t is always at least 0.
|
assert(maxAPStations <= 8); // Valid values are 0 to 8, but uint8_t is always at least 0.
|
||||||
|
|
||||||
@ -178,28 +178,28 @@ void TcpIpMeshBackend::setMaxAPStations(uint8_t maxAPStations)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpIpMeshBackend::getMaxAPStations() {return _maxAPStations;}
|
bool TcpIpMeshBackend::getMaxAPStations() const {return _maxAPStations;}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setConnectionAttemptTimeout(uint32_t connectionAttemptTimeoutMs)
|
void TcpIpMeshBackend::setConnectionAttemptTimeout(const uint32_t connectionAttemptTimeoutMs)
|
||||||
{
|
{
|
||||||
_connectionAttemptTimeoutMs = connectionAttemptTimeoutMs;
|
_connectionAttemptTimeoutMs = connectionAttemptTimeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TcpIpMeshBackend::getConnectionAttemptTimeout() {return _connectionAttemptTimeoutMs;}
|
uint32_t TcpIpMeshBackend::getConnectionAttemptTimeout() const {return _connectionAttemptTimeoutMs;}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setStationModeTimeout(int stationModeTimeoutMs)
|
void TcpIpMeshBackend::setStationModeTimeout(const int stationModeTimeoutMs)
|
||||||
{
|
{
|
||||||
_stationModeTimeoutMs = stationModeTimeoutMs;
|
_stationModeTimeoutMs = stationModeTimeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TcpIpMeshBackend::getStationModeTimeout() {return _stationModeTimeoutMs;}
|
int TcpIpMeshBackend::getStationModeTimeout() const {return _stationModeTimeoutMs;}
|
||||||
|
|
||||||
void TcpIpMeshBackend::setAPModeTimeout(uint32_t apModeTimeoutMs)
|
void TcpIpMeshBackend::setAPModeTimeout(const uint32_t apModeTimeoutMs)
|
||||||
{
|
{
|
||||||
_apModeTimeoutMs = apModeTimeoutMs;
|
_apModeTimeoutMs = apModeTimeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TcpIpMeshBackend::getAPModeTimeout() {return _apModeTimeoutMs;}
|
uint32_t TcpIpMeshBackend::getAPModeTimeout() const {return _apModeTimeoutMs;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnect completely from a network.
|
* Disconnect completely from a network.
|
||||||
@ -218,7 +218,7 @@ void TcpIpMeshBackend::fullStop(WiFiClient &currClient)
|
|||||||
* @return True if the client is ready, false otherwise.
|
* @return True if the client is ready, false otherwise.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool TcpIpMeshBackend::waitForClientTransmission(WiFiClient &currClient, uint32_t maxWait)
|
bool TcpIpMeshBackend::waitForClientTransmission(WiFiClient &currClient, const uint32_t maxWait)
|
||||||
{
|
{
|
||||||
ExpiringTimeTracker timeout(maxWait);
|
ExpiringTimeTracker timeout(maxWait);
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ TransmissionStatusType TcpIpMeshBackend::attemptDataTransferKernel()
|
|||||||
return transmissionOutcome;
|
return transmissionOutcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpIpMeshBackend::initiateConnectionToAP(const String &targetSSID, int targetChannel, uint8_t *targetBSSID)
|
void TcpIpMeshBackend::initiateConnectionToAP(const String &targetSSID, const int targetChannel, const uint8_t *targetBSSID)
|
||||||
{
|
{
|
||||||
if(targetChannel == NETWORK_INFO_DEFAULT_INT)
|
if(targetChannel == NETWORK_INFO_DEFAULT_INT)
|
||||||
WiFi.begin( targetSSID.c_str(), getMeshPassword().c_str() ); // Without giving channel and BSSID, connection time is longer.
|
WiFi.begin( targetSSID.c_str(), getMeshPassword().c_str() ); // Without giving channel and BSSID, connection time is longer.
|
||||||
@ -342,7 +342,7 @@ void TcpIpMeshBackend::initiateConnectionToAP(const String &targetSSID, int targ
|
|||||||
* @return A status code based on the outcome of the connection and data transfer process.
|
* @return A status code based on the outcome of the connection and data transfer process.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TransmissionStatusType TcpIpMeshBackend::connectToNode(const String &targetSSID, int targetChannel, uint8_t *targetBSSID)
|
TransmissionStatusType TcpIpMeshBackend::connectToNode(const String &targetSSID, const int targetChannel, const uint8_t *targetBSSID)
|
||||||
{
|
{
|
||||||
if(staticIPActivated && !lastSSID.isEmpty() && lastSSID != targetSSID) // So we only do this once per connection, in case there is a performance impact.
|
if(staticIPActivated && !lastSSID.isEmpty() && lastSSID != targetSSID) // So we only do this once per connection, in case there is a performance impact.
|
||||||
{
|
{
|
||||||
@ -413,7 +413,7 @@ TransmissionStatusType TcpIpMeshBackend::initiateTransmission(const TcpIpNetwork
|
|||||||
return connectToNode(targetSSID, targetWiFiChannel, targetBSSID);
|
return connectToNode(targetSSID, targetWiFiChannel, targetBSSID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpIpMeshBackend::enterPostTransmissionState(bool concludingDisconnect)
|
void TcpIpMeshBackend::enterPostTransmissionState(const bool concludingDisconnect)
|
||||||
{
|
{
|
||||||
if(WiFi.status() == WL_CONNECTED && staticIP != emptyIP && !staticIPActivated)
|
if(WiFi.status() == WL_CONNECTED && staticIP != emptyIP && !staticIPActivated)
|
||||||
{
|
{
|
||||||
@ -429,7 +429,7 @@ void TcpIpMeshBackend::enterPostTransmissionState(bool concludingDisconnect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpIpMeshBackend::attemptTransmission(const String &message, bool scan, bool scanAllWiFiChannels, bool concludingDisconnect, bool initialDisconnect)
|
void TcpIpMeshBackend::attemptTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels, const bool concludingDisconnect, const bool initialDisconnect)
|
||||||
{
|
{
|
||||||
MutexTracker mutexTracker(_tcpIpTransmissionMutex);
|
MutexTracker mutexTracker(_tcpIpTransmissionMutex);
|
||||||
if(!mutexTracker.mutexCaptured())
|
if(!mutexTracker.mutexCaptured())
|
||||||
@ -485,12 +485,12 @@ void TcpIpMeshBackend::attemptTransmission(const String &message, bool scan, boo
|
|||||||
enterPostTransmissionState(concludingDisconnect);
|
enterPostTransmissionState(concludingDisconnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpIpMeshBackend::attemptTransmission(const String &message, bool scan, bool scanAllWiFiChannels)
|
void TcpIpMeshBackend::attemptTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels)
|
||||||
{
|
{
|
||||||
attemptTransmission(message, scan, scanAllWiFiChannels, true, false);
|
attemptTransmission(message, scan, scanAllWiFiChannels, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmissionStatusType TcpIpMeshBackend::attemptTransmission(const String &message, const TcpIpNetworkInfo &recipientInfo, bool concludingDisconnect, bool initialDisconnect)
|
TransmissionStatusType TcpIpMeshBackend::attemptTransmission(const String &message, const TcpIpNetworkInfo &recipientInfo, const bool concludingDisconnect, const bool initialDisconnect)
|
||||||
{
|
{
|
||||||
MutexTracker mutexTracker(_tcpIpTransmissionMutex);
|
MutexTracker mutexTracker(_tcpIpTransmissionMutex);
|
||||||
if(!mutexTracker.mutexCaptured())
|
if(!mutexTracker.mutexCaptured())
|
||||||
|
@ -61,9 +61,9 @@ public:
|
|||||||
* This is managed automatically by the activateAP method.
|
* This is managed automatically by the activateAP method.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TcpIpMeshBackend(requestHandlerType requestHandler, responseHandlerType responseHandler, networkFilterType networkFilter,
|
TcpIpMeshBackend(const requestHandlerType requestHandler, const responseHandlerType responseHandler, const networkFilterType networkFilter,
|
||||||
const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, bool verboseMode = false,
|
const String &meshPassword, const String &ssidPrefix, const String &ssidSuffix, const bool verboseMode = false,
|
||||||
uint8 meshWiFiChannel = 1, uint16_t serverPort = 4011);
|
const uint8 meshWiFiChannel = 1, const uint16_t serverPort = 4011);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a vector that contains the NetworkInfo for each WiFi network to connect to.
|
* Returns a vector that contains the NetworkInfo for each WiFi network to connect to.
|
||||||
@ -114,9 +114,9 @@ public:
|
|||||||
* Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
|
* Note that if the ESP8266 has an active AP, that AP will switch WiFi channel to match that of any other AP the ESP8266 connects to.
|
||||||
* This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
|
* This can make it impossible for other nodes to detect the AP if they are scanning the wrong WiFi channel.
|
||||||
*/
|
*/
|
||||||
void attemptTransmission(const String &message, bool scan, bool scanAllWiFiChannels, bool concludingDisconnect, bool initialDisconnect = false);
|
void attemptTransmission(const String &message, const bool scan, const bool scanAllWiFiChannels, const bool concludingDisconnect, const bool initialDisconnect = false);
|
||||||
|
|
||||||
void attemptTransmission(const String &message, bool scan = true, bool scanAllWiFiChannels = false) override;
|
void attemptTransmission(const String &message, const bool scan = true, const bool scanAllWiFiChannels = false) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transmit message to a single recipient without changing the local transmission state (apart from connecting to the recipient if required).
|
* Transmit message to a single recipient without changing the local transmission state (apart from connecting to the recipient if required).
|
||||||
@ -124,7 +124,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Note that if wifiChannel and BSSID are missing from recipientInfo, connection time will be longer.
|
* Note that if wifiChannel and BSSID are missing from recipientInfo, connection time will be longer.
|
||||||
*/
|
*/
|
||||||
TransmissionStatusType attemptTransmission(const String &message, const TcpIpNetworkInfo &recipientInfo, bool concludingDisconnect = true, bool initialDisconnect = false);
|
TransmissionStatusType attemptTransmission(const String &message, const TcpIpNetworkInfo &recipientInfo, const bool concludingDisconnect = true, const bool initialDisconnect = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any clients are connected, accept their requests and call the requestHandler function for each one.
|
* If any clients are connected, accept their requests and call the requestHandler function for each one.
|
||||||
@ -135,14 +135,14 @@ public:
|
|||||||
* Get the TCP/IP message that is currently scheduled for transmission.
|
* Get the TCP/IP message that is currently scheduled for transmission.
|
||||||
* Unlike the getMessage() method, this will be correct even when the single recipient attemptTransmission method is used.
|
* Unlike the getMessage() method, this will be correct even when the single recipient attemptTransmission method is used.
|
||||||
*/
|
*/
|
||||||
String getCurrentMessage();
|
String getCurrentMessage() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a static IP address for the ESP8266 and activate use of static IP.
|
* Set a static IP address for the ESP8266 and activate use of static IP.
|
||||||
* The static IP needs to be at the same subnet as the server's gateway.
|
* The static IP needs to be at the same subnet as the server's gateway.
|
||||||
*/
|
*/
|
||||||
void setStaticIP(const IPAddress &newIP);
|
void setStaticIP(const IPAddress &newIP);
|
||||||
IPAddress getStaticIP();
|
IPAddress getStaticIP() const;
|
||||||
void disableStaticIP();
|
void disableStaticIP();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,8 +161,8 @@ public:
|
|||||||
* @param serverPort The server port to use.
|
* @param serverPort The server port to use.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void setServerPort(uint16_t serverPort);
|
void setServerPort(const uint16_t serverPort);
|
||||||
uint16_t getServerPort();
|
uint16_t getServerPort() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the maximum number of stations that can simultaneously be connected to the AP controlled by this TcpIpMeshBackend instance.
|
* Set the maximum number of stations that can simultaneously be connected to the AP controlled by this TcpIpMeshBackend instance.
|
||||||
@ -174,8 +174,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param maxAPStations The maximum number of simultaneous station connections allowed. Valid values are 0 to 8.
|
* @param maxAPStations The maximum number of simultaneous station connections allowed. Valid values are 0 to 8.
|
||||||
*/
|
*/
|
||||||
void setMaxAPStations(uint8_t maxAPStations);
|
void setMaxAPStations(const uint8_t maxAPStations);
|
||||||
bool getMaxAPStations();
|
bool getMaxAPStations() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the timeout for each attempt to connect to another AP that occurs through the attemptTransmission method by this TcpIpMeshBackend instance.
|
* Set the timeout for each attempt to connect to another AP that occurs through the attemptTransmission method by this TcpIpMeshBackend instance.
|
||||||
@ -183,8 +183,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param connectionAttemptTimeoutMs The timeout for each connection attempt, in milliseconds.
|
* @param connectionAttemptTimeoutMs The timeout for each connection attempt, in milliseconds.
|
||||||
*/
|
*/
|
||||||
void setConnectionAttemptTimeout(uint32_t connectionAttemptTimeoutMs);
|
void setConnectionAttemptTimeout(const uint32_t connectionAttemptTimeoutMs);
|
||||||
uint32_t getConnectionAttemptTimeout();
|
uint32_t getConnectionAttemptTimeout() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the timeout to use for transmissions when this TcpIpMeshBackend instance acts as a station (i.e. when connected to another AP).
|
* Set the timeout to use for transmissions when this TcpIpMeshBackend instance acts as a station (i.e. when connected to another AP).
|
||||||
@ -193,8 +193,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param stationModeTimeoutMs The timeout to use, in milliseconds.
|
* @param stationModeTimeoutMs The timeout to use, in milliseconds.
|
||||||
*/
|
*/
|
||||||
void setStationModeTimeout(int stationModeTimeoutMs);
|
void setStationModeTimeout(const int stationModeTimeoutMs);
|
||||||
int getStationModeTimeout();
|
int getStationModeTimeout() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the timeout to use for transmissions when this TcpIpMeshBackend instance acts as an AP (i.e. when receiving connections from other stations).
|
* Set the timeout to use for transmissions when this TcpIpMeshBackend instance acts as an AP (i.e. when receiving connections from other stations).
|
||||||
@ -205,8 +205,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param apModeTimeoutMs The timeout to use, in milliseconds.
|
* @param apModeTimeoutMs The timeout to use, in milliseconds.
|
||||||
*/
|
*/
|
||||||
void setAPModeTimeout(uint32_t apModeTimeoutMs);
|
void setAPModeTimeout(const uint32_t apModeTimeoutMs);
|
||||||
uint32_t getAPModeTimeout();
|
uint32_t getAPModeTimeout() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ protected:
|
|||||||
* @param newMessage The message to send.
|
* @param newMessage The message to send.
|
||||||
*/
|
*/
|
||||||
void setTemporaryMessage(const String &newMessage);
|
void setTemporaryMessage(const String &newMessage);
|
||||||
String getTemporaryMessage();
|
String getTemporaryMessage() const;
|
||||||
void clearTemporaryMessage();
|
void clearTemporaryMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -270,14 +270,14 @@ private:
|
|||||||
static IPAddress subnetMask;
|
static IPAddress subnetMask;
|
||||||
|
|
||||||
void fullStop(WiFiClient &currClient);
|
void fullStop(WiFiClient &currClient);
|
||||||
void initiateConnectionToAP(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
|
void initiateConnectionToAP(const String &targetSSID, const int targetChannel = NETWORK_INFO_DEFAULT_INT, const uint8_t *targetBSSID = NULL);
|
||||||
TransmissionStatusType connectToNode(const String &targetSSID, int targetChannel = NETWORK_INFO_DEFAULT_INT, uint8_t *targetBSSID = NULL);
|
TransmissionStatusType connectToNode(const String &targetSSID, const int targetChannel = NETWORK_INFO_DEFAULT_INT, const uint8_t *targetBSSID = NULL);
|
||||||
TransmissionStatusType exchangeInfo(WiFiClient &currClient);
|
TransmissionStatusType exchangeInfo(WiFiClient &currClient);
|
||||||
bool waitForClientTransmission(WiFiClient &currClient, uint32_t maxWait);
|
bool waitForClientTransmission(WiFiClient &currClient, const uint32_t maxWait);
|
||||||
TransmissionStatusType attemptDataTransfer();
|
TransmissionStatusType attemptDataTransfer();
|
||||||
TransmissionStatusType attemptDataTransferKernel();
|
TransmissionStatusType attemptDataTransferKernel();
|
||||||
TransmissionStatusType initiateTransmission(const TcpIpNetworkInfo &recipientInfo);
|
TransmissionStatusType initiateTransmission(const TcpIpNetworkInfo &recipientInfo);
|
||||||
void enterPostTransmissionState(bool concludingDisconnect);
|
void enterPostTransmissionState(const bool concludingDisconnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "TcpIpNetworkInfo.h"
|
#include "TcpIpNetworkInfo.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
TcpIpNetworkInfo::TcpIpNetworkInfo(int networkIndex) : NetworkInfoBase(networkIndex) { };
|
TcpIpNetworkInfo::TcpIpNetworkInfo(const int networkIndex) : NetworkInfoBase(networkIndex) { };
|
||||||
|
|
||||||
|
|
||||||
TcpIpNetworkInfo::TcpIpNetworkInfo(const NetworkInfoBase &originalNetworkInfo) : NetworkInfoBase(originalNetworkInfo)
|
TcpIpNetworkInfo::TcpIpNetworkInfo(const NetworkInfoBase &originalNetworkInfo) : NetworkInfoBase(originalNetworkInfo)
|
||||||
@ -33,6 +33,6 @@ TcpIpNetworkInfo::TcpIpNetworkInfo(const NetworkInfoBase &originalNetworkInfo) :
|
|||||||
assert(SSID() != defaultSSID); // We need at least SSID to be able to connect.
|
assert(SSID() != defaultSSID); // We need at least SSID to be able to connect.
|
||||||
};
|
};
|
||||||
|
|
||||||
TcpIpNetworkInfo::TcpIpNetworkInfo(const String &SSID, int32_t wifiChannel, const uint8_t BSSID[6], uint8_t encryptionType, int32_t RSSI , bool isHidden)
|
TcpIpNetworkInfo::TcpIpNetworkInfo(const String &SSID, const int32_t wifiChannel, const uint8_t BSSID[6], const uint8_t encryptionType, const int32_t RSSI , const bool isHidden)
|
||||||
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden)
|
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden)
|
||||||
{ }
|
{ }
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
* Automatically fill in the rest of the network info using networkIndex and the WiFi scan results.
|
||||||
*/
|
*/
|
||||||
TcpIpNetworkInfo(int networkIndex);
|
TcpIpNetworkInfo(const int networkIndex);
|
||||||
|
|
||||||
|
|
||||||
TcpIpNetworkInfo(const NetworkInfoBase &originalNetworkInfo);
|
TcpIpNetworkInfo(const NetworkInfoBase &originalNetworkInfo);
|
||||||
@ -42,8 +42,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Without giving wifiChannel and BSSID, connection time is longer.
|
* Without giving wifiChannel and BSSID, connection time is longer.
|
||||||
*/
|
*/
|
||||||
TcpIpNetworkInfo(const String &SSID, int32_t wifiChannel = defaultWifiChannel, const uint8_t BSSID[6] = defaultBSSID, uint8_t encryptionType = defaultEncryptionType,
|
TcpIpNetworkInfo(const String &SSID, const int32_t wifiChannel = defaultWifiChannel, const uint8_t BSSID[6] = defaultBSSID, const uint8_t encryptionType = defaultEncryptionType,
|
||||||
int32_t RSSI = defaultRSSI, bool isHidden = defaultIsHidden);
|
const int32_t RSSI = defaultRSSI, const bool isHidden = defaultIsHidden);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "TimeTracker.h"
|
#include "TimeTracker.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
TimeTracker::TimeTracker(uint32_t creationTimeMs) : _creationTimeMs(creationTimeMs)
|
TimeTracker::TimeTracker(const uint32_t creationTimeMs) : _creationTimeMs(creationTimeMs)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
uint32_t TimeTracker::timeSinceCreation() const
|
uint32_t TimeTracker::timeSinceCreation() const
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
virtual ~TimeTracker() = default;
|
virtual ~TimeTracker() = default;
|
||||||
|
|
||||||
TimeTracker(uint32_t creationTimeMs);
|
TimeTracker(const uint32_t creationTimeMs);
|
||||||
uint32_t timeSinceCreation() const;
|
uint32_t timeSinceCreation() const;
|
||||||
uint32_t creationTimeMs() const;
|
uint32_t creationTimeMs() const;
|
||||||
|
|
||||||
|
@ -24,13 +24,14 @@
|
|||||||
|
|
||||||
#include "TransmissionOutcome.h"
|
#include "TransmissionOutcome.h"
|
||||||
|
|
||||||
TransmissionOutcome::TransmissionOutcome(const NetworkInfoBase &origin, TransmissionStatusType transmissionStatus)
|
TransmissionOutcome::TransmissionOutcome(const NetworkInfoBase &origin, const TransmissionStatusType transmissionStatus)
|
||||||
: NetworkInfoBase(origin), _transmissionStatus(transmissionStatus)
|
: NetworkInfoBase(origin), _transmissionStatus(transmissionStatus)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
TransmissionOutcome::TransmissionOutcome(const String &SSID, int32_t wifiChannel, const uint8_t BSSID[6], uint8_t encryptionType, int32_t RSSI, bool isHidden, TransmissionStatusType transmissionStatus)
|
TransmissionOutcome::TransmissionOutcome(const String &SSID, const int32_t wifiChannel, const uint8_t BSSID[6], const uint8_t encryptionType,
|
||||||
|
const int32_t RSSI, const bool isHidden, const TransmissionStatusType transmissionStatus)
|
||||||
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden), _transmissionStatus(transmissionStatus)
|
: NetworkInfoBase(SSID, wifiChannel, BSSID, encryptionType, RSSI, isHidden), _transmissionStatus(transmissionStatus)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void TransmissionOutcome::setTransmissionStatus(TransmissionStatusType transmissionStatus) { _transmissionStatus = transmissionStatus; }
|
void TransmissionOutcome::setTransmissionStatus(const TransmissionStatusType transmissionStatus) { _transmissionStatus = transmissionStatus; }
|
||||||
TransmissionStatusType TransmissionOutcome::transmissionStatus() const { return _transmissionStatus; }
|
TransmissionStatusType TransmissionOutcome::transmissionStatus() const { return _transmissionStatus; }
|
||||||
|
@ -39,11 +39,12 @@ class TransmissionOutcome : public NetworkInfoBase {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TransmissionOutcome(const NetworkInfoBase &origin, TransmissionStatusType transmissionStatus);
|
TransmissionOutcome(const NetworkInfoBase &origin, const TransmissionStatusType transmissionStatus);
|
||||||
|
|
||||||
TransmissionOutcome(const String &SSID, int32_t wifiChannel, const uint8_t BSSID[6], uint8_t encryptionType, int32_t RSSI, bool isHidden, TransmissionStatusType transmissionStatus);
|
TransmissionOutcome(const String &SSID, const int32_t wifiChannel, const uint8_t BSSID[6], const uint8_t encryptionType,
|
||||||
|
const int32_t RSSI, const bool isHidden, const TransmissionStatusType transmissionStatus);
|
||||||
|
|
||||||
void setTransmissionStatus(TransmissionStatusType transmissionStatus);
|
void setTransmissionStatus(const TransmissionStatusType transmissionStatus);
|
||||||
TransmissionStatusType transmissionStatus() const;
|
TransmissionStatusType transmissionStatus() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,10 +27,10 @@
|
|||||||
#include "MeshBackendBase.h"
|
#include "MeshBackendBase.h"
|
||||||
#include "EspnowMeshBackend.h"
|
#include "EspnowMeshBackend.h"
|
||||||
|
|
||||||
void MeshBackendBase::setVerboseModeState(bool enabled) {_verboseMode = enabled;}
|
void MeshBackendBase::setVerboseModeState(const bool enabled) {_verboseMode = enabled;}
|
||||||
bool MeshBackendBase::verboseMode() {return _verboseMode;}
|
bool MeshBackendBase::verboseMode() const {return _verboseMode;}
|
||||||
|
|
||||||
void MeshBackendBase::verboseModePrint(const String &stringToPrint, bool newline)
|
void MeshBackendBase::verboseModePrint(const String &stringToPrint, const bool newline) const
|
||||||
{
|
{
|
||||||
if(verboseMode())
|
if(verboseMode())
|
||||||
{
|
{
|
||||||
@ -41,10 +41,10 @@ void MeshBackendBase::verboseModePrint(const String &stringToPrint, bool newline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspnowMeshBackend::setVerboseModeState(bool enabled) {MeshBackendBase::setVerboseModeState(enabled); _staticVerboseMode = enabled;}
|
void EspnowMeshBackend::setVerboseModeState(const bool enabled) {MeshBackendBase::setVerboseModeState(enabled); _staticVerboseMode = enabled;}
|
||||||
bool EspnowMeshBackend::verboseMode() {return staticVerboseMode();}
|
bool EspnowMeshBackend::verboseMode() const {return staticVerboseMode();}
|
||||||
|
|
||||||
void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, bool newline)
|
void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, const bool newline) const
|
||||||
{
|
{
|
||||||
if(verboseMode())
|
if(verboseMode())
|
||||||
{
|
{
|
||||||
@ -57,7 +57,7 @@ void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, bool newli
|
|||||||
|
|
||||||
bool EspnowMeshBackend::staticVerboseMode() {return _staticVerboseMode;}
|
bool EspnowMeshBackend::staticVerboseMode() {return _staticVerboseMode;}
|
||||||
|
|
||||||
void EspnowMeshBackend::staticVerboseModePrint(const String &stringToPrint, bool newline)
|
void EspnowMeshBackend::staticVerboseModePrint(const String &stringToPrint, const bool newline)
|
||||||
{
|
{
|
||||||
if(staticVerboseMode())
|
if(staticVerboseMode())
|
||||||
{
|
{
|
||||||
@ -68,10 +68,10 @@ void EspnowMeshBackend::staticVerboseModePrint(const String &stringToPrint, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshBackendBase::setPrintWarnings(bool printEnabled) {_printWarnings = printEnabled;}
|
void MeshBackendBase::setPrintWarnings(const bool printEnabled) {_printWarnings = printEnabled;}
|
||||||
bool MeshBackendBase::printWarnings() {return _printWarnings;}
|
bool MeshBackendBase::printWarnings() {return _printWarnings;}
|
||||||
|
|
||||||
void MeshBackendBase::warningPrint(const String &stringToPrint, bool newline)
|
void MeshBackendBase::warningPrint(const String &stringToPrint, const bool newline)
|
||||||
{
|
{
|
||||||
if(printWarnings())
|
if(printWarnings())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user