more client code
[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_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  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
178  */
179 int
180 GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender,
181                             const struct GNUNET_MessageHeader *hdr,
182                             const char *plugin_name,
183                             const void *sender_address,
184                             size_t sender_address_len)
185 {
186   return GNUNET_SYSERR;
187 }
188
189
190 /**
191  * We have received a CONNECT.  Set the peer to connected.
192  *
193  * @param sender peer sending the PONG
194  * @param hdr the PONG message (presumably)
195  * @param plugin_name name of transport that delivered the PONG
196  * @param sender_address address of the other peer, NULL if other peer
197  *                       connected to us
198  * @param sender_address_len number of bytes in sender_address
199  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
200  */
201 int
202 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
203                                const struct GNUNET_MessageHeader *hdr,
204                                const char *plugin_name,
205                                const void *sender_address,
206                                size_t sender_address_len)
207 {
208   return GNUNET_SYSERR;
209 }
210
211
212 /**
213  * We have received a DISCONNECT.  Set the peer to disconnected.
214  *
215  * @param sender peer sending the PONG
216  * @param hdr the PONG message (presumably)
217  * @param plugin_name name of transport that delivered the PONG
218  * @param sender_address address of the other peer, NULL if other peer
219  *                       connected to us
220  * @param sender_address_len number of bytes in sender_address
221  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
222  */
223 int
224 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
225                                   const struct GNUNET_MessageHeader *hdr,
226                                   const char *plugin_name,
227                                   const void *sender_address,
228                                   size_t sender_address_len)
229 {
230   return GNUNET_SYSERR;
231 }
232
233
234 /* end of file gnunet-service-transport_neighbours.c */