more work on peers, paths and tunnels
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new_connection.c
1
2 /*
3      This file is part of GNUnet.
4      Copyright (C) 2001-2017 GNUnet e.V.
5
6      GNUnet is free software; you can redistribute it and/or modify
7      it under the terms of the GNU General Public License as published
8      by the Free Software Foundation; either version 3, or (at your
9      option) any later version.
10
11      GNUnet is distributed in the hope that it will be useful, but
12      WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14      General Public License for more details.
15
16      You should have received a copy of the GNU General Public License
17      along with GNUnet; see the file COPYING.  If not, write to the
18      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19      Boston, MA 02110-1301, USA.
20 */
21
22 /**
23  * @file cadet/gnunet-service-cadet-new_connection.c
24  * @brief
25  * @author Bartlomiej Polot
26  * @author Christian Grothoff
27  */
28 #include "platform.h"
29 #include "gnunet-service-cadet-new_channel.h"
30 #include "gnunet-service-cadet-new_paths.h"
31 #include "gnunet-service-cadet-new_peer.h"
32 #include "gnunet-service-cadet-new_connection.h"
33
34
35 /**
36  * Low-level connection to a destination.
37  */
38 struct CadetConnection
39 {
40   /**
41    * To which peer does this connection go?
42    */
43   struct CadetPeer *destination;
44
45   /**
46    * Path we are using to our destination.
47    */
48   struct CadetPeerPath *path;
49
50   /**
51    * Function to call once we are ready to transmit.
52    */
53   GNUNET_SCHEDULER_TaskCallback ready_cb;
54
55   /**
56    * Closure for @e ready_cb.
57    */
58   void *ready_cb_cls;
59
60   /**
61    * Offset of our @e destination in @e path.
62    */
63   unsigned int off;
64
65 };
66
67
68 /**
69  * Is the given connection currently ready for transmission?
70  *
71  * @param cc connection to transmit on
72  * @return #GNUNET_YES if we could transmit
73  */
74 int
75 GCC_is_ready (struct CadetConnection *cc)
76 {
77   GNUNET_break (0);
78   return GNUNET_NO;
79 }
80
81
82 /**
83  * Destroy a connection.
84  *
85  * @param cc connection to destroy
86  */
87 void
88 GCC_destroy (struct CadetConnection *cc)
89 {
90   GCPP_del_connection (cc->path,
91                        cc->off,
92                        cc);
93   GNUNET_assert (0); // FIXME: incomplete implementation!
94   GNUNET_free (cc);
95 }
96
97
98 /**
99  * Create a connection to @a destination via @a path and
100  * notify @a cb whenever we are ready for more data.
101  *
102  * @param destination where to go
103  * @param path which path to take (may not be the full path)
104  * @param ready_cb function to call when ready to transmit
105  * @param ready_cb_cls closure for @a cb
106  */
107 struct CadetConnection *
108 GCC_create (struct CadetPeer *destination,
109             struct CadetPeerPath *path,
110             GNUNET_SCHEDULER_TaskCallback ready_cb,
111             void *ready_cb_cls)
112 {
113   struct CadetConnection *cc;
114   unsigned int off;
115
116   off = GCPP_find_peer (path,
117                         destination);
118   GNUNET_assert (UINT_MAX > off);
119
120   GNUNET_assert (0); // fIXME: unfinished
121
122   cc = GNUNET_new (struct CadetConnection);
123   cc->path = path;
124   cc->off = off;
125   GCPP_add_connection (path,
126                        off,
127                        cc);
128   for (unsigned int i=0;i<off;i++)
129   {
130     // FIXME: remember existence of this connection with
131     // ALL peers on the path!
132     // (and remove on destruction of connection!)
133   }
134   return cc;
135 }
136
137
138 /**
139  * Transmit message @a msg via connection @a cc.  Must only be called
140  * (once) after the connection has signalled that it is ready via the
141  * `ready_cb`.  Clients can also use #GCC_is_ready() to check if the
142  * connection is right now ready for transmission.
143  *
144  * @param cc connection identification
145  * @param msg message to transmit
146  */
147 void
148 GCC_transmit (struct CadetConnection *cc,
149               const struct GNUNET_MessageHeader *msg)
150 {
151   GNUNET_assert (0); // FIXME
152 }
153
154
155 /**
156  * Obtain the path used by this connection.
157  *
158  * @param cc connection
159  * @return path to @a cc
160  */
161 struct CadetPeerPath *
162 GCC_get_path (struct CadetConnection *cc)
163 {
164   return cc->path;
165 }
166
167
168 /**
169  * Obtain unique ID for the connection.
170  *
171  * @param cc connection.
172  * @return unique number of the connection
173  */
174 const struct GNUNET_CADET_ConnectionTunnelIdentifier *
175 GCC_get_id (struct CadetConnection *cc)
176 {
177   GNUNET_assert (0); // FIXME
178   return NULL;
179 }
180
181
182 /**
183  * Log connection info.
184  *
185  * @param cc connection
186  * @param level Debug level to use.
187  */
188 void
189 GCC_debug (struct CadetConnection *cc,
190            enum GNUNET_ErrorType level)
191 {
192 }