Communication: Fix NetID VNET conflict

There exists a potential conflict with some existing NetIDs and VNET NetIDs in the 200 range. To resolve this there is now an additional optional "expand" argument in various functions that could conflict. In most situations this should be false, and is false for MessageFilters to retain the existing behavior.
pull/61/head
Jonathan Schwartz 2023-08-14 21:47:35 +00:00 committed by Kyle Schwarz
parent 41d6927496
commit 53e66b8772
3 changed files with 1234 additions and 1247 deletions

View File

@ -72,7 +72,7 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
packetLength = bytes[2]; // Long packets have a little endian length on bytes 3 and 4 packetLength = bytes[2]; // Long packets have a little endian length on bytes 3 and 4
packetLength |= bytes[3] << 8; packetLength |= bytes[3] << 8;
packet.network = Network((bytes[5] << 8) | bytes[4]); // Long packets have their netid stored as little endian on bytes 5 and 6 packet.network = Network(((bytes[5] << 8) | bytes[4]), false); // Long packets have their netid stored as little endian on bytes 5 and 6. Devices never send actual VNET IDs so we must not perform ID expansion here.
currentIndex += 4; currentIndex += 4;
/* Long packets can't have a length less than 6, because that would indicate a negative payload size. /* Long packets can't have a length less than 6, because that would indicate a negative payload size.

View File

@ -13,7 +13,7 @@ class MessageFilter {
public: public:
MessageFilter() {} MessageFilter() {}
MessageFilter(Message::Type type) : includeInternalInAny(neomessagetype_t(type) & 0x8000), messageType(type) {} MessageFilter(Message::Type type) : includeInternalInAny(neomessagetype_t(type) & 0x8000), messageType(type) {}
MessageFilter(Network::NetID netid) : MessageFilter(Network::GetTypeOfNetID(netid), netid) {} MessageFilter(Network::NetID netid) : MessageFilter(Network::GetTypeOfNetID(netid, false), netid) {} // Messages on the communication layer are never encoded as VNET ID + common ID, so skip the expansion step
MessageFilter(Network::Type type, Network::NetID net = Network::NetID::Any) : networkType(type), netid(net) { MessageFilter(Network::Type type, Network::NetID net = Network::NetID::Any) : networkType(type), netid(net) {
// If a Network::Type::Internal is used, we want to also get internal Message::Types // If a Network::Type::Internal is used, we want to also get internal Message::Types
// The NetID we want may be in there // The NetID we want may be in there

File diff suppressed because it is too large Load Diff