more work on TNG
[oweals/gnunet.git] / src / include / gnunet_transport_monitor_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * Monitoring / diagnostics API for the transport service
24  *
25  * @defgroup transport TRANSPORT service
26  * Communication with other peers
27  *
28  * @see [Documentation](https://gnunet.org/transport-service)
29  *
30  * @{
31  */
32 #ifndef GNUNET_TRANSPORT_MONITOR_SERVICE_H
33 #define GNUNET_TRANSPORT_MONITOR_SERVICE_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_util_lib.h"
44 #include "gnunet_ats_service.h"
45 #include "gnunet_transport_communication_service.h"
46
47
48 /**
49  * Version number of the transport API.
50  */
51 #define GNUNET_TRANSPORT_MONITOR_VERSION 0x00000000
52
53
54 /**
55  * Information about another peer's address.
56  */
57 struct GNUNET_TRANSPORT_MonitorInformation
58 {
59
60   /**
61    * Address we have for the peer, human-readable, 0-terminated, in UTF-8.
62    */
63   const char *address;
64
65   /**
66    * Network type of the address.
67    */
68   enum GNUNET_ATS_Network_Type nt;
69
70   /**
71    * Connection status.
72    */
73   enum GNUNET_TRANSPORT_ConnectionStatus cs;
74
75   /**
76    * Number of messages pending transmission for this @e address.
77    */
78   uint32_t num_msg_pending;
79
80   /**
81    * Number of bytes pending transmission for this @e address.
82    */
83   uint32_t num_bytes_pending;
84
85   /**
86    * When was this address last validated.
87    */
88   struct GNUNET_TIME_Absolute last_validation;
89
90   /**
91    * When does this address expire.
92    */
93   struct GNUNET_TIME_Absolute valid_until;
94
95   /**
96    * Time of the next validation operation.
97    */
98   struct GNUNET_TIME_Absolute next_validation;
99
100   /**
101    * Current estimate of the RTT.
102    */
103   struct GNUNET_TIME_Relative rtt;
104
105 };
106
107
108 /**
109  * Function to call with information about a peer.
110  *
111  * If one_shot was set to #GNUNET_YES to iterate over all peers once,
112  * a final call with NULL for peer and address will follow when done.
113  * In this case state and timeout do not contain valid values.
114  *
115  * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
116  * within this function!
117  *
118  *
119  * @param cls closure
120  * @param peer peer this update is about,
121  *        NULL if this is the final last callback for a iteration operation
122  * @param mi monitoring data on the peer
123  */
124 typedef void
125 (*GNUNET_TRANSPORT_MonitorCallback) (void *cls,
126                                      const struct GNUNET_PeerIdentity *peer,
127                                      const struct GNUNET_TRANSPORT_MonitorInformation *mi);
128
129
130 /**
131  * Handle for a #GNUNET_TRANSPORT_monitor() operation.
132  */
133 struct GNUNET_TRANSPORT_MonitorContext;
134
135
136 /**
137  * Return information about a specific peer or all peers currently known to
138  * transport service once or in monitoring mode. To obtain information about
139  * a specific peer, a peer identity can be passed. To obtain information about
140  * all peers currently known to transport service, NULL can be passed as peer
141  * identity.
142  *
143  * For each peer, the callback is called with information about the address used
144  * to communicate with this peer, the state this peer is currently in and the
145  * the current timeout for this state.
146  *
147  * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
148  * more time with `NULL`. After this, the operation must no longer be
149  * explicitly canceled.
150  *
151  * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
152  * the peer_callback!
153  *
154  * @param cfg configuration to use
155  * @param peer a specific peer identity to obtain information for,
156  *      NULL for all peers
157  * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL),
158  *                 #GNUNET_NO to monitor peers continuously
159  * @param cb function to call with the results
160  * @param cb_cls closure for @a mc
161  */
162 struct GNUNET_TRANSPORT_MonitorContext *
163 GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
164                           const struct GNUNET_PeerIdentity *peer,
165                           int one_shot,
166                           GNUNET_TRANSPORT_MonitorCallback cb,
167                           void *cb_cls);
168
169
170 /**
171  * Cancel request to monitor peers
172  *
173  * @param mc handle for the request to cancel
174  */
175 void
176 GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc);
177
178
179 #if 0                           /* keep Emacsens' auto-indent happy */
180 {
181 #endif
182 #ifdef __cplusplus
183 }
184 #endif
185
186 /* ifndef GNUNET_TRANSPORT_MONITOR_SERVICE_H */
187 #endif
188
189 /** @} */  /* end of group */
190
191 /* end of gnunet_transport_monitor_service.h */