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

This commit is contained in:
Atlante45 2015-07-09 12:33:23 -07:00
commit 2b6d79e030
12 changed files with 30 additions and 224 deletions

View file

@ -101,7 +101,7 @@ int EntityServer::sendSpecialPackets(const SharedNodePointer& node, OctreeQueryN
totalBytes += specialPacket->getSizeWithHeader();
packetsSent++;
DependencyManager::get<NodeList>()->sendPacket(std::move(specialPacket), SharedNodePointer(node));
DependencyManager::get<NodeList>()->sendPacket(std::move(specialPacket), node);
}
nodeData->setLastDeletedEntitiesSentAt(deletePacketSentAt);

View file

@ -528,7 +528,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
}
// If we're not running compressed, then we know we can just send now. Or if we're running compressed, but
// the packet doesn't have enough space to bother attempting to pack more...packet
// the packet doesn't have enough space to bother attempting to pack more...
bool sendNow = true;
if (nodeData->getCurrentPacketIsCompressed() &&

View file

@ -620,9 +620,10 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
// this is an agent and we've decided we won't let them connect - send them a packet to deny connection
QByteArray utfString = reason.toUtf8();
int payloadSize = utfString.size();
qint16 payloadSize = utfString.size();
auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied, payloadSize);
auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied, payloadSize + sizeof(payloadSize));
connectionDeniedPacket->writePrimitive(payloadSize);
connectionDeniedPacket->write(utfString);
// tell client it has been refused.
@ -1029,7 +1030,7 @@ void DomainServer::broadcastNewNode(const SharedNodePointer& addedNode) {
addNodePacket->write(rfcConnectionSecret);
// send off this packet to the node
limitedNodeList->sendUnreliablePacket(addNodePacket, node);
limitedNodeList->sendUnreliablePacket(*addNodePacket, node);
}
);
}
@ -1093,7 +1094,7 @@ void DomainServer::readAvailableDatagrams() {
assignmentStream << uniqueAssignment;
limitedNodeList->sendUnreliablePacket(assignmentPacket, senderSockAddr);
limitedNodeList->sendUnreliablePacket(*assignmentPacket, senderSockAddr);
// add the information for that deployed assignment to the hash of pending assigned nodes
PendingAssignedNodeData* pendingNodeData = new PendingAssignedNodeData(assignmentToDeploy->getUUID(),
@ -1117,14 +1118,14 @@ void DomainServer::readAvailableDatagrams() {
static std::unique_ptr<NLPacket> dtlsRequiredPacket;
if (!dtlsRequiredPacket) {
dtlsRequiredPacket = NLPacket::create(PacketType::DomainServerRequireDTLS);
dtlsRequiredPacket = NLPacket::create(PacketType::DomainServerRequireDTLS, sizeof(unsigned short));
// pack the port that we accept DTLS traffic on
unsigned short dtlsPort = limitedNodeList->getDTLSSocket().localPort();
dtlsRequiredPacket->writePrimitive(dtlsPort);
}
limitedNodeList->sendUnreliablePacket(dtlsRequiredPacket, senderSockAddr);
limitedNodeList->sendUnreliablePacket(*dtlsRequiredPacket, senderSockAddr);
}
}
}

View file

@ -2891,7 +2891,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
queryPacket->setSizeUsed(packetSize);
// make sure we still have an active socket
nodeList->sendUnreliablePacket(queryPacket, node);
nodeList->sendUnreliablePacket(*queryPacket, node);
}
});
}

View file

@ -882,7 +882,7 @@ void AudioClient::handleAudioInput() {
nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPacket);
nodeList->sendUnreliablePacket(_audioPacket, audioMixer);
nodeList->sendUnreliablePacket(*_audioPacket, audioMixer);
_outgoingAvatarAudioSequenceNumber++;
}

View file

