mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 09:53:30 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into loginInitiative2
This commit is contained in:
commit
9af164cb94
4 changed files with 43 additions and 80 deletions
|
@ -59,6 +59,7 @@ $(document).ready(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/content/upload',
|
url: '/content/upload',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
timeout: 3600000, // Set timeout to 1h
|
||||||
cache: false,
|
cache: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
|
|
@ -37,7 +37,6 @@ Socket::Socket(QObject* parent, bool shouldChangeSocketOptions) :
|
||||||
_shouldChangeSocketOptions(shouldChangeSocketOptions)
|
_shouldChangeSocketOptions(shouldChangeSocketOptions)
|
||||||
{
|
{
|
||||||
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
|
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
|
||||||
connect(this, &Socket::pendingDatagrams, this, &Socket::processPendingDatagrams, Qt::QueuedConnection);
|
|
||||||
|
|
||||||
// make sure we hear about errors and state changes from the underlying socket
|
// make sure we hear about errors and state changes from the underlying socket
|
||||||
connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
connect(&_udpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
|
@ -316,85 +315,64 @@ void Socket::checkForReadyReadBackup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::readPendingDatagrams() {
|
void Socket::readPendingDatagrams() {
|
||||||
int packetsRead = 0;
|
using namespace std::chrono;
|
||||||
|
static const auto MAX_PROCESS_TIME { 100ms };
|
||||||
|
const auto abortTime = system_clock::now() + MAX_PROCESS_TIME;
|
||||||
int packetSizeWithHeader = -1;
|
int packetSizeWithHeader = -1;
|
||||||
// Max datagrams to read before processing:
|
|
||||||
static const int MAX_DATAGRAMS_CONSECUTIVELY = 10000;
|
|
||||||
while (_udpSocket.hasPendingDatagrams()
|
|
||||||
&& (packetSizeWithHeader = _udpSocket.pendingDatagramSize()) != -1
|
|
||||||
&& packetsRead <= MAX_DATAGRAMS_CONSECUTIVELY) {
|
|
||||||
// grab a time point we can mark as the receive time of this packet
|
|
||||||
auto receiveTime = p_high_resolution_clock::now();
|
|
||||||
|
|
||||||
|
while (_udpSocket.hasPendingDatagrams() &&
|
||||||
// setup a buffer to read the packet into
|
(packetSizeWithHeader = _udpSocket.pendingDatagramSize()) != -1) {
|
||||||
auto buffer = std::unique_ptr<char[]>(new char[packetSizeWithHeader]);
|
if (system_clock::now() > abortTime) {
|
||||||
|
// We've been running for too long, stop processing packets for now
|
||||||
QHostAddress senderAddress;
|
// Once we've processed the event queue, we'll come back to packet processing
|
||||||
quint16 senderPort;
|
break;
|
||||||
|
|
||||||
// pull the datagram
|
|
||||||
auto sizeRead = _udpSocket.readDatagram(buffer.get(), packetSizeWithHeader,
|
|
||||||
&senderAddress, &senderPort);
|
|
||||||
|
|
||||||
// we either didn't pull anything for this packet or there was an error reading (this seems to trigger
|
|
||||||
// on windows even if there's not a packet available)
|
|
||||||
if (sizeRead < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_incomingDatagrams.push_back({ senderAddress, senderPort, packetSizeWithHeader,
|
|
||||||
std::move(buffer), receiveTime });
|
|
||||||
++packetsRead;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packetsRead > _maxDatagramsRead) {
|
|
||||||
_maxDatagramsRead = packetsRead;
|
|
||||||
qCDebug(networking) << "readPendingDatagrams: Datagrams read:" << packetsRead;
|
|
||||||
}
|
|
||||||
emit pendingDatagrams(packetsRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Socket::processPendingDatagrams(int) {
|
|
||||||
// setup a HifiSockAddr to read into
|
|
||||||
HifiSockAddr senderSockAddr;
|
|
||||||
|
|
||||||
while (!_incomingDatagrams.empty()) {
|
|
||||||
auto& datagram = _incomingDatagrams.front();
|
|
||||||
senderSockAddr.setAddress(datagram._senderAddress);
|
|
||||||
senderSockAddr.setPort(datagram._senderPort);
|
|
||||||
int datagramSize = datagram._datagramLength;
|
|
||||||
auto receiveTime = datagram._receiveTime;
|
|
||||||
|
|
||||||
// we're reading a packet so re-start the readyRead backup timer
|
// we're reading a packet so re-start the readyRead backup timer
|
||||||
_readyReadBackupTimer->start();
|
_readyReadBackupTimer->start();
|
||||||
|
|
||||||
|
// grab a time point we can mark as the receive time of this packet
|
||||||
|
auto receiveTime = p_high_resolution_clock::now();
|
||||||
|
|
||||||
|
// setup a HifiSockAddr to read into
|
||||||
|
HifiSockAddr senderSockAddr;
|
||||||
|
|
||||||
|
// setup a buffer to read the packet into
|
||||||
|
auto buffer = std::unique_ptr<char[]>(new char[packetSizeWithHeader]);
|
||||||
|
|
||||||
|
// pull the datagram
|
||||||
|
auto sizeRead = _udpSocket.readDatagram(buffer.get(), packetSizeWithHeader,
|
||||||
|
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
|
||||||
|
|
||||||
// save information for this packet, in case it is the one that sticks readyRead
|
// save information for this packet, in case it is the one that sticks readyRead
|
||||||
_lastPacketSizeRead = datagramSize;
|
_lastPacketSizeRead = sizeRead;
|
||||||
_lastPacketSockAddr = senderSockAddr;
|
_lastPacketSockAddr = senderSockAddr;
|
||||||
|
|
||||||
// Process unfiltered packets first.
|
if (sizeRead <= 0) {
|
||||||
|
// we either didn't pull anything for this packet or there was an error reading (this seems to trigger
|
||||||
|
// on windows even if there's not a packet available)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto it = _unfilteredHandlers.find(senderSockAddr);
|
auto it = _unfilteredHandlers.find(senderSockAddr);
|
||||||
|
|
||||||
if (it != _unfilteredHandlers.end()) {
|
if (it != _unfilteredHandlers.end()) {
|
||||||
// we have a registered unfiltered handler for this HifiSockAddr (eg. STUN packet) - call that and return
|
// we have a registered unfiltered handler for this HifiSockAddr - call that and return
|
||||||
if (it->second) {
|
if (it->second) {
|
||||||
auto basePacket = BasePacket::fromReceivedPacket(std::move(datagram._datagram),
|
auto basePacket = BasePacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
datagramSize, senderSockAddr);
|
|
||||||
basePacket->setReceiveTime(receiveTime);
|
basePacket->setReceiveTime(receiveTime);
|
||||||
it->second(std::move(basePacket));
|
it->second(std::move(basePacket));
|
||||||
}
|
}
|
||||||
_incomingDatagrams.pop_front();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this was a control packet or a data packet
|
// check if this was a control packet or a data packet
|
||||||
bool isControlPacket = *reinterpret_cast<uint32_t*>(datagram._datagram.get()) & CONTROL_BIT_MASK;
|
bool isControlPacket = *reinterpret_cast<uint32_t*>(buffer.get()) & CONTROL_BIT_MASK;
|
||||||
|
|
||||||
if (isControlPacket) {
|
if (isControlPacket) {
|
||||||
// setup a control packet from the data we just read
|
// setup a control packet from the data we just read
|
||||||
auto controlPacket = ControlPacket::fromReceivedPacket(std::move(datagram._datagram), datagramSize, senderSockAddr);
|
auto controlPacket = ControlPacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
controlPacket->setReceiveTime(receiveTime);
|
controlPacket->setReceiveTime(receiveTime);
|
||||||
|
|
||||||
// move this control packet to the matching connection, if there is one
|
// move this control packet to the matching connection, if there is one
|
||||||
|
@ -406,13 +384,13 @@ void Socket::processPendingDatagrams(int) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// setup a Packet from the data we just read
|
// setup a Packet from the data we just read
|
||||||
auto packet = Packet::fromReceivedPacket(std::move(datagram._datagram), datagramSize, senderSockAddr);
|
auto packet = Packet::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr);
|
||||||
packet->setReceiveTime(receiveTime);
|
packet->setReceiveTime(receiveTime);
|
||||||
|
|
||||||
// save the sequence number in case this is the packet that sticks readyRead
|
// save the sequence number in case this is the packet that sticks readyRead
|
||||||
_lastReceivedSequenceNumber = packet->getSequenceNumber();
|
_lastReceivedSequenceNumber = packet->getSequenceNumber();
|
||||||
|
|
||||||
// call our hash verification operator to see if this packet is verified
|
// call our verification operator to see if this packet is verified
|
||||||
if (!_packetFilterOperator || _packetFilterOperator(*packet)) {
|
if (!_packetFilterOperator || _packetFilterOperator(*packet)) {
|
||||||
if (packet->isReliable()) {
|
if (packet->isReliable()) {
|
||||||
// if this was a reliable packet then signal the matching connection with the sequence number
|
// if this was a reliable packet then signal the matching connection with the sequence number
|
||||||
|
@ -426,7 +404,6 @@ void Socket::processPendingDatagrams(int) {
|
||||||
qCDebug(networking) << "Can't process packet: version" << (unsigned int)NLPacket::versionInHeader(*packet)
|
qCDebug(networking) << "Can't process packet: version" << (unsigned int)NLPacket::versionInHeader(*packet)
|
||||||
<< ", type" << NLPacket::typeInHeader(*packet);
|
<< ", type" << NLPacket::typeInHeader(*packet);
|
||||||
#endif
|
#endif
|
||||||
_incomingDatagrams.pop_front();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,8 +419,6 @@ void Socket::processPendingDatagrams(int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_incomingDatagrams.pop_front();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,6 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clientHandshakeRequestComplete(const HifiSockAddr& sockAddr);
|
void clientHandshakeRequestComplete(const HifiSockAddr& sockAddr);
|
||||||
void pendingDatagrams(int datagramCount);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cleanupConnection(HifiSockAddr sockAddr);
|
void cleanupConnection(HifiSockAddr sockAddr);
|
||||||
|
@ -103,7 +102,6 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void readPendingDatagrams();
|
void readPendingDatagrams();
|
||||||
void processPendingDatagrams(int datagramCount);
|
|
||||||
void checkForReadyReadBackup();
|
void checkForReadyReadBackup();
|
||||||
|
|
||||||
void handleSocketError(QAbstractSocket::SocketError socketError);
|
void handleSocketError(QAbstractSocket::SocketError socketError);
|
||||||
|
@ -147,17 +145,6 @@ private:
|
||||||
int _lastPacketSizeRead { 0 };
|
int _lastPacketSizeRead { 0 };
|
||||||
SequenceNumber _lastReceivedSequenceNumber;
|
SequenceNumber _lastReceivedSequenceNumber;
|
||||||
HifiSockAddr _lastPacketSockAddr;
|
HifiSockAddr _lastPacketSockAddr;
|
||||||
|
|
||||||
struct Datagram {
|
|
||||||
QHostAddress _senderAddress;
|
|
||||||
int _senderPort;
|
|
||||||
int _datagramLength;
|
|
||||||
std::unique_ptr<char[]> _datagram;
|
|
||||||
p_high_resolution_clock::time_point _receiveTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::list<Datagram> _incomingDatagrams;
|
|
||||||
int _maxDatagramsRead { 0 };
|
|
||||||
|
|
||||||
friend UDTTest;
|
friend UDTTest;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,11 +38,11 @@ std::shared_ptr<PickQuery> PickManager::findPick(unsigned int uid) const {
|
||||||
|
|
||||||
void PickManager::removePick(unsigned int uid) {
|
void PickManager::removePick(unsigned int uid) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
auto type = _typeMap.find(uid);
|
auto typeIt = _typeMap.find(uid);
|
||||||
if (type != _typeMap.end()) {
|
if (typeIt != _typeMap.end()) {
|
||||||
_picks[type->second].erase(uid);
|
_picks[typeIt->second].erase(uid);
|
||||||
_typeMap.erase(uid);
|
_totalPickCounts[typeIt->second]--;
|
||||||
_totalPickCounts[type->second]--;
|
_typeMap.erase(typeIt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue