-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
84 lines (71 loc) · 2.68 KB
/
main.cpp
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
#include <iostream>
#include <thread>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <cpr/cpr.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/range/irange.hpp>
// A lot of the following will be removed with a config file or passed in from
// the command line ultimately
static const int num_threads = 50;
const char* size = "10240";
const char* host = "myhost.mydomain.com";
const char* port = "8080";
const char* account = "myaccount";
const char* user = "myusername";
const char* password = "mypassword";
const char* container = "mycontainer";
std::vector<char> ipayload;
auto credentials = std::string(account) + ":" + std::string(user);
auto url = std::string(host) + ":" + std::string(port) + "/auth/v1.0";
std::string ihexbyte() {
std::random_device r;
std::uniform_int_distribution<int> dist(0,255);
std::stringstream ss;
ss << std::hex << std::setfill('0') << std::setw(2);
ss << dist(r);
return ss.str();
}
void iwork() {
auto r = cpr::Get(cpr::Url{url},
cpr::Header{{"X-Storage-User", credentials},
{"X-Storage-Pass", password}});
auto auth_token = r.header["X-Auth-Token"];
while(true)
{
std::stringstream ssmd5;
std::generate_n(std::ostream_iterator<std::string>(ssmd5), 16, ihexbyte);
std::string sr1(ihexbyte());
std::string sr2(ihexbyte());
auto nuuid = boost::uuids::random_generator()();
std::stringstream path;
path << host << ":" << port << "/v1/AUTH_" << account << "/" << container
<< "/" << sr1 << "/" << sr2 << "/" << boost::uuids::to_string(nuuid)
<< "/" << ssmd5.str() << ".dat";
auto rtoo = cpr::Put(cpr::Url{path.str()},
cpr::Header{{"X-Auth-Token", auth_token}, {"Content-Length", size}},
cpr::Body{&ipayload[0], boost::lexical_cast<size_t>(size)});
std::cout << rtoo.url << std::endl;
std::cout << rtoo.status_code << std::endl;
for(auto iiter : rtoo.header)
std::cout << iiter.first << ": " << iiter.second << std::endl;
std::cout << std::endl;
}
}
int main(int argc, char** argv) {
ipayload.resize(boost::lexical_cast<size_t>(size));
std::ifstream urandom("/dev/urandom", std::ios::in|std::ios::binary);
urandom.read(&ipayload.front(), boost::lexical_cast<size_t>(size));
urandom.close();
std::vector<std::thread> threads;
for (auto i : boost::irange(0, num_threads))
threads.push_back(std::thread(iwork));
for(auto& thread : threads)
thread.join();
return 0;
}