Revision 0457266a som/ChunkTrading/chunk_signalling.c
som/ChunkTrading/chunk_signalling.c | ||
---|---|---|
53 | 53 |
return 1; |
54 | 54 |
} |
55 | 55 |
|
56 |
int sendSignallingBIS(int type, const struct nodeID *to_id, const struct nodeID *owner_id, struct chunkID_set *cset, int max_deliver, int cb_size, int trans_id)
|
|
56 |
int sendSignalling(int type, const struct nodeID *to_id, const struct nodeID *owner_id, struct chunkID_set *cset, int max_deliver, int cb_size, int trans_id) |
|
57 | 57 |
{ |
58 | 58 |
int buff_len, meta_len, msg_len, ret; |
59 | 59 |
uint8_t *buff; |
... | ... | |
188 | 188 |
|
189 | 189 |
int offerChunks(const struct nodeID *to, struct chunkID_set *cset, int max_deliver, int trans_id) |
190 | 190 |
{ |
191 |
return sendSignallingBIS(MSG_SIG_OFF, to, NULL, cset, max_deliver, -1, trans_id);
|
|
191 |
return sendSignalling(MSG_SIG_OFF, to, NULL, cset, max_deliver, -1, trans_id); |
|
192 | 192 |
} |
193 |
/* |
|
194 |
int offerChunks(const struct nodeID *to, ChunkIDSet *cset, int cset_len, int max_deliver, int trans_id) { |
|
195 |
int buff_len; |
|
196 |
int res; |
|
197 |
uint8_t *buff; |
|
198 |
struct sig_nal *sigmex; |
|
199 |
sigmex = malloc(sizeof(struct sig_nal)); |
|
200 |
sigmex->type = MSG_SIG_OFF; |
|
201 |
sigmex->max_deliver = max_deliver; |
|
202 |
sigmex->trans_id = trans_id; |
|
203 |
fprintf(stdout, "SIG_HEADER: Type %d Tx %d PP %d\n", sigmex->type, sigmex->trans_id, sigmex->third_peer); |
|
204 |
buff_len = cset_len * 4 + 12 + sizeof(struct sig_nal); // Signaling type + set len |
|
205 |
buff = malloc(buff_len + 1); |
|
206 |
res = encodeChunkSignaling(cset, sigmex, sizeof(struct sig_nal), buff+1, buff_len); |
|
207 |
if (res < 0) { |
|
208 |
fprintf(stderr, "Error in encoding chunk set for chunks request\n"); |
|
209 |
return -1; |
|
210 |
} else { |
|
211 |
buff[0] = MSG_TYPE_SIGNALLING; //the message type is CHUNK |
|
212 |
res = send_to_peer(localID, to, buff, buff_len + 1); //actual send chunk |
|
213 |
free(buff); //free memory allocated for the buffer |
|
214 |
free(sigmex); |
|
215 |
} |
|
216 |
return 1; |
|
217 |
}*/ |
|
218 |
|
|
219 | 193 |
|
220 | 194 |
/** |
221 | 195 |
* Accept a (sub)set of chunks from a Peer. |
... | ... | |
230 | 204 |
* @return 1 on success, <0 on error |
231 | 205 |
*/ |
232 | 206 |
int acceptChunks(const struct nodeID *to, struct chunkID_set *cset, int max_deliver, int trans_id) { |
233 |
return sendSignallingBIS(MSG_SIG_ACC, to, NULL, cset, max_deliver, -1, trans_id); |
|
234 |
}/* |
|
235 |
int acceptChunks(const struct nodeID *to, ChunkIDSet *cset, int cset_len, int max_deliver, int trans_id) { |
|
236 |
int buff_len; |
|
237 |
int res; |
|
238 |
uint8_t *buff; |
|
239 |
struct sig_nal *sigmex; |
|
240 |
sigmex = malloc(sizeof(struct sig_nal)); |
|
241 |
sigmex->type = MSG_SIG_ACC; |
|
242 |
sigmex->max_deliver = max_deliver; |
|
243 |
sigmex->trans_id = trans_id; |
|
244 |
fprintf(stdout, "SIG_HEADER: Type %d Tx %d PP %d\n", sigmex->type, sigmex->trans_id, sigmex->third_peer); |
|
245 |
buff_len = cset_len * 4 + 12 + sizeof(struct sig_nal); // Signaling type + set len |
|
246 |
buff = malloc(buff_len + 1); |
|
247 |
res = encodeChunkSignaling(cset, sigmex, sizeof(struct sig_nal), buff+1, buff_len); |
|
248 |
if (res < 0) { |
|
249 |
fprintf(stderr, "Error in encoding chunk set for chunks request\n"); |
|
250 |
return -1; |
|
251 |
} else { |
|
252 |
buff[0] = MSG_TYPE_SIGNALLING; //the message type is CHUNK |
|
253 |
res = send_to_peer(localID, to, buff, buff_len + 1); //actual send chunk |
|
254 |
free(buff); //free memory allocated for the buffer |
|
255 |
free(sigmex); |
|
256 |
} |
|
257 |
return 1; |
|
258 |
}*/ |
|
207 |
return sendSignalling(MSG_SIG_ACC, to, NULL, cset, max_deliver, -1, trans_id); |
|
208 |
} |
|
259 | 209 |
|
260 | 210 |
/** |
261 | 211 |
* Send a BufferMap to a Peer. |
... | ... | |
268 | 218 |
* @param[in] bmap_len length of the buffer map |
269 | 219 |
* @param[in] trans_id transaction number associated with this send |
270 | 220 |
* @return 1 on success, <0 on error |
271 |
*//* |
|
272 |
int sendBufferMap(const struct nodeID *to, const struct nodeID *owner, ChunkIDSet *bmap, int bmap_len, int trans_id) { |
|
273 |
int buff_len; |
|
274 |
int res; |
|
275 |
uint8_t *buff; |
|
276 |
struct sig_nal *sigmex; |
|
277 |
sigmex = malloc(sizeof(struct sig_nal)); |
|
278 |
sigmex->type = MSG_SIG_BMOFF; |
|
279 |
sigmex->trans_id = trans_id; |
|
280 |
|
|
281 |
//sigmex->third_peer->fd = owner->fd ; |
|
282 |
//sigmex->third_peer->refcnt = owner->refcnt ; |
|
283 |
//socklen_t raddr_size = sizeof(struct sockaddr_in); |
|
284 |
//memcpy(&sigmex->third_peer->addr,&owner->addr, raddr_size); |
|
285 |
|
|
286 |
fprintf(stdout, "SIG_HEADER: Type %d Tx %d\n", sigmex->type, sigmex->trans_id); |
|
287 |
buff_len = bmap_len * 4 + 12 + sizeof(struct sig_nal); // Signaling type + set len |
|
288 |
buff = malloc(buff_len + 1); |
|
289 |
res = encodeChunkSignaling(bmap, sigmex, sizeof(struct sig_nal), buff+1, buff_len); |
|
290 |
if (res < 0) { |
|
291 |
fprintf(stderr, "Error in encoding chunk set for chunks request\n"); |
|
292 |
return -1; |
|
293 |
} else { |
|
294 |
buff[0] = MSG_TYPE_SIGNALLING; //the message type is CHUNK |
|
295 |
res = send_to_peer(localID, to, buff, buff_len + 1); //actual send chunk |
|
296 |
free(buff); //free memory allocated for the buffer |
|
297 |
free(sigmex); |
|
298 |
} |
|
299 |
return 1; |
|
221 |
*/ |
|
222 |
int sendBufferMap(const struct nodeID *to, const struct nodeID *owner_id, struct chunkID_set *bmap, int bmap_len, int trans_id) { |
|
223 |
return sendSignalling(MSG_SIG_BMOFF, to, (!owner_id?localID:owner_id), bmap, 0, bmap_len, trans_id);//owner NULL -> my buffermap |
|
300 | 224 |
} |
301 |
*/ |
|
225 |
|
|
302 | 226 |
|
303 | 227 |
/** |
304 | 228 |
* Request a BufferMap to a Peer. |
Also available in: Unified diff