more refactoring
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.c
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.c
23  * @brief neighbour management
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet-service-transport_neighbours.h"
28 #include "gnunet-service-transport.h"
29
30 // TODO:
31 // - have a way to access the currently 'connected' session
32 //   (for sending and to notice disconnect of it!)
33 // - have a way to access/update bandwidth/quota information per peer
34 //   (for CostReport/TrafficReport callbacks)
35
36
37
38 /**
39  * Initialize the neighbours subsystem.
40  *
41  * @param cls closure for callbacks
42  * @param connect_cb function to call if we connect to a peer
43  * @param disconnect_cb function to call if we disconnect from a peer
44  */
45 void 
46 GST_neighbours_start (void *cls,
47                       GNUNET_TRANSPORT_NotifyConnect connect_cb,
48                       GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
49 {
50 }
51
52
53 /**
54  * Cleanup the neighbours subsystem.
55  */
56 void
57 GST_neighbours_stop ()
58 {
59 }
60
61
62 /**
63  * Try to create a connection to the given target (eventually).
64  *
65  * @param target peer to try to connect to
66  */
67 void
68 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
69 {
70 }
71
72
73 /**
74  * Test if we're connected to the given peer.
75  * 
76  * @param target peer to test
77  * @return GNUNET_YES if we are connected, GNUNET_NO if not
78  */
79 int
80 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
81 {
82   return GNUNET_NO;
83 }
84
85
86 /**
87  * Transmit a message to the given target using the active connection.
88  *
89  * @param target destination
90  * @param msg message to send
91  * @param cont function to call when done
92  * @param cont_cls closure for 'cont'
93  */
94 void
95 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
96                      const struct GNUNET_MessageHeader *msg,
97                      GST_NeighbourSendContinuation cont,
98                      void *cont_cls)
99 {
100 }
101
102
103 /**
104  * Change the incoming quota for the given peer.
105  *
106  * @param neighbour identity of peer to change qutoa for
107  * @param quota new quota 
108  */
109 void
110 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
111                                    struct GNUNET_BANDWIDTH_Value32NBO quota)
112 {
113 #if 0
114
115   n = find_neighbour (neighbour);
116   if (n == NULL)
117     {
118       GNUNET_STATISTICS_update (stats,
119                                 gettext_noop ("# SET QUOTA messages ignored (no such peer)"),
120                                 1,
121                                 GNUNET_NO);
122       return;
123     }
124   GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
125                                          quota);
126   if (0 != ntohl (qsm->quota.value__))
127     return;
128 #if DEBUG_TRANSPORT
129   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130               "Disconnecting peer `%4s' due to `%s'\n",
131               GNUNET_i2s(&n->id),
132               "SET_QUOTA");
133 #endif
134   GNUNET_STATISTICS_update (stats,
135                             gettext_noop ("# disconnects due to quota of 0"),
136                             1,
137                             GNUNET_NO);
138   GST_neighbours_force_disconnect (neighbour);
139
140 #endif
141 }
142
143
144 /**
145  * If we have an active connection to the given target, it must be shutdown.
146  *
147  * @param target peer to disconnect from
148  */
149 void
150 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
151 {
152 }
153
154
155 /**
156  * Iterate over all connected neighbours.
157  *
158  * @param cb function to call 
159  * @param cb_cls closure for cb
160  */
161 void
162 GST_neighbours_iterate (GST_NeighbourIterator cb,
163                         void *cb_cls)
164 {
165 }
166
167
168 /**
169  * We have received a PONG.  Update lifeness of the neighbour.
170  *
171  * @param sender peer sending the PONG
172  * @param hdr the PONG message (presumably)
173  * @param plugin_name name of transport that delivered the PONG
174  * @param sender_address address of the other peer, NULL if other peer
175  *                       connected to us
176  * @param sender_address_len number of bytes in sender_address
177  * @param ats performance data
178  * @param ats_count number of entries in ats (excluding 0-termination)
179  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
180  */
181 int
182 GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender,
183                             const struct GNUNET_MessageHeader *hdr,
184                             const char *plugin_name,
185                             const void *sender_address,
186                             size_t sender_address_len,
187                             const struct GNUNET_TRANSPORT_ATS_Information *ats,
188                             uint32_t ats_count)
189 {
190   return GNUNET_SYSERR;
191 }
192
193
194 /**
195  * We have received a CONNECT.  Set the peer to connected.
196  *
197  * @param sender peer sending the PONG
198  * @param hdr the PONG message (presumably)
199  * @param plugin_name name of transport that delivered the PONG
200  * @param sender_address address of the other peer, NULL if other peer
201  *                       connected to us
202  * @param sender_address_len number of bytes in sender_address
203  * @param ats performance data
204  * @param ats_count number of entries in ats (excluding 0-termination)
205  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
206  */
207 int
208 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
209                                const struct GNUNET_MessageHeader *hdr,
210                                const char *plugin_name,
211                                const void *sender_address,
212                                size_t sender_address_len,
213                                const struct GNUNET_TRANSPORT_ATS_Information *ats,
214                                uint32_t ats_count)
215 {
216   return GNUNET_SYSERR;
217 }
218
219
220 /**
221  * We have received a DISCONNECT.  Set the peer to disconnected.
222  *
223  * @param sender peer sending the PONG
224  * @param hdr the PONG message (presumably)
225  * @param plugin_name name of transport that delivered the PONG
226  * @param sender_address address of the other peer, NULL if other peer
227  *                       connected to us
228  * @param sender_address_len number of bytes in sender_address
229  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
230  */
231 int
232 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
233                                   const struct GNUNET_MessageHeader *hdr,
234                                   const char *plugin_name,
235                                   const void *sender_address,
236                                   size_t sender_address_len)
237 {
238   return GNUNET_SYSERR;
239 }
240
241
242 /* end of file gnunet-service-transport_neighbours.c */