Commit c795791f authored by LIly's avatar LIly
Browse files

draw from haggle traces works

parent c6d3a8e7
#include <SSLClient.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <chrono>
#include <thread>
#include <vector>
#include <queue>
#include <map>
......@@ -16,8 +15,12 @@
#define FANOUT 2
#define PROPORTION_SATISFY 1
#define USEST 1
#define USENETWORK 0
#define USETRACEDATA 1
#define TRACE_FILE "haggle_traces.csv"
int user_index = 0;
int num_trace_users = 0;
struct EncounterInfo {
int user1;
......@@ -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() {
char str[56 + 1];
for(int i = 0; i < 56; i++) {
......@@ -58,10 +55,39 @@ std::string generate_random_hex_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
// creates chains of length CHAIN_LEN from SENDER, where each level has a fanout of FANOUT
std::vector<EncounterInfo> generate_encounters() {
// create chains of length CHAIN_LEN from SENDER, where each level has a fanout of FANOUT
struct UserBFSPair{
int user;
int level;
UserBFSPair(int user, int level) : user(user), level(level) {}
};
std::vector<EncounterInfo> generate_synthesized_encounters() {
std::vector<EncounterInfo> encs;
std::queue<UserBFSPair> usersToProcess;
usersToProcess.push(UserBFSPair(user_index, 0));
......@@ -132,7 +158,7 @@ std::vector<EncounterInfo> generate_encounters() {
printf("%s\n", enc.to_string().c_str());
encs.push_back(enc);
}
return encs;
return encs;
}
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++) {
snprintf(buffer, sizeof(buffer), "%dAUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1MzgzfQ.qOfRCnuO0wn6ntBMkCRgcKYzd0Ymzn5a6Tm56Wc5nlI\r\n", i);
myfile << buffer;
//printf("Return: %d\n", call_client_with_message(buffer));
//std::this_thread::sleep_for (std::chrono::milliseconds(250));
#if USENETWORK
printf("Return: %d\n", call_client_with_message(buffer));
#endif
}
myfile.close();
}
......@@ -186,27 +213,27 @@ void insert_encs(std::vector<EncounterInfo>& encs)
snprintf(buffer, sizeof(buffer), "%dENCDELIMITER%sENCDELIMITER%s\r\n",
i, encountersStr.c_str(), locationsStr.c_str());
myfile << buffer;
//printf("Return: %d\n", call_client_with_message(buffer));
//std::this_thread::sleep_for (std::chrono::milliseconds(250));
#if USENETWORK
printf("Return: %d\n", call_client_with_message(buffer));
#endif
}
myfile.close();
}
void query_constraint() {
char buffer[1000];
// always call from user 0 (the sender)
#if USETRACEDATA
// all query
/*snprintf(buffer, sizeof(buffer),
snprintf(buffer, sizeof(buffer),
"%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\
"MESSAGEDELIMITER%dMESSAGEDELIMITER"\
"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);
call_client_with_message(buffer);*/
// non-proj traj query
call_client_with_message(buffer);
#else
#if USEST
// always call from user 0 (the sender)
snprintf(buffer, sizeof(buffer),
"%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\
"MESSAGEDELIMITER%dMESSAGEDELIMITER"\
......@@ -225,10 +252,15 @@ void query_constraint() {
printf("Query: %s\n", buffer);
call_client_with_message(buffer);
#endif
#endif // USETRACEDATA
}
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_encs(encs);
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