Revision f217ce38 src/ChunkTrading/chunk_signaling.c

View differences:

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