forked from ali-z-can/SummerSeedProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions2.c
178 lines (99 loc) · 4.21 KB
/
functions2.c
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
//___________manager_______________________
char* retrievePast(file* fp)
//yarıda kalan dosyaların verilerinin getirilmesi
//return dosya adı + geçmiş buffer
void printScreen(char* ch)
//ekrana sistem durumunu bastır
int createReciever(struct reciever** clientList, char* clientName)
//alınacak her yeni dosya için client structu oluşturup listeye ekler
int createPublisher(struct Publisher** publisherList, char* publisherName)
//yollanıcak her yeni dosya için publisher structu oluşturup listeye ekler
int listen(char* fileName)
//listens for user input and network requests
int deleteClient(struct Client** clientList, char* clientName)
int deletePublisher(struct Publisher** publisherList, char* publisherName)
int notifyUserNoPublisher(char* fileName)
//notify user that no one sending packets from specific file
//__________reciever______________
int createSocket(struct sockaddr_in sockaddr)
int closeSocket(struct sockaddr_in sockaddr)
char* requestHash(char* fileName, int* size,file* trustedSourceFile)
//requests hash code from trusted source
//return hash code and file size
int evaluatePublisherData(int hashFromTS, struct publisher* publisherList)
//send hashcode from trusted source to network
//return # of publisher and their info
partition(int size, int numberOfPublishers, struct publisher* publisherList)
//partition the file in any state of downloading
//called every 3 mins to refresh network info
askForPartitions(struct publisher publisherList)
//tell publisher their partitions and request them
int evaluateHash(char* hashFromTS, struct publisher pd)
//calculate if incoming data is correct
//return 0 if ok 1 if not
void pause(struct publisher* publisherList)
//stops recieving and notifies publishers
void sendBufferToPlayer(no fooking idea)
//indirme devam ederken oynatma aksiyonu
int downloadFinishSignal()
//notifies manager and publishersthat the download is complete
int noPublishers()
//notifies manager that no publisher left in network
int addToBlackList(file* blackList, struct publisher* publisher)
//if smo sent a invalid packet take em to blacklist
void write_to_file(int *sizes, char **fragments, char *fname, int fragsize)
int addPublisher(struct publisherData* publisherList)
int removePublisher(struct publisherData* publisherList)
int sendHashToLocalPublisher(char* finalHash)
//sent hashes retrieved from another source to local publisher
//__________publisher______________
int createSocket(struct sockaddr_in sockaddr)
int closeSocket(struct sockaddr_in sockaddr)
int check_if_file_exists(char* hash, file* fp);
//checks local shared folder for file requested
int validate_if_file_exists(int result_of_checking,struct sockaddr_in ip,struct fileStatus* fs);
//sends if file exist and if it is the status of file(full or still downloading if downloading existing parts)
int calculate_hash(const file* fp, int numberOfFragments, struct hashPacket* hp);
//takes numberOfFragment and returns the hashPacket
int calculateHashFileNotReady(const file* fp, char* hash)
//if file still downloading sends the required hashs to reciever
int requestHashFromLocalReciever(char* finalHash)
//for an unfinished file asks local reciever the hashes retrived from remote publisher
int getPartitionInfo()
//recieve packet numbers to be sent
int send_hash(char* hash);
//send hash information to reciever
int send(char* buf)
//send actual data packets
int finished()
//after reciever validates downloading complete notify manager and close publisher
//_________structs____________
struct Reciever{
struct Publisher* publisherList;//for reciever
char* name;//for publisher
int dataSize;//for reciever
struct fileStatus;
}
struct Publisher{
char* name;
struct sockaddr_in;
uint16_t startingIndex;
uint16_t finishIndex;
char** md5Array;
}
struct fileStatus{
int* dataStartingIndexes;
int* dataFinishedIndexes;
int finished;
}
packets:
struct reciever_to_publisher_packet_hdr {
uint16_t startingIndex;
uint16_t finsishIndex;
char isFinished;
uint16_t fragSize;
}__attribute__((packed));
struct publisher_to_reciever_packet_hdr{
uint16_t frindex;
char packetType;
}__attribute__((packed))