-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexchange.h
50 lines (47 loc) · 1.26 KB
/
exchange.h
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
//
// Created by fangzhuhe on 2020/10/16.
//
#pragma once
#ifndef EXCHANGE_EXCHANGE_H
#define EXCHANGE_EXCHANGE_H
#define LIMIT 1000000000
#define MOD_LIMIT 1000
#define CHUNK_NUM 10240
#define THREAD_NUM 4
#define MSG_SIZE 4*1024*1024
#define PER_MSG_SIZE 1*1024*1024
#include <string>
#include <grpcpp/grpcpp.h>
#include <thread>
#include <stdlib.h>
#include <iostream>
#include "exchange.grpc.pb.h"
using exchange::ReqChunk;
struct ServerAddr{
std::string ip;
std::string port;
}addr[100];
ReqChunk* GenChunk(uint64_t size) {
ReqChunk* chk = new ReqChunk;
char* dataChunk = new char[PER_MSG_SIZE];
chk->set_data(dataChunk,PER_MSG_SIZE);
chk->set_size(PER_MSG_SIZE);
return chk;
}
ReqChunk** GenChunkList(uint64_t size) {
ReqChunk **chk_list = new ReqChunk*[size];
uint64_t msg_size = 0;
for (auto i = 0; i < size; ++i) {
ReqChunk *chk = new ReqChunk;
msg_size = MSG_SIZE + PER_MSG_SIZE + std::abs(rand()) % MSG_SIZE;
char *dataChunk = (char*)malloc(msg_size);
memset(dataChunk,0,msg_size);
memset(dataChunk,1,msg_size-i-1);
chk->set_data(dataChunk, msg_size);
chk->set_size(msg_size);
chk_list[i] = chk;
}
std::cout<<"generate chunk size= "<< size << std::endl;
return chk_list;
}
#endif //EXCHANGE_EXCHANGE_H