|
@@ -9,12 +9,15 @@ extern "C" {
|
|
|
#include <arpa/inet.h>
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <set>
|
|
#include <set>
|
|
|
|
|
+#include <map>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "evutils.h"
|
|
#include "evutils.h"
|
|
|
#include "subproblem.h"
|
|
#include "subproblem.h"
|
|
|
|
|
|
|
|
|
|
+typedef map<std::string, pair<ZZ,ZZ> > DTable;
|
|
|
|
|
+
|
|
|
typedef enum {
|
|
typedef enum {
|
|
|
DPSTATE_START,
|
|
DPSTATE_START,
|
|
|
DPSTATE_END
|
|
DPSTATE_END
|
|
@@ -26,6 +29,16 @@ struct DPNodeConnInfo {
|
|
|
DPNodeConnInfo() : state(DPSTATE_START) {}
|
|
DPNodeConnInfo() : state(DPSTATE_START) {}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+static struct DPControllerState {
|
|
|
|
|
+ Subproblem *current_problem;
|
|
|
|
|
+ struct evconnlistener *listener;
|
|
|
|
|
+ std::set<struct bufferevent *> workers;
|
|
|
|
|
+ DTable table;
|
|
|
|
|
+ unsigned long long numdps;
|
|
|
|
|
+
|
|
|
|
|
+ DPControllerState() : current_problem(NULL), listener(NULL) {}
|
|
|
|
|
+} dpctrlstate;
|
|
|
|
|
+
|
|
|
static void dpnode_event_cb(struct bufferevent *bev, short events,
|
|
static void dpnode_event_cb(struct bufferevent *bev, short events,
|
|
|
void *ctx)
|
|
void *ctx)
|
|
|
{
|
|
{
|
|
@@ -41,13 +54,29 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
|
|
|
{
|
|
{
|
|
|
struct evbuffer *input = bufferevent_get_input(bev);
|
|
struct evbuffer *input = bufferevent_get_input(bev);
|
|
|
unsigned int dp[WORDS+6];
|
|
unsigned int dp[WORDS+6];
|
|
|
- int num_read = 0;
|
|
|
|
|
|
|
+ pair<DTable::iterator, bool> res;
|
|
|
|
|
|
|
|
while(1) {
|
|
while(1) {
|
|
|
size_t len = evbuffer_get_length(input);
|
|
size_t len = evbuffer_get_length(input);
|
|
|
if (len < ((WORDS+6)*sizeof(unsigned int))) break;
|
|
if (len < ((WORDS+6)*sizeof(unsigned int))) break;
|
|
|
bufferevent_read(bev, dp, (WORDS+6)*sizeof(unsigned int));
|
|
bufferevent_read(bev, dp, (WORDS+6)*sizeof(unsigned int));
|
|
|
- ++num_read;
|
|
|
|
|
|
|
+ // The (WORDS+6) unsigned ints we read are:
|
|
|
|
|
+ // - WORDS words for the value of the dp
|
|
|
|
|
+ // - 3 words for a
|
|
|
|
|
+ // - 3 words for b
|
|
|
|
|
+ ZZ zz_a, zz_b;
|
|
|
|
|
+ ZZFromBytes(zz_a, (const unsigned char *)(dp+WORDS),
|
|
|
|
|
+ 3*sizeof(unsigned int));
|
|
|
|
|
+ ZZFromBytes(zz_b, (const unsigned char *)(dp+WORDS+3),
|
|
|
|
|
+ 3*sizeof(unsigned int));
|
|
|
|
|
+ string x((const char *)(dp), WORDS*sizeof(unsigned int));
|
|
|
|
|
+ pair<ZZ,ZZ> ab(zz_a,zz_b);
|
|
|
|
|
+ res = dpctrlstate.table.insert(DTable::value_type(x,ab));
|
|
|
|
|
+ if (!res.second) {
|
|
|
|
|
+ // Collision!
|
|
|
|
|
+ cerr << "Collision!\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ ++dpctrlstate.numdps;
|
|
|
}
|
|
}
|
|
|
// cerr << num_read << " DPs read\n";
|
|
// cerr << num_read << " DPs read\n";
|
|
|
}
|
|
}
|
|
@@ -66,7 +95,7 @@ static void dpnode_accept_cb(struct evconnlistener *listener,
|
|
|
bufferevent_setcb(bev, dpnode_reader, NULL,
|
|
bufferevent_setcb(bev, dpnode_reader, NULL,
|
|
|
dpnode_event_cb, info);
|
|
dpnode_event_cb, info);
|
|
|
|
|
|
|
|
- bufferevent_enable(bev, EV_READ|EV_WRITE);
|
|
|
|
|
|
|
+ bufferevent_enable(bev, EV_READ);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Create a new DPnode socket. ip and boundport are set to the IP and
|
|
// Create a new DPnode socket. ip and boundport are set to the IP and
|
|
@@ -90,14 +119,6 @@ struct DPControllerConnInfo {
|
|
|
DPControllerConnInfo() : state(DPCCSTATE_AWAITCMD) {}
|
|
DPControllerConnInfo() : state(DPCCSTATE_AWAITCMD) {}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-static struct DPControllerState {
|
|
|
|
|
- Subproblem *current_problem;
|
|
|
|
|
- struct evconnlistener *listener;
|
|
|
|
|
- std::set<struct bufferevent *> workers;
|
|
|
|
|
-
|
|
|
|
|
- DPControllerState() : current_problem(NULL), listener(NULL) {}
|
|
|
|
|
-} dpctrlstate;
|
|
|
|
|
-
|
|
|
|
|
static void stop_problem(void)
|
|
static void stop_problem(void)
|
|
|
{
|
|
{
|
|
|
if (dpctrlstate.current_problem) {
|
|
if (dpctrlstate.current_problem) {
|
|
@@ -113,6 +134,8 @@ static void stop_problem(void)
|
|
|
bufferevent_free(*wit);
|
|
bufferevent_free(*wit);
|
|
|
}
|
|
}
|
|
|
dpctrlstate.workers.clear();
|
|
dpctrlstate.workers.clear();
|
|
|
|
|
+ dpctrlstate.table.clear();
|
|
|
|
|
+ dpctrlstate.numdps = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void start_problem(struct bufferevent *bev,
|
|
static void start_problem(struct bufferevent *bev,
|