diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-11-22 15:49:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-11-22 15:49:49 +0000 |
commit | c2d88b4c711713ee4d5511cb30142aa4c7738548 (patch) | |
tree | f2d6c6059e12ed80ef0ec2276d383e8f566b2de4 /src | |
parent | 71896114a4f9c2bd7eb1c3f67cc7ba23d6522152 (diff) | |
download | gnunet-c2d88b4c711713ee4d5511cb30142aa4c7738548.tar.gz gnunet-c2d88b4c711713ee4d5511cb30142aa4c7738548.zip |
starting to use stream in fs
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/fs/Makefile.am | 4 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs.c | 3 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_stream.c | 219 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_stream.h | 42 | ||||
-rw-r--r-- | src/include/gnunet_applications.h | 4 | ||||
-rw-r--r-- | src/include/gnunet_stream_lib.h | 1 | ||||
-rw-r--r-- | src/stream/stream_api.c | 7 |
8 files changed, 278 insertions, 4 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 08b93efb0..9a240c8c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -52,11 +52,11 @@ SUBDIRS = \ | |||
52 | dht \ | 52 | dht \ |
53 | hostlist \ | 53 | hostlist \ |
54 | topology \ | 54 | topology \ |
55 | fs \ | ||
56 | regex \ | 55 | regex \ |
57 | mesh \ | 56 | mesh \ |
58 | lockmanager \ | 57 | lockmanager \ |
59 | stream \ | 58 | stream \ |
59 | fs \ | ||
60 | $(LINUX_DIR) \ | 60 | $(LINUX_DIR) \ |
61 | $(MINGW_DIR) \ | 61 | $(MINGW_DIR) \ |
62 | integration-tests \ | 62 | integration-tests \ |
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index f7af07682..419e878d6 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -164,13 +164,15 @@ gnunet_service_fs_SOURCES = \ | |||
164 | gnunet-service-fs_pe.c gnunet-service-fs_pe.h \ | 164 | gnunet-service-fs_pe.c gnunet-service-fs_pe.h \ |
165 | gnunet-service-fs_pr.c gnunet-service-fs_pr.h \ | 165 | gnunet-service-fs_pr.c gnunet-service-fs_pr.h \ |
166 | gnunet-service-fs_push.c gnunet-service-fs_push.h \ | 166 | gnunet-service-fs_push.c gnunet-service-fs_push.h \ |
167 | gnunet-service-fs_put.c gnunet-service-fs_put.h | 167 | gnunet-service-fs_put.c gnunet-service-fs_put.h \ |
168 | gnunet-service-fs_stream.c gnunet-service-fs_sream.h | ||
168 | gnunet_service_fs_LDADD = \ | 169 | gnunet_service_fs_LDADD = \ |
169 | $(top_builddir)/src/fs/libgnunetfs.la \ | 170 | $(top_builddir)/src/fs/libgnunetfs.la \ |
170 | $(top_builddir)/src/dht/libgnunetdht.la \ | 171 | $(top_builddir)/src/dht/libgnunetdht.la \ |
171 | $(top_builddir)/src/block/libgnunetblock.la \ | 172 | $(top_builddir)/src/block/libgnunetblock.la \ |
172 | $(top_builddir)/src/datastore/libgnunetdatastore.la \ | 173 | $(top_builddir)/src/datastore/libgnunetdatastore.la \ |
173 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 174 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
175 | $(top_builddir)/src/stream/libgnunetstream.la \ | ||
174 | $(top_builddir)/src/ats/libgnunetats.la \ | 176 | $(top_builddir)/src/ats/libgnunetats.la \ |
175 | $(top_builddir)/src/core/libgnunetcore.la \ | 177 | $(top_builddir)/src/core/libgnunetcore.la \ |
176 | $(top_builddir)/src/util/libgnunetutil.la \ | 178 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index a129288ab..3a8a076f6 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include "gnunet-service-fs_pr.h" | 46 | #include "gnunet-service-fs_pr.h" |
47 | #include "gnunet-service-fs_push.h" | 47 | #include "gnunet-service-fs_push.h" |
48 | #include "gnunet-service-fs_put.h" | 48 | #include "gnunet-service-fs_put.h" |
49 | #include "gnunet-service-fs_stream.h" | ||
49 | #include "fs.h" | 50 | #include "fs.h" |
50 | 51 | ||
51 | /** | 52 | /** |
@@ -439,6 +440,7 @@ handle_start_search (void *cls, struct GNUNET_SERVER_Client *client, | |||
439 | static void | 440 | static void |
440 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 441 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
441 | { | 442 | { |
443 | GSF_stream_stop (); | ||
442 | if (NULL != GSF_core) | 444 | if (NULL != GSF_core) |
443 | { | 445 | { |
444 | GNUNET_CORE_disconnect (GSF_core); | 446 | GNUNET_CORE_disconnect (GSF_core); |
@@ -595,6 +597,7 @@ main_init (struct GNUNET_SERVER_Handle *server, | |||
595 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters, | 597 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters, |
596 | NULL); | 598 | NULL); |
597 | datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); | 599 | datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); |
600 | GSF_stream_start (); | ||
598 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 601 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
599 | NULL); | 602 | NULL); |
600 | return GNUNET_OK; | 603 | return GNUNET_OK; |
diff --git a/src/fs/gnunet-service-fs_stream.c b/src/fs/gnunet-service-fs_stream.c new file mode 100644 index 000000000..befa90dd5 --- /dev/null +++ b/src/fs/gnunet-service-fs_stream.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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 fs/gnunet-service-fs_stream.c | ||
23 | * @brief non-anonymous file-transfer | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - limit # concurrent clients, timeout for read | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_constants.h" | ||
31 | #include "gnunet_util_lib.h" | ||
32 | #include "gnunet_stream_lib.h" | ||
33 | #include "gnunet_protocols.h" | ||
34 | #include "gnunet_applications.h" | ||
35 | #include "gnunet-service-fs.h" | ||
36 | #include "gnunet-service-fs_stream.h" | ||
37 | |||
38 | /** | ||
39 | * Information we keep around for each active streaming client. | ||
40 | */ | ||
41 | struct StreamClient | ||
42 | { | ||
43 | /** | ||
44 | * DLL | ||
45 | */ | ||
46 | struct StreamClient *next; | ||
47 | |||
48 | /** | ||
49 | * DLL | ||
50 | */ | ||
51 | struct StreamClient *prev; | ||
52 | |||
53 | /** | ||
54 | * Socket for communication. | ||
55 | */ | ||
56 | struct GNUNET_STREAM_Socket *socket; | ||
57 | |||
58 | /** | ||
59 | * Handle for active read operation, or NULL. | ||
60 | */ | ||
61 | struct GNUNET_STREAM_IOReadHandle *rh; | ||
62 | |||
63 | /** | ||
64 | * Handle for active write operation, or NULL. | ||
65 | */ | ||
66 | struct GNUNET_STREAM_IOWriteHandle *wh; | ||
67 | |||
68 | /** | ||
69 | * Size of the last write that was initiated. | ||
70 | */ | ||
71 | size_t reply_size; | ||
72 | |||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Listen socket for incoming requests. | ||
78 | */ | ||
79 | static struct GNUNET_STREAM_ListenSocket *listen_socket; | ||
80 | |||
81 | /** | ||
82 | * Head of DLL of stream clients. | ||
83 | */ | ||
84 | static struct StreamClient *sc_head; | ||
85 | |||
86 | /** | ||
87 | * Tail of DLL of stream clients. | ||
88 | */ | ||
89 | static struct StreamClient *sc_tail; | ||
90 | |||
91 | |||
92 | /** | ||
93 | * We're done with a particular client, clean up. | ||
94 | * | ||
95 | * @param sc client to clean up | ||
96 | */ | ||
97 | static void | ||
98 | terminate_stream (struct StreamClient *sc) | ||
99 | { | ||
100 | if (NULL != sc->rh) | ||
101 | GNUNET_STREAM_io_read_cancel (sc->rh); | ||
102 | if (NULL != sc->wh) | ||
103 | GNUNET_STREAM_io_write_cancel (sc->wh); | ||
104 | GNUNET_STREAM_close (sc->socket); | ||
105 | GNUNET_CONTAINER_DLL_remove (sc_head, | ||
106 | sc_tail, | ||
107 | sc); | ||
108 | GNUNET_free (sc); | ||
109 | } | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Functions of this signature are called whenever data is available from the | ||
114 | * stream. | ||
115 | * | ||
116 | * @param cls the closure from GNUNET_STREAM_read | ||
117 | * @param status the status of the stream at the time this function is called | ||
118 | * @param data traffic from the other side | ||
119 | * @param size the number of bytes available in data read; will be 0 on timeout | ||
120 | * @return number of bytes of processed from 'data' (any data remaining should be | ||
121 | * given to the next time the read processor is called). | ||
122 | */ | ||
123 | static size_t | ||
124 | process_request (void *cls, | ||
125 | enum GNUNET_STREAM_Status status, | ||
126 | const void *data, | ||
127 | size_t size) | ||
128 | { | ||
129 | struct StreamClient *sc = cls; | ||
130 | |||
131 | sc->rh = NULL; | ||
132 | switch (status) | ||
133 | { | ||
134 | case GNUNET_STREAM_OK: | ||
135 | // fixme: handle request... | ||
136 | break; | ||
137 | case GNUNET_STREAM_TIMEOUT: | ||
138 | case GNUNET_STREAM_SHUTDOWN: | ||
139 | case GNUNET_STREAM_SYSERR: | ||
140 | case GNUNET_STREAM_BROKEN: | ||
141 | terminate_stream (sc); | ||
142 | return size; | ||
143 | default: | ||
144 | GNUNET_break (0); | ||
145 | return size; | ||
146 | } | ||
147 | sc->rh = GNUNET_STREAM_read (sc->socket, | ||
148 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
149 | &process_request, | ||
150 | sc); | ||
151 | return size; | ||
152 | } | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Functions of this type are called upon new stream connection from other peers | ||
157 | * or upon binding error which happen when the app_port given in | ||
158 | * GNUNET_STREAM_listen() is already taken. | ||
159 | * | ||
160 | * @param cls the closure from GNUNET_STREAM_listen | ||
161 | * @param socket the socket representing the stream; NULL on binding error | ||
162 | * @param initiator the identity of the peer who wants to establish a stream | ||
163 | * with us; NULL on binding error | ||
164 | * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the | ||
165 | * stream (the socket will be invalid after the call) | ||
166 | */ | ||
167 | static int | ||
168 | accept_cb (void *cls, | ||
169 | struct GNUNET_STREAM_Socket *socket, | ||
170 | const struct GNUNET_PeerIdentity *initiator) | ||
171 | { | ||
172 | struct StreamClient *sc; | ||
173 | |||
174 | if (NULL == socket) | ||
175 | return GNUNET_SYSERR; | ||
176 | sc = GNUNET_malloc (sizeof (struct StreamClient)); | ||
177 | sc->socket = socket; | ||
178 | sc->rh = GNUNET_STREAM_read (sc->socket, | ||
179 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
180 | &process_request, | ||
181 | sc); | ||
182 | GNUNET_CONTAINER_DLL_insert (sc_head, | ||
183 | sc_tail, | ||
184 | sc); | ||
185 | return GNUNET_OK; | ||
186 | } | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Initialize subsystem for non-anonymous file-sharing. | ||
191 | */ | ||
192 | void | ||
193 | GSF_stream_start () | ||
194 | { | ||
195 | listen_socket = GNUNET_STREAM_listen (GSF_cfg, | ||
196 | GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER, | ||
197 | &accept_cb, NULL, | ||
198 | GNUNET_STREAM_OPTION_END); | ||
199 | } | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Shutdown subsystem for non-anonymous file-sharing. | ||
204 | */ | ||
205 | void | ||
206 | GSF_stream_stop () | ||
207 | { | ||
208 | struct StreamClient *sc; | ||
209 | |||
210 | while (NULL != (sc = sc_head)) | ||
211 | terminate_stream (sc); | ||
212 | if (NULL != listen_socket) | ||
213 | { | ||
214 | GNUNET_STREAM_listen_close (listen_socket); | ||
215 | listen_socket = NULL; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | /* end of gnunet-service-fs_stream.c */ | ||
diff --git a/src/fs/gnunet-service-fs_stream.h b/src/fs/gnunet-service-fs_stream.h new file mode 100644 index 000000000..daa617290 --- /dev/null +++ b/src/fs/gnunet-service-fs_stream.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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 fs/gnunet-service-fs_stream.h | ||
23 | * @brief non-anonymous file-transfer | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef GNUNET_SERVICE_FS_STREAM_H | ||
27 | #define GNUNET_SERVICE_FS_STREAM_H | ||
28 | |||
29 | /** | ||
30 | * Initialize subsystem for non-anonymous file-sharing. | ||
31 | */ | ||
32 | void | ||
33 | GSF_stream_start (void); | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Shutdown subsystem for non-anonymous file-sharing. | ||
38 | */ | ||
39 | void | ||
40 | GSF_stream_stop (void); | ||
41 | |||
42 | #endif | ||
diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h index 1e9db3e72..142194ec0 100644 --- a/src/include/gnunet_applications.h +++ b/src/include/gnunet_applications.h | |||
@@ -50,6 +50,10 @@ extern "C" | |||
50 | */ | 50 | */ |
51 | #define GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER 2 | 51 | #define GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER 2 |
52 | 52 | ||
53 | /** | ||
54 | * Transfer of blocks for non-anonymmous file-sharing. | ||
55 | */ | ||
56 | #define GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER 3 | ||
53 | 57 | ||
54 | /** | 58 | /** |
55 | * Internet IPv4 gateway (any TCP/UDP/ICMP). | 59 | * Internet IPv4 gateway (any TCP/UDP/ICMP). |
diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h index 5d5307f5f..b7e3e4ce2 100644 --- a/src/include/gnunet_stream_lib.h +++ b/src/include/gnunet_stream_lib.h | |||
@@ -66,6 +66,7 @@ enum GNUNET_STREAM_Status | |||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * An error resulted in an unusable stream | 68 | * An error resulted in an unusable stream |
69 | * FIXME: status code unused? | ||
69 | */ | 70 | */ |
70 | GNUNET_STREAM_BROKEN | 71 | GNUNET_STREAM_BROKEN |
71 | }; | 72 | }; |
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index fd2f86e51..46f7abb47 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -34,7 +34,6 @@ | |||
34 | * @author Sree Harsha Totakura | 34 | * @author Sree Harsha Totakura |
35 | */ | 35 | */ |
36 | 36 | ||
37 | |||
38 | #include "platform.h" | 37 | #include "platform.h" |
39 | #include "gnunet_common.h" | 38 | #include "gnunet_common.h" |
40 | #include "gnunet_crypto_lib.h" | 39 | #include "gnunet_crypto_lib.h" |
@@ -1918,6 +1917,8 @@ handle_receive_close (struct GNUNET_STREAM_Socket *socket, | |||
1918 | that that stream has been shutdown */ | 1917 | that that stream has been shutdown */ |
1919 | if (NULL != socket->write_handle) | 1918 | if (NULL != socket->write_handle) |
1920 | { | 1919 | { |
1920 | // FIXME: this breaks if 'write_cont' decides to | ||
1921 | // call SOCKET_close! | ||
1921 | if (NULL != socket->write_handle->write_cont) | 1922 | if (NULL != socket->write_handle->write_cont) |
1922 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, | 1923 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, |
1923 | GNUNET_STREAM_SHUTDOWN, 0); | 1924 | GNUNET_STREAM_SHUTDOWN, 0); |
@@ -2040,6 +2041,8 @@ handle_close (struct GNUNET_STREAM_Socket *socket, | |||
2040 | that that stream has been shutdown */ | 2041 | that that stream has been shutdown */ |
2041 | if (NULL != socket->write_handle) | 2042 | if (NULL != socket->write_handle) |
2042 | { | 2043 | { |
2044 | // FIXME: this breaks if 'write_cont' decides to | ||
2045 | // call SOCKET_close! | ||
2043 | if (NULL != socket->write_handle->write_cont) | 2046 | if (NULL != socket->write_handle->write_cont) |
2044 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, | 2047 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, |
2045 | GNUNET_STREAM_SHUTDOWN, 0); | 2048 | GNUNET_STREAM_SHUTDOWN, 0); |
@@ -3543,11 +3546,11 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3543 | case STATE_RECEIVE_CLOSE_WAIT: | 3546 | case STATE_RECEIVE_CLOSE_WAIT: |
3544 | case STATE_CLOSED: | 3547 | case STATE_CLOSED: |
3545 | case STATE_CLOSE_WAIT: | 3548 | case STATE_CLOSE_WAIT: |
3546 | proc (proc_cls, GNUNET_STREAM_SHUTDOWN, NULL, 0); | ||
3547 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3549 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3548 | "%s: %s() END\n", | 3550 | "%s: %s() END\n", |
3549 | GNUNET_i2s (&socket->other_peer), | 3551 | GNUNET_i2s (&socket->other_peer), |
3550 | __func__); | 3552 | __func__); |
3553 | proc (proc_cls, GNUNET_STREAM_SHUTDOWN, NULL, 0); | ||
3551 | return NULL; | 3554 | return NULL; |
3552 | default: | 3555 | default: |
3553 | break; | 3556 | break; |