Revision 82438fe3

View differences:

include/peerset.h
97 97
  * @param h a pointer to the set
98 98
  * @return the list of peer structures
99 99
  */
100
struct peer *peerset_get_peers(const struct peerset *h);
100
struct peer **peerset_get_peers(const struct peerset *h);
101 101

  
102 102
 /**
103 103
  * @brief Check if a peer is in a set
src/PeerSet/peerset_ops.c
43 43
  }
44 44
  free(cfg_tags);
45 45
  if (p->size) {
46
    p->elements = malloc(p->size * sizeof(struct peer));
46
    p->elements = malloc(p->size * sizeof(struct peer *));
47 47
  } else {
48 48
    p->elements = NULL;
49 49
  }
......
59 59
  }
60 60

  
61 61
  if (h->n_elements == h->size) {
62
    int *res;
62
    struct peer **res;
63 63

  
64
    res = realloc(h->elements, (h->size + DEFAULT_SIZE_INCREMENT) * sizeof(struct peer));
64
    res = realloc(h->elements, (h->size + DEFAULT_SIZE_INCREMENT) * sizeof(struct peer *));
65 65
    if (res == NULL) {
66 66
      return -1;
67 67
    }
68 68
    h->size += DEFAULT_SIZE_INCREMENT;
69
    h->elements = (struct peer*) res;
69
    h->elements = res;
70 70
  }
71
  e = &(h->elements[h->n_elements++]);
71
  e = malloc(sizeof(struct peer));
72
  h->elements[h->n_elements++] = e;
72 73
  e->id = nodeid_dup(id);
73 74
  gettimeofday(&e->creation_timestamp,NULL);
74 75
  e->bmap = chunkID_set_init("type=bitmap");
75 76
  timerclear(&e->bmap_timestamp);
76
  e->cb_size = INT_MAX;
77
  e->cb_size = 0;
77 78

  
78 79
  return h->n_elements;
79 80
}
......
92 93
  return h->n_elements;
93 94
}
94 95

  
95
struct peer* peerset_get_peers(const struct peerset *h)
96
struct peer **peerset_get_peers(const struct peerset *h)
96 97
{
97 98
  return h->elements;
98 99
}
......
100 101
struct peer *peerset_get_peer(const struct peerset *h, const struct nodeID *id)
101 102
{
102 103
  int i = peerset_check(h,id);
103
  return (i<0) ? NULL : &(h->elements[i]);
104
  return (i<0) ? NULL : h->elements[i];
104 105
}
105 106

  
106 107
int peerset_remove_peer(struct peerset *h, const struct nodeID *id){
107 108
  int i = peerset_check(h,id);
108 109
  if (i >= 0) {
109
    struct peer *e = h->elements + i;
110
    struct peer *e = h->elements[i];
110 111
    nodeid_free(e->id);
111 112
    chunkID_set_free(e->bmap);
112
    memmove(e, e + 1, ((h->n_elements--) - (i+1)) * sizeof(struct peer));
113
    memmove(e, e + 1, ((h->n_elements--) - (i+1)) * sizeof(struct peer *));
114
    free(e);
115

  
113 116
    return i;
114 117
  }
115 118
  return -1;
......
120 123
  int i;
121 124

  
122 125
  for (i = 0; i < h->n_elements; i++) {
123
    if (nodeid_equal(h->elements[i].id, id)) {
126
    if (nodeid_equal(h->elements[i]->id, id)) {
124 127
      return i;
125 128
    }
126 129
  }
......
133 136
  int i;
134 137

  
135 138
  for (i = 0; i < h->n_elements; i++) {
136
    struct peer *e = h->elements + i;
139
    struct peer *e = h->elements[i];
137 140
    nodeid_free(e->id);
138 141
    chunkID_set_free(e->bmap);
142
    free(e);
139 143
  }
140 144

  
141 145
  h->n_elements = 0;
142 146
  h->size = size;
143
  h->elements = realloc(h->elements, size * sizeof(struct peer));
147
  h->elements = realloc(h->elements, size * sizeof(struct peer *));
144 148
  if (h->elements == NULL) {
145 149
    h->size = 0;
146 150
  }
src/PeerSet/peerset_private.h
4 4
struct peerset {
5 5
  int size;  //  
6 6
  int n_elements; // Number of ids in this array of chunks ids
7
  struct peer *elements;  // id number
7
  struct peer **elements;  // id number
8 8
};
9 9

  
10 10
#endif /* PEERSET_PRIVATE */

Also available in: Unified diff