Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-06 11:11:49 -07:00
commit 632bc3aa40
32 changed files with 150 additions and 122 deletions

View file

@ -18,7 +18,7 @@ AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Se
{ {
} }
int AvatarAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) { int AvatarAudioStream::parseStreamProperties (PacketType::Value type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
int readBytes = 0; int readBytes = 0;
if (type == PacketTypeSilentAudioFrame) { if (type == PacketTypeSilentAudioFrame) {

View file

@ -25,7 +25,7 @@ private:
AvatarAudioStream(const AvatarAudioStream&); AvatarAudioStream(const AvatarAudioStream&);
AvatarAudioStream& operator= (const AvatarAudioStream&); AvatarAudioStream& operator= (const AvatarAudioStream&);
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples); int parseStreamProperties (PacketType::Value type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
}; };
#endif // hifi_AvatarAudioStream_h #endif // hifi_AvatarAudioStream_h

View file

@ -1322,14 +1322,14 @@ void DomainServer::pingPunchForConnectingPeer(const SharedNetworkPeer& peer) {
_icePeers.remove(peer->getUUID()); _icePeers.remove(peer->getUUID());
} else { } else {
auto nodeList = DependencyManager::get<LimitedNodeList>(); auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
// send the ping packet to the local and public sockets for this node // send the ping packet to the local and public sockets for this node
QByteArray localPingPacket = nodeList->constructPingPacket(PingType::Local, false); auto localPingPacket = nodeList->constructICEPingPacket(PingType::Local, limitedNodeList->getSessionUUID());
nodeList->writeUnverifiedDatagram(localPingPacket, peer->getLocalSocket()); limitedNodeList->sendPacket(localPingPacket, peer->getLocalSocket());
QByteArray publicPingPacket = nodeList->constructPingPacket(PingType::Public, false); auto publicPingPacket = nodeList->constructICEPingPacket(PingType::Public, limitedNodeList->getSessionUUID());
nodeList->writeUnverifiedDatagram(publicPingPacket, peer->getPublicSocket()); limitedNodeList->sendPacket(publicPingPacket, peer->getPublicSocket());
peer->incrementConnectionAttempts(); peer->incrementConnectionAttempts();
} }

View file

@ -1097,13 +1097,6 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum)
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }
void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) {
foreach(NodeType_t type, destinationNodeTypes) {
// Perform the broadcast for one type
DependencyManager::get<NodeList>()->broadcastToNodes(packet, NodeSet() << type);
}
}
bool Application::importSVOFromURL(const QString& urlString) { bool Application::importSVOFromURL(const QString& urlString) {
QUrl url(urlString); QUrl url(urlString);
emit svoImportRequested(url.url()); emit svoImportRequested(url.url());
@ -1763,10 +1756,21 @@ bool Application::acceptSnapshot(const QString& urlString) {
} }
void Application::sendPingPackets() { void Application::sendPingPackets() {
QByteArray pingPacket = DependencyManager::get<NodeList>()->constructPingPacket();
controlledBroadcastToNodes(pingPacket, NodeSet() auto nodeList = DependencyManager::get<NodeList>();
<< NodeType::EntityServer
<< NodeType::AudioMixer << NodeType::AvatarMixer); nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool {
switch (node->getType()) {
case NodeType::AvatarMixer:
case NodeType::AudioMixer:
case NodeType::EntityServer:
return true;
default:
return false;
}
}, [nodeList](const SharedNodePointer& node) {
nodeList->sendPacket(std::move(nodeList->constructPingPacket()), node);
});
} }
// Every second, check the frame rates and other stuff // Every second, check the frame rates and other stuff

View file

@ -271,8 +271,6 @@ public:
void resetProfile(const QString& username); void resetProfile(const QString& username);
void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes);
virtual void setupWorldLight(); virtual void setupWorldLight();
virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera); virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera);

View file

@ -168,7 +168,7 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
return readBytes; return readBytes;
} }
int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) { int InboundAudioStream::parseStreamProperties (PacketType::Value type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
if (type == PacketTypeSilentAudioFrame) { if (type == PacketTypeSilentAudioFrame) {
quint16 numSilentSamples = 0; quint16 numSilentSamples = 0;
memcpy(&numSilentSamples, packetAfterSeqNum.constData(), sizeof(quint16)); memcpy(&numSilentSamples, packetAfterSeqNum.constData(), sizeof(quint16));
@ -181,7 +181,7 @@ int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray&
} }
} }
int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) { int InboundAudioStream::parseAudioData (PacketType::Value type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t)); return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t));
} }

View file

