remove senderWithAddress from NodeList

This commit is contained in:
Stephen Birarda 2014-02-06 14:43:46 -08:00
parent a823722d27
commit 97a7369c76
15 changed files with 42 additions and 66 deletions

View file

@ -39,7 +39,7 @@ void OctreeInboundPacketProcessor::resetStats() {
} }
void OctreeInboundPacketProcessor::processPacket(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { void OctreeInboundPacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
bool debugProcessPacket = _myServer->wantsVerboseDebug(); bool debugProcessPacket = _myServer->wantsVerboseDebug();
@ -55,8 +55,6 @@ void OctreeInboundPacketProcessor::processPacket(const HifiSockAddr& senderSockA
if (_myServer->getOctree()->handlesEditPacketType(packetType)) { if (_myServer->getOctree()->handlesEditPacketType(packetType)) {
PerformanceWarning warn(debugProcessPacket, "processPacket KNOWN TYPE",debugProcessPacket); PerformanceWarning warn(debugProcessPacket, "processPacket KNOWN TYPE",debugProcessPacket);
_receivedPacketCount++; _receivedPacketCount++;
SharedNodePointer senderNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
const unsigned char* packetData = reinterpret_cast<const unsigned char*>(packet.data()); const unsigned char* packetData = reinterpret_cast<const unsigned char*>(packet.data());
@ -90,7 +88,7 @@ void OctreeInboundPacketProcessor::processPacket(const HifiSockAddr& senderSockA
int editDataBytesRead = _myServer->getOctree()->processEditPacketData(packetType, int editDataBytesRead = _myServer->getOctree()->processEditPacketData(packetType,
reinterpret_cast<const unsigned char*>(packet.data()), reinterpret_cast<const unsigned char*>(packet.data()),
packet.size(), packet.size(),
editData, maxSize, senderNode.data()); editData, maxSize, sendingNode.data());
_myServer->getOctree()->unlock(); _myServer->getOctree()->unlock();
quint64 endProcess = usecTimestampNow(); quint64 endProcess = usecTimestampNow();
@ -113,9 +111,9 @@ void OctreeInboundPacketProcessor::processPacket(const HifiSockAddr& senderSockA
// Make sure our Node and NodeList knows we've heard from this node. // Make sure our Node and NodeList knows we've heard from this node.
QUuid& nodeUUID = DEFAULT_NODE_ID_REF; QUuid& nodeUUID = DEFAULT_NODE_ID_REF;
if (senderNode) { if (sendingNode) {
senderNode->setLastHeardMicrostamp(usecTimestampNow()); sendingNode->setLastHeardMicrostamp(usecTimestampNow());
nodeUUID = senderNode->getUUID(); nodeUUID = sendingNode->getUUID();
if (debugProcessPacket) { if (debugProcessPacket) {
qDebug() << "sender has uuid=" << nodeUUID; qDebug() << "sender has uuid=" << nodeUUID;
} }

View file

@ -63,7 +63,7 @@ public:
NodeToSenderStatsMap& getSingleSenderStats() { return _singleSenderStats; } NodeToSenderStatsMap& getSingleSenderStats() { return _singleSenderStats; }
protected: protected:
virtual void processPacket(const HifiSockAddr& senderSockAddr, const QByteArray& packet); virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
private: private:
void trackInboundPackets(const QUuid& nodeUUID, int sequence, quint64 transitTime, void trackInboundPackets(const QUuid& nodeUUID, int sequence, quint64 transitTime,

View file

@ -3948,27 +3948,25 @@ void Application::nodeKilled(SharedNodePointer node) {
} }
} }
void Application::trackIncomingVoxelPacket(const QByteArray& packet, const HifiSockAddr& senderSockAddr, bool wasStatsPacket) { void Application::trackIncomingVoxelPacket(const QByteArray& packet, const SharedNodePointer& sendingNode, bool wasStatsPacket) {
// Attempt to identify the sender from it's address. // Attempt to identify the sender from it's address.
SharedNodePointer serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr); if (sendingNode) {
if (serverNode) { QUuid nodeUUID = sendingNode->getUUID();
QUuid nodeUUID = serverNode->getUUID();
// now that we know the node ID, let's add these stats to the stats for that node... // now that we know the node ID, let's add these stats to the stats for that node...
_voxelSceneStatsLock.lockForWrite(); _voxelSceneStatsLock.lockForWrite();
if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) {
VoxelSceneStats& stats = _octreeServerSceneStats[nodeUUID]; VoxelSceneStats& stats = _octreeServerSceneStats[nodeUUID];
stats.trackIncomingOctreePacket(packet, wasStatsPacket, serverNode->getClockSkewUsec()); stats.trackIncomingOctreePacket(packet, wasStatsPacket, sendingNode->getClockSkewUsec());
} }
_voxelSceneStatsLock.unlock(); _voxelSceneStatsLock.unlock();
} }
} }
int Application::parseOctreeStats(const QByteArray& packet, const HifiSockAddr& senderSockAddr) { int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePointer& sendingNode) {
// But, also identify the sender, and keep track of the contained jurisdiction root for this server // But, also identify the sender, and keep track of the contained jurisdiction root for this server
SharedNodePointer server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
// parse the incoming stats datas stick it in a temporary object for now, while we // parse the incoming stats datas stick it in a temporary object for now, while we
// determine which server it belongs to // determine which server it belongs to
@ -3976,8 +3974,8 @@ int Application::parseOctreeStats(const QByteArray& packet, const HifiSockAddr&
int statsMessageLength = temp.unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), packet.size()); int statsMessageLength = temp.unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), packet.size());
// quick fix for crash... why would voxelServer be NULL? // quick fix for crash... why would voxelServer be NULL?
if (server) { if (sendingNode) {
QUuid nodeUUID = server->getUUID(); QUuid nodeUUID = sendingNode->getUUID();
// now that we know the node ID, let's add these stats to the stats for that node... // now that we know the node ID, let's add these stats to the stats for that node...
_voxelSceneStatsLock.lockForWrite(); _voxelSceneStatsLock.lockForWrite();
@ -3994,7 +3992,7 @@ int Application::parseOctreeStats(const QByteArray& packet, const HifiSockAddr&
// see if this is the first we've heard of this node... // see if this is the first we've heard of this node...
NodeToJurisdictionMap* jurisdiction = NULL; NodeToJurisdictionMap* jurisdiction = NULL;
if (server->getType() == NodeType::VoxelServer) { if (sendingNode->getType() == NodeType::VoxelServer) {
jurisdiction = &_voxelServerJurisdictions; jurisdiction = &_voxelServerJurisdictions;
} else { } else {
jurisdiction = &_particleServerJurisdictions; jurisdiction = &_particleServerJurisdictions;

View file

@ -470,8 +470,8 @@ private:
PieMenu _pieMenu; PieMenu _pieMenu;
int parseOctreeStats(const QByteArray& packet, const HifiSockAddr& senderAddress); int parseOctreeStats(const QByteArray& packet, const SharedNodePointer& sendingNode);
void trackIncomingVoxelPacket(const QByteArray& packet, const HifiSockAddr& senderSockAddr, bool wasStatsPacket); void trackIncomingVoxelPacket(const QByteArray& packet, const SharedNodePointer& sendingNode, bool wasStatsPacket);
NodeToJurisdictionMap _voxelServerJurisdictions; NodeToJurisdictionMap _voxelServerJurisdictions;
NodeToJurisdictionMap _particleServerJurisdictions; NodeToJurisdictionMap _particleServerJurisdictions;

View file

@ -40,6 +40,9 @@ void DatagramProcessor::processDatagrams() {
_packetCount++; _packetCount++;
_byteCount += incomingPacket.size(); _byteCount += incomingPacket.size();
QUuid nodeUUID;
deconstructPacketHeader(incomingPacket, nodeUUID);
if (packetVersionMatch(incomingPacket)) { if (packetVersionMatch(incomingPacket)) {
// only process this packet if we have a match on the packet version // only process this packet if we have a match on the packet version
switch (packetTypeForPacket(incomingPacket)) { switch (packetTypeForPacket(incomingPacket)) {
@ -84,9 +87,6 @@ void DatagramProcessor::processDatagrams() {
printf("got PacketType_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime); printf("got PacketType_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
} }
QUuid nodeUUID;
deconstructPacketHeader(incomingPacket, nodeUUID);
SharedNodePointer matchedNode = NodeList::getInstance()->nodeWithUUID(nodeUUID); SharedNodePointer matchedNode = NodeList::getInstance()->nodeWithUUID(nodeUUID);
if (matchedNode) { if (matchedNode) {
@ -103,7 +103,7 @@ void DatagramProcessor::processDatagrams() {
case PacketTypeKillAvatar: case PacketTypeKillAvatar:
case PacketTypeAvatarIdentity: { case PacketTypeAvatarIdentity: {
// update having heard from the avatar-mixer and record the bytes received // update having heard from the avatar-mixer and record the bytes received
SharedNodePointer avatarMixer = NodeList::getInstance()->nodeWithAddress(senderSockAddr); SharedNodePointer avatarMixer = nodeList->nodeWithUUID(nodeUUID);
if (avatarMixer) { if (avatarMixer) {
avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); avatarMixer->setLastHeardMicrostamp(usecTimestampNow());

View file

@ -14,7 +14,7 @@
#include "Menu.h" #include "Menu.h"
#include "VoxelPacketProcessor.h" #include "VoxelPacketProcessor.h"
void VoxelPacketProcessor::processPacket(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { void VoxelPacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"VoxelPacketProcessor::processPacket()"); "VoxelPacketProcessor::processPacket()");
@ -44,7 +44,7 @@ void VoxelPacketProcessor::processPacket(const HifiSockAddr& senderSockAddr, con
// then process any remaining bytes as if it was another packet // then process any remaining bytes as if it was another packet
if (voxelPacketType == PacketTypeOctreeStats) { if (voxelPacketType == PacketTypeOctreeStats) {
int statsMessageLength = app->parseOctreeStats(mutablePacket, senderSockAddr); int statsMessageLength = app->parseOctreeStats(mutablePacket, sendingNode);
wasStatsPacket = true; wasStatsPacket = true;
if (messageLength > statsMessageLength) { if (messageLength > statsMessageLength) {
mutablePacket = mutablePacket.mid(statsMessageLength); mutablePacket = mutablePacket.mid(statsMessageLength);
@ -60,26 +60,25 @@ void VoxelPacketProcessor::processPacket(const HifiSockAddr& senderSockAddr, con
voxelPacketType = packetTypeForPacket(mutablePacket); voxelPacketType = packetTypeForPacket(mutablePacket);
if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
app->trackIncomingVoxelPacket(mutablePacket, senderSockAddr, wasStatsPacket); app->trackIncomingVoxelPacket(mutablePacket, sendingNode, wasStatsPacket);
SharedNodePointer serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr); if (sendingNode) {
if (serverNode && serverNode->getActiveSocket() && *serverNode->getActiveSocket() == senderSockAddr) {
switch(voxelPacketType) { switch(voxelPacketType) {
case PacketTypeParticleErase: { case PacketTypeParticleErase: {
app->_particles.processEraseMessage(mutablePacket, senderSockAddr, serverNode.data()); app->_particles.processEraseMessage(mutablePacket, *sendingNode->getActiveSocket(), sendingNode.data());
} break; } break;
case PacketTypeParticleData: { case PacketTypeParticleData: {
app->_particles.processDatagram(mutablePacket, senderSockAddr, serverNode.data()); app->_particles.processDatagram(mutablePacket, *sendingNode->getActiveSocket(), sendingNode.data());
} break; } break;
case PacketTypeEnvironmentData: { case PacketTypeEnvironmentData: {
app->_environment.parseData(senderSockAddr, mutablePacket); app->_environment.parseData(*sendingNode->getActiveSocket(), mutablePacket);
} break; } break;
default : { default : {
app->_voxels.setDataSourceUUID(serverNode->getUUID()); app->_voxels.setDataSourceUUID(sendingNode->getUUID());
app->_voxels.parseData(mutablePacket); app->_voxels.parseData(mutablePacket);
app->_voxels.setDataSourceUUID(QUuid()); app->_voxels.setDataSourceUUID(QUuid());
} break; } break;

View file

@ -17,6 +17,6 @@
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket() /// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
class VoxelPacketProcessor : public ReceivedPacketProcessor { class VoxelPacketProcessor : public ReceivedPacketProcessor {
protected: protected:
virtual void processPacket(const HifiSockAddr& senderSockAddr, const QByteArray& packet); virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
}; };
#endif // __shared__VoxelPacketProcessor__ #endif // __shared__VoxelPacketProcessor__

View file

@ -61,16 +61,13 @@ bool JurisdictionListener::queueJurisdictionRequest() {
return isStillRunning(); return isStillRunning();
} }
void JurisdictionListener::processPacket(const HifiSockAddr& senderAddress, const QByteArray& packet) { void JurisdictionListener::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
//qDebug() << "JurisdictionListener::processPacket()"; //qDebug() << "JurisdictionListener::processPacket()";
if (packetTypeForPacket(packet) == PacketTypeJurisdictionRequest) { if (packetTypeForPacket(packet) == PacketTypeJurisdictionRequest && sendingNode) {
SharedNodePointer node = NodeList::getInstance()->nodeWithAddress(senderAddress); QUuid nodeUUID = sendingNode->getUUID();
if (node) { JurisdictionMap map;
QUuid nodeUUID = node->getUUID(); map.unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), packet.size());
JurisdictionMap map; _jurisdictions[nodeUUID] = map;
map.unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), packet.size());
_jurisdictions[nodeUUID] = map;
}
} }
} }

View file

@ -49,7 +49,7 @@ protected:
/// \param packetData pointer to received data /// \param packetData pointer to received data
/// \param ssize_t packetLength size of received data /// \param ssize_t packetLength size of received data
/// \thread "this" individual processing thread /// \thread "this" individual processing thread
virtual void processPacket(const HifiSockAddr& senderAddress, const QByteArray& packet); virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
private: private:
NodeToJurisdictionMap _jurisdictions; NodeToJurisdictionMap _jurisdictions;

View file

@ -28,13 +28,11 @@ JurisdictionSender::~JurisdictionSender() {
} }
void JurisdictionSender::processPacket(const HifiSockAddr& senderAddress, const QByteArray& packet) { void JurisdictionSender::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
if (packetTypeForPacket(packet) == PacketTypeJurisdictionRequest) { if (packetTypeForPacket(packet) == PacketTypeJurisdictionRequest) {
QUuid nodeUUID; if (sendingNode) {
deconstructPacketHeader(packet, nodeUUID);
if (!nodeUUID.isNull()) {
lockRequestingNodes(); lockRequestingNodes();
_nodesRequestingJurisdictions.push(nodeUUID); _nodesRequestingJurisdictions.push(sendingNode->getUUID());
unlockRequestingNodes(); unlockRequestingNodes();
} }
} }

View file

@ -37,7 +37,7 @@ public:
void setNodeType(NodeType_t type) { _nodeType = type; } void setNodeType(NodeType_t type) { _nodeType = type; }
protected: protected:
virtual void processPacket(const HifiSockAddr& senderAddress, const QByteArray& packet); virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
/// Locks all the resources of the thread. /// Locks all the resources of the thread.
void lockRequestingNodes() { _requestingNodeMutex.lock(); } void lockRequestingNodes() { _requestingNodeMutex.lock(); }

View file

@ -246,18 +246,6 @@ int NodeList::updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr,
} }
} }
SharedNodePointer NodeList::nodeWithAddress(const HifiSockAddr &senderSockAddr) {
// naively returns the first node that has a matching active HifiSockAddr
// note that there can be multiple nodes that have a matching active socket, so this isn't a good way to uniquely identify
foreach (const SharedNodePointer& node, getNodeHash()) {
if (node->getActiveSocket() && *node->getActiveSocket() == senderSockAddr) {
return node;
}
}
return SharedNodePointer();
}
SharedNodePointer NodeList::nodeWithUUID(const QUuid& nodeUUID) { SharedNodePointer NodeList::nodeWithUUID(const QUuid& nodeUUID) {
QMutexLocker locker(&_nodeHashMutex); QMutexLocker locker(&_nodeHashMutex);
return _nodeHash.value(nodeUUID); return _nodeHash.value(nodeUUID);

View file

@ -104,7 +104,6 @@ public:
QByteArray constructPingReplyPacket(const QByteArray& pingPacket); QByteArray constructPingReplyPacket(const QByteArray& pingPacket);
void pingPublicAndLocalSocketsForInactiveNode(Node* node); void pingPublicAndLocalSocketsForInactiveNode(Node* node);
SharedNodePointer nodeWithAddress(const HifiSockAddr& senderSockAddr);
SharedNodePointer nodeWithUUID(const QUuid& nodeUUID); SharedNodePointer nodeWithUUID(const QUuid& nodeUUID);
SharedNodePointer addOrUpdateNode(const QUuid& uuid, char nodeType, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); SharedNodePointer addOrUpdateNode(const QUuid& uuid, char nodeType, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);

View file

@ -41,8 +41,7 @@ bool ReceivedPacketProcessor::process() {
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
_packets.erase(_packets.begin()); // remove the oldest packet _packets.erase(_packets.begin()); // remove the oldest packet
unlock(); // let others add to the packets unlock(); // let others add to the packets
processPacket(*temporary.getDestinationNode()->getActiveSocket(), processPacket(temporary.getDestinationNode(), temporary.getByteArray()); // process our temporary copy
temporary.getByteArray()); // process our temporary copy
} }
return isStillRunning(); // keep running till they terminate us return isStillRunning(); // keep running till they terminate us
} }

View file

@ -38,7 +38,7 @@ protected:
/// \param packetData pointer to received data /// \param packetData pointer to received data
/// \param ssize_t packetLength size of received data /// \param ssize_t packetLength size of received data
/// \thread "this" individual processing thread /// \thread "this" individual processing thread
virtual void processPacket(const HifiSockAddr& senderAddress, const QByteArray& packet) = 0; virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) = 0;
/// Implements generic processing behavior for this thread. /// Implements generic processing behavior for this thread.
virtual bool process(); virtual bool process();