diff --git a/proto b/proto index 2cb162a3..e95239a2 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 2cb162a3036b8513c743f05bd4f06aacb0b0680d +Subproject commit e95239a2ec9ac41ba77fac47ae531640bb0f8078 diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 0b63247e..fba0aee4 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -195,7 +195,15 @@ void Router::handleReceived(MeshPacket *p) void Router::perhapsHandleReceived(MeshPacket *p) { - if (!shouldFilterReceived(p)) + assert(radioConfig.has_preferences); + bool inIgnore = is_in_repeated(radioConfig.preferences.ignore_incoming, p->from); + + if (inIgnore) + DEBUG_MSG("Ignoring incoming message, 0x%x is in our ignore list\n", p->from); + + // Note: we avoid calling shouldFilterReceived if we are supposed to ignore certain nodes - because some overrides might + // cache/learn of the existence of nodes (i.e. FloodRouter) that they should not + if (!inIgnore && !shouldFilterReceived(p)) handleReceived(p); packetPool.release(p); diff --git a/src/mesh/mesh-pb-constants.cpp b/src/mesh/mesh-pb-constants.cpp index 7e380011..894afe47 100644 --- a/src/mesh/mesh-pb-constants.cpp +++ b/src/mesh/mesh-pb-constants.cpp @@ -64,3 +64,12 @@ bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count) return false; #endif } + +bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count) +{ + for (int i = 0; i < count; i++) + if (array[i] == n) + return true; + + return false; +} \ No newline at end of file diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index 661c1388..baa9f5b5 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -25,3 +25,13 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count); /// Write to an arduino file bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count); + +/** is_in_repeated is a macro/function that returns true if a specified word appears in a repeated protobuf array. + * It relies on the following naming conventions from nanopb: + * + * pb_size_t ignore_incoming_count; + * uint32_t ignore_incoming[3]; + */ +bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count); + +#define is_in_repeated(name, n) is_in_helper(n, name, name##_count) \ No newline at end of file diff --git a/src/mesh/mesh.pb.h b/src/mesh/mesh.pb.h index 1c2ecff8..3a324161 100644 --- a/src/mesh/mesh.pb.h +++ b/src/mesh/mesh.pb.h @@ -91,6 +91,8 @@ typedef struct _RadioConfig_UserPreferences { uint32_t min_wake_secs; bool keep_all_packets; bool promiscuous_mode; + pb_size_t ignore_incoming_count; + uint32_t ignore_incoming[3]; } RadioConfig_UserPreferences; typedef struct _RouteDiscovery { @@ -220,7 +222,7 @@ typedef struct _ToRadio { #define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, ""} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0} #define MyNodeInfo_init_default {0, 0, 0, "", "", "", 0, 0, 0} #define DeviceState_init_default {false, RadioConfig_init_default, false, MyNodeInfo_init_default, false, User_init_default, 0, {NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default}, 0, {MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default}, false, MeshPacket_init_default, 0} @@ -236,7 +238,7 @@ typedef struct _ToRadio { #define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, ""} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0} #define MyNodeInfo_init_zero {0, 0, 0, "", "", "", 0, 0, 0} #define DeviceState_init_zero {false, RadioConfig_init_zero, false, MyNodeInfo_init_zero, false, User_init_zero, 0, {NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero}, 0, {MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero}, false, MeshPacket_init_zero, 0} @@ -284,6 +286,7 @@ typedef struct _ToRadio { #define RadioConfig_UserPreferences_min_wake_secs_tag 11 #define RadioConfig_UserPreferences_keep_all_packets_tag 100 #define RadioConfig_UserPreferences_promiscuous_mode_tag 101 +#define RadioConfig_UserPreferences_ignore_incoming_tag 102 #define RouteDiscovery_route_tag 2 #define User_id_tag 1 #define User_long_name_tag 2 @@ -424,7 +427,8 @@ X(a, STATIC, SINGULAR, UINT32, sds_secs, 9) \ X(a, STATIC, SINGULAR, UINT32, ls_secs, 10) \ X(a, STATIC, SINGULAR, UINT32, min_wake_secs, 11) \ X(a, STATIC, SINGULAR, BOOL, keep_all_packets, 100) \ -X(a, STATIC, SINGULAR, BOOL, promiscuous_mode, 101) +X(a, STATIC, SINGULAR, BOOL, promiscuous_mode, 101) \ +X(a, STATIC, REPEATED, UINT32, ignore_incoming, 102) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -553,11 +557,11 @@ extern const pb_msgdesc_t ManufacturingData_msg; #define SubPacket_size 273 #define MeshPacket_size 312 #define ChannelSettings_size 60 -#define RadioConfig_size 136 -#define RadioConfig_UserPreferences_size 72 +#define RadioConfig_size 157 +#define RadioConfig_UserPreferences_size 93 #define NodeInfo_size 132 #define MyNodeInfo_size 80 -#define DeviceState_size 15016 +#define DeviceState_size 15037 #define DebugString_size 258 #define FromRadio_size 321 #define ToRadio_size 315