@ -194,11 +194,11 @@ protected:
/// parses the info between the seq num and the audio data in the network packet and calculates /// parses the info between the seq num and the audio data in the network packet and calculates
/// how many audio samples this packet contains (used when filling in samples for dropped packets). /// how many audio samples this packet contains (used when filling in samples for dropped packets).
/// default implementation assumes no stream properties and raw audio samples after stream propertiess /// default implementation assumes no stream properties and raw audio samples after stream propertiess
virtual int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& networkSamples); virtual int parseStreamProperties (PacketType::Value type, const QByteArray& packetAfterSeqNum, int& networkSamples);
/// parses the audio data in the network packet. /// parses the audio data in the network packet.
/// default implementation assumes packet contains raw audio samples after stream properties /// default implementation assumes packet contains raw audio samples after stream properties
virtual int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples); virtual int parseAudioData (PacketType::Value type, const QByteArray& packetAfterStreamProperties, int networkSamples);
/// writes silent samples to the buffer that may be dropped to reduce latency caused by the buffer /// writes silent samples to the buffer that may be dropped to reduce latency caused by the buffer
virtual int writeDroppableSilentSamples(int silentSamples); virtual int writeDroppableSilentSamples(int silentSamples);

View file

@ -30,7 +30,7 @@ InjectedAudioStream::InjectedAudioStream(const QUuid& streamIdentifier, const bo
const uchar MAX_INJECTOR_VOLUME = 255; const uchar MAX_INJECTOR_VOLUME = 255;
int InjectedAudioStream::parseStreamProperties(PacketType type, int InjectedAudioStream::parseStreamProperties (PacketType::Value type,
const QByteArray& packetAfterSeqNum, const QByteArray& packetAfterSeqNum,
int& numAudioSamples) { int& numAudioSamples) {
// setup a data stream to read from this packet // setup a data stream to read from this packet

View file

@ -31,7 +31,7 @@ private:
InjectedAudioStream& operator= (const InjectedAudioStream&); InjectedAudioStream& operator= (const InjectedAudioStream&);
AudioStreamStats getAudioStreamStats() const; AudioStreamStats getAudioStreamStats() const;
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples); int parseStreamProperties (PacketType::Value type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
const QUuid _streamIdentifier; const QUuid _streamIdentifier;
float _radius; float _radius;

View file

@ -42,7 +42,7 @@ int MixedProcessedAudioStream::writeLastFrameRepeatedWithFade(int samples) {
return deviceSamplesWritten; return deviceSamplesWritten;
} }
int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples) { int MixedProcessedAudioStream::parseAudioData (PacketType::Value type, const QByteArray& packetAfterStreamProperties, int networkSamples) {
emit addedStereoSamples(packetAfterStreamProperties); emit addedStereoSamples(packetAfterStreamProperties);

View file

@ -35,7 +35,7 @@ public:
protected: protected:
int writeDroppableSilentSamples(int silentSamples); int writeDroppableSilentSamples(int silentSamples);
int writeLastFrameRepeatedWithFade(int samples); int writeLastFrameRepeatedWithFade(int samples);
int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int networkSamples); int parseAudioData (PacketType::Value type, const QByteArray& packetAfterStreamProperties, int networkSamples);
private: private:
int networkToDeviceSamples(int networkSamples); int networkToDeviceSamples(int networkSamples);

View file

@ -18,7 +18,7 @@
#include "EntityItem.h" #include "EntityItem.h"
void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, void EntityEditPacketSender::adjustEditPacketForClockSkew (PacketType::Value type,
unsigned char* editBuffer, size_t length, int clockSkew) { unsigned char* editBuffer, size_t length, int clockSkew) {
if (type == PacketTypeEntityAdd || type == PacketTypeEntityEdit) { if (type == PacketTypeEntityAdd || type == PacketTypeEntityEdit) {
@ -26,7 +26,7 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type,
} }
} }
void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, void EntityEditPacketSender::queueEditEntityMessage (PacketType::Value type, EntityItemID modelID,
const EntityItemProperties& properties) { const EntityItemProperties& properties) {
if (!_shouldSend) { if (!_shouldSend) {
return; // bail early return; // bail early

View file

@ -24,12 +24,12 @@ public:
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in /// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known. /// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
/// NOTE: EntityItemProperties assumes that all distances are in meter units /// NOTE: EntityItemProperties assumes that all distances are in meter units
void queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties); void queueEditEntityMessage (PacketType::Value type, EntityItemID modelID, const EntityItemProperties& properties);
void queueEraseEntityMessage(const EntityItemID& entityItemID); void queueEraseEntityMessage(const EntityItemID& entityItemID);
// My server type is the model server // My server type is the model server
virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual char getMyNodeType() const { return NodeType::EntityServer; }
virtual void adjustEditPacketForClockSkew(PacketType type, unsigned char* editBuffer, size_t length, int clockSkew); virtual void adjustEditPacketForClockSkew (PacketType::Value type, unsigned char* editBuffer, size_t length, int clockSkew);
}; };
#endif // hifi_EntityEditPacketSender_h #endif // hifi_EntityEditPacketSender_h

View file

@ -614,7 +614,7 @@ void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object
// //
// TODO: Implement support for script and visible properties. // TODO: Implement support for script and visible properties.
// //
bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, bool EntityItemProperties::encodeEntityEditPacket (PacketType::Value command, EntityItemID id, const EntityItemProperties& properties,
unsigned char* bufferOut, int sizeIn, int& sizeOut) { unsigned char* bufferOut, int sizeIn, int& sizeOut) {
OctreePacketData ourDataPacket(false, sizeIn); // create a packetData object to add out packet details too. OctreePacketData ourDataPacket(false, sizeIn); // create a packetData object to add out packet details too.
OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro

View file

@ -174,7 +174,7 @@ public:
void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; }
void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; } void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; }
static bool encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, static bool encodeEntityEditPacket (PacketType::Value command, EntityItemID id, const EntityItemProperties& properties,
unsigned char* bufferOut, int sizeIn, int& sizeOut); unsigned char* bufferOut, int sizeIn, int& sizeOut);
static bool encodeEraseEntityMessage(const EntityItemID& entityItemID, static bool encodeEraseEntityMessage(const EntityItemID& entityItemID,

View file

@ -32,7 +32,7 @@ EntityScriptingInterface::EntityScriptingInterface() :
connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged); connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged);
} }
void EntityScriptingInterface::queueEntityMessage(PacketType packetType, void EntityScriptingInterface::queueEntityMessage (PacketType::Value packetType,
EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID entityID, const EntityItemProperties& properties) {
getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties);
} }

