History

link mesh URL and UUID in prefs to data server client

Stephen Birarda committed 13 years ago

Commit 98f435c1 parent fea3ca86 files · +149 −99Browse files

Showing the changes to interface/src/DataServerClient.cpp (1 of 6 files). Show all

Unified · Split

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