Revision 637f87e0

View differences:

chunk_signaling.c
17 17
#include <sys/time.h>
18 18
#include <errno.h>
19 19
#include <assert.h>
20
#include <string.h>
20 21
#include "peer.h"
21 22
#include "peerset.h"
22 23
#include "chunkidset.h"
......
48 49

  
49 50
int sendSignalling(int type, const struct nodeID *to_id, const struct nodeID *owner_id, struct chunkID_set *cset, int max_deliver, int trans_id)
50 51
{
51
    int buff_len, id_len, msg_len, ret;
52
    int buff_len, meta_len, msg_len, ret;
52 53
    uint8_t *buff;
53
    struct sig_nal sigmex;
54
    sigmex.type = type;
55
    sigmex.max_deliver = max_deliver;
56
    sigmex.trans_id = trans_id;
54
    struct sig_nal *sigmex;
55
    uint8_t *meta;
56

  
57
    meta = malloc(1024);
58

  
59
    sigmex = (struct sig_nal*) meta;
60
    sigmex->type = type;
61
    sigmex->max_deliver = max_deliver;
62
    sigmex->trans_id = trans_id;
63
    meta_len = sizeof(*sigmex)-1;
64
      sigmex->third_peer = 0;
57 65
    if (owner_id) {
58
      id_len = nodeid_dump(&sigmex.third_peer, owner_id);
59
    } else {
60
      id_len = 1;
66
      meta_len += nodeid_dump(&sigmex->third_peer, owner_id);
61 67
    }
62
    buff_len = 1 + chunkID_set_size(cset) * 4 + 12 + sizeof(sigmex)-1 + id_len; // this should be enough
68

  
69
    buff_len = 1 + chunkID_set_size(cset) * 4 + 12 + meta_len; // this should be enough
63 70
    buff = malloc(buff_len);
64 71
    if (!buff) {
72
      fprintf(stderr, "Error allocating buffer\n");
65 73
      return -1;
66 74
    }
75

  
67 76
    buff[0] = MSG_TYPE_SIGNALLING;
68
    msg_len = 1 + encodeChunkSignaling(cset, &sigmex, sizeof(sigmex)-1 + id_len, buff+1, buff_len-1);
77
    msg_len = 1 + encodeChunkSignaling(cset, meta, meta_len, buff+1, buff_len-1);
78
    free(meta);
69 79
    if (msg_len < 0) {
70 80
      fprintf(stderr, "Error in encoding chunk set for sending a buffermap\n");
71 81
      ret = -1;

Also available in: Unified diff