Revision f217ce38

View differences:

include/trade_msg_ha.h
38 38
  * @param[in] transid the ID of transaction this send belongs to (if any)
39 39
  * @return 0 on success, <0 on error
40 40
  */
41
int sendChunk(const struct nodeID *to, const struct chunk *c, uint16_t transid);
41
int sendChunk(const struct nodeID * localID, const struct nodeID *to, const struct chunk *c, uint16_t transid);
42 42

  
43 43
/**
44 44
  * @brief Init the Chunk trading internals.
include/trade_sig_ha.h
62 62
 * @param[in] trans_id transaction number associated with this request.
63 63
 * @return 1 on success, <0 on error.
64 64
 */
65
int requestChunks(const struct nodeID *to, const struct chunkID_set *cset, int max_deliver, uint16_t trans_id);
65
int requestChunks(const struct nodeID *localID, const struct nodeID *to, const struct chunkID_set *cset, int max_deliver, uint16_t trans_id);
66 66

  
67 67
/**
68 68
 * @brief Deliver a set of Chunks to a Peer as a reply of its previous request of Chunks.
......
75 75
 * @param[in] trans_id transaction number associated with this request.
76 76
 * @return 1 on success, <0 on error.
77 77
 */
78
int deliverChunks(const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
78
int deliverChunks(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
79 79

  
80 80
/**
81 81
 * @brief Offer a (sub)set of chunks to a Peer.
......
89 89
 * @param[in] trans_id transaction number associated with this request.
90 90
 * @return 1 on success, <0 on error.
91 91
 */
92
int offerChunks(const struct nodeID *to, struct chunkID_set *cset, int max_deliver, uint16_t trans_id);
92
int offerChunks(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, int max_deliver, uint16_t trans_id);
93 93

  
94 94
/**
95 95
 * @brief Accept a (sub)set of chunks from a Peer.
......
102 102
 * @param[in] trans_id transaction number associated with this request.
103 103
 * @return 1 on success, <0 on error.
104 104
 */
105
int acceptChunks(const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
105
int acceptChunks(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
106 106

  
107 107
/**
108 108
 * @brief Send a BufferMap to a Peer.
......
116 116
 * @param[in] trans_id transaction number associated with this send.
117 117
 * @return 1 Success, <0 on error.
118 118
 */
119
int sendBufferMap(const struct nodeID *to, const struct nodeID *owner, struct chunkID_set *bmap, int cb_size, uint16_t trans_id);
119
int sendBufferMap(const struct nodeID *localID, const struct nodeID *to, const struct nodeID *owner, struct chunkID_set *bmap, int cb_size, uint16_t trans_id);
120 120

  
121 121
/**
122 122
 * @brief Request a BufferMap to a Peer.
......
128 128
 * @param[in] trans_id transaction number associated with this request.
129 129
 * @return 1 Success, <0 on error.
130 130
 */
131
int requestBufferMap(const struct nodeID *to, const struct nodeID *owner, uint16_t trans_id);
131
int requestBufferMap(const struct nodeID *localID, const struct nodeID *to, const struct nodeID *owner, uint16_t trans_id);
132 132

  
133 133
/**
134 134
 * @brief Send an Acknoledgement to a Peer.
......
140 140
 * @param[in] trans_id transaction number associated with this send.
141 141
 * @return 1 Success, <0 on error.
142 142
 */
143
int sendAck(const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
143
int sendAck(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id);
144 144

  
145 145
#endif //TRADE_SIG_HA_H 
src/ChunkTrading/chunk_delivery.c
14 14
#include "trade_msg_ha.h"
15 15
#include "grapes_msg_types.h"
16 16

  
17
static struct nodeID *localID;
18

  
19 17
int parseChunkMsg(const uint8_t *buff, int buff_len, struct chunk *c, uint16_t *transid)
20 18
{
21 19
  int res;
......
45 43
 */
46 44
//TO CHECK AND CORRECT
47 45
//XXX Send data is in char while our buffer is in uint8
48
int sendChunk(const struct nodeID *to, const struct chunk *c, uint16_t transid)
46
int sendChunk(const struct nodeID * localID, const struct nodeID *to, const struct chunk *c, uint16_t transid)
49 47
{
50 48
  int buff_len;
51 49
  uint8_t *buff;
......
72 70

  
73 71
int chunkDeliveryInit(struct nodeID *myID)
74 72
{
75
  localID = myID;
76

  
77 73
  return 1;
78 74
}
79 75

  
src/ChunkTrading/chunk_signaling.c
50 50
  uint8_t third_peer;//for buffer map exchange from other peers, just the first byte!
51 51
} __attribute__((packed));
52 52

  
53
//set the local node ID
54
static struct nodeID *localID;
55 53

  
56 54
int chunkSignalingInit(struct nodeID *myID)
57 55
{
58
  if(!myID)
59
      return -1;
60
  localID = myID;
61

  
62 56
  return 1;
63 57
}
64 58

  
......
111 105
  return 1;
112 106
}
113 107

  
114
static int sendSignaling(int type, const struct nodeID *to_id,
108
static int sendSignaling(const struct nodeID *localID, int type, const struct nodeID *to_id,
115 109
                         const struct nodeID *owner_id,
116 110
                         const struct chunkID_set *cset, int max_deliver,
117 111
                         uint16_t trans_id)
......
158 152
  return 1;
159 153
}
160 154

  
161
int requestChunks(const struct nodeID *to, const ChunkIDSet *cset,
155
int requestChunks(const struct nodeID *localID, const struct nodeID *to, const ChunkIDSet *cset,
162 156
                  int max_deliver, uint16_t trans_id)
163 157
{
164
  return sendSignaling(MSG_SIG_REQ, to, NULL, cset, max_deliver, trans_id);
158
  return sendSignaling(localID, MSG_SIG_REQ, to, NULL, cset, max_deliver, trans_id);
165 159
}
166 160

  
167
int deliverChunks(const struct nodeID *to, ChunkIDSet *cset, uint16_t trans_id)
161
int deliverChunks(const struct nodeID * localID, const struct nodeID *to, ChunkIDSet *cset, uint16_t trans_id)
168 162
{
169
  return sendSignaling(MSG_SIG_DEL, to, NULL, cset, 0, trans_id);
163
  return sendSignaling(localID, MSG_SIG_DEL, to, NULL, cset, 0, trans_id);
170 164
}
171 165

  
172
int offerChunks(const struct nodeID *to, struct chunkID_set *cset,
166
int offerChunks(const struct nodeID * localID, const struct nodeID *to, struct chunkID_set *cset,
173 167
                int max_deliver, uint16_t trans_id)
174 168
{
175
  return sendSignaling(MSG_SIG_OFF, to, NULL, cset, max_deliver, trans_id);
169
  return sendSignaling(localID, MSG_SIG_OFF, to, NULL, cset, max_deliver, trans_id);
176 170
}
177 171

  
178
int acceptChunks(const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id)
172
int acceptChunks(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id)
179 173
{
180
  return sendSignaling(MSG_SIG_ACC, to, NULL, cset, 0, trans_id);
174
  return sendSignaling(localID, MSG_SIG_ACC, to, NULL, cset, 0, trans_id);
181 175
}
182 176

  
183
int sendBufferMap(const struct nodeID *to, const struct nodeID *owner,
177
int sendBufferMap(const struct nodeID *localID, const struct nodeID *to, const struct nodeID *owner,
184 178
                  struct chunkID_set *bmap, int cb_size, uint16_t trans_id)
185 179
{
186
  return sendSignaling(MSG_SIG_BMOFF, to, (!owner ? localID : owner), bmap,
180
  return sendSignaling(localID, MSG_SIG_BMOFF, to, (!owner ? localID : owner), bmap,
187 181
                       cb_size, trans_id);
188 182
}
189 183

  
190
int sendAck(const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id)
184
int sendAck(const struct nodeID *localID, const struct nodeID *to, struct chunkID_set *cset, uint16_t trans_id)
191 185
{
192
    return sendSignaling(MSG_SIG_ACK, to, NULL, cset, 0, trans_id);
186
    return sendSignaling(localID, MSG_SIG_ACK, to, NULL, cset, 0, trans_id);
193 187
}
194 188

  
195
int requestBufferMap(const struct nodeID *to, const struct nodeID *owner,
189
int requestBufferMap(const struct nodeID *localID, const struct nodeID *to, const struct nodeID *owner,
196 190
                     uint16_t trans_id)
197 191
{
198
  return sendSignaling(MSG_SIG_BMREQ, to, (!owner?localID:owner), NULL,
192
  return sendSignaling(localID, MSG_SIG_BMREQ, to, (!owner?localID:owner), NULL,
199 193
                       0, trans_id);
200 194
}

Also available in: Unified diff