@ -238,7 +238,7 @@ void AudioInjector::injectToMixer() {
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
// send off this audio packet
nodeList->sendUnreliablePacket(audioPacket, audioMixer);
nodeList->sendUnreliablePacket(*audioPacket, audioMixer);
outgoingInjectedAudioSequenceNumber++;
_currentSendPosition += bytesToCopy;

View file

@ -220,16 +220,16 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) {
}
qint64 LimitedNodeList::readDatagram(QByteArray& incomingPacket, QHostAddress* address = 0, quint16* port = 0) {
qint64 result = getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), address, port);
qint64 result = getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), address, port);
SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket);
if (sendingNode) {
emit dataReceived(sendingNode->getType(), incomingPacket.size());
} else {
emit dataReceived(NodeType::Unassigned, incomingPacket.size());
}
SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket);
if (sendingNode) {
emit dataReceived(sendingNode->getType(), incomingPacket.size());
} else {
emit dataReceived(NodeType::Unassigned, incomingPacket.size());
}
return result;
return result;
}
qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr) {
@ -248,107 +248,6 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock
return bytesWritten;
}
//qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram,
// const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr) {
// if (destinationNode) {
// PacketType::Value packetType = packetTypeForPacket(datagram);
//
// if (NON_VERIFIED_PACKETS.contains(packetType)) {
// return writeUnverifiedDatagram(datagram, destinationNode, overridenSockAddr);
// }
//
// // if we don't have an overridden address, assume they want to send to the node's active socket
// const HifiSockAddr* destinationSockAddr = &overridenSockAddr;
// if (overridenSockAddr.isNull()) {
// if (destinationNode->getActiveSocket()) {
// // use the node's active socket as the destination socket
// destinationSockAddr = destinationNode->getActiveSocket();
// } else {
// // we don't have a socket to send to, return 0
// return 0;
// }
// }
//
// QByteArray datagramCopy = datagram;
//
// // if we're here and the connection secret is null, debug out - this could be a problem
// if (destinationNode->getConnectionSecret().isNull()) {
// qDebug() << "LimitedNodeList::writeDatagram called for verified datagram with null connection secret for"
// << "destination node" << destinationNode->getUUID() << " - this is either not secure or will cause"
// << "this packet to be unverifiable on the receiving side.";
// }
//
// // perform replacement of hash and optionally also sequence number in the header
// if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
// PacketSequenceNumber sequenceNumber = getNextSequenceNumberForPacket(destinationNode->getUUID(), packetType);
// replaceHashAndSequenceNumberInPacket(datagramCopy, destinationNode->getConnectionSecret(),
// sequenceNumber, packetType);
// } else {
// replaceHashInPacket(datagramCopy, destinationNode->getConnectionSecret(), packetType);
// }
//
// emit dataSent(destinationNode->getType(), datagram.size());
// auto bytesWritten = writeDatagram(datagramCopy, *destinationSockAddr);
// // Keep track of per-destination-node bandwidth
// destinationNode->recordBytesSent(bytesWritten);
// return bytesWritten;
// }
//
// // didn't have a destinationNode to send to, return 0
// return 0;
//}
//
//qint64 LimitedNodeList::writeUnverifiedDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr) {
// if (destinationNode) {
// // if we don't have an ovveriden address, assume they want to send to the node's active socket
// const HifiSockAddr* destinationSockAddr = &overridenSockAddr;
// if (overridenSockAddr.isNull()) {
// if (destinationNode->getActiveSocket()) {
// // use the node's active socket as the destination socket
// destinationSockAddr = destinationNode->getActiveSocket();
// } else {
// // we don't have a socket to send to, return 0
// return 0;
// }
// }
//
// PacketType::Value packetType = packetTypeForPacket(datagram);
//
// // optionally peform sequence number replacement in the header
// if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
//
// QByteArray datagramCopy = datagram;
//
// PacketSequenceNumber sequenceNumber = getNextSequenceNumberForPacket(destinationNode->getUUID(), packetType);
// replaceSequenceNumberInPacket(datagramCopy, sequenceNumber, packetType);
//
// // send the datagram with sequence number replaced in header
// return writeDatagram(datagramCopy, *destinationSockAddr);
// } else {
// return writeDatagram(datagram, *destinationSockAddr);
// }
// }
//
// // didn't have a destinationNode to send to, return 0
// return 0;
//}
//
//qint64 LimitedNodeList::writeUnverifiedDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr) {
// return writeDatagram(datagram, destinationSockAddr);
//}
//
//qint64 LimitedNodeList::writeDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr) {
// return writeDatagram(QByteArray(data, size), destinationNode, overridenSockAddr);
//}
//
//qint64 LimitedNodeList::writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr) {
// return writeUnverifiedDatagram(QByteArray(data, size), destinationNode, overridenSockAddr);
//}
PacketSequenceNumber LimitedNodeList::getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType::Value packetType) {
// Thanks to std::map and std::unordered_map this line either default constructs the
// PacketType::SequenceMap and the PacketSequenceNumber or returns the existing value.
@ -506,19 +405,6 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
}
}
// unsigned LimitedNodeList::broadcastToNodes(PacketList& packetList, const NodeSet& destinationNodeTypes) {
// unsigned n = 0;
//
// eachNode([&](const SharedNodePointer& node){
// if (destinationNodeTypes.contains(node->getType())) {
// writeDatagram(packet, node);
// ++n;
// }
// });
//
// return n;
// }
std::unique_ptr<NLPacket> LimitedNodeList::constructPingPacket(PingType_t pingType) {
int packetSize = sizeof(PingType_t) + sizeof(quint64);
auto pingPacket = NLPacket::create(PacketType::Ping, packetSize);

View file

@ -121,49 +121,16 @@ public:
bool packetVersionAndHashMatch(const QByteArray& packet);
// QByteArray byteArrayWithPopulatedHeader(PacketType::Value packetType)
// { return byteArrayWithUUIDPopulatedHeader(packetType, _sessionUUID); }
// int populatePacketHeader(QByteArray& packet, PacketType::Value packetType)
// { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); }
// int populatePacketHeader(char* packet, PacketType::Value packetType)
// { return populatePacketHeaderWithUUID(packet, packetType, _sessionUUID); }
qint64 readDatagram(QByteArray& incomingPacket, QHostAddress* address, quint16 * port);
//
// qint64 writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
// qint64 writeUnverifiedDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
// qint64 writeUnverifiedDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
//
// qint64 writeDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
// qint64 writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 sendUnreliablePacket(const NLPacket& packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
qint64 sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
// TODO remove those
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
qint64 sendUnreliablePacket(const NLPacket& packet, const SharedNodePointer& destinationNode) { assert(false); return 0; }
qint64 sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr) { assert(false); return 0; }
qint64 sendPacketList(NLPacketList& packetList, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
qint64 sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const SharedNodePointer& destinationNode) { assert(false); return 0; }
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr) { assert(false); return 0; }
qint64 sendPacketList(NLPacketList& packetList, const SharedNodePointer& destinationNode) { assert(false); return 0; }
qint64 sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) { assert(false); return 0; }
void (*linkedDataCreateCallback)(Node *);
@ -188,8 +155,7 @@ public:
int updateNodeWithDataFromPacket(const SharedNodePointer& matchingNode, const QByteArray& packet);
int findNodeAndUpdateWithDataFromPacket(const QByteArray& packet);
unsigned broadcastToNodes(std::unique_ptr<NLPacket> packet, const NodeSet& destinationNodeTypes)
{ assert(false); return 0; }
unsigned broadcastToNodes(std::unique_ptr<NLPacket> packet, const NodeSet& destinationNodeTypes) { assert(false); return 0; }
SharedNodePointer soloNodeOfType(char nodeType);
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);

