Showing the changes to interface/src/DataServerClient.cpp (1 of 6 files). Show all
Unified · Split
| @@ -16,56 +16,60 @@ · 15 unmodified lines | ||
| 16 | 16 | QUuid DataServerClient::_clientUUID; |
| 17 | 17 | std::vector<unsigned char*> DataServerClient::_unconfirmedPackets; |
| 18 | 18 | |
| 19 | −const char DATA_SERVER_HOSTNAME[] = "data.highfidelity.io"; | |
| 19 | +const char DATA_SERVER_HOSTNAME[] = "127.0.0.1"; | |
| 20 | 20 | const unsigned short DATA_SERVER_PORT = 3282; |
| 21 | 21 | const sockaddr_in DATA_SERVER_SOCKET = socketForHostnameAndHostOrderPort(DATA_SERVER_HOSTNAME, DATA_SERVER_PORT); |
| 22 | 22 | |
| 23 | 23 | void DataServerClient::putValueForKey(const char* key, const char* value) { |
| 24 | − unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 25 | − | |
| 26 | − // setup the header for this packet | |
| 27 | − int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 28 | − | |
| 29 | − // pack the client UUID | |
| 30 | − QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); | |
| 31 | − memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 32 | − numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 33 | − | |
| 34 | − // pack the key, null terminated | |
| 35 | − strcpy((char*) putPacket + numPacketBytes, key); | |
| 36 | − numPacketBytes += strlen(key); | |
| 37 | − putPacket[numPacketBytes++] = '\0'; | |
| 38 | − | |
| 39 | − // pack the value, null terminated | |
| 40 | − strcpy((char*) putPacket + numPacketBytes, value); | |
| 41 | − numPacketBytes += strlen(value); | |
| 42 | − putPacket[numPacketBytes++] = '\0'; | |
| 43 | − | |
| 44 | − // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed | |
| 45 | − _unconfirmedPackets.push_back(putPacket); | |
| 46 | − | |
| 47 | − // send this put request to the data server | |
| 48 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 24 | + if (!_clientUUID.isNull()) { | |
| 25 | + unsigned char* putPacket = new unsigned char[MAX_PACKET_SIZE]; | |
| 26 | + | |
| 27 | + // setup the header for this packet | |
| 28 | + int numPacketBytes = populateTypeAndVersion(putPacket, PACKET_TYPE_DATA_SERVER_PUT); | |
| 29 | + | |
| 30 | + // pack the client UUID | |
| 31 | + QString uuidString = uuidStringWithoutCurlyBraces(_clientUUID); | |
| 32 | + memcpy(putPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 33 | + numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 34 | + | |
| 35 | + // pack the key, null terminated | |
| 36 | + strcpy((char*) putPacket + numPacketBytes, key); | |
| 37 | + numPacketBytes += strlen(key); | |
| 38 | + putPacket[numPacketBytes++] = '\0'; | |
| 39 | + | |
| 40 | + // pack the value, null terminated | |
| 41 | + strcpy((char*) putPacket + numPacketBytes, value); | |
| 42 | + numPacketBytes += strlen(value); | |
| 43 | + putPacket[numPacketBytes++] = '\0'; | |
| 44 | + | |
| 45 | + // add the putPacket to our vector of unconfirmed packets, will be deleted once put is confirmed | |
| 46 | + _unconfirmedPackets.push_back(putPacket); | |
| 47 | + | |
| 48 | + // send this put request to the data server | |
| 49 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, putPacket, numPacketBytes); | |
| 50 | + } | |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | void DataServerClient::getValueForKeyAndUUID(const char* key, QUuid &uuid) { |
| 52 | − unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 53 | − | |
| 54 | − // setup the header for this packet | |
| 55 | − int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 56 | − | |
| 57 | − // pack the UUID we're asking for data for | |
| 58 | − QString uuidString = uuidStringWithoutCurlyBraces(uuid); | |
| 59 | − memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 60 | − numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 61 | − | |
| 62 | − // pack the key, null terminated | |
| 63 | − strcpy((char*) getPacket + numPacketBytes, key); | |
| 64 | − numPacketBytes += strlen(key); | |
| 65 | − getPacket[numPacketBytes++] = '\0'; | |
| 66 | − | |
| 67 | − // send the get to the data server | |
| 68 | − NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 54 | + if (!uuid.isNull()) { | |
| 55 | + unsigned char getPacket[MAX_PACKET_SIZE]; | |
| 56 | + | |
| 57 | + // setup the header for this packet | |
| 58 | + int numPacketBytes = populateTypeAndVersion(getPacket, PACKET_TYPE_DATA_SERVER_GET); | |
| 59 | + | |
| 60 | + // pack the UUID we're asking for data for | |
| 61 | + QString uuidString = uuidStringWithoutCurlyBraces(uuid); | |
| 62 | + memcpy(getPacket + numPacketBytes, uuidString.toLocal8Bit().constData(), uuidString.toLocal8Bit().size()); | |
| 63 | + numPacketBytes += uuidString.toLocal8Bit().size(); | |
| 64 | + | |
| 65 | + // pack the key, null terminated | |
| 66 | + strcpy((char*) getPacket + numPacketBytes, key); | |
| 67 | + numPacketBytes += strlen(key); | |
| 68 | + getPacket[numPacketBytes++] = '\0'; | |
| 69 | + | |
| 70 | + // send the get to the data server | |
| 71 | + NodeList::getInstance()->getNodeSocket()->send((sockaddr*) &DATA_SERVER_SOCKET, getPacket, numPacketBytes); | |
| 72 | + } | |
| 69 | 73 | } |
| 70 | 74 | |
| 71 | 75 | void DataServerClient::processConfirmFromDataServer(unsigned char* packetData, int numPacketBytes) { |