~ubuntu-branches/ubuntu/intrepid/gnunet/intrepid

« back to all changes in this revision

Viewing changes to src/applications/dht/module/dstore.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-31 17:40:18 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080131174018-sfnbb8wv7p4nmut1
Tags: 0.7.3-2ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/rules:
    = Make use of code from cdbs' clean-la.mk file to clear the
      dependency_libs field in all .la files in the gnunet-dev package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
      This file is part of GNUnet
3
 
      (C) 2004, 2005, 2006 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 module/dstore.c
23
 
 * @brief entries in local DHT
24
 
 * @author Simo Viitanen, Christian Grothoff
25
 
 */
26
 
 
27
 
#include "platform.h"
28
 
#include "dstore.h"
29
 
#include "gnunet_blockstore.h"
30
 
 
31
 
#define DEBUG_DSTORE NO
32
 
 
33
 
static Dstore_ServiceAPI *dstore;
34
 
 
35
 
static CoreAPIForApplication *coreAPI;
36
 
 
37
 
/**
38
 
 * Lookup in the local datastore.
39
 
 * @return total number of results found
40
 
 */
41
 
int
42
 
dht_store_get (const HashCode512 * key,
43
 
               unsigned int type, ResultHandler handler, void *cls)
44
 
{
45
 
  return dstore->get (key, type, handler, cls);
46
 
}
47
 
 
48
 
/**
49
 
 * Store the given data in the local datastore.
50
 
 */
51
 
void
52
 
dht_store_put (unsigned int type,
53
 
               const HashCode512 * key,
54
 
               cron_t discard_time, unsigned int size, const char *data)
55
 
{
56
 
  if (discard_time < get_time ())
57
 
    {
58
 
#if DEBUG_DSTORE
59
 
      GE_LOG (coreAPI->ectx,
60
 
              GE_DEBUG | GE_REQUEST | GE_DEVELOPER,
61
 
              "Content already expired (%llu < %llu), will not keep.\n",
62
 
              discard_time, get_time ());
63
 
#endif
64
 
      return;
65
 
    }
66
 
  dstore->put (key, type, discard_time, size, data);
67
 
}
68
 
 
69
 
/**
70
 
 * Initialize dstore DHT component.
71
 
 *
72
 
 * @param capi the core API
73
 
 * @return OK on success
74
 
 */
75
 
int
76
 
init_dht_store (size_t max_size, CoreAPIForApplication * capi)
77
 
{
78
 
  coreAPI = capi;
79
 
  dstore = coreAPI->requestService ("dstore");
80
 
  if (dstore == NULL)
81
 
    return SYSERR;
82
 
  return OK;
83
 
}
84
 
 
85
 
/**
86
 
 * Shutdown dstore DHT component.
87
 
 *
88
 
 * @return OK on success
89
 
 */
90
 
int
91
 
done_dht_store ()
92
 
{
93
 
  coreAPI->releaseService (dstore);
94
 
  coreAPI = NULL;
95
 
  dstore = NULL;
96
 
  return OK;
97
 
}
98
 
 
99
 
/* end of dstore.c */