~raghavendra-prabhu/percona-xtradb-cluster/release-5.5.30-galera-2.x

« back to all changes in this revision

Viewing changes to gcs/src/gcs_act_proto.c

  • Committer: Raghavendra D Prabhu
  • Date: 2013-04-05 13:55:24 UTC
  • mfrom: (95.2.22 2.x)
  • Revision ID: raghavendra.prabhu@percona.com-20130405135524-aa4f4y9rko7t3cvt
Merge galera/2.x branch.

We merge upto r148 of galera/2.x branch for 5.5.30-23.7.4 PXC release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2008-2011 Codership Oy <info@codership.com>
 
2
 * Copyright (C) 2008-2013 Codership Oy <info@codership.com>
3
3
 *
4
 
 * $Id: gcs_act_proto.c 2832 2012-06-25 20:06:26Z alex $
 
4
 * $Id: gcs_act_proto.c 2962 2013-02-12 12:06:38Z alex $
5
5
 */
6
6
/*
7
7
 * Interface to action protocol
31
31
static const size_t PROTO_AT_OFFSET       = 16;
32
32
static const size_t PROTO_DATA_OFFSET     = 20;
33
33
 
34
 
static const gcs_seqno_t PROTO_ACT_ID_MAX   = 0x00FFFFFFFFFFFFLL;
35
 
static const size_t      PROTO_ACT_SIZE_MAX = 0xFFFFFFFF;
36
 
static const ulong       PROTO_FRAG_NO_MAX  = 0xFFFFFFFF;
37
 
static const ulong       PROTO_AT_MAX       = 0xFF;
 
34
static const gcs_seqno_t   PROTO_ACT_ID_MAX   = 0x00FFFFFFFFFFFFLL;
 
35
static const unsigned int  PROTO_FRAG_NO_MAX  = 0xFFFFFFFF;
 
36
static const unsigned char PROTO_AT_MAX       = 0xFF;
38
37
 
39
 
static const int    PROTO_VERSION = GCS_ACT_PROTO_MAX;
 
38
static const int PROTO_VERSION = GCS_ACT_PROTO_MAX;
40
39
 
41
40
#define PROTO_MAX_HDR_SIZE PROTO_DATA_OFFSET // for now
42
41
 
48
47
gcs_act_proto_write (gcs_act_frag_t* frag, void* buf, size_t buf_len)
49
48
{
50
49
#ifdef GCS_DEBUG_PROTO
51
 
    if ((frag->act_id   > PROTO_ACT_ID_MAX)   ||
52
 
        (frag->act_size > PROTO_ACT_SIZE_MAX) ||
53
 
        (frag->frag_no  > PROTO_FRAG_NO_MAX)  ||
 
50
    if ((frag->act_id   > PROTO_ACT_ID_MAX)  ||
 
51
        (frag->act_size > GCS_MAX_ACT_SIZE)  ||
 
52
        (frag->frag_no  > PROTO_FRAG_NO_MAX) ||
54
53
        (frag->act_type > PROTO_AT_MAX)) {
55
54
        gu_error ("Exceeded protocol limits: %d(%d), %d(%d), %d(%d), %d(%d)",
56
55
                  frag->act_id,   PROTO_ACT_ID_MAX,
57
 
                  frag->act_size, PROTO_ACT_SIZE_MAX,
 
56
                  frag->act_size, GCS_MAX_ACT_SIZE,
58
57
                  frag->frag_no,  PROTO_FRAG_NO_MAX,
59
58
                  frag->act_type, PROTO_AT_MAX);
60
59
        return -EOVERFLOW;
63
62
    if (buf_len      < PROTO_DATA_OFFSET) return -EMSGSIZE;
64
63
#endif
65
64
 
 
65
    // assert (frag->act_size <= PROTO_ACT_SIZE_MAX);
 
66
 
66
67
    ((uint64_t*)buf)[0] = gu_be64(frag->act_id);
67
68
    ((uint32_t*)buf)[2] = htogl  ((uint32_t)frag->act_size);
68
69
    ((uint32_t*)buf)[3] = htogl  (frag->frag_no);
84
85
gcs_act_proto_read (gcs_act_frag_t* frag, const void* buf, size_t buf_len)
85
86
{
86
87
    frag->proto_ver = ((uint8_t*)buf)[PROTO_PV_OFFSET];
87
 
#ifdef GCS_DEBUG_PROTO
 
88
 
 
89
    if (gu_unlikely(buf_len < PROTO_DATA_OFFSET)) {
 
90
        gu_error ("Action message too short: %zu, expected at least %d",
 
91
                  buf_len, PROTO_DATA_OFFSET);
 
92
        return -EBADMSG;
 
93
    }
 
94
 
88
95
    if (gu_unlikely(frag->proto_ver > PROTO_VERSION)) {
89
96
        gu_error ("Bad protocol version %d, expected %d",
90
97
                  frag->proto_ver, PROTO_VERSION);
91
98
        return -EPROTO; // this fragment should be dropped
92
99
    }
93
 
    if (gu_unlikely(buf_len < PROTO_DATA_OFFSET)) {
94
 
        gu_error ("Action message too short: %zu, expected at least %d",
95
 
                  buf_len, PROTO_DATA_OFFSET);
96
 
        return -EMSGSIZE;
97
 
    }
98
 
#endif
 
100
 
99
101
    ((uint8_t*)buf)[PROTO_PV_OFFSET] = 0x0;
100
102
    frag->act_id   = gu_be64(*(uint64_t*)buf);
101
103
    frag->act_size = gtohl  (((uint32_t*)buf)[2]);
102
104
    frag->frag_no  = gtohl  (((uint32_t*)buf)[3]);
103
105
    frag->act_type = ((uint8_t*)buf)[PROTO_AT_OFFSET];
104
 
 
105
106
    frag->frag     = ((uint8_t*)buf) + PROTO_DATA_OFFSET;
106
107
    frag->frag_len = buf_len - PROTO_DATA_OFFSET;
107
 
    return 0;
 
108
 
 
109
    /* return 0 or -EMSGSIZE */
 
110
    return ((frag->act_size > GCS_MAX_ACT_SIZE) * -EMSGSIZE);
108
111
}
109
112
 
110
113
/*! Returns protocol header size */