|
@@ -45,7 +45,9 @@ static void dpnode_event_cb(struct bufferevent *bev, short events,
|
|
|
void *ctx)
|
|
void *ctx)
|
|
|
{
|
|
{
|
|
|
if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
|
|
if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
|
|
|
- fprintf(stderr, "Closing connection\n");
|
|
|
|
|
|
|
+ fprintf(stderr, "Closing connection (%s%s)\n",
|
|
|
|
|
+ (events & BEV_EVENT_EOF) ? "EOF" : "",
|
|
|
|
|
+ (events & BEV_EVENT_ERROR) ? "ERR" : "");
|
|
|
DPNodeConnInfo *info = (DPNodeConnInfo*)ctx;
|
|
DPNodeConnInfo *info = (DPNodeConnInfo*)ctx;
|
|
|
delete info;
|
|
delete info;
|
|
|
bufferevent_free(bev);
|
|
bufferevent_free(bev);
|
|
@@ -63,6 +65,7 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
|
|
|
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));
|
|
|
|
|
+ if (dpctrlstate.current_problem == NULL) continue;
|
|
|
// The (WORDS+6) unsigned ints we read are:
|
|
// The (WORDS+6) unsigned ints we read are:
|
|
|
// - WORDS words for the value of the dp
|
|
// - WORDS words for the value of the dp
|
|
|
// - 3 words for a
|
|
// - 3 words for a
|
|
@@ -80,8 +83,8 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
|
|
|
if (!res.second) {
|
|
if (!res.second) {
|
|
|
const ZZ& order = dpctrlstate.current_problem->order;
|
|
const ZZ& order = dpctrlstate.current_problem->order;
|
|
|
// Collision!
|
|
// Collision!
|
|
|
- ZZ adiff = to_ZZ(res.first->second.first) - zz_a;
|
|
|
|
|
- ZZ bdiff = zz_b - to_ZZ(res.first->second.second);
|
|
|
|
|
|
|
+ ZZ adiff = res.first->second.first - zz_a;
|
|
|
|
|
+ ZZ bdiff = zz_b - res.first->second.second;
|
|
|
while (bdiff < 0) bdiff += order;
|
|
while (bdiff < 0) bdiff += order;
|
|
|
while (bdiff >= order) bdiff -= order;
|
|
while (bdiff >= order) bdiff -= order;
|
|
|
while (adiff < 0) adiff += order;
|
|
while (adiff < 0) adiff += order;
|
|
@@ -90,11 +93,15 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
|
|
|
if (InvModStatus(binv, bdiff, order) == 0) {
|
|
if (InvModStatus(binv, bdiff, order) == 0) {
|
|
|
ZZ expon = MulMod(binv, adiff, order);
|
|
ZZ expon = MulMod(binv, adiff, order);
|
|
|
cerr << "Collision after " << dpctrlstate.numdps << " DPs\n";
|
|
cerr << "Collision after " << dpctrlstate.numdps << " DPs\n";
|
|
|
- unsigned char exponbytes[3*sizeof(unsigned int)];
|
|
|
|
|
- BytesFromZZ(exponbytes, expon, 3*sizeof(unsigned int));
|
|
|
|
|
|
|
+ unsigned char exponbytes[3+3*sizeof(unsigned int)];
|
|
|
|
|
+ exponbytes[0] = 'E';
|
|
|
|
|
+ memmove(exponbytes+1,
|
|
|
|
|
+ &(dpctrlstate.current_problem->problemid), 2);
|
|
|
|
|
+ BytesFromZZ(exponbytes+3, expon, 3*sizeof(unsigned int));
|
|
|
bufferevent_write(dpctrlstate.controller_bev, exponbytes,
|
|
bufferevent_write(dpctrlstate.controller_bev, exponbytes,
|
|
|
- 3*sizeof(unsigned int));
|
|
|
|
|
|
|
+ 3+3*sizeof(unsigned int));
|
|
|
stop_problem();
|
|
stop_problem();
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
++dpctrlstate.numdps;
|
|
++dpctrlstate.numdps;
|
|
@@ -142,6 +149,7 @@ struct DPControllerConnInfo {
|
|
|
static void stop_problem(void)
|
|
static void stop_problem(void)
|
|
|
{
|
|
{
|
|
|
if (dpctrlstate.current_problem) {
|
|
if (dpctrlstate.current_problem) {
|
|
|
|
|
+ delete dpctrlstate.current_problem;
|
|
|
dpctrlstate.current_problem = NULL;
|
|
dpctrlstate.current_problem = NULL;
|
|
|
}
|
|
}
|
|
|
if (dpctrlstate.listener) {
|
|
if (dpctrlstate.listener) {
|