Statistics
| Branch: | Revision:

napa-baselibs / ml / transmissionHandler.h @ 98141414

History | View | Annotate | Download (6.84 KB)

1
/*
2
 * Copyright (c) 2009 NEC Europe Ltd. All Rights Reserved.
3
 * Authors: Kristian Beckers  <beckers@nw.neclab.eu>
4
 *          Sebastian Kiesel  <kiesel@nw.neclab.eu>
5
 * Copyright (c) 2011 Csaba Kiraly <kiraly@disi.unitn.it>
6
 *
7
 * This file is part of the Messaging Library.
8
 *
9
 * The Messaging Library is free software: you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * The Messaging Library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
17
 * General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with the Messaging Library.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23

    
24

    
25
/**
26
 * @file transmissionHandler.h
27
 * @brief The transmissionHandler takes care of connecting peers and exchanging data between them.
28
 *
29
 * @author Kristian Beckers  <beckers@nw.neclab.eu>                             
30
 * @author Sebastian Kiesel  <kiesel@nw.neclab.eu> 
31
 *
32
 *                                                                              
33
 * @date 7/28/2009 
34
 */
35

    
36
#ifndef TRANSMISSIONHANDLER_H
37
#define TRANSMISSIONHANDLER_H
38
#include <sys/time.h>
39
#ifndef _WIN32
40
#include <netinet/in.h>
41
#include <sys/socket.h>
42
#include <arpa/inet.h>
43
#include <sys/uio.h>
44
#endif
45
#include <fcntl.h>
46
#include <event2/event.h>
47
#include <sys/types.h>
48
#include "util/udpSocket.h"
49
#include "util/stun.h"
50
#include "ml.h"
51

    
52
#ifndef _WIN32
53
#ifndef boolean
54
typedef bool boolean;
55
#endif
56
#endif
57

    
58
#ifndef TRUE
59
#define TRUE ((bool)1)
60
#endif
61
#ifndef FALSE
62
#define FALSE ((bool)0)
63
#endif
64

    
65
#ifdef RTX
66
/**
67
 * This is the maximum number of gaps RTX can keep track of inside one message
68
 */
69
#define RTX_MAX_GAPS 25
70

    
71
#define ML_NACK_MSG 128
72
#endif
73
/**
74
 * This is the maximum size of the monitoring module header that can be added to the messaging layer header
75
 */
76
#define MON_DATA_HEADER_SPACE 32
77
#define MON_PKT_HEADER_SPACE 32
78

    
79
/**
80
  * Define the size of the messaging layer header 
81
  */
82
#define MSGL_HEADER_SIZE 18
83

    
84
/**
85
  * Define a type that is a pointer to a libevent event 
86
  */
87
typedef struct event *sock_event_ptr;
88

    
89
/**
90
 * Defined a mtu size - IP size - UDP size
91
 */
92
typedef enum {MAX = 1472, DSL = 1464, DSLMEDIUM = 1422, DSLSLIM = 1372, BELOWDSL = 1172, MIN = 472, P_ERROR = -1} pmtu;
93

    
94
/**
95
 * Define connection command types
96
 */
97
typedef enum {INVITE = 0, CONNECT, READY} con_msg_types;
98

    
99
/**
100
 * Define receiver buffer status
101
 */
102

    
103
typedef enum {ACTIVE = 0, INACTIVE, COMPLETE} recvbuf_status_types;
104

    
105
/**
106
 * A union that considers IPv4 and IPv6 addresses 
107
 */
108
typedef union{
109

    
110
  struct sockaddr_in udpaddr; ///< ipv4 address
111
  struct sockaddr_in6 udpaddr6; ///< ipv6 address
112

    
113
} socketaddrgen;
114

    
115
/**
116
  the socketID contains the internal and the external IP+Port 
117
 */
118
typedef struct _socket_ID {
119

    
120
  socketaddrgen internal_addr; ///< internal address
121
  socketaddrgen external_addr; ///< external or reflexive address
122
} socket_ID;
123

    
124
#ifdef RTX
125
struct gap {
126
        int offsetFrom;
127
        int offsetTo;
128
};
129
#endif
130

    
131
/**
132
  * A struct that contains information about data that is being received
133
  */
