157f4ef225c729a56d79d61d7f75c2d03f51be0a
[oweals/gnunet.git] / src / fs / fs.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 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 2, 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/fs.c
23  * @brief main FS functions
24  * @author Christian Grothoff
25  */
26
27 #include "platform.h"
28 #include "gnunet_fs_service.h"
29 #include "fs.h"
30
31
32 /**
33  * Setup a connection to the file-sharing service.
34  *
35  * @param sched scheduler to use
36  * @param cfg configuration to use
37  * @param client_name unique identifier for this client 
38  * @param upcb function to call to notify about FS actions
39  * @param upcb_cls closure for upcb
40  */
41 struct GNUNET_FS_Handle *
42 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
43                  const struct GNUNET_CONFIGURATION_Handle *cfg,
44                  const char *client_name,
45                  GNUNET_FS_ProgressCallback upcb,
46                  void *upcb_cls)
47 {
48   struct GNUNET_FS_Handle *ret;
49   struct GNUNET_CLIENT_Connection *client;
50   
51   client = GNUNET_CLIENT_connect (sched,
52                                   "fs",
53                                   cfg);
54   if (NULL == client)
55     return NULL;
56   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Handle));
57   ret->sched = sched;
58   ret->cfg = cfg;
59   ret->client_name = GNUNET_strdup (client_name);
60   ret->upcb = upcb;
61   ret->upcb_cls = upcb_cls;
62   ret->client = client;
63   // FIXME: setup receive-loop with client
64   // FIXME: deserialize state; use client-name to find master-directory!
65   // Deserialize-Upload:
66   // * read FNs for upload FIs, deserialize each
67   // Deserialize Search:
68   // * read search queries
69   // * for each query, read file with search results
70   // * for each search result with active download, deserialize download
71   // * for each directory search result, check for active downloads of contents
72   // Deserialize Download:
73   // * always part of search???
74   // Deserialize Unindex:
75   // * read FNs for unindex with progress offset
76   return ret;
77 }
78
79
80 /**
81  * Close our connection with the file-sharing service.
82  * The callback given to GNUNET_FS_start will no longer be
83  * called after this function returns.
84  *
85  * @param h handle that was returned from GNUNET_FS_start
86  */                    
87 void 
88 GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
89 {
90   // FIXME: serialize state!? (or is it always serialized???)
91   // FIXME: terminate receive-loop with client  
92   GNUNET_CLIENT_disconnect (h->client);
93   GNUNET_free (h->client_name);
94   GNUNET_free (h);
95 }
96
97
98 /* end of fs.c */