grapes / som / ChunkTrading / chunk_delivery.c @ 94488777
History | View | Annotate | Download (1000 Bytes)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2009 Alessandro Russo.
|
3 |
*
|
4 |
* This is free software;
|
5 |
* see GPL.txt
|
6 |
*/
|
7 |
#include <stdlib.h> |
8 |
#include <stdint.h> |
9 |
|
10 |
#include "chunk.h" |
11 |
#include "net_helper.h" |
12 |
#include "trade_msg_la.h" |
13 |
#include "trade_msg_ha.h" |
14 |
|
15 |
static struct nodeID *localID; |
16 |
|
17 |
/**
|
18 |
* Send a Chunk to a target Peer
|
19 |
*
|
20 |
* Send a single Chunk to a given Peer
|
21 |
*
|
22 |
* @param[in] to destination peer
|
23 |
* @param[in] c Chunk to send
|
24 |
* @return 0 on success, <0 on error
|
25 |
*/
|
26 |
|
27 |
//TO CHECK AND CORRECT
|
28 |
//XXX Send data is in char while our buffer is in uint8
|
29 |
int sendChunk(const struct nodeID *to, struct chunk *c){ |
30 |
int buff_len;
|
31 |
uint8_t *buff; |
32 |
int res;
|
33 |
|
34 |
buff_len = 20 + c->size + c->attributes_size;
|
35 |
buff = malloc(buff_len + 1);
|
36 |
if (buff == NULL) { |
37 |
return -1; |
38 |
} |
39 |
res = encodeChunk(c, buff + 1, buff_len);
|
40 |
buff[0] = 12; |
41 |
send_data(localID, to, buff, buff_len + 1);
|
42 |
free(buff); |
43 |
|
44 |
return (EXIT_SUCCESS);
|
45 |
} |
46 |
|
47 |
int chunkInit(struct nodeID *myID) |
48 |
{ |
49 |
localID = myID; |
50 |
return 1; |
51 |
} |
52 |
|