|
@@ -18,11 +18,11 @@ extern "C" {
|
|
|
#include <vector>
|
|
#include <vector>
|
|
|
#include <set>
|
|
#include <set>
|
|
|
#include <map>
|
|
#include <map>
|
|
|
-#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "evutils.h"
|
|
#include "evutils.h"
|
|
|
#include "subproblem.h"
|
|
#include "subproblem.h"
|
|
|
|
|
+#include "controller.h"
|
|
|
|
|
|
|
|
NTL_CLIENT
|
|
NTL_CLIENT
|
|
|
|
|
|
|
@@ -33,7 +33,7 @@ struct SubproblemProgress;
|
|
|
typedef std::set<struct bufferevent *> BESet;
|
|
typedef std::set<struct bufferevent *> BESet;
|
|
|
typedef std::map<struct bufferevent *, SubproblemProgress *> BEMap;
|
|
typedef std::map<struct bufferevent *, SubproblemProgress *> BEMap;
|
|
|
|
|
|
|
|
-void besetdump(const BESet &bes, ostream &os)
|
|
|
|
|
|
|
+static void besetdump(const BESet &bes, ostream &os)
|
|
|
{
|
|
{
|
|
|
BESet::const_iterator besit;
|
|
BESet::const_iterator besit;
|
|
|
|
|
|
|
@@ -44,7 +44,7 @@ void besetdump(const BESet &bes, ostream &os)
|
|
|
os << dec << "\n";
|
|
os << dec << "\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void besetfree(BESet &bes)
|
|
|
|
|
|
|
+static void besetfree(BESet &bes)
|
|
|
{
|
|
{
|
|
|
BESet::iterator besit;
|
|
BESet::iterator besit;
|
|
|
|
|
|
|
@@ -55,7 +55,7 @@ void besetfree(BESet &bes)
|
|
|
bes.clear();
|
|
bes.clear();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void bemapdump(const BEMap &bem, ostream &os)
|
|
|
|
|
|
|
+static void bemapdump(const BEMap &bem, ostream &os)
|
|
|
{
|
|
{
|
|
|
BEMap::const_iterator bemit;
|
|
BEMap::const_iterator bemit;
|
|
|
|
|
|
|
@@ -66,7 +66,7 @@ void bemapdump(const BEMap &bem, ostream &os)
|
|
|
os << dec << "\n";
|
|
os << dec << "\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void bemapfree(BEMap &bem)
|
|
|
|
|
|
|
+static void bemapfree(BEMap &bem)
|
|
|
{
|
|
{
|
|
|
BEMap::iterator bemit;
|
|
BEMap::iterator bemit;
|
|
|
|
|
|
|
@@ -100,7 +100,7 @@ struct FactorDecomp {
|
|
|
vec_ZZ fvec;
|
|
vec_ZZ fvec;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-void vsppdump(const vector<SubproblemProgress> &spv, ostream &os);
|
|
|
|
|
|
|
+static void vsppdump(const vector<SubproblemProgress> &spv, ostream &os);
|
|
|
|
|
|
|
|
static struct ControllerState {
|
|
static struct ControllerState {
|
|
|
ZZ rho;
|
|
ZZ rho;
|
|
@@ -162,7 +162,7 @@ struct IPPort {
|
|
|
|
|
|
|
|
typedef vector<IPPort> IPPortSet;
|
|
typedef vector<IPPort> IPPortSet;
|
|
|
|
|
|
|
|
-void ipportsetdump(const IPPortSet &ipps, ostream &os)
|
|
|
|
|
|
|
+static void ipportsetdump(const IPPortSet &ipps, ostream &os)
|
|
|
{
|
|
{
|
|
|
IPPortSet::const_iterator ippsit;
|
|
IPPortSet::const_iterator ippsit;
|
|
|
|
|
|
|
@@ -256,7 +256,7 @@ struct SubproblemProgress : Subproblem {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Dump the state for debug purposes
|
|
// Dump the state for debug purposes
|
|
|
-void vsppdump(const vector<SubproblemProgress> &spv, ostream &os)
|
|
|
|
|
|
|
+static void vsppdump(const vector<SubproblemProgress> &spv, ostream &os)
|
|
|
{
|
|
{
|
|
|
vector<SubproblemProgress>::const_iterator spiter;
|
|
vector<SubproblemProgress>::const_iterator spiter;
|
|
|
int count = 0;
|
|
int count = 0;
|
|
@@ -738,14 +738,32 @@ static void controller_accept_cb(struct evconnlistener *listener,
|
|
|
// Create a new controller socket. bindport is the port to bind to (in
|
|
// Create a new controller socket. bindport is the port to bind to (in
|
|
|
// host byte order), or 0 if any port will do. ip and boundport are set
|
|
// host byte order), or 0 if any port will do. ip and boundport are set
|
|
|
// to the IP and port of the socket, in network byte order.
|
|
// to the IP and port of the socket, in network byte order.
|
|
|
-struct evconnlistener *controller_create(struct event_base *evbase,
|
|
|
|
|
|
|
+static struct evconnlistener *controller_create(struct event_base *evbase,
|
|
|
unsigned short bindport, unsigned int *ip, unsigned short *boundport)
|
|
unsigned short bindport, unsigned int *ip, unsigned short *boundport)
|
|
|
{
|
|
{
|
|
|
return listener_create(evbase, bindport, controller_accept_cb, NULL,
|
|
return listener_create(evbase, bindport, controller_accept_cb, NULL,
|
|
|
ip, boundport, false);
|
|
ip, boundport, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int main(int argc, char **argv)
|
|
|
|
|
|
|
+// Read the modulus (and the factorization of the modulus and its
|
|
|
|
|
+// totient) from the given file. "-" means cin. Returns true if
|
|
|
|
|
+// successful.
|
|
|
|
|
+static bool read_modulus(const char *filename)
|
|
|
|
|
+{
|
|
|
|
|
+ if (strcmp(filename, "-")) {
|
|
|
|
|
+ ifstream ins(filename);
|
|
|
|
|
+ if (!ins.good()) return false;
|
|
|
|
|
+ ins >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
|
|
+ ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
|
|
+ ins.close();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cin >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
|
|
+ ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int controller_main(const char *modulus_file, unsigned short bindport)
|
|
|
{
|
|
{
|
|
|
// Initialize the prng with some randomness from the kernel
|
|
// Initialize the prng with some randomness from the kernel
|
|
|
unsigned char randbuf[1024];
|
|
unsigned char randbuf[1024];
|
|
@@ -755,14 +773,11 @@ int main(int argc, char **argv)
|
|
|
ZZ randzz = ZZFromBytes(randbuf, sizeof(randbuf));
|
|
ZZ randzz = ZZFromBytes(randbuf, sizeof(randbuf));
|
|
|
SetSeed(randzz);
|
|
SetSeed(randzz);
|
|
|
|
|
|
|
|
- // Read the modulus and the factorization of its totient from cin
|
|
|
|
|
- cin >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
|
|
- ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
|
|
-
|
|
|
|
|
- unsigned short bindport = 0;
|
|
|
|
|
-
|
|
|
|
|
- if (argc > 1) {
|
|
|
|
|
- bindport = strtoul(argv[1], NULL, 10);
|
|
|
|
|
|
|
+ // Read the modulus and the factorization of its totient from the
|
|
|
|
|
+ // specified file
|
|
|
|
|
+ if (!read_modulus(modulus_file)) {
|
|
|
|
|
+ cerr << "Unable to read file " << modulus_file << "\n";
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
struct event_base *evbase = event_base_new();
|
|
struct event_base *evbase = event_base_new();
|