914134ac51eb861252f4ab42e15816500a455530
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/gnunet-service-transport_neighbours.h
23  * @brief neighbour management API
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
27 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
28
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_util_lib.h"
32
33 // TODO:
34 // - have a way to access the currently 'connected' session
35 //   (for sending and to notice disconnect of it!)
36 // - have a way to access/update bandwidth/quota information per peer
37 //   (for CostReport/TrafficReport callbacks)
38
39
40
41 /**
42  * Initialize the neighbours subsystem.
43  *
44  * @param cls closure for callbacks
45  * @param connect_cb function to call if we connect to a peer
46  * @param disconnect_cb function to call if we disconnect from a peer
47  */
48 void 
49 GST_neighbours_start (void *cls,
50                       GNUNET_TRANSPORT_NotifyConnect connect_cb,
51                       GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
52
53
54 /**
55  * Cleanup the neighbours subsystem.
56  */
57 void
58 GST_neighbours_stop (void);
59
60
61 /**
62  * Try to create a connection to the given target (eventually).
63  *
64  * @param target peer to try to connect to
65  */
66 void
67 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
68
69
70 /**
71  * Test if we're connected to the given peer.
72  * 
73  * @param target peer to test
74  * @return GNUNET_YES if we are connected, GNUNET_NO if not
75  */
76 int
77 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
78
79
80 /**
81  * If we have an active connection to the given target, it must be shutdown.
82  *
83  * @param target peer to disconnect from
84  */
85 void
86 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
87
88
89 /**
90  * Function called for each connected neighbour.
91  *
92  * @param cls closure
93  * @param neighbour identity of the neighbour
94  */
95 typedef void (*GST_NeighbourIterator)(void *cls,
96                                       const struct GNUNET_PeerIdentity *neighbour);
97
98
99 /**
100  * Iterate over all connected neighbours.
101  *
102  * @param cb function to call 
103  * @param cb_cls closure for cb
104  */
105 void
106 GST_neighbours_iterate (GST_NeighbourIterator cb,
107                         void *cb_cls);
108
109
110 /**
111  * We have received a PONG.  Update lifeness of the neighbour.
112  *
113  * @param sender peer sending the PONG
114  * @param hdr the PONG message (presumably)
115  * @param plugin_name name of transport that delivered the PONG
116  * @param sender_address address of the other peer, NULL if other peer
117  *                       connected to us
118  * @param sender_address_len number of bytes in sender_address
119  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
120  */
121 int
122 GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender,
123                             const struct GNUNET_MessageHeader *hdr,
124                             const char *plugin_name,
125                             const void *sender_address,
126                             size_t sender_address_len);
127
128
129 /**
130  * We have received a CONNECT.  Set the peer to connected.
131  *
132  * @param sender peer sending the PONG
133  * @param hdr the PONG message (presumably)
134  * @param plugin_name name of transport that delivered the PONG
135  * @param sender_address address of the other peer, NULL if other peer
136  *                       connected to us
137  * @param sender_address_len number of bytes in sender_address
138  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
139  */
140 int
141 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
142                                const struct GNUNET_MessageHeader *hdr,
143                                const char *plugin_name,
144                                const void *sender_address,
145                                size_t sender_address_len);
146
147
148 /**
149  * We have received a DISCONNECT.  Set the peer to disconnected.
150  *
151  * @param sender peer sending the PONG
152  * @param hdr the PONG message (presumably)
153  * @param plugin_name name of transport that delivered the PONG
154  * @param sender_address address of the other peer, NULL if other peer
155  *                       connected to us
156  * @param sender_address_len number of bytes in sender_address
157  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
158  */
159 int
160 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
161                                   const struct GNUNET_MessageHeader *hdr,
162                                   const char *plugin_name,
163                                   const void *sender_address,
164                                   size_t sender_address_len);
165
166
167 #endif
168 /* end of file gnunet-service-transport_neighbours.h */