summaryrefslogtreecommitdiff
path: root/apps/Gateway/Gateway/Peer_Message.h
blob: d9e65650095e50464e9fbbb7d7cd8972f89d1f9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- C++ -*- */
// $Id$


// ============================================================================
//
// = LIBRARY
//    apps
// 
// = FILENAME
//    Peer_Message.h
//
// = AUTHOR
//    Doug Schmidt 
// 
// ============================================================================

#if !defined (PEER_MESSAGE)
#define PEER_MESSAGE

// This is the unique connection identifier that denotes a particular
// Channel in the Gateway.
typedef short CONN_ID;

class Peer_Addr
  // = TITLE
  //     Peer address is used to identify the source/destination of a 
  //     routing message.
{
public:
  Peer_Addr (CONN_ID cid = -1, u_char lid = 0, u_char pay = 0)
    : conn_id_ (cid), logical_id_ (lid), payload_ (pay) {}

  int operator== (const Peer_Addr &pa) const
  {
    return this->conn_id_ == pa.conn_id_ 
      && this->logical_id_ == pa.logical_id_
      && this->payload_ == pa.payload_;
  }

  CONN_ID conn_id_;
  // Unique connection identifier that denotes a particular Channel.

  u_char logical_id_;
  // Logical ID.

  u_char payload_;
  // Payload type.
};


class Peer_Header
  // = TITLE
  //    Fixed sized header.
{
public:
  typedef u_short ROUTING_ID;
  // Type used to route messages from gatewayd.

  enum
  {
    INVALID_ID = -1 // No peer can validly use this number.
  };

  ROUTING_ID routing_id_;
  // Source ID.

  size_t  len_;
  // Length of the message in bytes.
};

class Peer_Message
  // = TITLE
  //    Variable-sized message (buf_ may be variable-sized between
  //    0 and MAX_PAYLOAD_SIZE).
{
public:
  enum { MAX_PAYLOAD_SIZE = 1024 };
  // The maximum size of an Peer message (see Peer protocol specs for
  // exact #).

  Peer_Header header_;
  // Message header.

  char buf_[MAX_PAYLOAD_SIZE];
  // Message payload.
};

#endif /* PEER_MESSAGE */