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

This commit is contained in:
Atlante45 2015-07-02 17:28:07 -07:00
commit d6ea493975
37 changed files with 188 additions and 184 deletions

View file

@ -56,7 +56,7 @@ void Agent::readPendingDatagrams() {
while (readAvailableDatagram(receivedPacket, senderSockAddr)) { while (readAvailableDatagram(receivedPacket, senderSockAddr)) {
if (nodeList->packetVersionAndHashMatch(receivedPacket)) { if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
PacketType datagramPacketType = packetTypeForPacket(receivedPacket); PacketType::Value datagramPacketType = packetTypeForPacket(receivedPacket);
if (datagramPacketType == PacketTypeJurisdiction) { if (datagramPacketType == PacketTypeJurisdiction) {
int headerBytes = numBytesForPacketHeader(receivedPacket); int headerBytes = numBytesForPacketHeader(receivedPacket);

View file

@ -535,7 +535,7 @@ void AudioMixer::readPendingDatagram(const QByteArray& receivedPacket, const Hif
if (nodeList->packetVersionAndHashMatch(receivedPacket)) { if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
// pull any new audio data from nodes off of the network stack // pull any new audio data from nodes off of the network stack
PacketType mixerPacketType = packetTypeForPacket(receivedPacket); PacketType::Value mixerPacketType = packetTypeForPacket(receivedPacket);
if (mixerPacketType == PacketTypeMicrophoneAudioNoEcho if (mixerPacketType == PacketTypeMicrophoneAudioNoEcho
|| mixerPacketType == PacketTypeMicrophoneAudioWithEcho || mixerPacketType == PacketTypeMicrophoneAudioWithEcho
|| mixerPacketType == PacketTypeInjectAudio || mixerPacketType == PacketTypeInjectAudio

View file

@ -50,7 +50,7 @@ AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() const {
} }
int AudioMixerClientData::parseData(const QByteArray& packet) { int AudioMixerClientData::parseData(const QByteArray& packet) {
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
if (packetType == PacketTypeAudioStreamStats) { if (packetType == PacketTypeAudioStreamStats) {
const char* dataAt = packet.data(); const char* dataAt = packet.data();

View file

@ -22,7 +22,7 @@ public:
OctreeQueryNode(), OctreeQueryNode(),
_lastDeletedEntitiesSentAt(0) { } _lastDeletedEntitiesSentAt(0) { }
virtual PacketType getMyPacketType() const { return PacketTypeEntityData; } virtual PacketType::Value getMyPacketType() const { return PacketTypeEntityData; }
quint64 getLastDeletedEntitiesSentAt() const { return _lastDeletedEntitiesSentAt; } quint64 getLastDeletedEntitiesSentAt() const { return _lastDeletedEntitiesSentAt; }
void setLastDeletedEntitiesSentAt(quint64 sentAt) { _lastDeletedEntitiesSentAt = sentAt; } void setLastDeletedEntitiesSentAt(quint64 sentAt) { _lastDeletedEntitiesSentAt = sentAt; }

View file

@ -28,11 +28,11 @@ public:
// Subclasses must implement these methods // Subclasses must implement these methods
virtual OctreeQueryNode* createOctreeQueryNode(); virtual OctreeQueryNode* createOctreeQueryNode();
virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual char getMyNodeType() const { return NodeType::EntityServer; }
virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } virtual PacketType::Value getMyQueryMessageType() const { return PacketTypeEntityQuery; }
virtual const char* getMyServerName() const { return MODEL_SERVER_NAME; } virtual const char* getMyServerName() const { return MODEL_SERVER_NAME; }
virtual const char* getMyLoggingServerTargetName() const { return MODEL_SERVER_LOGGING_TARGET_NAME; } virtual const char* getMyLoggingServerTargetName() const { return MODEL_SERVER_LOGGING_TARGET_NAME; }
virtual const char* getMyDefaultPersistFilename() const { return LOCAL_MODELS_PERSIST_FILE; } virtual const char* getMyDefaultPersistFilename() const { return LOCAL_MODELS_PERSIST_FILE; }
virtual PacketType getMyEditNackType() const { return PacketTypeEntityEditNack; } virtual PacketType::Value getMyEditNackType() const { return PacketTypeEntityEditNack; }
virtual QString getMyDomainSettingsKey() const { return QString("entity_server_settings"); } virtual QString getMyDomainSettingsKey() const { return QString("entity_server_settings"); }
// subclass may implement these method // subclass may implement these method

View file

@ -90,7 +90,7 @@ void OctreeInboundPacketProcessor::processPacket(const SharedNodePointer& sendin
// Ask our tree subclass if it can handle the incoming packet... // Ask our tree subclass if it can handle the incoming packet...
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
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++;

View file

@ -35,7 +35,7 @@ public:
virtual ~OctreeQueryNode(); virtual ~OctreeQueryNode();
void init(); // called after creation to set up some virtual items void init(); // called after creation to set up some virtual items
virtual PacketType getMyPacketType() const = 0; virtual PacketType::Value getMyPacketType() const = 0;
void resetOctreePacket(); // resets octree packet to after "V" header void resetOctreePacket(); // resets octree packet to after "V" header
@ -155,7 +155,7 @@ private:
quint64 _lastRootTimestamp; quint64 _lastRootTimestamp;
PacketType _myPacketType; PacketType::Value _myPacketType;
bool _isShuttingDown; bool _isShuttingDown;
SentPacketHistory _sentPacketHistory; SentPacketHistory _sentPacketHistory;

View file

@ -862,7 +862,7 @@ void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const H
if (!_isShuttingDown) { if (!_isShuttingDown) {
if (nodeList->packetVersionAndHashMatch(receivedPacket)) { if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
PacketType packetType = packetTypeForPacket(receivedPacket); PacketType::Value packetType = packetTypeForPacket(receivedPacket);
SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket);
if (packetType == getMyQueryMessageType()) { if (packetType == getMyQueryMessageType()) {
// If we got a query packet, then we're talking to an agent, and we // If we got a query packet, then we're talking to an agent, and we

View file

@ -63,11 +63,11 @@ public:
// Subclasses must implement these methods // Subclasses must implement these methods
virtual OctreeQueryNode* createOctreeQueryNode() = 0; virtual OctreeQueryNode* createOctreeQueryNode() = 0;
virtual char getMyNodeType() const = 0; virtual char getMyNodeType() const = 0;
virtual PacketType getMyQueryMessageType() const = 0; virtual PacketType::Value getMyQueryMessageType() const = 0;
virtual const char* getMyServerName() const = 0; virtual const char* getMyServerName() const = 0;
virtual const char* getMyLoggingServerTargetName() const = 0; virtual const char* getMyLoggingServerTargetName() const = 0;
virtual const char* getMyDefaultPersistFilename() const = 0; virtual const char* getMyDefaultPersistFilename() const = 0;
virtual PacketType getMyEditNackType() const = 0; virtual PacketType::Value getMyEditNackType() const = 0;
virtual QString getMyDomainSettingsKey() const { return QString("octree_server_settings"); } virtual QString getMyDomainSettingsKey() const { return QString("octree_server_settings"); }
// subclass may implement these method // subclass may implement these method

View file

@ -43,7 +43,7 @@ void OctreeServerDatagramProcessor::readPendingDatagrams() {
_nodeSocket.readDatagram(incomingPacket.data(), incomingPacket.size(), _nodeSocket.readDatagram(incomingPacket.data(), incomingPacket.size(),
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
PacketType packetType = packetTypeForPacket(incomingPacket); PacketType::Value packetType = packetTypeForPacket(incomingPacket);
if (packetType == PacketTypePing) { if (packetType == PacketTypePing) {
DependencyManager::get<NodeList>()->processNodeData(senderSockAddr, incomingPacket); DependencyManager::get<NodeList>()->processNodeData(senderSockAddr, incomingPacket);
return; // don't emit return; // don't emit

View file

@ -1390,7 +1390,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
auto nodeList = DependencyManager::get<LimitedNodeList>(); auto nodeList = DependencyManager::get<LimitedNodeList>();
if (nodeList->packetVersionAndHashMatch(receivedPacket)) { if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
PacketType requestType = packetTypeForPacket(receivedPacket); PacketType::Value requestType = packetTypeForPacket(receivedPacket);
switch (requestType) { switch (requestType) {
case PacketTypeDomainConnectRequest: case PacketTypeDomainConnectRequest:
handleConnectRequest(receivedPacket, senderSockAddr); handleConnectRequest(receivedPacket, senderSockAddr);

View file

@ -54,7 +54,7 @@ void IceServer::processDatagrams() {
_serverSocket.readDatagram(incomingPacket.data(), incomingPacket.size(), _serverSocket.readDatagram(incomingPacket.data(), incomingPacket.size(),
sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer()); sendingSockAddr.getAddressPointer(), sendingSockAddr.getPortPointer());
PacketType packetType = packetTypeForPacket(incomingPacket); PacketType::Value packetType = packetTypeForPacket(incomingPacket);
if (packetType == PacketTypeIceServerHeartbeat) { if (packetType == PacketTypeIceServerHeartbeat) {
SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(incomingPacket); SharedNetworkPeer peer = addOrUpdateHeartbeatingPeer(incomingPacket);

View file

@ -2729,7 +2729,7 @@ int Application::sendNackPackets() {
return packetsSent; return packetsSent;
} }
void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { void Application::queryOctree(NodeType_t serverType, PacketType::Value packetType, NodeToJurisdictionMap& jurisdictions) {
//qCDebug(interfaceapp) << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); //qCDebug(interfaceapp) << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView();
bool wantExtraDebugging = getLogger()->extraDebugging(); bool wantExtraDebugging = getLogger()->extraDebugging();

View file

@ -511,7 +511,7 @@ private:
void renderLookatIndicator(glm::vec3 pointOfInterest); void renderLookatIndicator(glm::vec3 pointOfInterest);
void queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions); void queryOctree(NodeType_t serverType, PacketType::Value packetType, NodeToJurisdictionMap& jurisdictions);
void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum); void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum);
glm::vec3 getSunDirection(); glm::vec3 getSunDirection();

View file

@ -52,7 +52,7 @@ void DatagramProcessor::processDatagrams() {
if (nodeList->packetVersionAndHashMatch(incomingPacket)) { if (nodeList->packetVersionAndHashMatch(incomingPacket)) {
PacketType incomingType = packetTypeForPacket(incomingPacket); PacketType::Value incomingType = packetTypeForPacket(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 (incomingType) { switch (incomingType) {
case PacketTypeAudioEnvironment: case PacketTypeAudioEnvironment:

View file

@ -33,7 +33,7 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode,
bool wasStatsPacket = false; bool wasStatsPacket = false;
PacketType voxelPacketType = packetTypeForPacket(mutablePacket); PacketType::Value voxelPacketType = packetTypeForPacket(mutablePacket);
// note: PacketType_OCTREE_STATS can have PacketType_VOXEL_DATA // note: PacketType_OCTREE_STATS can have PacketType_VOXEL_DATA
// immediately following them inside the same packet. So, we process the PacketType_OCTREE_STATS first // immediately following them inside the same packet. So, we process the PacketType_OCTREE_STATS first

View file

@ -844,7 +844,7 @@ void AudioClient::handleAudioInput() {
glm::quat headOrientation = _orientationGetter(); glm::quat headOrientation = _orientationGetter();
quint8 isStereo = _isStereoInput ? 1 : 0; quint8 isStereo = _isStereoInput ? 1 : 0;
PacketType packetType; PacketType::Value packetType;
if (_lastInputLoudness == 0) { if (_lastInputLoudness == 0) {
packetType = PacketTypeSilentAudioFrame; packetType = PacketTypeSilentAudioFrame;
} else { } else {

View file

@ -98,7 +98,7 @@ void InboundAudioStream::perSecondCallbackForUpdatingStats() {
int InboundAudioStream::parseData(const QByteArray& packet) { int InboundAudioStream::parseData(const QByteArray& packet) {
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
QUuid senderUUID = uuidFromPacketHeader(packet); QUuid senderUUID = uuidFromPacketHeader(packet);
// parse header // parse header

View file

@ -43,8 +43,8 @@ public:
virtual ~EntityTreeRenderer(); virtual ~EntityTreeRenderer();
virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual char getMyNodeType() const { return NodeType::EntityServer; }
virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } virtual PacketType::Value getMyQueryMessageType() const { return PacketTypeEntityQuery; }
virtual PacketType getExpectedPacketType() const { return PacketTypeEntityData; } virtual PacketType::Value getExpectedPacketType() const { return PacketTypeEntityData; }
virtual void renderElement(OctreeElement* element, RenderArgs* args); virtual void renderElement(OctreeElement* element, RenderArgs* args);
virtual float getSizeScale() const; virtual float getSizeScale() const;
virtual int getBoundaryLevelAdjust() const; virtual int getBoundaryLevelAdjust() const;

View file

@ -62,7 +62,7 @@ public:
// These methods will allow the OctreeServer to send your tree inbound edit packets of your // These methods will allow the OctreeServer to send your tree inbound edit packets of your
// own definition. Implement these to allow your octree based server to support editing // own definition. Implement these to allow your octree based server to support editing
virtual bool getWantSVOfileVersions() const { return true; } virtual bool getWantSVOfileVersions() const { return true; }
virtual PacketType 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 packetType) const;

View file

@ -31,8 +31,8 @@ public:
virtual ~EntityTreeHeadlessViewer(); virtual ~EntityTreeHeadlessViewer();
virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual char getMyNodeType() const { return NodeType::EntityServer; }
virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } virtual PacketType::Value getMyQueryMessageType() const { return PacketTypeEntityQuery; }
virtual PacketType getExpectedPacketType() const { return PacketTypeEntityData; } virtual PacketType::Value getExpectedPacketType() const { return PacketTypeEntityData; }
void update(); void update();

View file

@ -66,7 +66,7 @@ Assignment::Assignment(const QByteArray& packet) :
_payload(), _payload(),
_walletUUID() _walletUUID()
{ {
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
if (packetType == PacketTypeRequestAssignment) { if (packetType == PacketTypeRequestAssignment) {
_command = Assignment::RequestCommand; _command = Assignment::RequestCommand;

View file

@ -164,12 +164,12 @@ void LimitedNodeList::changeSocketBufferSizes(int numBytes) {
} }
bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) { bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) {
PacketType checkType = packetTypeForPacket(packet); PacketType::Value checkType = packetTypeForPacket(packet);
int numPacketTypeBytes = numBytesArithmeticCodingFromBuffer(packet.data()); int numPacketTypeBytes = numBytesArithmeticCodingFromBuffer(packet.data());
if (packet[numPacketTypeBytes] != versionForPacketType(checkType) if (packet[numPacketTypeBytes] != versionForPacketType(checkType)
&& checkType != PacketTypeStunResponse) { && checkType != PacketTypeStunResponse) {
PacketType mismatchType = packetTypeForPacket(packet); PacketType::Value mismatchType = packetTypeForPacket(packet);
static QMultiMap<QUuid, PacketType> versionDebugSuppressMap; static QMultiMap<QUuid, PacketType> versionDebugSuppressMap;
@ -254,7 +254,7 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram,
const SharedNodePointer& destinationNode, const SharedNodePointer& destinationNode,
const HifiSockAddr& overridenSockAddr) { const HifiSockAddr& overridenSockAddr) {
if (destinationNode) { if (destinationNode) {
PacketType packetType = packetTypeForPacket(datagram); PacketType::Value packetType = packetTypeForPacket(datagram);
if (NON_VERIFIED_PACKETS.contains(packetType)) { if (NON_VERIFIED_PACKETS.contains(packetType)) {
return writeUnverifiedDatagram(datagram, destinationNode, overridenSockAddr); return writeUnverifiedDatagram(datagram, destinationNode, overridenSockAddr);
@ -316,7 +316,7 @@ qint64 LimitedNodeList::writeUnverifiedDatagram(const QByteArray& datagram, cons
} }
} }
PacketType packetType = packetTypeForPacket(datagram); PacketType::Value packetType = packetTypeForPacket(datagram);
// optionally peform sequence number replacement in the header // optionally peform sequence number replacement in the header
if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) { if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
@ -351,7 +351,7 @@ qint64 LimitedNodeList::writeUnverifiedDatagram(const char* data, qint64 size, c
return writeUnverifiedDatagram(QByteArray(data, size), destinationNode, overridenSockAddr); return writeUnverifiedDatagram(QByteArray(data, size), destinationNode, overridenSockAddr);
} }
PacketSequenceNumber LimitedNodeList::getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType packetType) { PacketSequenceNumber LimitedNodeList::getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType::Value packetType) {
// Thanks to std::map and std::unordered_map this line either default constructs the // Thanks to std::map and std::unordered_map this line either default constructs the
// PacketTypeSequenceMap and the PacketSequenceNumber or returns the existing value. // PacketTypeSequenceMap and the PacketSequenceNumber or returns the existing value.
// We use the postfix increment so that the stored value is incremented and the next // We use the postfix increment so that the stored value is incremented and the next
@ -376,7 +376,7 @@ int LimitedNodeList::updateNodeWithDataFromPacket(const SharedNodePointer& match
// if this was a sequence numbered packet we should store the last seq number for // if this was a sequence numbered packet we should store the last seq number for
// a packet of this type for this node // a packet of this type for this node
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) { if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
matchingNode->setLastSequenceNumberForPacketType(sequenceNumberFromHeader(packet, packetType), packetType); matchingNode->setLastSequenceNumberForPacketType(sequenceNumberFromHeader(packet, packetType), packetType);
} }
@ -546,7 +546,7 @@ QByteArray LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacke
quint64 timeFromOriginalPing; quint64 timeFromOriginalPing;
pingPacketStream >> timeFromOriginalPing; pingPacketStream >> timeFromOriginalPing;
PacketType replyType = (packetTypeForPacket(pingPacket) == PacketTypePing) PacketType::Value replyType = (packetTypeForPacket(pingPacket) == PacketTypePing)
? PacketTypePingReply : PacketTypeUnverifiedPingReply; ? PacketTypePingReply : PacketTypeUnverifiedPingReply;
QUuid packetUUID = packetHeaderID.isNull() ? _sessionUUID : packetHeaderID; QUuid packetUUID = packetHeaderID.isNull() ? _sessionUUID : packetHeaderID;

View file

@ -118,12 +118,12 @@ public:
bool packetVersionAndHashMatch(const QByteArray& packet); bool packetVersionAndHashMatch(const QByteArray& packet);
QByteArray byteArrayWithPopulatedHeader(PacketType packetType) // QByteArray byteArrayWithPopulatedHeader(PacketType packetType)
{ return byteArrayWithUUIDPopulatedHeader(packetType, _sessionUUID); } // { return byteArrayWithUUIDPopulatedHeader(packetType, _sessionUUID); }
int populatePacketHeader(QByteArray& packet, PacketType packetType) // int populatePacketHeader(QByteArray& packet, PacketType::Value packetType)
{ return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); } // { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); }
int populatePacketHeader(char* packet, PacketType 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);
@ -266,7 +266,7 @@ protected:
qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr); qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
PacketSequenceNumber getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType packetType); PacketSequenceNumber getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType::Value packetType);
void changeSocketBufferSizes(int numBytes); void changeSocketBufferSizes(int numBytes);

View file

@ -65,7 +65,7 @@ public:
void setCanRez(bool canRez) { _canRez = canRez; } void setCanRez(bool canRez) { _canRez = canRez; }
bool getCanRez() { return _canRez; } bool getCanRez() { return _canRez; }
void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType packetType) void setLastSequenceNumberForPacketType(PacketSequenceNumber sequenceNumber, PacketType::Value packetType)
{ _lastSequenceNumbers[packetType] = sequenceNumber; } { _lastSequenceNumbers[packetType] = sequenceNumber; }
PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType packetType) const; PacketSequenceNumber getLastSequenceNumberForPacketType(PacketType packetType) const;

View file

@ -173,7 +173,7 @@ 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 packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
switch (packetType) { switch (packetType) {
case PacketTypeDomainList: case PacketTypeDomainList:
case PacketTypeDomainServerAddedNode: { case PacketTypeDomainServerAddedNode: {
@ -309,7 +309,7 @@ void NodeList::sendDomainServerCheckIn() {
} else if (!_domainHandler.getIP().isNull()) { } else if (!_domainHandler.getIP().isNull()) {
bool isUsingDTLS = false; bool isUsingDTLS = false;
PacketType domainPacketType = !_domainHandler.isConnected() PacketType::Value domainPacketType = !_domainHandler.isConnected()
? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest;
if (!_domainHandler.isConnected()) { if (!_domainHandler.isConnected()) {
@ -600,7 +600,7 @@ void NodeList::parseNodeFromPacketStream(QDataStream& packetStream) {
void NodeList::sendAssignment(Assignment& assignment) { void NodeList::sendAssignment(Assignment& assignment) {
PacketType assignmentPacketType = assignment.getCommand() == Assignment::CreateCommand PacketType::Value assignmentPacketType = assignment.getCommand() == Assignment::CreateCommand
? PacketTypeCreateAssignment ? PacketTypeCreateAssignment
: PacketTypeRequestAssignment; : PacketTypeRequestAssignment;

View file

@ -15,6 +15,22 @@
#include <QtCore/QDebug> #include <QtCore/QDebug>
using namespace PacketType;
const QSet<PacketType::Value> NON_VERIFIED_PACKETS = QSet<PacketType::Value>()
<< DomainServerRequireDTLS << DomainConnectRequest
<< DomainList << DomainListRequest << DomainConnectionDenied
<< CreateAssignment << RequestAssignment << StunResponse
<< NodeJsonStats << EntityQuery
<< OctreeDataNack << EntityEditNack
<< IceServerHeartbeat << IceServerPeerInformation
<< IceServerQuery << UnverifiedPing
<< UnverifiedPingReply << StopNode
<< DomainServerPathQuery << DomainServerPathResponse
<< DomainServerAddedNode;
const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType::Value>() << AvatarData;
int arithmeticCodingValueFromBuffer(const char* checkValue) { int arithmeticCodingValueFromBuffer(const char* checkValue) {
if (((uchar) *checkValue) < 255) { if (((uchar) *checkValue) < 255) {
return *checkValue; return *checkValue;
@ -43,43 +59,43 @@ int packArithmeticallyCodedValue(int value, char* destination) {
} }
} }
PacketVersion versionForPacketType(PacketType packetType) { PacketVersion versionForPacketType(PacketType::Value packetType) {
switch (packetType) { switch (packetType) {
case PacketTypeMicrophoneAudioNoEcho: case MicrophoneAudioNoEcho:
case PacketTypeMicrophoneAudioWithEcho: case MicrophoneAudioWithEcho:
return 2; return 2;
case PacketTypeSilentAudioFrame: case SilentAudioFrame:
return 4; return 4;
case PacketTypeMixedAudio: case MixedAudio:
return 1; return 1;
case PacketTypeInjectAudio: case InjectAudio:
return 1; return 1;
case PacketTypeAvatarData: case AvatarData:
return 6; return 6;
case PacketTypeAvatarIdentity: case AvatarIdentity:
return 1; return 1;
case PacketTypeEnvironmentData: case EnvironmentData:
return 2; return 2;
case PacketTypeDomainList: case DomainList:
case PacketTypeDomainListRequest: case DomainListRequest:
return 5; return 5;
case PacketTypeCreateAssignment: case CreateAssignment:
case PacketTypeRequestAssignment: case RequestAssignment:
return 2; return 2;
case PacketTypeOctreeStats: case OctreeStats:
return 1; return 1;
case PacketTypeStopNode: case StopNode:
return 1; return 1;
case PacketTypeEntityAdd: case EntityAdd:
case PacketTypeEntityEdit: case EntityEdit:
case PacketTypeEntityData: case EntityData:
return VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE; return VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE;
case PacketTypeEntityErase: case EntityErase:
return 2; return 2;
case PacketTypeAudioStreamStats: case AudioStreamStats:
return 1; return 1;
case PacketTypeIceServerHeartbeat: case IceServerHeartbeat:
case PacketTypeIceServerQuery: case IceServerQuery:
return 1; return 1;
default: default:
return 0; return 0;
@ -88,53 +104,53 @@ PacketVersion versionForPacketType(PacketType packetType) {
#define PACKET_TYPE_NAME_LOOKUP(x) case x: return QString(#x); #define PACKET_TYPE_NAME_LOOKUP(x) case x: return QString(#x);
QString nameForPacketType(PacketType packetType) { QString nameForPacketType(PacketType::Value packetType) {
switch (packetType) { switch (packetType) {
PACKET_TYPE_NAME_LOOKUP(PacketTypeUnknown); PACKET_TYPE_NAME_LOOKUP(Unknown);
PACKET_TYPE_NAME_LOOKUP(PacketTypeStunResponse); PACKET_TYPE_NAME_LOOKUP(StunResponse);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainList); PACKET_TYPE_NAME_LOOKUP(DomainList);
PACKET_TYPE_NAME_LOOKUP(PacketTypePing); PACKET_TYPE_NAME_LOOKUP(Ping);
PACKET_TYPE_NAME_LOOKUP(PacketTypePingReply); PACKET_TYPE_NAME_LOOKUP(PingReply);
PACKET_TYPE_NAME_LOOKUP(PacketTypeKillAvatar); PACKET_TYPE_NAME_LOOKUP(KillAvatar);
PACKET_TYPE_NAME_LOOKUP(PacketTypeAvatarData); PACKET_TYPE_NAME_LOOKUP(AvatarData);
PACKET_TYPE_NAME_LOOKUP(PacketTypeInjectAudio); PACKET_TYPE_NAME_LOOKUP(InjectAudio);
PACKET_TYPE_NAME_LOOKUP(PacketTypeMixedAudio); PACKET_TYPE_NAME_LOOKUP(MixedAudio);
PACKET_TYPE_NAME_LOOKUP(PacketTypeMicrophoneAudioNoEcho); PACKET_TYPE_NAME_LOOKUP(MicrophoneAudioNoEcho);
PACKET_TYPE_NAME_LOOKUP(PacketTypeMicrophoneAudioWithEcho); PACKET_TYPE_NAME_LOOKUP(MicrophoneAudioWithEcho);
PACKET_TYPE_NAME_LOOKUP(PacketTypeBulkAvatarData); PACKET_TYPE_NAME_LOOKUP(BulkAvatarData);
PACKET_TYPE_NAME_LOOKUP(PacketTypeSilentAudioFrame); PACKET_TYPE_NAME_LOOKUP(SilentAudioFrame);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEnvironmentData); PACKET_TYPE_NAME_LOOKUP(EnvironmentData);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainListRequest); PACKET_TYPE_NAME_LOOKUP(DomainListRequest);
PACKET_TYPE_NAME_LOOKUP(PacketTypeRequestAssignment); PACKET_TYPE_NAME_LOOKUP(RequestAssignment);
PACKET_TYPE_NAME_LOOKUP(PacketTypeCreateAssignment); PACKET_TYPE_NAME_LOOKUP(CreateAssignment);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainConnectionDenied); PACKET_TYPE_NAME_LOOKUP(DomainConnectionDenied);
PACKET_TYPE_NAME_LOOKUP(PacketTypeMuteEnvironment); PACKET_TYPE_NAME_LOOKUP(MuteEnvironment);
PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioStreamStats); PACKET_TYPE_NAME_LOOKUP(AudioStreamStats);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDataServerConfirm); PACKET_TYPE_NAME_LOOKUP(DataServerConfirm);
PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeStats); PACKET_TYPE_NAME_LOOKUP(OctreeStats);
PACKET_TYPE_NAME_LOOKUP(PacketTypeJurisdiction); PACKET_TYPE_NAME_LOOKUP(Jurisdiction);
PACKET_TYPE_NAME_LOOKUP(PacketTypeJurisdictionRequest); PACKET_TYPE_NAME_LOOKUP(JurisdictionRequest);
PACKET_TYPE_NAME_LOOKUP(PacketTypeAvatarIdentity); PACKET_TYPE_NAME_LOOKUP(AvatarIdentity);
PACKET_TYPE_NAME_LOOKUP(PacketTypeAvatarBillboard); PACKET_TYPE_NAME_LOOKUP(AvatarBillboard);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainConnectRequest); PACKET_TYPE_NAME_LOOKUP(DomainConnectRequest);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainServerRequireDTLS); PACKET_TYPE_NAME_LOOKUP(DomainServerRequireDTLS);
PACKET_TYPE_NAME_LOOKUP(PacketTypeNodeJsonStats); PACKET_TYPE_NAME_LOOKUP(NodeJsonStats);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityQuery); PACKET_TYPE_NAME_LOOKUP(EntityQuery);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData); PACKET_TYPE_NAME_LOOKUP(EntityData);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase); PACKET_TYPE_NAME_LOOKUP(EntityErase);
PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack); PACKET_TYPE_NAME_LOOKUP(OctreeDataNack);
PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode); PACKET_TYPE_NAME_LOOKUP(StopNode);
PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioEnvironment); PACKET_TYPE_NAME_LOOKUP(AudioEnvironment);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEditNack); PACKET_TYPE_NAME_LOOKUP(EntityEditNack);
PACKET_TYPE_NAME_LOOKUP(PacketTypeSignedTransactionPayment); PACKET_TYPE_NAME_LOOKUP(SignedTransactionPayment);
PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerHeartbeat); PACKET_TYPE_NAME_LOOKUP(IceServerHeartbeat);
PACKET_TYPE_NAME_LOOKUP(PacketTypeDomainServerAddedNode); PACKET_TYPE_NAME_LOOKUP(DomainServerAddedNode);
PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerQuery); PACKET_TYPE_NAME_LOOKUP(IceServerQuery);
PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerPeerInformation); PACKET_TYPE_NAME_LOOKUP(IceServerPeerInformation);
PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPing); PACKET_TYPE_NAME_LOOKUP(UnverifiedPing);
PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPingReply); PACKET_TYPE_NAME_LOOKUP(UnverifiedPingReply);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAdd); PACKET_TYPE_NAME_LOOKUP(EntityAdd);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEdit); PACKET_TYPE_NAME_LOOKUP(EntityEdit);
default: default:
return QString("Type: ") + QString::number((int)packetType); return QString("Type: ") + QString::number((int)packetType);
} }
@ -143,13 +159,13 @@ QString nameForPacketType(PacketType packetType) {
QByteArray byteArrayWithUUIDPopulatedHeader(PacketType packetType, const QUuid& connectionUUID) { QByteArray byteArrayWithUUIDPopulatedHeader(PacketType::Value packetType, const QUuid& connectionUUID) {
QByteArray freshByteArray(MAX_PACKET_HEADER_BYTES, 0); QByteArray freshByteArray(MAX_PACKET_HEADER_BYTES, 0);
freshByteArray.resize(populatePacketHeaderWithUUID(freshByteArray, packetType, connectionUUID)); freshByteArray.resize(populatePacketHeaderWithUUID(freshByteArray, packetType, connectionUUID));
return freshByteArray; return freshByteArray;
} }
int populatePacketHeaderWithUUID(QByteArray& packet, PacketType packetType, const QUuid& connectionUUID) { int populatePacketHeaderWithUUID(QByteArray& packet, PacketType::Value packetType, const QUuid& connectionUUID) {
if (packet.size() < numBytesForPacketHeaderGivenPacketType(packetType)) { if (packet.size() < numBytesForPacketHeaderGivenPacketType(packetType)) {
packet.resize(numBytesForPacketHeaderGivenPacketType(packetType)); packet.resize(numBytesForPacketHeaderGivenPacketType(packetType));
} }
@ -157,7 +173,7 @@ int populatePacketHeaderWithUUID(QByteArray& packet, PacketType packetType, cons
return populatePacketHeaderWithUUID(packet.data(), packetType, connectionUUID); return populatePacketHeaderWithUUID(packet.data(), packetType, connectionUUID);
} }
int populatePacketHeaderWithUUID(char* packet, PacketType packetType, const QUuid& connectionUUID) { int populatePacketHeaderWithUUID(char* packet, PacketType::Value packetType, const QUuid& connectionUUID) {
int numTypeBytes = packArithmeticallyCodedValue(packetType, packet); int numTypeBytes = packArithmeticallyCodedValue(packetType, packet);
packet[numTypeBytes] = versionForPacketType(packetType); packet[numTypeBytes] = versionForPacketType(packetType);
@ -185,31 +201,31 @@ int populatePacketHeaderWithUUID(char* packet, PacketType packetType, const QUui
} }
int numBytesForPacketHeader(const QByteArray& packet) { int numBytesForPacketHeader(const QByteArray& packet) {
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
return numBytesForPacketHeaderGivenPacketType(packetType); return numBytesForPacketHeaderGivenPacketType(packetType);
} }
int numBytesForPacketHeader(const char* packet) { int numBytesForPacketHeader(const char* packet) {
PacketType packetType = packetTypeForPacket(packet); PacketType::Value packetType = packetTypeForPacket(packet);
return numBytesForPacketHeaderGivenPacketType(packetType); return numBytesForPacketHeaderGivenPacketType(packetType);
} }
int numBytesForArithmeticCodedPacketType(PacketType packetType) { int numBytesForArithmeticCodedPacketType(PacketType::Value packetType) {
return (int) ceilf((float) packetType / 255); return (int) ceilf((float) packetType / 255);
} }
int numBytesForPacketHeaderGivenPacketType(PacketType packetType) { int numBytesForPacketHeaderGivenPacketType(PacketType::Value packetType) {
return numBytesForArithmeticCodedPacketType(packetType) return numBytesForArithmeticCodedPacketType(packetType)
+ numHashBytesForType(packetType) + numHashBytesForType(packetType)
+ numSequenceNumberBytesForType(packetType) + numSequenceNumberBytesForType(packetType)
+ NUM_STATIC_HEADER_BYTES; + NUM_STATIC_HEADER_BYTES;
} }
int numHashBytesForType(PacketType packetType) { int numHashBytesForType(PacketType::Value packetType) {
return (NON_VERIFIED_PACKETS.contains(packetType) ? 0 : NUM_BYTES_MD5_HASH); return (NON_VERIFIED_PACKETS.contains(packetType) ? 0 : NUM_BYTES_MD5_HASH);
} }
int numSequenceNumberBytesForType(PacketType packetType) { int numSequenceNumberBytesForType(PacketType::Value packetType) {
return (SEQUENCE_NUMBERED_PACKETS.contains(packetType) ? sizeof(PacketSequenceNumber) : 0); return (SEQUENCE_NUMBERED_PACKETS.contains(packetType) ? sizeof(PacketSequenceNumber) : 0);
} }
@ -218,11 +234,11 @@ QUuid uuidFromPacketHeader(const QByteArray& packet) {
NUM_BYTES_RFC4122_UUID)); NUM_BYTES_RFC4122_UUID));
} }
int hashOffsetForPacketType(PacketType packetType) { int hashOffsetForPacketType(PacketType::Value packetType) {
return numBytesForArithmeticCodedPacketType(packetType) + NUM_STATIC_HEADER_BYTES; return numBytesForArithmeticCodedPacketType(packetType) + NUM_STATIC_HEADER_BYTES;
} }
int sequenceNumberOffsetForPacketType(PacketType packetType) { int sequenceNumberOffsetForPacketType(PacketType::Value packetType) {
return numBytesForPacketHeaderGivenPacketType(packetType) - sizeof(PacketSequenceNumber); return numBytesForPacketHeaderGivenPacketType(packetType) - sizeof(PacketSequenceNumber);
} }
@ -235,8 +251,8 @@ QByteArray hashForPacketAndConnectionUUID(const QByteArray& packet, const QUuid&
QCryptographicHash::Md5); QCryptographicHash::Md5);
} }
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType packetType) { PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType) {
if (packetType == PacketTypeUnknown) { if (packetType == PacketType::Unknown) {
packetType = packetTypeForPacket(packet); packetType = packetTypeForPacket(packet);
} }
@ -249,8 +265,8 @@ PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketTy
return result; return result;
} }
void replaceHashInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketType packetType) { void replaceHashInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketType::Value packetType) {
if (packetType == PacketTypeUnknown) { if (packetType == PacketType::Unknown) {
packetType = packetTypeForPacket(packet); packetType = packetTypeForPacket(packet);
} }
@ -258,8 +274,8 @@ void replaceHashInPacket(QByteArray& packet, const QUuid& connectionUUID, Packet
hashForPacketAndConnectionUUID(packet, connectionUUID)); hashForPacketAndConnectionUUID(packet, connectionUUID));
} }
void replaceSequenceNumberInPacket(QByteArray& packet, PacketSequenceNumber sequenceNumber, PacketType packetType) { void replaceSequenceNumberInPacket(QByteArray& packet, PacketSequenceNumber sequenceNumber, PacketType::Value packetType) {
if (packetType == PacketTypeUnknown) { if (packetType == PacketType::Unknown) {
packetType = packetTypeForPacket(packet); packetType = packetTypeForPacket(packet);
} }
@ -268,8 +284,8 @@ void replaceSequenceNumberInPacket(QByteArray& packet, PacketSequenceNumber sequ
} }
void replaceHashAndSequenceNumberInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketSequenceNumber sequenceNumber, void replaceHashAndSequenceNumberInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketSequenceNumber sequenceNumber,
PacketType packetType) { PacketType::Value packetType) {
if (packetType == PacketTypeUnknown) { if (packetType == PacketType::Unknown) {
packetType = packetTypeForPacket(packet); packetType = packetTypeForPacket(packet);
} }
@ -277,10 +293,10 @@ void replaceHashAndSequenceNumberInPacket(QByteArray& packet, const QUuid& conne
replaceSequenceNumberInPacket(packet, sequenceNumber, packetType); replaceSequenceNumberInPacket(packet, sequenceNumber, packetType);
} }
PacketType packetTypeForPacket(const QByteArray& packet) { PacketType::Value packetTypeForPacket(const QByteArray& packet) {
return (PacketType) arithmeticCodingValueFromBuffer(packet.data()); return (PacketType::Value) arithmeticCodingValueFromBuffer(packet.data());
} }
PacketType packetTypeForPacket(const char* packet) { PacketType::Value packetTypeForPacket(const char* packet) {
return (PacketType) arithmeticCodingValueFromBuffer(packet); return (PacketType::Value) arithmeticCodingValueFromBuffer(packet);
} }

View file

@ -89,67 +89,55 @@ typedef char PacketVersion;
typedef uint16_t PacketSequenceNumber; typedef uint16_t PacketSequenceNumber;
const PacketSequenceNumber DEFAULT_SEQUENCE_NUMBER = 0; const PacketSequenceNumber DEFAULT_SEQUENCE_NUMBER = 0;
typedef std::map<PacketType, PacketSequenceNumber> PacketTypeSequenceMap; typedef std::map<PacketType::Value, PacketSequenceNumber> PacketTypeSequenceMap;
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>() extern const QSet<PacketType::Value> NON_VERIFIED_PACKETS;
<< PacketTypeDomainServerRequireDTLS << PacketTypeDomainConnectRequest extern const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS;
<< PacketTypeDomainList << PacketTypeDomainListRequest << PacketTypeDomainConnectionDenied
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
<< PacketTypeNodeJsonStats << PacketTypeEntityQuery
<< PacketTypeOctreeDataNack << PacketTypeEntityEditNack
<< PacketTypeIceServerHeartbeat << PacketTypeIceServerPeerInformation
<< PacketTypeIceServerQuery << PacketTypeUnverifiedPing
<< PacketTypeUnverifiedPingReply << PacketTypeStopNode
<< PacketTypeDomainServerPathQuery << PacketTypeDomainServerPathResponse
<< PacketTypeDomainServerAddedNode;
const QSet<PacketType> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType>()
<< PacketTypeAvatarData;
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;
const int MAX_PACKET_HEADER_BYTES = sizeof(PacketType) + NUM_BYTES_MD5_HASH + NUM_STATIC_HEADER_BYTES; const int MAX_PACKET_HEADER_BYTES = sizeof(PacketType::Value) + NUM_BYTES_MD5_HASH + NUM_STATIC_HEADER_BYTES;
PacketType packetTypeForPacket(const QByteArray& packet); PacketType::Value packetTypeForPacket(const QByteArray& packet);
PacketType packetTypeForPacket(const char* packet); PacketType::Value packetTypeForPacket(const char* packet);
PacketVersion versionForPacketType(PacketType packetType); PacketVersion versionForPacketType(PacketType::Value packetType);
QString nameForPacketType(PacketType packetType); QString nameForPacketType(PacketType::Value packetType);
const QUuid nullUUID = QUuid(); const QUuid nullUUID = QUuid();
QByteArray byteArrayWithUUIDPopulatedHeader(PacketType packetType, const QUuid& connectionUUID); QByteArray byteArrayWithUUIDPopulatedHeader(PacketType::Value packetType, const QUuid& connectionUUID);
int populatePacketHeaderWithUUID(QByteArray& packet, PacketType packetType, const QUuid& connectionUUID); int populatePacketHeaderWithUUID(QByteArray& packet, PacketType::Value packetType, const QUuid& connectionUUID);
int populatePacketHeaderWithUUID(char* packet, PacketType packetType, const QUuid& connectionUUID); int populatePacketHeaderWithUUID(char* packet, PacketType::Value packetType, const QUuid& connectionUUID);
int numHashBytesForType(PacketType packetType); int numHashBytesForType(PacketType::Value packetType);
int numSequenceNumberBytesForType(PacketType packetType); int numSequenceNumberBytesForType(PacketType::Value packetType);
int numBytesForPacketHeader(const QByteArray& packet); int numBytesForPacketHeader(const QByteArray& packet);
int numBytesForPacketHeader(const char* packet); int numBytesForPacketHeader(const char* packet);
int numBytesForArithmeticCodedPacketType(PacketType packetType); int numBytesForArithmeticCodedPacketType(PacketType::Value packetType);
int numBytesForPacketHeaderGivenPacketType(PacketType packetType); int numBytesForPacketHeaderGivenPacketType(PacketType::Value packetType);
QUuid uuidFromPacketHeader(const QByteArray& packet); QUuid uuidFromPacketHeader(const QByteArray& packet);
int hashOffsetForPacketType(PacketType packetType); int hashOffsetForPacketType(PacketType::Value packetType);
int sequenceNumberOffsetForPacketType(PacketType packetType); int sequenceNumberOffsetForPacketType(PacketType::Value packetType);
QByteArray hashFromPacketHeader(const QByteArray& packet); QByteArray hashFromPacketHeader(const QByteArray& packet);
QByteArray hashForPacketAndConnectionUUID(const QByteArray& packet, const QUuid& connectionUUID); QByteArray hashForPacketAndConnectionUUID(const QByteArray& packet, const QUuid& connectionUUID);
// NOTE: The following four methods accept a PacketType which defaults to PacketTypeUnknown. // NOTE: The following four methods accept a PacketType::Value which defaults to PacketType::Unknown.
// If the caller has already looked at the packet type and can provide it then the methods below won't have to look it up. // If the caller has already looked at the packet type and can provide it then the methods below won't have to look it up.
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType packetType = PacketTypeUnknown); PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType = PacketType::Unknown);
void replaceHashInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketType packetType = PacketTypeUnknown); void replaceHashInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketType::Value packetType = PacketType::Unknown);
void replaceSequenceNumberInPacket(QByteArray& packet, PacketSequenceNumber sequenceNumber, void replaceSequenceNumberInPacket(QByteArray& packet, PacketSequenceNumber sequenceNumber,
PacketType packetType = PacketTypeUnknown); PacketType::Value packetType = PacketType::Unknown);
void replaceHashAndSequenceNumberInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketSequenceNumber sequenceNumber, void replaceHashAndSequenceNumberInPacket(QByteArray& packet, const QUuid& connectionUUID, PacketSequenceNumber sequenceNumber,
PacketType packetType = PacketTypeUnknown); PacketType::Value packetType = PacketType::Unknown);
int arithmeticCodingValueFromBuffer(const char* checkValue); int arithmeticCodingValueFromBuffer(const char* checkValue);
int numBytesArithmeticCodingFromBuffer(const char* checkValue); int numBytesArithmeticCodingFromBuffer(const char* checkValue);

View file

@ -25,7 +25,7 @@ public:
qint64 satoshiCost = 0, const QUuid nodeUUID = QUuid()); qint64 satoshiCost = 0, const QUuid nodeUUID = QUuid());
QUuid _nodeUUID; QUuid _nodeUUID;
PacketType _currentType; PacketType::Value _currentType;
unsigned char _currentBuffer[MAX_PACKET_SIZE]; unsigned char _currentBuffer[MAX_PACKET_SIZE];
size_t _currentSize; size_t _currentSize;
qint64 _satoshiCost; qint64 _satoshiCost;

View file

@ -1936,7 +1936,7 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
bool wantImportProgress = true; bool wantImportProgress = true;
PacketType expectedType = expectedDataPacketType(); PacketType::Value expectedType = expectedDataPacketType();
PacketVersion expectedVersion = versionForPacketType(expectedType); PacketVersion expectedVersion = versionForPacketType(expectedType);
bool hasBufferBreaks = versionHasSVOfileBreaks(expectedVersion); bool hasBufferBreaks = versionHasSVOfileBreaks(expectedVersion);
@ -1954,7 +1954,7 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
unsigned long dataLength = HEADER_LENGTH; unsigned long dataLength = HEADER_LENGTH;
// if so, read the first byte of the file and see if it matches the expected version code // if so, read the first byte of the file and see if it matches the expected version code
PacketType gotType; PacketType::Value gotType;
memcpy(&gotType, dataAt, sizeof(gotType)); memcpy(&gotType, dataAt, sizeof(gotType));
dataAt += sizeof(expectedType); dataAt += sizeof(expectedType);
@ -2097,7 +2097,7 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
} }
// include the "bitstream" version // include the "bitstream" version
PacketType expectedType = expectedDataPacketType(); PacketType::Value expectedType = expectedDataPacketType();
PacketVersion expectedVersion = versionForPacketType(expectedType); PacketVersion expectedVersion = versionForPacketType(expectedType);
entityDescription["Version"] = (int) expectedVersion; entityDescription["Version"] = (int) expectedVersion;
@ -2118,7 +2118,7 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
if(file.is_open()) { if(file.is_open()) {
qCDebug(octree, "Saving binary SVO to file %s...", fileName); qCDebug(octree, "Saving binary SVO to file %s...", fileName);
PacketType expectedType = expectedDataPacketType(); PacketType::Value expectedType = expectedDataPacketType();
PacketVersion expectedVersion = versionForPacketType(expectedType); PacketVersion expectedVersion = versionForPacketType(expectedType);
bool hasBufferBreaks = versionHasSVOfileBreaks(expectedVersion); bool hasBufferBreaks = versionHasSVOfileBreaks(expectedVersion);

View file

@ -226,7 +226,7 @@ public:
// These methods will allow the OctreeServer to send your tree inbound edit packets of your // These methods will allow the OctreeServer to send your tree inbound edit packets of your
// own definition. Implement these to allow your octree based server to support editing // own definition. Implement these to allow your octree based server to support editing
virtual bool getWantSVOfileVersions() const { return false; } virtual bool getWantSVOfileVersions() const { return false; }
virtual PacketType expectedDataPacketType() const { return PacketTypeUnknown; } virtual PacketType::Value expectedDataPacketType() const { return PacketTypeUnknown; }
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()); }

View file

@ -327,7 +327,7 @@ void OctreeEditPacketSender::releaseQueuedPacket(EditPacketBuffer& packetBuffer)
_releaseQueuedPacketMutex.unlock(); _releaseQueuedPacketMutex.unlock();
} }
void OctreeEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, PacketType type, int nodeClockSkew) { void OctreeEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, PacketType::Value type, int nodeClockSkew) {
packetBuffer._currentSize = packetBuffer._currentSize =
DependencyManager::get<NodeList>()->populatePacketHeader(reinterpret_cast<char*>(&packetBuffer._currentBuffer[0]), type); DependencyManager::get<NodeList>()->populatePacketHeader(reinterpret_cast<char*>(&packetBuffer._currentBuffer[0]), type);

View file

@ -101,7 +101,7 @@ protected:
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 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 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
void processPreServerExistsPackets(); void processPreServerExistsPackets();

View file

@ -33,7 +33,7 @@ void OctreeHeadlessViewer::init() {
void OctreeHeadlessViewer::queryOctree() { void OctreeHeadlessViewer::queryOctree() {
char serverType = getMyNodeType(); char serverType = getMyNodeType();
PacketType packetType = getMyQueryMessageType(); PacketType::Value packetType = getMyQueryMessageType();
NodeToJurisdictionMap& jurisdictions = *_jurisdictionListener->getJurisdictions(); NodeToJurisdictionMap& jurisdictions = *_jurisdictionListener->getJurisdictions();
bool wantExtraDebugging = false; bool wantExtraDebugging = false;

View file

@ -42,7 +42,7 @@ typedef quint64 OCTREE_PACKET_SENT_TIME;
typedef uint16_t OCTREE_PACKET_INTERNAL_SECTION_SIZE; typedef uint16_t OCTREE_PACKET_INTERNAL_SECTION_SIZE;
const int MAX_OCTREE_PACKET_SIZE = MAX_PACKET_SIZE; const int MAX_OCTREE_PACKET_SIZE = MAX_PACKET_SIZE;
// this is overly conservative - sizeof(PacketType) is 8 bytes but a packed PacketType could be as small as one byte // this is overly conservative - sizeof(PacketType) is 8 bytes but a packed PacketType::Value could be as small as one byte
const unsigned int OCTREE_PACKET_EXTRA_HEADERS_SIZE = sizeof(OCTREE_PACKET_FLAGS) const unsigned int OCTREE_PACKET_EXTRA_HEADERS_SIZE = sizeof(OCTREE_PACKET_FLAGS)
+ sizeof(OCTREE_PACKET_SEQUENCE) + sizeof(OCTREE_PACKET_SENT_TIME); + sizeof(OCTREE_PACKET_SEQUENCE) + sizeof(OCTREE_PACKET_SENT_TIME);

View file

@ -62,10 +62,10 @@ void OctreeRenderer::processDatagram(const QByteArray& dataByteArray, const Shar
PerformanceWarning warn(showTimingDetails, "OctreeRenderer::processDatagram()",showTimingDetails); PerformanceWarning warn(showTimingDetails, "OctreeRenderer::processDatagram()",showTimingDetails);
unsigned int packetLength = dataByteArray.size(); unsigned int packetLength = dataByteArray.size();
PacketType command = packetTypeForPacket(dataByteArray); PacketType::Value command = packetTypeForPacket(dataByteArray);
unsigned int numBytesPacketHeader = numBytesForPacketHeader(dataByteArray); unsigned int numBytesPacketHeader = numBytesForPacketHeader(dataByteArray);
QUuid sourceUUID = uuidFromPacketHeader(dataByteArray); QUuid sourceUUID = uuidFromPacketHeader(dataByteArray);
PacketType expectedType = getExpectedPacketType(); PacketType::Value expectedType = getExpectedPacketType();
// packetVersion is the second byte // packetVersion is the second byte
PacketVersion packetVersion = dataByteArray[1]; PacketVersion packetVersion = dataByteArray[1];

View file

@ -36,8 +36,8 @@ public:
virtual ~OctreeRenderer(); virtual ~OctreeRenderer();
virtual char getMyNodeType() const = 0; virtual char getMyNodeType() const = 0;
virtual PacketType getMyQueryMessageType() const = 0; virtual PacketType::Value getMyQueryMessageType() const = 0;
virtual PacketType getExpectedPacketType() const = 0; virtual PacketType::Value getExpectedPacketType() const = 0;
virtual void renderElement(OctreeElement* element, RenderArgs* args) = 0; virtual void renderElement(OctreeElement* element, RenderArgs* args) = 0;
virtual float getSizeScale() const { return DEFAULT_OCTREE_SIZE_SCALE; } virtual float getSizeScale() const { return DEFAULT_OCTREE_SIZE_SCALE; }
virtual int getBoundaryLevelAdjust() const { return 0; } virtual int getBoundaryLevelAdjust() const { return 0; }