View file

@ -164,7 +164,7 @@ private:
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor); bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor); bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor); bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor);
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); void queueEntityMessage (PacketType::Value packetType, EntityItemID entityID, const EntityItemProperties& properties);
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,

View file

@ -63,7 +63,7 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
Octree::eraseAllOctreeElements(createNewRoot); Octree::eraseAllOctreeElements(createNewRoot);
} }
bool EntityTree::handlesEditPacketType(PacketType packetType) const { bool EntityTree::handlesEditPacketType (PacketType::Value packetType) const {
// we handle these types of "edit" packets // we handle these types of "edit" packets
switch (packetType) { switch (packetType) {
case PacketTypeEntityAdd: case PacketTypeEntityAdd:
@ -572,7 +572,7 @@ EntityItemPointer EntityTree::findEntityByEntityItemID(const EntityItemID& entit
return foundEntity; return foundEntity;
} }
int EntityTree::processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, int EntityTree::processEditPacketData (PacketType::Value packetType, const unsigned char* packetData, int packetLength,
const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode) { const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode) {
if (!getIsServer()) { if (!getIsServer()) {

View file

@ -65,8 +65,8 @@ public:
virtual PacketType::Value expectedDataPacketType() const { return PacketTypeEntityData; } virtual PacketType::Value expectedDataPacketType() const { return PacketTypeEntityData; }
virtual bool canProcessVersion(PacketVersion thisVersion) const virtual bool canProcessVersion(PacketVersion thisVersion) const
{ return thisVersion >= VERSION_ENTITIES_USE_METERS_AND_RADIANS; } { return thisVersion >= VERSION_ENTITIES_USE_METERS_AND_RADIANS; }
virtual bool handlesEditPacketType(PacketType packetType) const; virtual bool handlesEditPacketType (PacketType::Value packetType) const;
virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, virtual int processEditPacketData (PacketType::Value packetType, const unsigned char* packetData, int packetLength,
const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode);
virtual bool rootElementHasData() const { return true; } virtual bool rootElementHasData() const { return true; }

View file

@ -68,9 +68,9 @@ Assignment::Assignment(const QByteArray& packet) :
{ {
PacketType::Value packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
if (packetType == PacketTypeRequestAssignment) { if (packetType == PacketType::RequestAssignment) {
_command = Assignment::RequestCommand; _command = Assignment::RequestCommand;
} else if (packetType == PacketTypeCreateAssignment) { } else if (packetType == PacketType::CreateAssignment) {
_command = Assignment::CreateCommand; _command = Assignment::CreateCommand;
} }

View file

@ -168,10 +168,10 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) {
int numPacketTypeBytes = numBytesArithmeticCodingFromBuffer(packet.data()); int numPacketTypeBytes = numBytesArithmeticCodingFromBuffer(packet.data());
if (packet[numPacketTypeBytes] != versionForPacketType(checkType) if (packet[numPacketTypeBytes] != versionForPacketType(checkType)
&& checkType != PacketTypeStunResponse) { && checkType != PacketType::StunResponse) {
PacketType::Value mismatchType = packetTypeForPacket(packet); PacketType::Value mismatchType = packetTypeForPacket(packet);
static QMultiMap<QUuid, PacketType> versionDebugSuppressMap; static QMultiMap<QUuid, PacketType::Value> versionDebugSuppressMap;
QUuid senderUUID = uuidFromPacketHeader(packet); QUuid senderUUID = uuidFromPacketHeader(packet);
if (!versionDebugSuppressMap.contains(senderUUID, checkType)) { if (!versionDebugSuppressMap.contains(senderUUID, checkType)) {
@ -195,7 +195,7 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) {
if (hashFromPacketHeader(packet) == hashForPacketAndConnectionUUID(packet, sendingNode->getConnectionSecret())) { if (hashFromPacketHeader(packet) == hashForPacketAndConnectionUUID(packet, sendingNode->getConnectionSecret())) {
return true; return true;
} else { } else {
static QMultiMap<QUuid, PacketType> hashDebugSuppressMap; static QMultiMap<QUuid, PacketType::Value> hashDebugSuppressMap;
QUuid senderUUID = uuidFromPacketHeader(packet); QUuid senderUUID = uuidFromPacketHeader(packet);
if (!hashDebugSuppressMap.contains(senderUUID, checkType)) { if (!hashDebugSuppressMap.contains(senderUUID, checkType)) {
@ -521,14 +521,11 @@ unsigned LimitedNodeList::broadcastToNodes(const QByteArray& packet, const NodeS
return n; return n;
} }
QByteArray LimitedNodeList::constructPingPacket(PingType_t pingType, bool isVerified, const QUuid& packetHeaderID) { NodeListPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
int packetSize = sizeof(PingType_t) + sizeof(quint64);
NodeListPacket pingPacket = NodeListPacket::create(PacketType::Ping, packetSize);
QUuid packetUUID = packetHeaderID.isNull() ? _sessionUUID : packetHeaderID; QDataStream packetStream(&pingPacket.payload(), QIODevice::Append);
QByteArray pingPacket = byteArrayWithUUIDPopulatedHeader(isVerified ? PacketTypePing : PacketTypeUnverifiedPing,
packetUUID);
QDataStream packetStream(&pingPacket, QIODevice::Append);
packetStream << pingType; packetStream << pingType;
packetStream << usecTimestampNow(); packetStream << usecTimestampNow();
@ -536,7 +533,7 @@ QByteArray LimitedNodeList::constructPingPacket(PingType_t pingType, bool isVeri
return pingPacket; return pingPacket;
} }
QByteArray LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket, const QUuid& packetHeaderID) { NodeListPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
QDataStream pingPacketStream(pingPacket); QDataStream pingPacketStream(pingPacket);
pingPacketStream.skipRawData(numBytesForPacketHeader(pingPacket)); pingPacketStream.skipRawData(numBytesForPacketHeader(pingPacket));
@ -546,19 +543,43 @@ QByteArray LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacke
quint64 timeFromOriginalPing; quint64 timeFromOriginalPing;
pingPacketStream >> timeFromOriginalPing; pingPacketStream >> timeFromOriginalPing;
PacketType::Value replyType = (packetTypeForPacket(pingPacket) == PacketTypePing) int packetSize = sizeof(PingType_t) + sizeof(quint64) + sizeof(quint64);
? PacketTypePingReply : PacketTypeUnverifiedPingReply;
QUuid packetUUID = packetHeaderID.isNull() ? _sessionUUID : packetHeaderID; NodeListPacket replyPacket = NodeListPacket::create(PacketType::Ping, packetSize);
QByteArray replyPacket = byteArrayWithUUIDPopulatedHeader(replyType, packetUUID);
QDataStream packetStream(&replyPacket, QIODevice::Append); QDataStream packetStream(&replyPacket, QIODevice::Append);
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow(); packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
return replyPacket; return replyPacket;
} }
NodeListPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID) {
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
NodeListPacket icePingPacket = NodeListPacket::create(PacketType::ICEPing, packetSize);
icePingPacket.payload().replace(0, NUM_BYTES_RFC4122_UUID, iceID.toRfc4122().data());
memcpy(icePingPacket.payload() + NUM_BYTES_RFC4122_UUID, &pingType, sizeof(PingType_t));
return icePingPacket;
}
NodeListPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID) {
// pull out the ping type so we can reply back with that
PingType_t pingType;
memcpy(&pingType, pingPacket.data() + NUM_BYTES_RFC4122_UUID, sizeof(PingType_t));
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
NodeListPacket icePingReplyPacket = NodeListPacket::create(PacketType::ICEPingReply, packetSize);
// pack the ICE ID and then the ping type
memcpy(icePingReplyPacket.payload(), iceID.toRfc4122().data(), NUM_BYTES_RFC4122_UUID);
memcpy(icePingReplyPacket.payload() + NUM_BYTES_RFC4122_UUID, &pingType, sizeof(PingType_t));
return icePingReplyPacket;
}
SharedNodePointer LimitedNodeList::soloNodeOfType(char nodeType) { SharedNodePointer LimitedNodeList::soloNodeOfType(char nodeType) {
return nodeMatchingPredicate([&](const SharedNodePointer& node){ return nodeMatchingPredicate([&](const SharedNodePointer& node){
return node->getType() == nodeType; return node->getType() == nodeType;
@ -835,7 +856,7 @@ void LimitedNodeList::sendPeerQueryToIceServer(const HifiSockAddr& iceServerSock
sendPacketToIceServer(PacketTypeIceServerQuery, iceServerSockAddr, clientID, peerID); sendPacketToIceServer(PacketTypeIceServerQuery, iceServerSockAddr, clientID, peerID);
} }
void LimitedNodeList::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, void LimitedNodeList::sendPacketToIceServer(PacketType::Value packetType, const HifiSockAddr& iceServerSockAddr,
const QUuid& headerID, const QUuid& peerID) { const QUuid& headerID, const QUuid& peerID) {
QByteArray iceRequestByteArray = byteArrayWithUUIDPopulatedHeader(packetType, headerID); QByteArray iceRequestByteArray = byteArrayWithUUIDPopulatedHeader(packetType, headerID);

View file

@ -118,28 +118,28 @@ public:
bool packetVersionAndHashMatch(const QByteArray& packet); bool packetVersionAndHashMatch(const QByteArray& packet);
// QByteArray byteArrayWithPopulatedHeader(PacketType packetType) // QByteArray byteArrayWithPopulatedHeader (PacketType::Value packetType)
// { return byteArrayWithUUIDPopulatedHeader(packetType, _sessionUUID); } // { return byteArrayWithUUIDPopulatedHeader(packetType, _sessionUUID); }
// int populatePacketHeader(QByteArray& packet, PacketType::Value packetType) // int populatePacketHeader(QByteArray& packet, PacketType::Value packetType)
// { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); } // { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); }
// int populatePacketHeader(char* packet, PacketType::Value packetType) // int populatePacketHeader(char* packet, PacketType::Value packetType)
// { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); } // { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); }
qint64 readDatagram(QByteArray& incomingPacket, QHostAddress* address, quint16 * port); // qint64 readDatagram(QByteArray& incomingPacket, QHostAddress* address, quint16 * port);
//
qint64 writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, // qint64 writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
const HifiSockAddr& overridenSockAddr = HifiSockAddr()); // const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 writeUnverifiedDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, // qint64 writeUnverifiedDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
const HifiSockAddr& overridenSockAddr = HifiSockAddr()); // const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 writeUnverifiedDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr); // qint64 writeUnverifiedDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
//
qint64 writeDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode, // qint64 writeDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
const HifiSockAddr& overridenSockAddr = HifiSockAddr()); // const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode, // qint64 writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
const HifiSockAddr& overridenSockAddr = HifiSockAddr()); // const HifiSockAddr& overridenSockAddr = HifiSockAddr());
void (*linkedDataCreateCallback)(Node *); void (*linkedDataCreateCallback)(Node *);
@ -170,9 +170,11 @@ public:
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond); void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
void resetPacketStats(); void resetPacketStats();
QByteArray constructPingPacket(PingType_t pingType = PingType::Agnostic, bool isVerified = true, NodeListPacket&& constructPingPacket(PingType_t pingType = PingType::Agnostic);
const QUuid& packetHeaderID = QUuid()); NodeListPacket&& constructPingReplyPacket(const QByteArray& pingPacket);
QByteArray constructPingReplyPacket(const QByteArray& pingPacket, const QUuid& packetHeaderID = QUuid());
NodeListPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID);
NodeListPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID);
virtual bool processSTUNResponse(const QByteArray& packet); virtual bool processSTUNResponse(const QByteArray& packet);
@ -274,7 +276,7 @@ protected:
void stopInitialSTUNUpdate(bool success); void stopInitialSTUNUpdate(bool success);
void sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& headerID, void sendPacketToIceServer (PacketType::Value packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& headerID,
const QUuid& peerRequestID = QUuid()); const QUuid& peerRequestID = QUuid());
QUuid _sessionUUID; QUuid _sessionUUID;

View file

@ -67,7 +67,7 @@ void Node::updateClockSkewUsec(int clockSkewSample) {
_clockSkewUsec = (int)_clockSkewMovingPercentile.getValueAtPercentile(); _clockSkewUsec = (int)_clockSkewMovingPercentile.getValueAtPercentile();
} }
PacketSequenceNumber Node::getLastSequenceNumberForPacketType(PacketType packetType) const { PacketSequenceNumber Node::getLastSequenceNumberForPacketType (PacketType::Value packetType) const {
auto typeMatch = _lastSequenceNumbers.find(packetType); auto typeMatch = _lastSequenceNumbers.find(packetType);
if (typeMatch != _lastSequenceNumbers.end()) { if (typeMatch != _lastSequenceNumbers.end()) {
return typeMatch->second; return typeMatch->second;

View file

@ -67,7 +67,7 @@ public:
void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType::Value packetType) void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType::Value packetType)
{ _lastSequenceNumbers[packetType] = sequenceNumber; } { _lastSequenceNumbers[packetType] = sequenceNumber; }
PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType packetType) const; PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType::Value packetType) const;
friend QDataStream& operator<<(QDataStream& out, const Node& node); friend QDataStream& operator<<(QDataStream& out, const Node& node);
friend QDataStream& operator>>(QDataStream& in, Node& node); friend QDataStream& operator>>(QDataStream& in, Node& node);

View file

@ -175,36 +175,36 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer&
void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) {
PacketType::Value packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
switch (packetType) { switch (packetType) {
case PacketTypeDomainList: case PacketType::DomainList:
case PacketTypeDomainServerAddedNode: { case PacketType::DomainServerAddedNode: {
if (!_domainHandler.getSockAddr().isNull()) { if (!_domainHandler.getSockAddr().isNull()) {
// only process a packet from domain-server if we're talking to a domain // only process a packet from domain-server if we're talking to a domain
// TODO: how do we make sure this is actually the domain we want the list from (DTLS probably) // TODO: how do we make sure this is actually the domain we want the list from (DTLS probably)
if (packetType == PacketTypeDomainList) { if (packetType == PacketType::DomainList) {
processDomainServerList(packet); processDomainServerList(packet);
} else if (packetType == PacketTypeDomainServerAddedNode) { } else if (packetType == PacketType::DomainServerAddedNode) {
processDomainServerAddedNode(packet); processDomainServerAddedNode(packet);
} }
} }
break; break;
} }
case PacketTypeDomainServerRequireDTLS: { case PacketType::DomainServerRequireDTLS: {
_domainHandler.parseDTLSRequirementPacket(packet); _domainHandler.parseDTLSRequirementPacket(packet);
break; break;
} }
case PacketTypeIceServerPeerInformation: { case PacketType::IceServerPeerInformation: {
if (!_domainHandler.getICEPeer().hasSockets()) { if (!_domainHandler.getICEPeer().hasSockets()) {
_domainHandler.processICEResponsePacket(packet); _domainHandler.processICEResponsePacket(packet);
} }
break; break;
} }
case PacketTypePing: { case PacketType::Ping: {
// send back a reply // send back a reply
SharedNodePointer matchingNode = sendingNodeForPacket(packet); SharedNodePointer matchingNode = sendingNodeForPacket(packet);
if (matchingNode) { if (matchingNode) {
matchingNode->setLastHeardMicrostamp(usecTimestampNow()); matchingNode->setLastHeardMicrostamp(usecTimestampNow());
QByteArray replyPacket = constructPingReplyPacket(packet); auto replyPacket = constructPingReplyPacket(packet);
writeDatagram(replyPacket, matchingNode, senderSockAddr); sendPacket(replyPacket, matchingNode, senderSockAddr);
// If we don't have a symmetric socket for this node and this socket doesn't match // If we don't have a symmetric socket for this node and this socket doesn't match
// what we have for public and local then set it as the symmetric. // what we have for public and local then set it as the symmetric.
@ -218,7 +218,7 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
break; break;
} }
case PacketTypePingReply: { case PacketType::PingReply: {
SharedNodePointer sendingNode = sendingNodeForPacket(packet); SharedNodePointer sendingNode = sendingNodeForPacket(packet);
if (sendingNode) { if (sendingNode) {
@ -233,13 +233,13 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
break; break;
} }
case PacketTypeUnverifiedPing: { case PacketType::ICEPing: {
// send back a reply // send back a reply
QByteArray replyPacket = constructPingReplyPacket(packet, _domainHandler.getICEClientID()); auto replyPacket = constructICEPingReplyPacket(packet, _domainHandler.getICEClientID());
writeUnverifiedDatagram(replyPacket, senderSockAddr); sendPacket(replyPacket, senderSockAddr);
break; break;
} }
case PacketTypeUnverifiedPingReply: { case PacketType::ICEPingReply: {
qCDebug(networking) << "Received reply from domain-server on" << senderSockAddr; qCDebug(networking) << "Received reply from domain-server on" << senderSockAddr;
if (_domainHandler.getIP().isNull()) { if (_domainHandler.getIP().isNull()) {
@ -256,13 +256,13 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr
} }
} }
case PacketTypeStunResponse: { case PacketType::StunResponse: {
// a STUN packet begins with 00, we've checked the second zero with packetVersionMatch // a STUN packet begins with 00, we've checked the second zero with packetVersionMatch
// pass it along so it can be processed into our public address and port // pass it along so it can be processed into our public address and port
processSTUNResponse(packet); processSTUNResponse(packet);
break; break;
} }
case PacketTypeDomainServerPathResponse: { case PacketType::DomainServerPathResponse: {
handleDSPathQueryResponse(packet); handleDSPathQueryResponse(packet);
break; break;
} }
@ -518,11 +518,11 @@ void NodeList::pingPunchForDomainServer() {
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendPingsToDS); flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendPingsToDS);
// send the ping packet to the local and public sockets for this node // send the ping packet to the local and public sockets for this node
QByteArray localPingPacket = constructPingPacket(PingType::Local, false, _domainHandler.getICEClientID()); auto localPingPacket = constructICEPingPacket(PingType::Local);
writeUnverifiedDatagram(localPingPacket, _domainHandler.getICEPeer().getLocalSocket()); sendPacket(localPingPacket, _domainHandler.getICEPeer().getLocalSocket());
QByteArray publicPingPacket = constructPingPacket(PingType::Public, false, _domainHandler.getICEClientID()); auto publicPingPacket = constructICEPingPacket(PingType::Public);
writeUnverifiedDatagram(publicPingPacket, _domainHandler.getICEPeer().getPublicSocket()); sendPacket(publicPingPacket, _domainHandler.getICEPeer().getPublicSocket());
_domainHandler.getICEPeer().incrementConnectionAttempts(); _domainHandler.getICEPeer().incrementConnectionAttempts();
} }
@ -625,15 +625,15 @@ void NodeList::pingPunchForInactiveNode(const SharedNodePointer& node) {
} }
// send the ping packet to the local and public sockets for this node // send the ping packet to the local and public sockets for this node
QByteArray localPingPacket = constructPingPacket(PingType::Local); auto localPingPacket = constructPingPacket(PingType::Local);
writeDatagram(localPingPacket, node, node->getLocalSocket()); sendPacket(localPingPacket, node, node->getLocalSocket());
QByteArray publicPingPacket = constructPingPacket(PingType::Public); auto publicPingPacket = constructPingPacket(PingType::Public);
writeDatagram(publicPingPacket, node, node->getPublicSocket()); sendPacket(publicPingPacket, node, node->getPublicSocket());
if (!node->getSymmetricSocket().isNull()) { if (!node->getSymmetricSocket().isNull()) {
QByteArray symmetricPingPacket = constructPingPacket(PingType::Symmetric); auto symmetricPingPacket = constructPingPacket(PingType::Symmetric);
writeDatagram(symmetricPingPacket, node, node->getSymmetricSocket()); sendPacket(symmetricPingPacket, node, node->getSymmetricSocket());
} }
node->incrementConnectionAttempts(); node->incrementConnectionAttempts();

View file

@ -31,6 +31,8 @@ const QSet<PacketType::Value> NON_VERIFIED_PACKETS = QSet<PacketType::Value>()
const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType::Value>() << AvatarData; const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType::Value>() << AvatarData;
const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>() << ICEPing << ICEPingReply;
int arithmeticCodingValueFromBuffer(const char* checkValue) { int arithmeticCodingValueFromBuffer(const char* checkValue) {
if (((uchar) *checkValue) < 255) { if (((uchar) *checkValue) < 255) {
return *checkValue; return *checkValue;

View file

@ -78,9 +78,9 @@ namespace PacketType {
AudioEnvironment, AudioEnvironment,
EntityEditNack, EntityEditNack,
SignedTransactionPayment, SignedTransactionPayment,
IceServerHeartbeat, // 50 ICEServerHeartbeat, // 50
UnverifiedPing, ICEPing,
UnverifiedPingReply ICEPingReply
}; };
}; };
@ -93,6 +93,7 @@ typedef std::map<PacketType::Value, PacketSequenceNumber> PacketTypeSequenceMap;
extern const QSet<PacketType::Value> NON_VERIFIED_PACKETS; extern const QSet<PacketType::Value> NON_VERIFIED_PACKETS;
extern const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS; extern const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS;
extern const QSet<PacketType::Value> NON_SOURCED_PACKETS;
const int NUM_BYTES_MD5_HASH = 16; const int NUM_BYTES_MD5_HASH = 16;
const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID; const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;

View file

@ -20,7 +20,7 @@ EditPacketBuffer::EditPacketBuffer() :
} }
EditPacketBuffer::EditPacketBuffer(PacketType type, unsigned char* buffer, size_t length, qint64 satoshiCost, QUuid nodeUUID) : EditPacketBuffer::EditPacketBuffer (PacketType::Value type, unsigned char* buffer, size_t length, qint64 satoshiCost, QUuid nodeUUID) :
_nodeUUID(nodeUUID), _nodeUUID(nodeUUID),
_currentType(type), _currentType(type),
_currentSize(length), _currentSize(length),

View file

@ -21,7 +21,7 @@
class EditPacketBuffer { class EditPacketBuffer {
public: public:
EditPacketBuffer(); EditPacketBuffer();
EditPacketBuffer(PacketType type, unsigned char* codeColorBuffer, size_t length, EditPacketBuffer (PacketType::Value type, unsigned char* codeColorBuffer, size_t length,
qint64 satoshiCost = 0, const QUuid nodeUUID = QUuid()); qint64 satoshiCost = 0, const QUuid nodeUUID = QUuid());
QUuid _nodeUUID; QUuid _nodeUUID;

View file

@ -230,8 +230,8 @@ public:
virtual bool canProcessVersion(PacketVersion thisVersion) const { virtual bool canProcessVersion(PacketVersion thisVersion) const {
return thisVersion == versionForPacketType(expectedDataPacketType()); } return thisVersion == versionForPacketType(expectedDataPacketType()); }
virtual PacketVersion expectedVersion() const { return versionForPacketType(expectedDataPacketType()); } virtual PacketVersion expectedVersion() const { return versionForPacketType(expectedDataPacketType()); }
virtual bool handlesEditPacketType(PacketType packetType) const { return false; } virtual bool handlesEditPacketType (PacketType::Value packetType) const { return false; }
virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, virtual int processEditPacketData (PacketType::Value packetType, const unsigned char* packetData, int packetLength,
const unsigned char* editData, int maxLength, const SharedNodePointer& sourceNode) { return 0; } const unsigned char* editData, int maxLength, const SharedNodePointer& sourceNode) { return 0; }
virtual bool recurseChildrenWithData() const { return true; } virtual bool recurseChildrenWithData() const { return true; }

View file

@ -159,7 +159,7 @@ void OctreeEditPacketSender::processPreServerExistsPackets() {
} }
} }
void OctreeEditPacketSender::queuePendingPacketToNodes(PacketType type, unsigned char* buffer, void OctreeEditPacketSender::queuePendingPacketToNodes (PacketType::Value type, unsigned char* buffer,
size_t length, qint64 satoshiCost) { size_t length, qint64 satoshiCost) {
// If we're asked to save messages while waiting for voxel servers to arrive, then do so... // If we're asked to save messages while waiting for voxel servers to arrive, then do so...
@ -213,7 +213,7 @@ void OctreeEditPacketSender::queuePacketToNodes(unsigned char* buffer, size_t le
// NOTE: editPacketBuffer - is JUST the octcode/color and does not contain the packet header! // NOTE: editPacketBuffer - is JUST the octcode/color and does not contain the packet header!
void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, unsigned char* editPacketBuffer, void OctreeEditPacketSender::queueOctreeEditMessage (PacketType::Value type, unsigned char* editPacketBuffer,
size_t length, qint64 satoshiCost) { size_t length, qint64 satoshiCost) {
if (!_shouldSend) { if (!_shouldSend) {

View file

@ -30,7 +30,7 @@ public:
/// Queues a single edit message. Will potentially send a pending multi-command packet. Determines which server /// Queues a single edit message. Will potentially send a pending multi-command packet. Determines which server
/// node or nodes the packet should be sent to. Can be called even before servers are known, in which case up to /// node or nodes the packet should be sent to. Can be called even before servers are known, in which case up to
/// MaxPendingMessages will be buffered and processed when servers are known. /// MaxPendingMessages will be buffered and processed when servers are known.
void queueOctreeEditMessage(PacketType type, unsigned char* buffer, size_t length, qint64 satoshiCost = 0); void queueOctreeEditMessage (PacketType::Value type, unsigned char* buffer, size_t length, qint64 satoshiCost = 0);
/// Releases all queued messages even if those messages haven't filled an MTU packet. This will move the packed message /// Releases all queued messages even if those messages haven't filled an MTU packet. This will move the packed message
/// packets onto the send queue. If running in threaded mode, the caller does not need to do any further processing to /// packets onto the send queue. If running in threaded mode, the caller does not need to do any further processing to
@ -81,7 +81,7 @@ public:
// you must override these... // you must override these...
virtual char getMyNodeType() const = 0; virtual char getMyNodeType() const = 0;
virtual void adjustEditPacketForClockSkew(PacketType type, virtual void adjustEditPacketForClockSkew (PacketType::Value type,
unsigned char* editPacketBuffer, size_t length, int clockSkew) { } unsigned char* editPacketBuffer, size_t length, int clockSkew) { }
bool hasDestinationWalletUUID() const { return !_destinationWalletUUID.isNull(); } bool hasDestinationWalletUUID() const { return !_destinationWalletUUID.isNull(); }
@ -99,7 +99,7 @@ signals:
protected: protected:
bool _shouldSend; bool _shouldSend;
void queuePacketToNode(const QUuid& nodeID, unsigned char* buffer, size_t length, qint64 satoshiCost = 0); void queuePacketToNode(const QUuid& nodeID, unsigned char* buffer, size_t length, qint64 satoshiCost = 0);
void queuePendingPacketToNodes(PacketType type, unsigned char* buffer, size_t length, qint64 satoshiCost = 0); void queuePendingPacketToNodes (PacketType::Value type, unsigned char* buffer, size_t length, qint64 satoshiCost = 0);
void queuePacketToNodes(unsigned char* buffer, size_t length, qint64 satoshiCost = 0); void queuePacketToNodes(unsigned char* buffer, size_t length, qint64 satoshiCost = 0);
void initializePacket(EditPacketBuffer& packetBuffer, PacketType::Value type, int nodeClockSkew); void initializePacket(EditPacketBuffer& packetBuffer, PacketType::Value type, int nodeClockSkew);
void releaseQueuedPacket(EditPacketBuffer& packetBuffer); // releases specific queued packet void releaseQueuedPacket(EditPacketBuffer& packetBuffer); // releases specific queued packet