View file

@ -63,7 +63,7 @@ qint64 NLPacketList::writeData(const char* data, qint64 maxSize) {
// but the PacketList is not going to be sent ordered
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
<< "larger than the payload size.";
return -1;
Q_ASSERT(false);
}
// copy from currentPacket where the segment started to the beginning of the newPacket

View file

@ -166,49 +166,6 @@ QString nameForPacketType(PacketType::Value packetType) {
return QString("unexpected");
}
QByteArray byteArrayWithUUIDPopulatedHeader(PacketType::Value packetType, const QUuid& connectionUUID) {
QByteArray freshByteArray(MAX_PACKET_HEADER_BYTES, 0);
freshByteArray.resize(populatePacketHeaderWithUUID(freshByteArray, packetType, connectionUUID));
return freshByteArray;
}
int populatePacketHeaderWithUUID(QByteArray& packet, PacketType::Value packetType, const QUuid& connectionUUID) {
if (packet.size() < numBytesForPacketHeaderGivenPacketType(packetType)) {
packet.resize(numBytesForPacketHeaderGivenPacketType(packetType));
}
return populatePacketHeaderWithUUID(packet.data(), packetType, connectionUUID);
}
int populatePacketHeaderWithUUID(char* packet, PacketType::Value packetType, const QUuid& connectionUUID) {
int numTypeBytes = packArithmeticallyCodedValue(packetType, packet);
packet[numTypeBytes] = versionForPacketType(packetType);
char* position = packet + numTypeBytes + sizeof(PacketVersion);
QByteArray rfcUUID = connectionUUID.toRfc4122();
memcpy(position, rfcUUID.constData(), NUM_BYTES_RFC4122_UUID);
position += NUM_BYTES_RFC4122_UUID;
if (!NON_VERIFIED_PACKETS.contains(packetType)) {
// pack 16 bytes of zeros where the md5 hash will be placed once data is packed
memset(position, 0, NUM_BYTES_MD5_HASH);
position += NUM_BYTES_MD5_HASH;
}
if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
// Pack zeros for the number of bytes that the sequence number requires.
// The LimitedNodeList will handle packing in the sequence number when sending out the packet.
memset(position, 0, sizeof(PacketSequenceNumber));
position += sizeof(PacketSequenceNumber);
}
// return the number of bytes written for pointer pushing
return position - packet;
}
int numBytesForPacketHeader(const QByteArray& packet) {
PacketType::Value packetType = packetTypeForPacket(packet);
return numBytesForPacketHeaderGivenPacketType(packetType);

View file

@ -107,10 +107,6 @@ QString nameForPacketType(PacketType::Value packetType);
const QUuid nullUUID = QUuid();
QByteArray byteArrayWithUUIDPopulatedHeader(PacketType::Value packetType, const QUuid& connectionUUID);
int populatePacketHeaderWithUUID(QByteArray& packet, PacketType::Value packetType, const QUuid& connectionUUID);
int populatePacketHeaderWithUUID(char* packet, PacketType::Value packetType, const QUuid& connectionUUID);
int numHashBytesForType(PacketType::Value packetType);
int numSequenceNumberBytesForType(PacketType::Value packetType);

View file

@ -272,7 +272,7 @@ bool PacketSender::nonThreadedProcess() {
unlock();
// send the packet through the NodeList...
DependencyManager::get<NodeList>()->sendUnreliablePacket(packetPair.second, packetPair.first);
DependencyManager::get<NodeList>()->sendUnreliablePacket(*(packetPair.second), packetPair.first);
packetsSentThisCall++;
_packetsOverCheckInterval++;