summaryrefslogtreecommitdiff
path: root/src/charon/encoding/payloads/endpoint_notify.h
blob: 272301d5b701a33a7797f003642f4952d1f577a0 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
 * @file endpoint_notify.h
 * 
 * @brief Interface of endpoint_notify_t.
 * 
 */

/*
 * Copyright (C) 2007 Tobias Brunner
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */


#ifndef ENDPOINT_NOTIFY_H_
#define ENDPOINT_NOTIFY_H_

#define P2P_PRIO_HOST   255
#define P2P_PRIO_SERVER 100
#define P2P_PRIO_PEER   120
#define P2P_PRIO_RELAY  0

typedef enum p2p_endpoint_family_t p2p_endpoint_family_t;
typedef enum p2p_endpoint_type_t p2p_endpoint_type_t;
typedef struct endpoint_notify_t endpoint_notify_t;

#include <encoding/payloads/notify_payload.h>

enum p2p_endpoint_family_t {
	
	NO_FAMILY = 0,
	
	IPv4 = 1,
	
	IPv6 = 2,
	
	MAX_FAMILY = 3
	
};

enum p2p_endpoint_type_t {
	
	NO_TYPE = 0,
	
	HOST = 1,
	
	SERVER_REFLEXIVE = 2,
	
	PEER_REFLEXIVE = 3,
	
	RELAYED = 4,
	
	MAX_TYPE = 5
	
};

/**
 * @brief Class representing a P2P_ENDPOINT notify. In fact it's not
 * the notify per se, but the notification data of that notify that is
 * handled with this class.
 * 
 * @b Constructors:
 * - endpoint_notify_create()
 * - endpoint_notify_create_from_host()
 *
 * @ingroup payloads
 */
struct endpoint_notify_t {
	/**
	 * @brief Returns the priority of this endpoint.
	 * 
	 * @param this		object
	 * @return			priority
	 */
	u_int32_t (*get_priority) (endpoint_notify_t *this);
	
	/**
	 * @brief Sets the priority of this endpoint.
	 * 
	 * @param this		object
	 * @param priority	priority
	 */
	void (*set_priority) (endpoint_notify_t *this, u_int32_t priority);
	
	/**
	 * @brief Returns the endpoint type of this endpoint.
	 * 
	 * @param this		object
	 * @return			endpoint type
	 */
	p2p_endpoint_type_t (*get_type) (endpoint_notify_t *this);
	
	/**
	 * @brief Returns the endpoint family of this endpoint.
	 * 
	 * @param this		object
	 * @return			endpoint family
	 */
	p2p_endpoint_family_t (*get_family) (endpoint_notify_t *this);
	
	/**
	 * @brief Returns the host of this endpoint.
	 * 
	 * @param this		object
	 * @return			host
	 */
	host_t *(*get_host) (endpoint_notify_t *this);
	
	/**
	 * @brief Returns the base of this endpoint.
	 * 
	 * If this is not a SERVER_REFLEXIVE endpoint, the returned host is the same
	 * as the one returned by get_host.
	 * 
	 * @param this		object
	 * @return			host
	 */
	host_t *(*get_base) (endpoint_notify_t *this);
	
	/**
	 * @brief Generates a notification payload from this endpoint. 
	 * 	
	 * @param this 		object
	 * @return 			built notify_payload_t
	 */
	notify_payload_t *(*build_notify) (endpoint_notify_t *this);

	/**
	 * @brief Clones an endpoint_notify_t object.
	 *
	 * @param this 	endpoint_notify_t object to clone
	 * @return		cloned object
	 */
	endpoint_notify_t *(*clone) (endpoint_notify_t *this);
	
	/**
	 * @brief Destroys an endpoint_notify_t object.
	 *
	 * @param this 	endpoint_notify_t object to destroy
	 */
	void (*destroy) (endpoint_notify_t *this);
};

/**
 * @brief Creates an empty endpoint_notify_t object.
 * 
 * @return			created endpoint_notify_t object
 * 
 * @ingroup payloads
 */
endpoint_notify_t *endpoint_notify_create(void);


/**
 * @brief Creates an endpoint_notify_t object from a host.
 * 
 * @param type		the endpoint type
 * @param host		host to base the notify on (gets cloned)
 * @param base		base of the endpoint, applies only to reflexive endpoints (gets cloned)
 * @return			created endpoint_notify_t object
 * 
 * @ingroup payloads
 */
endpoint_notify_t *endpoint_notify_create_from_host(p2p_endpoint_type_t type, host_t *host, host_t *base);

/**
 * @brief Creates an endpoint_notify_t object from a notify payload.
 * 
 * @param notify	the notify payload
 * @return			- created endpoint_notify_t object
 * 					- NULL if invalid payload
 * @ingroup payloads
 */
endpoint_notify_t *endpoint_notify_create_from_payload(notify_payload_t *notify);

#endif /*ENDPOINT_NOTIFY_H_*/