Commit c795791f authored by LIly's avatar LIly
Browse files

draw from haggle traces works

parent c6d3a8e7
#include <SSLClient.h> #include <SSLClient.h>
#include <iostream> #include <iostream>
#include <algorithm>
#include <ctime> #include <ctime>
#include <chrono>
#include <thread>
#include <vector> #include <vector>
#include <queue> #include <queue>
#include <map> #include <map>
...@@ -16,8 +15,12 @@ ...@@ -16,8 +15,12 @@
#define FANOUT 2 #define FANOUT 2
#define PROPORTION_SATISFY 1 #define PROPORTION_SATISFY 1
#define USEST 1 #define USEST 1
#define USENETWORK 0
#define USETRACEDATA 1
#define TRACE_FILE "haggle_traces.csv"
int user_index = 0; int user_index = 0;
int num_trace_users = 0;
struct EncounterInfo { struct EncounterInfo {
int user1; int user1;
...@@ -45,12 +48,6 @@ struct EncounterInfo { ...@@ -45,12 +48,6 @@ struct EncounterInfo {
} }
}; };
struct UserBFSPair{
int user;
int level;
UserBFSPair(int user, int level) : user(user), level(level) {}
};
std::string generate_random_hex_str() { std::string generate_random_hex_str() {
char str[56 + 1]; char str[56 + 1];
for(int i = 0; i < 56; i++) { for(int i = 0; i < 56; i++) {
...@@ -58,10 +55,39 @@ std::string generate_random_hex_str() { ...@@ -58,10 +55,39 @@ std::string generate_random_hex_str() {
} }
return std::string(str); return std::string(str);
} }
std::vector<EncounterInfo> generate_trace_encounters() {
std::vector<EncounterInfo> encs;
int user1, user2;
long start, end;
double lat, longi;
std::ifstream infile(TRACE_FILE);
std::string line;
while (std::getline(infile, line)) {
std::istringstream iss(line);
if (!(iss >> user1 >> user2 >> start >> end)) {
printf("ERROR\n");
continue;
}
lat = (rand() % (2*CONSTRAINT_LOCATION_RANGE)) - CONSTRAINT_LOCATION_RANGE;
longi = (rand() % (2*CONSTRAINT_LOCATION_RANGE)) - CONSTRAINT_LOCATION_RANGE;
EncounterInfo enc = EncounterInfo(user1, user2, generate_random_hex_str(),
start, end, lat, longi);
printf("%s\n", enc.to_string().c_str());
encs.push_back(enc);
num_trace_users = user2 > user1 ? std::max(user2, num_trace_users)
: std::max(user1, num_trace_users);
}
return encs;
}
// returns undirected edges representing encounters between users // create chains of length CHAIN_LEN from SENDER, where each level has a fanout of FANOUT
// creates chains of length CHAIN_LEN from SENDER, where each level has a fanout of FANOUT struct UserBFSPair{
std::vector<EncounterInfo> generate_encounters() { int user;
int level;
UserBFSPair(int user, int level) : user(user), level(level) {}
};
std::vector<EncounterInfo> generate_synthesized_encounters() {
std::vector<EncounterInfo> encs; std::vector<EncounterInfo> encs;
std::queue<UserBFSPair> usersToProcess; std::queue<UserBFSPair> usersToProcess;
usersToProcess.push(UserBFSPair(user_index, 0)); usersToProcess.push(UserBFSPair(user_index, 0));
...@@ -132,7 +158,7 @@ std::vector<EncounterInfo> generate_encounters() { ...@@ -132,7 +158,7 @@ std::vector<EncounterInfo> generate_encounters() {
printf("%s\n", enc.to_string().c_str()); printf("%s\n", enc.to_string().c_str());
encs.push_back(enc); encs.push_back(enc);
} }
return encs; return encs;
} }
void insert_auths(std::vector<EncounterInfo>& encs) void insert_auths(std::vector<EncounterInfo>& encs)
...@@ -143,8 +169,9 @@ void insert_auths(std::vector<EncounterInfo>& encs) ...@@ -143,8 +169,9 @@ void insert_auths(std::vector<EncounterInfo>& encs)
for (int i = 0; i <= user_index; i++) { for (int i = 0; i <= user_index; i++) {
snprintf(buffer, sizeof(buffer), "%dAUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1MzgzfQ.qOfRCnuO0wn6ntBMkCRgcKYzd0Ymzn5a6Tm56Wc5nlI\r\n", i); snprintf(buffer, sizeof(buffer), "%dAUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1MzgzfQ.qOfRCnuO0wn6ntBMkCRgcKYzd0Ymzn5a6Tm56Wc5nlI\r\n", i);
myfile << buffer; myfile << buffer;
//printf("Return: %d\n", call_client_with_message(buffer)); #if USENETWORK
//std::this_thread::sleep_for (std::chrono::milliseconds(250)); printf("Return: %d\n", call_client_with_message(buffer));
#endif
} }
myfile.close(); myfile.close();
} }
...@@ -186,27 +213,27 @@ void insert_encs(std::vector<EncounterInfo>& encs) ...@@ -186,27 +213,27 @@ void insert_encs(std::vector<EncounterInfo>& encs)
snprintf(buffer, sizeof(buffer), "%dENCDELIMITER%sENCDELIMITER%s\r\n", snprintf(buffer, sizeof(buffer), "%dENCDELIMITER%sENCDELIMITER%s\r\n",
i, encountersStr.c_str(), locationsStr.c_str()); i, encountersStr.c_str(), locationsStr.c_str());
myfile << buffer; myfile << buffer;
//printf("Return: %d\n", call_client_with_message(buffer)); #if USENETWORK
//std::this_thread::sleep_for (std::chrono::milliseconds(250)); printf("Return: %d\n", call_client_with_message(buffer));
#endif
} }
myfile.close(); myfile.close();
} }
void query_constraint() { void query_constraint() {
char buffer[1000]; char buffer[1000];
// always call from user 0 (the sender) #if USETRACEDATA
// all query // all query
/*snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
"%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\ "%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\
"MESSAGEDELIMITER%dMESSAGEDELIMITER"\ "MESSAGEDELIMITER%dMESSAGEDELIMITER"\
"ALLMESSAGEDELIMITER%s\r\n", "ALLMESSAGEDELIMITER%s\r\n",
0, CHAIN_LEN, FANOUT, INT_MAX, "False", 0, "hello world"); rand() % num_trace_users, CHAIN_LEN, FANOUT, INT_MAX, "False", 0, "hello world");
printf("Query: %s\n", buffer); printf("Query: %s\n", buffer);
call_client_with_message(buffer);*/ call_client_with_message(buffer);
#else
// non-proj traj query
#if USEST #if USEST
// always call from user 0 (the sender)
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
"%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\ "%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\
"MESSAGEDELIMITER%dMESSAGEDELIMITER"\ "MESSAGEDELIMITER%dMESSAGEDELIMITER"\
...@@ -225,10 +252,15 @@ void query_constraint() { ...@@ -225,10 +252,15 @@ void query_constraint() {
printf("Query: %s\n", buffer); printf("Query: %s\n", buffer);
call_client_with_message(buffer); call_client_with_message(buffer);
#endif #endif
#endif // USETRACEDATA
} }
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
std::vector<EncounterInfo> encs = generate_encounters(); #if !USETRACEDATA
std::vector<EncounterInfo> encs = generate_synthesized_encounters();
#else
std::vector<EncounterInfo> encs = generate_trace_encounters();
#endif
insert_auths(encs); insert_auths(encs);
insert_encs(encs); insert_encs(encs);
query_constraint(); query_constraint();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment