qsieve

qsieve Mercurial Source Tree


Root/src/transfer-client.cc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*! @file
 * @brief
 * a small program to transfer sieved relations to the server
 *
 * If the sieving is done offline by a file-client, the sieved relations
 * are stored in files. These data need to be transmitted to the server
 * somehow. This is done by the transfer-client, which is implemented here.
 *
 */
 
 
#include <cstdlib>
#include "unix_buffer.H"
#include <fstream>
#include <string>
#include "qsieve-fwd.H" // for server port
 
extern "C"
{
 #include <getopt.h>
}
 
using namespace std;
 
const char* const option_string = "+hgpvi:f:";
static const struct option long_options[] =
{
  { "help", 0, 0, 'h' },
  { "get", 0, 0, 'g' },
  { "put", 0, 0, 'p' },
  { "verbose", 0, 0, 'v' },
  { "interval", 1, 0, 'i' },
  { "file", 1, 0, 'f' },
  { 0, 0, 0, 0 }
}; // refer "man 3 getopt" for this struct
 
void usage(void)
{
  cout << "usage: transfer-client [-h] [-v] [-g]|-p [-i interval] [-f file] <server>" << endl;
  cout << " -h, --help     this text" << endl;
  cout << " -g, --get      get-mode for fetching of sieve parameters from server" << endl;
  cout << " -p, --put      put-mode for sending relations to server" << endl;
  cout << " -v, --verbose  be verbose" << endl;
  cout << " -i, --interval <interval>" << endl;
  cout << "                number of polynomial intervals to fetch (default:25000)" << endl;
  cout << " -f, --file <file>" << endl;
  cout << "                file to save transmitted data (default:qsieve-fc.param)" << endl;
}
 
int main(const int argc, char* const argv[])
{
  int polynome = 25000;
  const char *file = NULL;
  bool get = true;
  bool option = false;
  bool help = false;
  bool verbose = false;
  string s;
  int i, option_index;
  // check for parameters ;-)
  while ((i=getopt_long(argc,argv,option_string,long_options,&option_index))!=-1)
    {
      switch (i)
    {
    case 'g':
      if (option && !get)
        {
          cerr << "error: -f und -p are mutual exclusive!" << endl;
          exit(1);
        }
      option = get = true;
      break;
    case 'p':
      if (option && get)
        {
          cerr << "error: -f und -p are mutual exclusive!" << endl;
          exit(1);
        }
      option = true;
      get = false;
      break;
    case 'f':
      if (file != NULL)
        {
          cerr << "error: -f must be specified at most once!" << endl;
          exit(1);
        }
      file = optarg;
      break;
    case 'h':
      help = true;
      usage();
      break;
    case 'i':
      polynome = atoi (optarg);
      break;
    case 'v':
      verbose = true;
      break;
    default:
      usage();
      exit(1);
    }
    }
   
  if (file == NULL)
    {
      if (get)
    file = "qsieve-fc.param";
      else
    file = "qsieve-fc.param.out";
    }
  if (optind+1 != argc) {
    if (help) exit(0);
    cerr << "wrong number of parameters!" << endl;
    exit(1);
  }
  const string server = argv[optind];
   
  if(get)
    {
      char c;
      ofstream file_stream(file, ios::out|ios::trunc);
      {
    unix_io_stream communication_stream(server, server_port);
    communication_stream << QsieveLogon << endl;
    if (communication_stream.eof())
         {
           cerr << "Unexpected EOF!" << endl;
           exit(1);
         }
        else
         {
           communication_stream.get(c);
           if (c=='-')
            {
             cout.put(c);
             while (!communication_stream.eof())
          {
           communication_stream.get(c);
               cout.put(c);
          }
             exit(1);
            }
           else communication_stream.putback(c);
         }
    while (!communication_stream.eof())
      {
        communication_stream.get(c);
        file_stream.put(c);
            if (verbose) cout.put(c);
      }
      }
      {
    unix_io_stream communication_stream(server, server_port);
    communication_stream << "DynamicFactors?_ab_fpos 0" << endl;
    while (!communication_stream.eof())
      {
        communication_stream.get(c);
        file_stream.put(c);
            if (verbose) cout.put(c);
      }
      }
      {
    unix_io_stream communication_stream(server, server_port);
    communication_stream << "Polynom? " << polynome << endl;
    while (!communication_stream.eof())
      {
        communication_stream.get(c);
        file_stream.put(c);
            if (verbose) cout.put(c);
      }
      }
    }
  else
    {
      char c;
      ifstream file_stream(file, ios::in);
      if (!file_stream)
       {
         cerr << "Unable to open \"" << file << "\"" << endl;
         exit(1);
       }
      char kN_str[1024]; // "1024 bytes should be enough for everyone"
      file_stream.getline(kN_str,sizeof(kN_str),'\n');
 
      char line[1024];
      while (file_stream.peek()!=EOF)
    {
      int count = 1000+1; // transmit maximal count-1 relations per block
          unix_io_stream communication_stream(server, server_port);
 
          communication_stream << "NewRelations! " << kN_str << endl;
          // verify, that relations belong to our factorization
          communication_stream >> s;
          if (s!="proceed")
           {
             cerr << "Oops! Server will not accept my relations: " << endl;
             cerr << s << endl;
             exit(1);
           }
 
          while (file_stream.peek()!=EOF && --count)
      {
            communication_stream << "RL "; // new token for "Relation! "
            while (file_stream.peek()!='\n')
             {
               file_stream.get(line,sizeof(line),'\n');
               communication_stream << line;
               if (verbose) cout << line;
             }
            file_stream.get(c);
            communication_stream << endl;
            if (verbose) cout << endl;
          }
          communication_stream << "Relationsblock_Ende " << flush;
      communication_stream >> s;
      if (s!="empfangen.")
            cerr << "transmitted relations were not acknowledged by server!" << endl;
          if (s=="ignoriert!")
            {
              cerr << "Oops! - Relations were ignored by server!" << endl;
              cerr << "Please check, whether transmitted data in "
                   << "\"" << file << "\"" << endl
                   << "really belong to current server session!"
                   << endl;
              exit(1);
            }
    }
    }
}
Source at commit b0b32840dfbc created 11 years 9 months ago.
By Nathan Adams, compile issues

Archive Download this file

Branches

Tags

Page rendered in 0.75768s using 11 queries.