Local IDs - add an explicit null value, use it for replicated packets

This commit is contained in:
Simon Walton 2018-03-30 18:29:26 -07:00
parent 734b48eee0
commit efb1fdbc0d
6 changed files with 9 additions and 5 deletions

View file

@ -137,7 +137,7 @@ void AudioMixer::queueReplicatedAudioPacket(QSharedPointer<ReceivedMessage> mess
auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(audioData, rewrittenType, auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(audioData, rewrittenType,
versionForPacketType(rewrittenType), versionForPacketType(rewrittenType),
message->getSenderSockAddr(), message->getSourceID()); message->getSenderSockAddr(), Node::NULL_LOCAL_ID);
getOrCreateClientData(replicatedNode.data())->queuePacket(replicatedMessage, replicatedNode); getOrCreateClientData(replicatedNode.data())->queuePacket(replicatedMessage, replicatedNode);
} }

View file

@ -127,7 +127,7 @@ void AvatarMixer::handleReplicatedBulkAvatarPacket(QSharedPointer<ReceivedMessag
// construct a "fake" avatar data received message from the byte array and packet list information // construct a "fake" avatar data received message from the byte array and packet list information
auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(avatarByteArray, PacketType::AvatarData, auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(avatarByteArray, PacketType::AvatarData,
versionForPacketType(PacketType::AvatarData), versionForPacketType(PacketType::AvatarData),
message->getSenderSockAddr(), message->getSourceID()); message->getSenderSockAddr(), Node::NULL_LOCAL_ID);
// queue up the replicated avatar data with the client data for the replicated node // queue up the replicated avatar data with the client data for the replicated node
auto start = usecTimestampNow(); auto start = usecTimestampNow();

View file

@ -1039,7 +1039,7 @@ Node::LocalID DomainGatekeeper::findOrCreateLocalID(const QUuid& uuid) {
do { do {
newLocalID = _currentLocalID; newLocalID = _currentLocalID;
_currentLocalID += _idIncrement; _currentLocalID += _idIncrement;
} while (newLocalID == 0 || _localIDs.find(newLocalID) != _localIDs.end()); } while (newLocalID == Node::NULL_LOCAL_ID || _localIDs.find(newLocalID) != _localIDs.end());
_uuidToLocalID.emplace(uuid, newLocalID); _uuidToLocalID.emplace(uuid, newLocalID);
_localIDs.insert(newLocalID); _localIDs.insert(newLocalID);

View file

@ -38,6 +38,8 @@ public:
// //
using LocalID = NetworkLocalID; using LocalID = NetworkLocalID;
static const LocalID NULL_LOCAL_ID = 0;
static const int NUM_BYTES_LOCALID = sizeof(LocalID); static const int NUM_BYTES_LOCALID = sizeof(LocalID);
// this is used by the Octree classes - must be known at compile time // this is used by the Octree classes - must be known at compile time
static const int MAX_PACKET_HEADER_SIZE = static const int MAX_PACKET_HEADER_SIZE =

View file

@ -41,6 +41,8 @@ public:
void setUUID(const QUuid& uuid) { _uuid = uuid; } void setUUID(const QUuid& uuid) { _uuid = uuid; }
using LocalID = NetworkLocalID; using LocalID = NetworkLocalID;
static const LocalID NULL_LOCAL_ID = 0;
LocalID getLocalID() const { return _localID; } LocalID getLocalID() const { return _localID; }
void setLocalID(LocalID localID) { _localID = localID; } void setLocalID(LocalID localID) { _localID = localID; }

View file

@ -25,7 +25,7 @@ public:
ReceivedMessage(const NLPacketList& packetList); ReceivedMessage(const NLPacketList& packetList);
ReceivedMessage(NLPacket& packet); ReceivedMessage(NLPacket& packet);
ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion, ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion,
const HifiSockAddr& senderSockAddr, NLPacket::LocalID sourceID = 0); const HifiSockAddr& senderSockAddr, NLPacket::LocalID sourceID = NLPacket::NULL_LOCAL_ID);
QByteArray getMessage() const { return _data; } QByteArray getMessage() const { return _data; }
const char* getRawMessage() const { return _data.constData(); } const char* getRawMessage() const { return _data.constData(); }
@ -93,7 +93,7 @@ private:
std::atomic<qint64> _position { 0 }; std::atomic<qint64> _position { 0 };
std::atomic<qint64> _numPackets { 0 }; std::atomic<qint64> _numPackets { 0 };
NLPacket::LocalID _sourceID; NLPacket::LocalID _sourceID { NLPacket::NULL_LOCAL_ID };
PacketType _packetType; PacketType _packetType;
PacketVersion _packetVersion; PacketVersion _packetVersion;
HifiSockAddr _senderSockAddr; HifiSockAddr _senderSockAddr;