134
typedef struct {
135

    
136
  int recvID; ///< the receive ID
137
  int connectionID; ///< The connectionID
138
  int seqnr; ///< The sequence number
139
  char *recvbuf; ///< A pointer to the receive buffer
140
  int bufsize; ///< The  buffersize
141
  int status; ///< The receive status. 1 if receiving finished
142
  char msgtype; ///< The message type
143
  char firstPacketArrived; ///< did the first packet arrive 
144
  int recvFragments; ///< the number of received framgents
145
  int arrivedBytes; ///< the number of received Bytes
146
  int monitoringDataHeaderLen; ///< size of the monitoring data header (0 == no header)
147
  struct event *timeout_event; ///< a timeout event
148
  struct timeval timeout_value; ///< the value for a libevent timeout
149
  time_t starttime; ///< the start time
150
#ifdef RTX
151
  struct event* last_pkt_timeout_event;
152
  int txConnectionID;
153
  int expectedOffset;
154
  int gapCounter; //index of the first "free slot"
155
  int firstGap;        //first gap which hasn't been handled yet (for which the NACK hasn't been sent yet)
156
  struct gap gapArray[RTX_MAX_GAPS];
157
#endif
158
#ifdef FEC
159
  int *pix; //Keep track of packet indexes.
160
  int *pix_chk; //to avoid multiple received packets.
161
  int nix; //counter incrimented after the arrivel of each packet. pix[nix]
162
  int finish;
163
#endif
164
} recvdata;
165

    
166
struct receive_connection_cb_list{
167
        struct receive_connection_cb_list *next;
168
        receive_connection_cb connection_cb;
169
        void *arg;
170
};
171

    
172
/**
173
 * A struct with information about a connection that exist or a connection that is being established
174
 */
175
typedef struct {
176

    
177
  int connectionID; ///< the connection ID
178
  socket_ID external_socketID; ///< the external socketID
179
  int external_connectionID; ///< the internal connectionID
180
  pmtu pmtusize; ///< the pmtu size
181
  bool delay;
182
  int trials;
183
  char *ctrl_msg_buf;
184
  int status; ///< the status of the connection. status has the following encoding: 0: INVITE send, 1: CONNECT send, 2: connection established
185
  time_t starttime; ///< the time when the first connection attempt was made
186
  uint32_t seqnr; ///< sequence number for connections that have been tried
187
  struct event *timeout_event;
188
  struct timeval timeout_value; ///< the timeout value for the connection establishment
189
  bool internal_connect; ///< set to true if a connection to the internal address could be established
190
  struct receive_connection_cb_list *connection_head;
191
  struct receive_connection_cb_list *connection_last;
192
  send_params defaultSendParams;
193
  uint32_t keepalive_seq; 
194
} connect_data;
195

    
196
#define ML_CON_MSG 127
197

    
198

    
199
/**
200
 * A struct with the messaging layer header for connection handling messages
201
 */
202
#pragma pack(push)  /* push current alignment to stack */
203
#pragma pack(1)     /* set alignment to 1 byte boundary */
204
struct conn_msg {
205
        uint32_t comand_type; ///< see con_msg_types
206
        int32_t pmtu_size;        /// the pmtu size 
207
        socket_ID sock_id;        /// the socketId of the sender
208
} __attribute__((packed));
209

    
210
#ifdef RTX
211
/************modifications-START************/
212

    
213
struct nack_msg {
214
        int32_t con_id;                ///local connectionID of the transmitter
215
        int32_t msg_seq_num;
216
        uint32_t offsetFrom;
217
        uint32_t offsetTo;
218
} __attribute__((packed));
219

    
220
/************modifications-END**************/
221
#endif
222

    
223
struct msg_header {
224
        uint32_t offset;
225
        uint32_t msg_length;
226
        int32_t local_con_id;        ///> the local connection id
227
        int32_t remote_con_id;        ///> the remote connection id
228
        int32_t msg_seq_num;
229
        uint8_t msg_type; ///< set to ML_CON_MSG
230
        uint8_t len_mon_data_hdr;
231
        uint8_t len_mon_packet_hdr;
232
};
233
#define MSG_HEADER_SIZE (sizeof(struct msg_header))
234
#pragma pack(pop)   /* restore original alignment from stack */
235

    
236
int sendPacket(const int udpSocket, struct iovec *iov, int len, struct sockaddr_in *socketaddr);
237

    
238
#endif