Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
613a57b5
Commit
613a57b5
authored
Apr 03, 2013
by
JINMEI Tatuya
Browse files
[master] Merge branch 'trac2833'
parents
ce9fdb30
ec52d37b
Changes
24
Hide whitespace changes
Inline
Side-by-side
src/bin/auth/tests/auth_srv_unittest.cc
View file @
613a57b5
...
...
@@ -78,7 +78,6 @@ using namespace isc::asiolink;
using
namespace
isc
::
testutils
;
using
namespace
isc
::
server_common
::
portconfig
;
using
namespace
isc
::
auth
::
unittest
;
using
isc
::
datasrc
::
memory
::
ZoneTableSegment
;
using
isc
::
UnitTestUtil
;
using
boost
::
scoped_ptr
;
using
isc
::
auth
::
statistics
::
Counters
;
...
...
@@ -264,8 +263,6 @@ updateDatabase(AuthSrv& server, const char* params) {
installDataSrcClientLists
(
server
,
configureDataSource
(
config
));
}
// Note: if with_static is set to true, the corresponding test should be
// disabled in case of USE_STATIC_LINK.
void
updateInMemory
(
AuthSrv
&
server
,
const
char
*
origin
,
const
char
*
filename
,
bool
with_static
=
true
)
...
...
@@ -280,8 +277,9 @@ updateInMemory(AuthSrv& server, const char* origin, const char* filename,
"}]"
;
if
(
with_static
)
{
spec_txt
+=
",
\"
CH
\"
: [{"
"
\"
type
\"
:
\"
static
\"
,"
"
\"
params
\"
:
\"
"
+
string
(
STATIC_DSRC_FILE
)
+
"
\"
"
"
\"
type
\"
:
\"
MasterFiles
\"
,"
"
\"
cache-enable
\"
: true,"
"
\"
params
\"
: {
\"
BIND
\"
:
\"
"
+
string
(
STATIC_DSRC_FILE
)
+
"
\"
}"
"}]"
;
}
spec_txt
+=
"}"
;
...
...
@@ -290,14 +288,13 @@ updateInMemory(AuthSrv& server, const char* origin, const char* filename,
installDataSrcClientLists
(
server
,
configureDataSource
(
config
));
}
// Note: tests using this function should be disabled in case of
// USE_STATIC_LINK.
void
updateBuiltin
(
AuthSrv
&
server
)
{
const
ConstElementPtr
config
(
Element
::
fromJSON
(
"{"
"
\"
CH
\"
: [{"
"
\"
type
\"
:
\"
static
\"
,"
"
\"
params
\"
:
\"
"
+
string
(
STATIC_DSRC_FILE
)
+
"
\"
"
"
\"
type
\"
:
\"
MasterFiles
\"
,"
"
\"
cache-enable
\"
: true,"
"
\"
params
\"
: {
\"
BIND
\"
:
\"
"
+
string
(
STATIC_DSRC_FILE
)
+
"
\"
}"
"}]}"
));
installDataSrcClientLists
(
server
,
configureDataSource
(
config
));
}
...
...
@@ -750,11 +747,7 @@ TEST_F(AuthSrvTest, notify) {
checkStatisticsCounters
(
stats_after
,
expect
);
}
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_notifyForCHClass
)
{
#else
TEST_F
(
AuthSrvTest
,
notifyForCHClass
)
{
#endif
// Same as the previous test, but for the CH RRClass (so we install the
// builtin (static) data source.
updateBuiltin
(
server
);
...
...
@@ -1003,11 +996,7 @@ TEST_F(AuthSrvTest, notifyNotAuthNoClass) {
// Try giving the server a TSIG signed request and see it can anwer signed as
// well
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_TSIGSigned
)
{
// Needs builtin
#else
TEST_F
(
AuthSrvTest
,
TSIGSigned
)
{
#endif
// Prepare key, the client message, etc
updateBuiltin
(
server
);
const
TSIGKey
key
(
"key:c2VjcmV0Cg==:hmac-sha1"
);
...
...
@@ -1065,11 +1054,7 @@ TEST_F(AuthSrvTest, TSIGSigned) {
// authoritative only server in terms of performance, and it's quite likely
// we need to drop it for the authoritative server implementation.
// At that point we can drop this test, too.
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_builtInQueryViaDNSServer
)
{
#else
TEST_F
(
AuthSrvTest
,
builtInQueryViaDNSServer
)
{
#endif
updateBuiltin
(
server
);
UnitTestUtil
::
createRequestMessage
(
request_message
,
Opcode
::
QUERY
(),
default_qid
,
Name
(
"VERSION.BIND."
),
...
...
@@ -1097,11 +1082,7 @@ TEST_F(AuthSrvTest, builtInQueryViaDNSServer) {
// The most primitive check: checking the result of the processMessage()
// method
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_builtInQuery
)
{
#else
TEST_F
(
AuthSrvTest
,
builtInQuery
)
{
#endif
updateBuiltin
(
server
);
UnitTestUtil
::
createRequestMessage
(
request_message
,
Opcode
::
QUERY
(),
default_qid
,
Name
(
"VERSION.BIND."
),
...
...
@@ -1118,11 +1099,7 @@ TEST_F(AuthSrvTest, builtInQuery) {
}
// Same type of test as builtInQueryViaDNSServer but for an error response.
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_iqueryViaDNSServer
)
{
// Needs builtin
#else
TEST_F
(
AuthSrvTest
,
iqueryViaDNSServer
)
{
// Needs builtin
#endif
TEST_F
(
AuthSrvTest
,
iqueryViaDNSServer
)
{
updateBuiltin
(
server
);
createDataFromFile
(
"iquery_fromWire.wire"
);
(
*
server
.
getDNSLookupProvider
())(
*
io_message
,
parse_message
,
...
...
@@ -1233,11 +1210,7 @@ TEST_F(AuthSrvTest, updateWithInMemoryClient) {
opcode
.
getCode
(),
QR_FLAG
,
1
,
0
,
0
,
0
);
}
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_queryWithInMemoryClientNoDNSSEC
)
{
#else
TEST_F
(
AuthSrvTest
,
queryWithInMemoryClientNoDNSSEC
)
{
#endif
// In this example, we do simple check that query is handled from the
// query handler class, and confirm it returns no error and a non empty
// answer section. Detailed examination on the response content
...
...
@@ -1253,11 +1226,7 @@ TEST_F(AuthSrvTest, queryWithInMemoryClientNoDNSSEC) {
opcode
.
getCode
(),
QR_FLAG
|
AA_FLAG
,
1
,
1
,
2
,
1
);
}
#ifdef USE_STATIC_LINK
TEST_F
(
AuthSrvTest
,
DISABLED_queryWithInMemoryClientDNSSEC
)
{
#else
TEST_F
(
AuthSrvTest
,
queryWithInMemoryClientDNSSEC
)
{
#endif
// Similar to the previous test, but the query has the DO bit on.
// The response should contain RRSIGs, and should have more RRs than
// the previous case.
...
...
@@ -1272,14 +1241,7 @@ TEST_F(AuthSrvTest, queryWithInMemoryClientDNSSEC) {
opcode
.
getCode
(),
QR_FLAG
|
AA_FLAG
,
1
,
2
,
3
,
3
);
}
TEST_F
(
AuthSrvTest
,
#ifdef USE_STATIC_LINK
DISABLED_chQueryWithInMemoryClient
#else
chQueryWithInMemoryClient
#endif
)
{
TEST_F
(
AuthSrvTest
,
chQueryWithInMemoryClient
)
{
// Set up the in-memory
updateInMemory
(
server
,
"example."
,
CONFIG_INMEMORY_EXAMPLE
);
...
...
@@ -1752,9 +1714,7 @@ public:
real_list
,
ThrowWhen
throw_when
,
bool
isc_exception
,
ConstRRsetPtr
fake_rrset
=
ConstRRsetPtr
())
:
ConfigurableClientList
(
RRClass
::
IN
()),
real_
(
real_list
),
config_
(
Element
::
fromJSON
(
"{}"
)),
ztable_segment_
(
ZoneTableSegment
::
create
(
*
config_
,
RRClass
::
IN
()))
real_
(
real_list
)
{
BOOST_FOREACH
(
const
DataSourceInfo
&
info
,
real_
->
getDataSources
())
{
const
isc
::
datasrc
::
DataSourceClientPtr
...
...
@@ -1766,13 +1726,13 @@ public:
data_sources_
.
push_back
(
DataSourceInfo
(
client
.
get
(),
isc
::
datasrc
::
DataSourceClientContainerPtr
(),
false
,
RRClass
::
IN
(),
ztable_segment_
,
""
));
boost
::
shared_ptr
<
isc
::
datasrc
::
internal
::
CacheConfig
>
(),
RRClass
::
IN
(),
""
));
}
}
private:
const
boost
::
shared_ptr
<
isc
::
datasrc
::
ConfigurableClientList
>
real_
;
const
ConstElementPtr
config_
;
boost
::
shared_ptr
<
ZoneTableSegment
>
ztable_segment_
;
vector
<
isc
::
datasrc
::
DataSourceClientPtr
>
clients_
;
};
...
...
@@ -1782,14 +1742,7 @@ private:
//
// Set the proxies to never throw, this should have the same result as
// queryWithInMemoryClientNoDNSSEC, and serves to test the two proxy classes
TEST_F
(
AuthSrvTest
,
#ifdef USE_STATIC_LINK
DISABLED_queryWithInMemoryClientProxy
#else
queryWithInMemoryClientProxy
#endif
)
{
TEST_F
(
AuthSrvTest
,
queryWithInMemoryClientProxy
)
{
// Set real inmem client to proxy
updateInMemory
(
server
,
"example."
,
CONFIG_INMEMORY_EXAMPLE
);
boost
::
shared_ptr
<
isc
::
datasrc
::
ConfigurableClientList
>
list
;
...
...
@@ -1836,14 +1789,7 @@ setupThrow(AuthSrv& server, ThrowWhen throw_when, bool isc_exception,
mgr
.
setDataSrcClientLists
(
lists
);
}
TEST_F
(
AuthSrvTest
,
#ifdef USE_STATIC_LINK
DISABLED_queryWithThrowingProxyServfails
#else
queryWithThrowingProxyServfails
#endif
)
{
TEST_F
(
AuthSrvTest
,
queryWithThrowingProxyServfails
)
{
// Test the common cases, all of which should simply return SERVFAIL
// Use THROW_NEVER as end marker
ThrowWhen
throws
[]
=
{
THROW_AT_FIND_ZONE
,
...
...
@@ -1867,14 +1813,7 @@ TEST_F(AuthSrvTest,
// Throw isc::Exception in getClass(). (Currently?) getClass is not called
// in the processMessage path, so this should result in a normal answer
TEST_F
(
AuthSrvTest
,
#ifdef USE_STATIC_LINK
DISABLED_queryWithInMemoryClientProxyGetClass
#else
queryWithInMemoryClientProxyGetClass
#endif
)
{
TEST_F
(
AuthSrvTest
,
queryWithInMemoryClientProxyGetClass
)
{
createDataFromFile
(
"nsec3query_nodnssec_fromWire.wire"
);
setupThrow
(
server
,
THROW_AT_GET_CLASS
,
true
);
...
...
@@ -1887,14 +1826,7 @@ TEST_F(AuthSrvTest,
opcode
.
getCode
(),
QR_FLAG
|
AA_FLAG
,
1
,
1
,
2
,
1
);
}
TEST_F
(
AuthSrvTest
,
#ifdef USE_STATIC_LINK
DISABLED_queryWithThrowingInToWire
#else
queryWithThrowingInToWire
#endif
)
{
TEST_F
(
AuthSrvTest
,
queryWithThrowingInToWire
)
{
// Set up a faked data source. It will return an empty RRset for the
// query.
ConstRRsetPtr
empty_rrset
(
new
RRset
(
Name
(
"foo.example"
),
...
...
src/bin/cfgmgr/plugins/datasrc.spec.pre.in
View file @
613a57b5
...
...
@@ -18,9 +18,9 @@
],
"CH": [
{
"type": "
static
",
"cache-enable":
fals
e,
"params": "@@STATIC_ZONE_FILE@@"
"type": "
MasterFiles
",
"cache-enable":
tru
e,
"params":
{"BIND":
"@@STATIC_ZONE_FILE@@"
}
}
]
},
...
...
src/bin/cfgmgr/plugins/tests/Makefile.am
View file @
613a57b5
...
...
@@ -11,6 +11,8 @@ LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/cryp
endif
# test using command-line arguments, so use check-local target instead of TESTS
# We need to set B10_FROM_BUILD as some of the tests need to create lock file
# for logging.
check-local
:
if
ENABLE_PYTHON_COVERAGE
touch
$(abs_top_srcdir)/.coverage
...
...
@@ -20,6 +22,7 @@ endif
for
pytest
in
$(PYTESTS)
;
do
\
echo Running test
:
$$pytest ;
\
B10_TEST_PLUGIN_DIR=$(abs_srcdir)/..:$(abs_builddir)/..
\
B10_FROM_BUILD=$(abs_top_builddir)
\
PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_builddir)/src/bin/cfgmgr:$(abs_top_builddir)/src/lib/dns/python/.libs
\
$(LIBRARY_PATH_PLACEHOLDER)
\
$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ;
\
...
...
src/lib/datasrc/Makefile.am
View file @
613a57b5
...
...
@@ -39,10 +39,11 @@ libb10_datasrc_la_SOURCES += master_loader_callbacks.h
libb10_datasrc_la_SOURCES
+=
master_loader_callbacks.cc
libb10_datasrc_la_SOURCES
+=
rrset_collection_base.h rrset_collection_base.cc
libb10_datasrc_la_SOURCES
+=
zone_loader.h zone_loader.cc
libb10_datasrc_la_SOURCES
+=
cache_config.h cache_config.cc
nodist_libb10_datasrc_la_SOURCES
=
datasrc_messages.h datasrc_messages.cc
libb10_datasrc_la_LDFLAGS
=
-no-undefined
-version-info
1:0:1
pkglib_LTLIBRARIES
=
sqlite3_ds.la
static_ds.la
pkglib_LTLIBRARIES
=
sqlite3_ds.la
sqlite3_ds_la_SOURCES
=
sqlite3_accessor.h sqlite3_accessor.cc
sqlite3_ds_la_SOURCES
+=
sqlite3_accessor_link.cc
...
...
@@ -53,12 +54,6 @@ sqlite3_ds_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
sqlite3_ds_la_LIBADD
+=
libb10-datasrc.la
sqlite3_ds_la_LIBADD
+=
$(SQLITE_LIBS)
static_ds_la_SOURCES
=
static_datasrc_link.cc
static_ds_la_SOURCES
+=
static_datasrc.h
static_ds_la_LDFLAGS
=
-module
-avoid-version
static_ds_la_LIBADD
=
$(top_builddir)
/src/lib/exceptions/libb10-exceptions.la
static_ds_la_LIBADD
+=
libb10-datasrc.la
libb10_datasrc_la_LIBADD
=
$(top_builddir)
/src/lib/exceptions/libb10-exceptions.la
libb10_datasrc_la_LIBADD
+=
$(top_builddir)
/src/lib/dns/libb10-dns++.la
libb10_datasrc_la_LIBADD
+=
$(top_builddir)
/src/lib/log/libb10-log.la
...
...
src/lib/datasrc/cache_config.cc
0 → 100644
View file @
613a57b5
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <datasrc/cache_config.h>
#include <datasrc/client.h>
#include <datasrc/memory/load_action.h>
#include <dns/name.h>
#include <cc/data.h>
#include <exceptions/exceptions.h>
#include <map>
#include <string>
using
namespace
isc
::
data
;
namespace
isc
{
namespace
datasrc
{
namespace
internal
{
namespace
{
bool
getEnabledFromConf
(
const
Element
&
conf
)
{
return
(
conf
.
contains
(
"cache-enable"
)
&&
conf
.
get
(
"cache-enable"
)
->
boolValue
());
}
std
::
string
getSegmentTypeFromConf
(
const
Element
&
conf
)
{
// If cache-zones is not explicitly configured, use the default type.
// (Ideally we should retrieve the default from the spec).
if
(
!
conf
.
contains
(
"cache-type"
))
{
return
(
"local"
);
}
return
(
conf
.
get
(
"cache-type"
)
->
stringValue
());
}
}
CacheConfig
::
CacheConfig
(
const
std
::
string
&
datasrc_type
,
const
DataSourceClient
*
datasrc_client
,
const
Element
&
datasrc_conf
,
bool
allowed
)
:
enabled_
(
allowed
&&
getEnabledFromConf
(
datasrc_conf
)),
segment_type_
(
getSegmentTypeFromConf
(
datasrc_conf
)),
datasrc_client_
(
datasrc_client
)
{
ConstElementPtr
params
=
datasrc_conf
.
get
(
"params"
);
if
(
!
params
)
{
params
.
reset
(
new
NullElement
());
}
if
(
datasrc_type
==
"MasterFiles"
)
{
if
(
datasrc_client_
)
{
isc_throw
(
InvalidParameter
,
"data source client is given for MasterFiles"
);
}
if
(
!
enabled_
)
{
isc_throw
(
CacheConfigError
,
"The cache must be enabled for the MasterFiles type"
);
}
typedef
std
::
map
<
std
::
string
,
ConstElementPtr
>
ZoneToFile
;
const
ZoneToFile
&
zone_to_file
=
params
->
mapValue
();
ZoneToFile
::
const_iterator
const
it_end
=
zone_to_file
.
end
();
for
(
ZoneToFile
::
const_iterator
it
=
zone_to_file
.
begin
();
it
!=
it_end
;
++
it
)
{
zone_config_
[
dns
::
Name
(
it
->
first
)]
=
it
->
second
->
stringValue
();
}
}
else
{
if
(
!
datasrc_client_
)
{
isc_throw
(
InvalidParameter
,
"data source client is missing for data source type: "
<<
datasrc_type
);
}
if
(
!
enabled_
)
{
return
;
}
if
(
!
datasrc_conf
.
contains
(
"cache-zones"
))
{
isc_throw
(
NotImplemented
,
"Auto-detection of zones "
"to cache is not yet implemented, supply "
"cache-zones parameter"
);
// TODO: Auto-detect list of all zones in the
// data source.
}
const
ConstElementPtr
zones
=
datasrc_conf
.
get
(
"cache-zones"
);
for
(
size_t
i
=
0
;
i
<
zones
->
size
();
++
i
)
{
const
dns
::
Name
zone_name
(
zones
->
get
(
i
)
->
stringValue
());
if
(
!
zone_config_
.
insert
(
Zones
::
value_type
(
zone_name
,
""
)).
second
)
{
isc_throw
(
CacheConfigError
,
"Duplicate cache zone: "
<<
zone_name
);
}
}
}
}
}
// namespace internal
}
// namespace datasrc
}
// namespace isc
src/lib/datasrc/cache_config.h
0 → 100644
View file @
613a57b5
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef DATASRC_CACHE_CONFIG_H
#define DATASRC_CACHE_CONFIG_H
#include <exceptions/exceptions.h>
#include <dns/name.h>
#include <cc/data.h>
#include <datasrc/memory/load_action.h>
#include <boost/noncopyable.hpp>
#include <map>
#include <string>
namespace
isc
{
namespace
datasrc
{
class
DataSourceClient
;
namespace
internal
{
/// \brief Exception thrown for configuration error related to in-memory cache.
class
CacheConfigError
:
public
Exception
{
public:
CacheConfigError
(
const
char
*
file
,
size_t
line
,
const
char
*
what
)
:
Exception
(
file
,
line
,
what
)
{}
};
/// \brief Configuration for in-memory cache of a data source.
///
/// This class understands and validates the configuration parameters for
/// \c DataSourceClient related to in-memory cache, and converts it to native,
/// type-safe objects for the convenience of the user of this class.
/// Specifically, it allows the user to get the underlying memory segment
/// type for the cache as a string and to iterate over zone names to be
/// cached in memory.
///
/// It also provides unified interface for getting \c memory::LoadAction
/// object that can be used for loading zones, regardless of the underlying
/// data source properties, i.e., whether it's special "MasterFiles" type
/// or other generic data sources.
/// NOTE: this part will be done in #2834.
///
/// This class is publicly defined so it can be tested directly, but
/// it's essentially private to the \c ConfigurableClientList class.
/// It's therefore defined in an "internal" namespace, and isn't expected
/// to be used by other classes or user applications. Likewise, this file
/// is not expected to be installed with other publicly usable header files.
///
/// It's defined as noncopyable, simply because it's not expected to be
/// copied in the intended usage for \c ConfigurableClientList. Prohibiting
/// copies will help avoid unexpected disruption due to accidental copy and
/// sharing internal resources as a result of that.
class
CacheConfig
:
boost
::
noncopyable
{
public:
/// \brief Constructor.
///
/// It performs the following validation on the given configuration:
/// - For the "MasterFiles" type
/// - datasrc_client_ must not be provided (must be null); throws
/// InvalidParameter otherwise.
/// - cache must be enabled: "cache-enable" configuration item exists
/// and is true, and allowed parameter is true, too; throws
/// CacheConfigError otherwise.
/// - "params" configuration item must be provided and of a map type,
/// and each map entry maps a string to another string; throws
/// data::TypeError otherwise.
/// - the key string of each map entry must be a valid textual
/// representation of a domain name. Otherwise corresponding
/// exception from the dns::Name class will be thrown.
/// - For other types
/// - datasrc_client_ must be provided (must not be null); throws
/// InvalidParameter otherwise.
/// - (Unless cache is disabled) "cache-zones" configuration item must
/// exist and must be a list of strings; throws data::TypeError
/// otherwise.
/// - Each string value of cache-zones entries must be a valid textual
/// representation of a domain name. Otherwise corresponding
/// exception from the dns::Name class will be thrown.
/// - Names in the list must not have duplicates;
/// throws CacheConfigError otherwise.
///
/// For other data source types than "MasterFiles", cache can be disabled.
/// In this case cache-zones configuration item is simply ignored, even
/// it contains an error that would otherwise trigger an exception.
///
/// The specified set of zones (directly in "params" in case of
/// "MasterFile", and specified in "cache-zones" for others) can be
/// empty.
///
/// This constructor also identifies the underlying memory segment type
/// used for the cache. It's given via the "cache-type" configuration
/// item if defined; otherwise it defaults to "local".
///
/// \throw InvalidParameter Program error at the caller side rather than
/// in the configuration (see above)
/// \throw CacheConfigError There is a semantics error in the given
/// configuration (see above)
/// \throw data::TypeError Invalid type of data is found in the
/// configuration (see above)
/// \throw Other Exceptions from the dns::Name class when conversion from
/// text fails (see above)
///
/// \param datasrc_type Type of data source. This must be the "type"
/// value of the data source configuration.
/// \param datasrc_client Client of the underlying data source for the
/// cache, if it's used; for MasterFiles types it's null.
/// \param datasrc_conf Configuration element for the data source.
/// This must be the value of, e.g., data_sources/classes/IN[0] of
/// BIND 10 configuration.
/// \param allowed Whether in-memory cache is allowed by the process.
/// This must be derived from the allow_cache parameter of
/// \c ConfigurableClientList::configure().
CacheConfig
(
const
std
::
string
&
datasrc_type
,
const
DataSourceClient
*
datasrc_client
,
const
data
::
Element
&
datasrc_conf
,
bool
allowed
);
/// \brief Return if the cache is enabled.
///
/// The cache is considered enabled iff the "cache-enable" configuration
/// item (given on construction) existed and was set to true, and
/// the \c allowed parameter to the constructor was true.
///
/// \throw None
bool
isEnabled
()
const
{
return
(
enabled_
);
}
/// \brief Return the memory segment type to be used for the zone table.
///
/// \throw None
const
std
::
string
&
getSegmentType
()
const
{
return
(
segment_type_
);
}
/// \todo the following definition is tentative, mainly for tests.
/// In #2834 we'll (probably) extend it to be a custom iterator so
/// the caller can iterate over the whole set of zones, loading the
/// content in memory.
typedef
std
::
map
<
dns
::
Name
,
std
::
string
>::
const_iterator
ConstZoneIterator
;
ConstZoneIterator
begin
()
const
{
return
(
zone_config_
.
begin
());
}
ConstZoneIterator
end
()
const
{
return
(
zone_config_
.
end
());
}
private:
const
bool
enabled_
;
// if the use of in-memory zone table is enabled
const
std
::
string
segment_type_
;
// client of underlying data source, will be NULL for MasterFile datasrc
const
DataSourceClient
*
datasrc_client_
;
typedef
std
::
map
<
dns
::
Name
,
std
::
string
>
Zones
;
Zones
zone_config_
;
};
}
}
}
#endif // DATASRC_CACHE_CONFIG_H
// Local Variables:
// mode: c++
// End:
src/lib/datasrc/client_list.cc
View file @
613a57b5
...
...
@@ -13,16 +13,17 @@
// PERFORMANCE OF THIS SOFTWARE.
#include "client_list.h"
#include "exceptions.h"
#include "client.h"
#include "factory.h"
#include "memory/memory_client.h"
#include "memory/zone_table_segment.h"
#include "memory/zone_writer.h"
#include "memory/zone_data_loader.h"
#include "memory/zone_data_updater.h"
#include "logger.h"
#include <datasrc/client_list.h>
#include <datasrc/exceptions.h>
#include <datasrc/client.h>
#include <datasrc/factory.h>
#include <datasrc/cache_config.h>
#include <datasrc/memory/memory_client.h>
#include <datasrc/memory/zone_table_segment.h>
#include <datasrc/memory/zone_writer.h>
#include <datasrc/memory/zone_data_loader.h>
#include <datasrc/memory/zone_data_updater.h>
#include <datasrc/logger.h>
#include <dns/masterload.h>
#include <util/memory_segment_local.h>
...
...
@@ -47,28 +48,18 @@ namespace datasrc {
ConfigurableClientList
::
DataSourceInfo
::
DataSourceInfo
(
DataSourceClient
*
data_src_client
,
const
DataSourceClientContainerPtr
&
container
,
bool
has_cache
,
const
RRClass
&
rrclass
,
const
shared_ptr
<
ZoneTableSegment
>&
segment
,
const
string
&
name
)
:
const
DataSourceClientContainerPtr
&
container
,
boost
::
shared_ptr
<
internal
::
CacheConfig
>
cache_conf
,
const
RRClass
&
rrclass
,
const
string
&
name
)
:
data_src_client_
(
data_src_client
),
container_
(
container
),
name_
(
name
)
name_
(
name
),
cache_conf_
(
cache_conf
)
{
if
(
has_cache
)
{