Commit 75d95625 authored by Lily Tsai's avatar Lily Tsai
Browse files

Merge branch 'master' of gitlab.mpi-sws.org:encounters/ebc

parents 6708d727 cb3d295e
#include <SSLClient.h>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#define CONSTRAINT_TIME_START 0
#define CONSTRAINT_TIME_END 200
#define CONSTRAINT_LOCATION_RANGE 100 // boxes centered around 0
#define NUM_CONSTRAINT_BOXES 1
const char* queries[] = {
"user1MESSAGEDELIMITER1MESSAGEDELIMITER10000MESSAGEDELIMITERhello worldMESSAGEDELIMITERSELECT DBEncounterEntries.userHandle, quote(DBEncounterEntries.ss), DBEncounterEntries.myTopicHandle, DBLocation.loctime FROM DBEncounterEntries INNER JOIN DBLocation ON (DBLocation.userHandle = DBEncounterEntries.userHandle) AND (DBLocation.loctime BETWEEN DBEncounterEntries.timestart AND DBEncounterEntries.timeend) OR (DBEncounterEntries.timeend = -1 AND DBLocation.loctime > DBEncounterEntries.timestart) WHERE (DBEncounterEntries.ss IS NOT NULL) ORDER BY DBEncounterEntries.ss, DBEncounterEntries.userHandle, DBLocation.loctime\r\n"
#define CHAIN_LEN 2
#define FANOUT 5
#define PROPORTION_SATISFY 0.5
int user_index = 0;
struct EncounterInfo {
int user1;
int user2;
std::string ss;
long start;
long end;
double lat;
double longi;
EncounterInfo(
int user1,int user2, std::string ss,
long timeStart,long timeEnd,
double lat, double longi)
:
user1(user1), user2(user2),
ss(ss), start(timeStart), end(timeEnd),
lat(lat), longi(longi) {}
std::string to_string() {
char buffer[1000];
snprintf(buffer, sizeof(buffer), "(%d, %d) [%ld-%ld] [%f-%f] %s",
user1, user2, start, end, lat, longi, ss.c_str());
return std::string(buffer);
}
};
const char* auths[] = {
"user1AUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzl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IUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1MzgzfQ.qOfRCnuO0wn6ntBMkCRgcKYzd0Ymzn5a6Tm56Wc5nlI\r\n",
//"3i9HK1h5fX1AUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzaTlISzFoNWZYMVxuR29vZ2xlXG4xMDgzNTc1Nzc0MTQwODMzNzQyNjMiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1NjM0fQ.xHrEoOP85vIVYUbg_UYun8_avhKsf4M8jCJv4XswOuk\r\n"
struct UserBFSPair{
int user;
int level;
UserBFSPair(int user, int level) : user(user), level(level) {}
};
const char* data[]={
"user1ENCDELIMITER0,-1,95A8E2D4C36737CAA153763B0A826017C59D3FA97645AF1395B187DA,3hdNBottVUQENCDELIMITER49.2576955,7.0462818,1529671674184;49.2576955,7.0462818,1529671674193;49.2576955,7.0462818,1529671794666;49.2576955,7.0462818,1529671794674\r\n",
"user2ENCDELIMITER0,-1,95a8e2d4c36737caa153763b0a826017c59d3fa97645af1395b187da,2hdnbottvuq;0,-1,85A8E2D4C36737CAA153763B0A826017C59D3FA97645AF1395B187DA,3hdNBottVUQENCDELIMITER49.2576955,7.0462818,1529671674184;49.2576955,7.0462818,1529671674193;49.2576955,7.0462818,1529671794666;49.2576955,7.0462818,1529671794674\r\n",
"user3ENCDELIMITER0,-1,85A8E2D4C36737CAA153763B0A826017C59D3FA97645AF1395B187DA,2hdNBottVUQ;0,-1,75A8E2D4C36737CAA153763B0A826017C59D3FA97645AF1395B187DA,2hdNBottVUQENCDELIMITER49.2576955,7.0462818,1529671674184;49.2576955,7.0462818,1529671674193;49.2576955,7.0462818,1529671794666;49.2576955,7.0462818,1529671794674\r\n",
"user4ENCDELIMITER0,-1,75A8E2D4C36737CAA153763B0A826017C59D3FA97645AF1395B187DA,2hdNBottVUQENCDELIMITER49.2576955,7.0462818,1529671674184;49.2576955,7.0462818,1529671674193;49.2576955,7.0462818,1529671794666;49.2576955,7.0462818,1529671794674\r\n",
std::string generate_random_hex_str() {
char str[56 + 1];
for(int i = 0; i < 56; i++) {
sprintf(str + i, "%x", rand() % 16);
}
return std::string(str);
}
// 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() {
std::vector<EncounterInfo> encs;
std::queue<UserBFSPair> usersToProcess;
usersToProcess.push(UserBFSPair(user_index, 0));
int nextLevel;
long start, end, time1, time2;
double lat, longi;
while (!usersToProcess.empty()) {
UserBFSPair curUser = usersToProcess.front();
usersToProcess.pop();
printf("Processing %d at level %d\n", curUser.user, curUser.level);
if (curUser.level + 1 > CHAIN_LEN) {
continue;
}
else {
for (int i = 0; i < FANOUT; i++) {
usersToProcess.push(UserBFSPair(user_index+1, curUser.level + 1));
// generate random satisfying things
// so that this encounter is a "point" satisfying the constraint
time1 = rand() % (CONSTRAINT_TIME_END-CONSTRAINT_TIME_START);
time2 = rand() % (CONSTRAINT_TIME_END-CONSTRAINT_TIME_START);
start = (time1 > time2? time2 : time1) + CONSTRAINT_TIME_START;
end = (time1 > time2? time1 : time2) + CONSTRAINT_TIME_START;
lat = (rand() % (2*CONSTRAINT_LOCATION_RANGE)) - CONSTRAINT_LOCATION_RANGE;
longi = (rand() % (2*CONSTRAINT_LOCATION_RANGE)) - CONSTRAINT_LOCATION_RANGE;
EncounterInfo enc = EncounterInfo(curUser.user, ++user_index, generate_random_hex_str(),
start, end, lat, longi);
printf("%s\n", enc.to_string().c_str());
encs.push_back(enc);
}
}
}
// now generate encounters not satisfying the constraint by
// choosing random two users in the graph and adding an encounter
int num_satisfying_encounters = encs.size();
int total_encs = (int)((double)num_satisfying_encounters / (double)PROPORTION_SATISFY);
int user1, user2;
for (int num_encs = num_satisfying_encounters; num_encs < total_encs; num_encs++) {
user1 = rand() % user_index;
user2 = rand() % user_index;
while (user2 == user1) {
user2 = rand() % user_index;
}
// for right now, ensure that the time doesn't overlap (or else we get weird
// jumpy behavior)
time1 = rand() % (2*(CONSTRAINT_TIME_END-CONSTRAINT_TIME_START)) + CONSTRAINT_TIME_END;
time2 = rand() % 2*((CONSTRAINT_TIME_END-CONSTRAINT_TIME_START)) + CONSTRAINT_TIME_END;
start = (time1 > time2? time2 : time1) ;
end = (time1 > time2? time1 : time2);
// 50% of the time it will be out of the lat range
lat = (rand() % (4*CONSTRAINT_LOCATION_RANGE)) - CONSTRAINT_LOCATION_RANGE;
// 50% of the time it will be out of the longi range
longi = (rand() % (4*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);
}
return encs;
}
void insert_auths(std::vector<EncounterInfo>& encs)
{
char buffer[1000];
for (int i = 0; i <= user_index; i++) {
snprintf(buffer, sizeof(buffer), "%dAUTHDELIMITERSocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ1MDU1MzgzfQ.qOfRCnuO0wn6ntBMkCRgcKYzd0Ymzn5a6Tm56Wc5nlI\r\n", i);
printf("Return: %d\n", call_client_with_message(buffer));
}
}
struct LocationEntry {
double lat;
double longi;
LocationEntry() {}
LocationEntry(double lat, double longi)
: lat(lat), longi(longi) {}
};
void insert_encs(std::vector<EncounterInfo>& encs)
{
for (int i = 0; i <= user_index; i++) {
std::string encountersStr;
std::string locationsStr;
std::map<long, LocationEntry> locs;
for (auto enc : encs) {
if (enc.user1 == i || enc.user2 == i) {
char buffer[1000];
snprintf(buffer, sizeof(buffer), "%ld,%ld,%s,%s",
enc.start, enc.end, enc.ss.c_str(), "3he-1Q0OaOj;");
encountersStr += buffer;
locs[enc.start] = LocationEntry(enc.lat, enc.longi);
locs[enc.end] = LocationEntry(enc.lat, enc.longi);
}
}
for (auto const& loc : locs) {
char buffer[1000];
snprintf(buffer, sizeof(buffer), "%f,%f,%ld;",
loc.second.lat, loc.second.longi, loc.first);
locationsStr += buffer;
}
char buffer[encountersStr.length() + locationsStr.length() + 100];
snprintf(buffer, sizeof(buffer), "%dENCDELIMITER%sENCDELIMITER%s\r\n",
i, encountersStr.c_str(), locationsStr.c_str());
printf("Return: %d\n", call_client_with_message(buffer));
}
}
void query_constraint() {
char buffer[1000];
// always call from user 0 (the sender)
snprintf(buffer, sizeof(buffer),
"%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%dMESSAGEDELIMITER%s"\
"MESSAGEDELIMITER%dMESSAGEDELIMITER"\
"%dSPACETIME%dSPACETIME%dSPACETIME%dSPACETIME%dMESSAGEDELIMITER%s\r\n",
0, CHAIN_LEN, FANOUT, INT_MAX, "False", 0,
CONSTRAINT_TIME_START, CONSTRAINT_TIME_END, 0, 0, CONSTRAINT_LOCATION_RANGE, "hello world");
printf("Query: %s\n", buffer);
call_client_with_message(buffer);
}
int main(int argc, char* argv[]){
for (const char* auth : auths) {
printf("Return: %d\n", call_client_with_message(auth));
}
for (const char* datum : data) {
printf("Return: %d\n", call_client_with_message(datum));
}
for (const char* query : queries) {
printf("Return: %d\n", call_client_with_message(query));
}
std::vector<EncounterInfo> encs = generate_encounters();
insert_auths(encs);
insert_encs(encs);
query_constraint();
return 0;
}
......@@ -16,7 +16,7 @@ public abstract class EncounterQueryConstraint implements Serializable {
public final static String TRAJDELIMITER = "TRAJ";
public final static String ALLMARKER = "ALL";
public Long duration;
public Long duration = 0L;
private long receivedFromEncStartingTimeMs = -1;
public void setCausalityEncounterStartingTimeMs(long time) {
this.receivedFromEncStartingTimeMs = time;
......
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