-
Notifications
You must be signed in to change notification settings - Fork 22
/
LT_code.h
65 lines (63 loc) · 2.09 KB
/
LT_code.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef LT_CODE_H
#define LT_CODE_H
#include<iostream>
#include<fstream>
#include<sys/stat.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
using namespace std;
typedef char* (*send_callback_fun)(char*,int);
class LT_code
{
public:
LT_code(const char* filename,double redundancy,send_callback_fun send):
_filename(filename),_buf(NULL),_redundancy(redundancy),_send_buf(NULL),_send(send),
_matrix_message(NULL),_matrix_message_row(0),
_H(NULL),
_matrix_encode(NULL),_matrix_encode_row(0),_matrix_dgree_distribution(NULL),
_matrix_H_decode(NULL),_matrix_message_decode(NULL){};
~LT_code();
//process fun
void LT_XOR(int* arr1,int* arr2,int len,int* result);
void LT_XOR(char* arr1,char* arr2,int len,char* result);
//sender
//read file record as binary
void ReadFile();
int get_filesize();
void encodeAndsend();
void init_sender();
int* robust_solition(int packet_num,double redundancy);
//receiver
void init_receiver(int row_max,int col_H_max,int col_message_max);
int receiveAndDecode(int row_max,char* buf,int& current_session_num,int& insert_index);
int Gussian_decode(int row_max,int col_H_max,int col_message_max);
int find_rank(int rank_max);
void WriteFile(const char* filename,int line_num);
protected:
private:
//sender
const char* _filename;
char* _buf;
double _redundancy;
char* _send_buf;
send_callback_fun _send;
//message
char** _matrix_message;
int _matrix_message_row;
//H
int** _H;
//encode
char** _matrix_encode;
int _matrix_encode_row;//matrix_row is the number of packages generated
int* _matrix_dgree_distribution;
//receiver
int** _matrix_H_decode;
char** _matrix_message_decode;
//constraint of sender and receiver
static const int _session_num_len = 4; //the first 4 byte of the package indicate the session num
static const int _packet_encode_num_len = 4; //the second 4 byte of the package indicate the num of of packages involved in mixing
static const int _matrix_encode_col = 1000;// this define that the data of one package is 1KB(Type char data requires 1 bytes)
};
#endif // LT_CODE_H