- gcc
- clang
before_script:
+ - sudo rm /etc/apt/sources.list.d/travis_ci_zeromq3-source.list
- sudo apt-get update
- - sudo apt-get install libboost-all-dev libtolua-dev bc libcdb-dev libnet-dns-perl unbound-host ldnsutils dnsutils bind9utils libtool libcdb-dev xmlto dblatex links asciidoc ruby-json ruby-sqlite3 rubygems libcurl4-openssl-dev ruby1.9.1 socat time
+ - sudo apt-get install libboost-all-dev libtolua-dev bc libcdb-dev libnet-dns-perl unbound-host ldnsutils dnsutils bind9utils libtool libcdb-dev xmlto dblatex links asciidoc ruby-json ruby-sqlite3 rubygems libcurl4-openssl-dev ruby1.9.1 socat time libzmq1 libzmq-dev pkg-config
- sudo update-alternatives --set ruby /usr/bin/ruby1.9.1
- - sudo gem install bundler --no-rdoc --no-ri --bindir /usr/local/bin
+ - gem install bundler --no-rdoc --no-ri
- cd regression-tests
- wget http://s3.amazonaws.com/alexa-static/top-1m.csv.zip
- unzip top-1m.csv.zip
- cd ..
- cd modules/remotebackend
- - sudo bundle install
+ - ruby -S bundle install
- cd ../..
script:
- ./bootstrap
- - ./configure --with-modules='bind gmysql gpgsql gsqlite3 mydns tinydns remote random' --enable-unit-tests --enable-remotebackend-http --enable-tools
+ - ./configure --with-modules='bind gmysql gpgsql gsqlite3 mydns tinydns remote random' --enable-unit-tests --enable-remotebackend-http --enable-tools --enable-remotebackend-zeromq
- make dist
- make -j 4
- make -j 4 check
- ./start-test-stop 5300 remotebackend-pipe-dnssec
- ./start-test-stop 5300 remotebackend-unix
- ./start-test-stop 5300 remotebackend-unix-dnssec
+ - ./start-test-stop 5300 remotebackend-http
+ - ./start-test-stop 5300 remotebackend-http-dnssec
+ - ./start-test-stop 5300 remotebackend-zeromq
+ - ./start-test-stop 5300 remotebackend-zeromq-dnssec
- THRESHOLD=90 TRACE=no ./recursor-test 5300
- cd ../regression-tests.nobackend/
- ./runtests
AC_SUBST(REMOTEBACKEND_HTTP)
fi
+AC_ARG_ENABLE(remotebackend_zeromq, AS_HELP_STRING([--enable-remotebackend-zeromq],[enable ZeroMQ connector for remotebackend]),[enable_remotebackend_zeromq=yes], [enable_remotebackend_zeromq=no])
+AC_MSG_CHECKING(whether to enable ZeroMQ connector in remotebackend)
+AC_MSG_RESULT($enable_remotebackend_zeromq)
+AM_CONDITIONAL(REMOTEBACKEND_HTTP,test x"$enable_remotebackend_zeromq" = "xyes")
+if test "x$enable_remotebackend_zeromq" = "xyes"
+then
+ PKG_CHECK_MODULES(LIBZMQ, libzmq, HAVE_LIBZMQ=yes, AC_MSG_ERROR([Could not find libzmq]))
+ REMOTEBACKEND_ZEROMQ=yes
+ AC_SUBST(LIBZMQ_LIBS)
+ AC_SUBST(LIBZMQ_CFLAGS)
+ AC_DEFINE(HAVE_LIBZMQ,1,[If we have libzmq])
+ AC_DEFINE(REMOTEBACKEND_ZEROMQ,1,[If we want ZeroMQ connector])
+ AC_SUBST(REMOTEBACKEND_ZEROMQ)
+fi
+
AC_MSG_CHECKING(whether we should build static binaries)
AC_ARG_ENABLE(static-binaries, AS_HELP_STRING([--enable-static-binaries],[Build static binaries]),
test_remotebackend_unix
test_remotebackend_json
test_remotebackend_post
+test_remotebackend_zeromq
source "https://rubygems.org"
gem "webrick"
+gem "zeromqrb"
+gem "sqlite3"
GEM
remote: https://rubygems.org/
specs:
+ ffi (1.9.3)
+ ffi-rzmq (1.0.3)
+ ffi
+ sqlite3 (1.3.8)
webrick (1.3.1)
+ zeromqrb (0.1.1)
+ ffi-rzmq (~> 1.0)
PLATFORMS
ruby
DEPENDENCIES
+ sqlite3
webrick
+ zeromqrb
# install .lib/libremotebackend.so.0.0.0 @libdir@
#endif
-EXTRA_DIST=OBJECTFILES OBJECTLIBS testrunner.sh unittest_http.rb unittest_json.rb unittest_pipe.rb unittest_post.rb unittest.rb Gemfile Gemfile.lock
-EXTRA_PROGRAMS=test_remotebackend_pipe test_remotebackend_unix test_remotebackend_http test_remotebackend_post test_remotebackend_json
+EXTRA_DIST=OBJECTFILES OBJECTLIBS testrunner.sh unittest_http.rb unittest_json.rb unittest_pipe.rb unittest_zeromq.rb unittest_post.rb unittest.rb Gemfile Gemfile.lock
+EXTRA_PROGRAMS=test_remotebackend_pipe test_remotebackend_unix test_remotebackend_http test_remotebackend_post test_remotebackend_json test_remotebackend_zeromq
EXTRA_LTLIBRARIES=libtestremotebackend.la
clean-local:
lib_LTLIBRARIES = libremotebackend.la
-libremotebackend_la_SOURCES=remotebackend.hh remotebackend.cc unixconnector.cc httpconnector.cc pipeconnector.cc
+libremotebackend_la_SOURCES=remotebackend.hh remotebackend.cc unixconnector.cc httpconnector.cc pipeconnector.cc zmqconnector.cc
libremotebackend_la_LDFLAGS=-module -avoid-version
-libremotebackend_la_LIBADD=$(LIBCURL_LIBS)
+libremotebackend_la_LIBADD=$(LIBCURL_LIBS) $(LIBZMQ_LIBS)
-TESTS_ENVIRONMENT = env BOOST_TEST_LOG_LEVEL=message REMOTEBACKEND_HTTP=$(REMOTEBACKEND_HTTP) ./testrunner.sh
-TESTS=test_remotebackend_pipe test_remotebackend_unix test_remotebackend_http test_remotebackend_post test_remotebackend_json
+TESTS_ENVIRONMENT = env BOOST_TEST_LOG_LEVEL=message REMOTEBACKEND_HTTP=$(REMOTEBACKEND_HTTP) REMOTEBACKEND_ZEROMQ==$(REMOTEBACKEND_ZEROMQ) ./testrunner.sh
+TESTS=test_remotebackend_pipe test_remotebackend_unix test_remotebackend_http test_remotebackend_post test_remotebackend_json test_remotebackend_zeromq
BUILT_SOURCES=../../pdns/dnslabeltext.cc
../../pdns/aes/aescpp.h ../../pdns/dns.hh ../../pdns/dns.cc ../../pdns/json.hh ../../pdns/json.cc \
../../pdns/aes/aescrypt.c ../../pdns/aes/aes.h ../../pdns/aes/aeskey.c ../../pdns/aes/aes_modes.c ../../pdns/aes/aesopt.h \
../../pdns/aes/aestab.c ../../pdns/aes/aestab.h ../../pdns/aes/brg_endian.h ../../pdns/aes/brg_types.h \
- remotebackend.hh remotebackend.cc unixconnector.cc httpconnector.cc pipeconnector.cc
+ remotebackend.hh remotebackend.cc unixconnector.cc httpconnector.cc pipeconnector.cc zmqconnector.cc
-libtestremotebackend_la_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(POLARSSL_CFLAGS) $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-libtestremotebackend_la_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(POLARSSL_CFLAGS) $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
+libtestremotebackend_la_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(POLARSSL_CFLAGS) $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+libtestremotebackend_la_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(POLARSSL_CFLAGS) $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
test_remotebackend_pipe_SOURCES=test-remotebackend.cc test-remotebackend-pipe.cc test-remotebackend-keys.hh
test_remotebackend_unix_SOURCES=test-remotebackend.cc test-remotebackend-unix.cc test-remotebackend-keys.hh
test_remotebackend_http_SOURCES=test-remotebackend.cc test-remotebackend-http.cc test-remotebackend-keys.hh
test_remotebackend_post_SOURCES=test-remotebackend.cc test-remotebackend-post.cc test-remotebackend-keys.hh
test_remotebackend_json_SOURCES=test-remotebackend.cc test-remotebackend-json.cc test-remotebackend-keys.hh
+test_remotebackend_zeromq_SOURCES=test-remotebackend.cc test-remotebackend-zeromq.cc test-remotebackend-keys.hh
-test_remotebackend_pipe_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_pipe_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_pipe_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS)
+test_remotebackend_pipe_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_pipe_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_pipe_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
-test_remotebackend_unix_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_unix_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_unix_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS)
+test_remotebackend_unix_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_unix_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_unix_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
-test_remotebackend_http_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_http_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_http_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS)
+test_remotebackend_http_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_http_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_http_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
-test_remotebackend_post_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_post_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_post_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS)
+test_remotebackend_post_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_post_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_post_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
+
+test_remotebackend_json_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_json_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_json_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
+
+test_remotebackend_zeromq_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_zeromq_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) $(LIBZMQ_CFLAGS) -g -O0 -I../../pdns
+test_remotebackend_zeromq_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS) $(LIBZMQ_LIBS)
-test_remotebackend_json_CFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_json_CXXFLAGS=$(BOOST_CPPFLAGS) @THREADFLAGS@ $(LIBCURL_CFLAGS) -g -O0 -I../../pdns
-test_remotebackend_json_LDADD=libtestremotebackend.la @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(BOOST_SERIALIZATION_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) @LIBDL@ $(POLARSSL_LIBS) $(LIBCURL_LIBS)
-remotebackend.lo unixconnector.lo httpconnector.lo pipeconnector.lo
+remotebackend.lo unixconnector.lo httpconnector.lo pipeconnector.lo zmqconnector.lo
-$(LIBCURL_LIBS)
+$(LIBCURL_LIBS) $(LIBZMQ_LIBS)
#!/usr/bin/ruby
require 'rubygems'
+require 'bundler/setup'
require 'json'
## this is an example stub for remote backend
gem 'webrick'
gem 'sqlite3'
+gem 'zeromqrb'
GEM
remote: https://rubygems.org/
specs:
- sqlite3 (1.3.6)
+ ffi (1.9.3)
+ ffi-rzmq (1.0.3)
+ ffi
+ sqlite3 (1.3.8)
webrick (1.3.1)
+ zeromqrb (0.1.1)
+ ffi-rzmq (~> 1.0)
PLATFORMS
ruby
DEPENDENCIES
sqlite3
webrick
+ zeromqrb
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/env ruby
+require 'rubygems'
require 'json'
require 'sqlite3'
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/env ruby
require "rubygems"
-#require "bundler/setup"
+require 'bundler/setup'
require "webrick"
require "../modules/remotebackend/regression-tests/dnsbackend"
require "../modules/remotebackend/regression-tests/backend"
-#!/usr/bin/ruby1.9.1
-
+#!/usr/bin/env ruby
+require "rubygems"
+require 'bundler/setup'
require 'json'
require '../modules/remotebackend/regression-tests/backend'
--- /dev/null
+#!/usr/bin/ruby1.9.1
+
+#!/usr/bin/env ruby
+require "rubygems"
+require 'bundler/setup'
+require 'json'
+require 'zero_mq'
+require '../modules/remotebackend/regression-tests/backend'
+
+h = Handler.new("../modules/remotebackend/regression-tests/remote.sqlite3")
+
+f = File.open "/tmp/tmp.txt","a"
+
+begin
+ context = ZeroMQ::Context.new
+ socket = context.socket ZMQ::REP
+ socket.setsockopt(ZMQ::HWM, 1000)
+ socket.bind("ipc:///tmp/pdns.0")
+
+ while(true) do
+ line = ""
+ rc = socket.recv_string line
+ f.puts line
+ # expect json
+ input = {}
+ line = line.strip
+ next if line.empty?
+ begin
+ input = JSON.parse(line)
+ method = "do_#{input["method"].downcase}"
+ args = input["parameters"] || []
+
+ if h.respond_to?(method.to_sym) == false
+ res = false
+ elsif args.size > 0
+ res, log = h.send(method,args)
+ else
+ res, log = h.send(method)
+ end
+ socket.send_string ({:result => res, :log => log}).to_json, 0
+ f.puts({:result => res, :log => log}).to_json
+ rescue JSON::ParserError
+ socket.send_string ({:result => false, :log => "Cannot parse input #{line}"}).to_json
+ next
+ end
+ end
+rescue SystemExit, Interrupt
+end
this->connector = new HTTPConnector(options);
#else
throw PDNSException("Invalid connection string: http connector support not enabled. Recompile with --enable-remotebackend-http");
+#endif
+ } else if (type == "zeromq") {
+#ifdef REMOTEBACKEND_ZEROMQ
+ this->connector = new ZeroMQConnector(options);
+#else
+ throw PDNSException("Invalid connection string: zeromq connector support not enabled. Recompile with --enable-remotebackend-zeromq");
#endif
} else if (type == "pipe") {
this->connector = new PipeConnector(options);
#ifdef REMOTEBACKEND_HTTP
#include <curl/curl.h>
#endif
-
+#ifdef REMOTEBACKEND_ZEROMQ
+#include <zmq.hpp>
+#endif
#define JSON_GET(obj,val,def) (obj.HasMember(val)?obj["" val ""]:def)
#define JSON_ADD_MEMBER(obj, name, val, alloc) { rapidjson::Value __xval; __xval = val; obj.AddMember(name, __xval, alloc); }
};
#endif
+#ifdef REMOTEBACKEND_ZEROMQ
+class ZeroMQConnector: public Connector {
+ public:
+ ZeroMQConnector(std::map<std::string,std::string> options);
+ virtual ~ZeroMQConnector();
+ virtual int send_message(const rapidjson::Document &input);
+ virtual int recv_message(rapidjson::Document &output);
+ private:
+ void connect();
+ std::string d_endpoint;
+ int d_timeout;
+ int d_timespent;
+ std::map<std::string,std::string> d_options;
+ zmq::context_t d_ctx;
+ zmq::socket_t d_sock;
+};
+#endif
+
class PipeConnector: public Connector {
public:
--- /dev/null
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_MODULE unit
+
+#include <boost/test/unit_test.hpp>
+#include <boost/assign/list_of.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
+#include "pdns/namespaces.hh"
+#include <pdns/dns.hh>
+#include <pdns/dnsbackend.hh>
+#include <pdns/dnspacket.hh>
+#include <pdns/ueberbackend.hh>
+#include <pdns/pdnsexception.hh>
+#include <pdns/logger.hh>
+#include <pdns/arguments.hh>
+#include "pdns/dnsrecords.hh"
+#include <boost/lexical_cast.hpp>
+#include <rapidjson/rapidjson.h>
+#include <rapidjson/document.h>
+#include "pdns/json.hh"
+#include "pdns/statbag.hh"
+#include "pdns/packetcache.hh"
+
+StatBag S;
+PacketCache PC;
+ArgvMap &arg()
+{
+ static ArgvMap arg;
+ return arg;
+};
+
+class RemoteLoader
+{
+ public:
+ RemoteLoader();
+};
+
+DNSBackend *be;
+
+#ifdef REMOTEBACKEND_ZEROMQ
+
+struct RemotebackendSetup {
+ RemotebackendSetup() {
+ be = 0;
+ try {
+ // setup minimum arguments
+ ::arg().set("module-dir")="";
+ new RemoteLoader();
+ BackendMakers().launch("remote");
+ // then get us a instance of it
+ ::arg().set("remote-connection-string")="zeromq:endpoint=tcp://127.0.0.1:43622";
+ ::arg().set("remote-dnssec")="yes";
+ be = BackendMakers().all()[0];
+ // load few record types to help out
+ SOARecordContent::report();
+ NSRecordContent::report();
+ ARecordContent::report();
+ } catch (PDNSException &ex) {
+ BOOST_TEST_MESSAGE("Cannot start remotebackend: " << ex.reason );
+ };
+ }
+ ~RemotebackendSetup() { }
+};
+
+BOOST_GLOBAL_FIXTURE( RemotebackendSetup );
+
+#else
+
+#include <iostream>
+
+int main(void) {
+ std::cout << "No HTTP support in remotebackend - skipping test" << std::endl;
+ return 0;
+}
+
+#endif
webrick_pid=""
socat_pid=""
+zeromq_pid=""
socat=/usr/bin/socat
function start_web() {
fi
}
+function start_zeromq() {
+ if [ x"$REMOTEBACKEND_ZEROMQ" == "xyes" ]; then
+ ./unittest_zeromq.rb &
+ zeromq_pid=$!
+ # need to wait a moment
+ sleep 5
+ fi
+}
+
+function stop_zeromq() {
+ if [ ! -z "$zeromq_pid" ]; then
+ kill -TERM $zeromq_pid
+ # wait a moment for it to die
+ i=0
+ while [ $i -lt 5 ]; do
+ sleep 1
+ kill -0 $zeromq_pid 2>/dev/null
+ if [ $? -ne 0 ]; then break; fi
+ let i=i+1
+ done
+ kill -0 $zeromq_pid 2>/dev/null
+ if [ $? -eq 0 ]; then kill -9 $zeromq_pid; fi
+ fi
+}
+
function start_unix() {
if [ ! -x $socat ]; then
echo "Cannot find socat - cannot test (non-fatal)"
rv=$?
stop_web
;;
+ test_remotebackend_zeromq)
+ start_zeromq
+ ./test_remotebackend_zeromq
+ rv=$?
+ stop_zeromq
+ ;;
*)
echo "Usage: $0 test_remotebackend_(pipe|http|post|json)"
;;
require 'rubygems'
+require 'bundler/setup'
require 'json'
# define a simple $domain
#!/usr/bin/env ruby
+require 'rubygems'
+require 'bundler/setup'
require 'json'
require 'thread'
-require "rubygems"
-require "webrick"
-require "./unittest"
+require 'webrick'
+require './unittest'
class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, dnsbackend)
#!/usr/bin/env ruby
+require 'rubygems'
+require 'bundler/setup'
require 'json'
require 'thread'
-require "rubygems"
-require "webrick"
-require "./unittest"
+require 'webrick'
+require './unittest'
class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, dnsbackend)
#!/usr/bin/env ruby
require 'rubygems'
+require 'bundler/setup'
require 'json'
require './unittest'
#!/usr/bin/env ruby
+require 'rubygems'
+require 'bundler/setup'
require 'json'
require 'thread'
-require "rubygems"
-require "webrick"
-require "./unittest"
+require 'webrick'
+require './unittest'
class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, dnsbackend)
--- /dev/null
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'bundler/setup'
+require 'json'
+require 'zero_mq'
+require './unittest'
+
+h = Handler.new()
+f = File.open "/tmp/tmp.txt","a"
+
+begin
+ context = ZeroMQ::Context.new
+ socket = context.socket ZMQ::REP
+ socket.setsockopt(ZMQ::HWM, 1000)
+ socket.bind("tcp://127.0.0.1:43622")
+
+ print "[#{Time.now.to_s}] ZeroMQ unit test responder running\n"
+
+ while(true) do
+ line = ""
+ rc = socket.recv_string line
+ f.puts line
+ # expect json
+ input = {}
+ line = line.strip
+ next if line.empty?
+ begin
+ input = JSON.parse(line)
+ method = "do_#{input["method"].downcase}"
+ args = input["parameters"] || []
+
+ if h.respond_to?(method.to_sym) == false
+ res = false
+ elsif args.size > 0
+ res, log = h.send(method,args)
+ else
+ res, log = h.send(method)
+ end
+ socket.send_string ({:result => res, :log => log}).to_json, 0
+ f.puts({:result => res, :log => log}).to_json
+ rescue JSON::ParserError
+ socket.send_string ({:result => false, :log => "Cannot parse input #{line}"}).to_json
+ next
+ end
+ end
+rescue SystemExit, Interrupt
+end
+
+print "[#{Time.now.to_s}] ZeroMQ unit test responder ended\n"
--- /dev/null
+#include "remotebackend.hh"
+#ifdef REMOTEBACKEND_ZEROMQ
+
+#include <sys/socket.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <boost/foreach.hpp>
+#include <sstream>
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/writer.h"
+
+ZeroMQConnector::ZeroMQConnector(std::map<std::string,std::string> options) : d_ctx(1), d_sock(d_ctx, ZMQ_REQ) {
+ rapidjson::Value val;
+ rapidjson::Document init,res;
+
+ // lookup timeout, target and stuff
+ if (options.count("endpoint") == 0) {
+ L<<Logger::Error<<"Cannot find 'endpoint' option in connection string"<<endl;
+ throw new PDNSException("Cannot find 'endpoint' option in connection string");
+ }
+ this->d_endpoint = options.find("endpoint")->second;
+ this->d_options = options;
+ this->d_timeout=2000;
+
+ if (options.find("timeout") != options.end()) {
+ this->d_timeout = boost::lexical_cast<int>(options.find("timeout")->second);
+ }
+
+ d_sock.connect(d_endpoint.c_str());
+
+ init.SetObject();
+ val = "initialize";
+
+ init.AddMember("method",val, init.GetAllocator());
+ val.SetObject();
+ init.AddMember("parameters", val, init.GetAllocator());
+
+ for(std::map<std::string,std::string>::iterator i = options.begin(); i != options.end(); i++) {
+ val = i->second.c_str();
+ init["parameters"].AddMember(i->first.c_str(), val, init.GetAllocator());
+ }
+
+ this->send(init);
+ if (this->recv(res)==false) {
+ L<<Logger::Error<<"Failed to initialize zeromq"<<std::endl;
+ }
+};
+
+ZeroMQConnector::~ZeroMQConnector() {
+};
+
+int ZeroMQConnector::send_message(const rapidjson::Document &input) {
+ std::string line;
+ line = makeStringFromDocument(input);
+ zmq::message_t message(line.size()+1);
+ line.copy(reinterpret_cast<char*>(message.data()), line.size());
+ reinterpret_cast<char*>(message.data())[line.size()]=0;
+
+ try {
+ zmq_pollitem_t item;
+ item.socket = d_sock;
+ item.events = ZMQ_POLLOUT;
+ // poll until it's sent or timeout is spent. try to leave
+ // leave few cycles for read. just in case.
+ for(d_timespent = 0; d_timespent < d_timeout-5; d_timespent++) {
+ if (zmq::poll(&item, 1, 1000)>0) {
+ if (d_sock.send(message, 0) == false) {
+ // message was not sent
+ L<<Logger::Error<<"Cannot send to " << this->d_endpoint << ": " << errno;
+ return 0;
+ }
+ return line.size();
+ }
+ }
+ } catch (std::exception &ex) {
+ L<<Logger::Error<<"Cannot send to " << this->d_endpoint << ": " << ex.what();
+ throw new PDNSException(ex.what());
+ }
+
+ return 0;
+}
+
+int ZeroMQConnector::recv_message(rapidjson::Document &output) {
+ int rv = 0;
+ // try to receive message
+ zmq_pollitem_t item;
+ rapidjson::GenericReader<rapidjson::UTF8<> , rapidjson::MemoryPoolAllocator<> > r;
+ zmq::message_t message;
+
+ item.socket = d_sock;
+ item.events = ZMQ_POLLIN;
+
+ try {
+ // do zmq::poll few times
+ // d_timespent should always be initialized by send_message, recv should never
+ // be called without send first.
+ for(; d_timespent < d_timeout; d_timespent++) {
+ if (zmq::poll(&item, 1, 1000)>0) {
+ // we have an event
+ if ((item.revents & ZMQ_POLLIN) == ZMQ_POLLIN) {
+ char *data;
+ // read something
+ if (d_sock.recv(&message, 0) && message.size() > 0) {
+ data = new char[message.size()+1];
+ // convert it into json
+ memcpy(data, message.data(), message.size());
+ data[message.size()]=0;
+ rapidjson::StringStream ss(data);
+ output.ParseStream<0>(ss);
+ delete [] data;
+ if (output.HasParseError() == false)
+ rv = message.size();
+ else
+ L<<Logger::Error<<"Cannot parse JSON reply from " << this->d_endpoint;
+ break;
+ } else if (errno == EAGAIN) { continue; // try again }
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ } catch (std::exception &ex) {
+ L<<Logger::Error<<"Cannot receive from " << this->d_endpoint << ": " << ex.what();
+ throw new PDNSException(ex.what());
+ }
+
+ return rv;
+}
+
+#endif
opendbx-sqlite3
tinydns
mydns
-remotebackend-pipe remotebackend-unix remotebackend-http
-remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec
+remotebackend-pipe remotebackend-unix remotebackend-http remotebackend-zeromq
+remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec remotebackend-zeromq-dnssec
#remotebackend-pipe-nsec3 remotebackend-unix-nsec3 remotebackend-http-nsec3
#remotebackend-pipe-nsec3-narrow remotebackend-unix-nsec3-narrow remotebackend-http-nsec3-narrow
done
set -e
;;
+ zeromq)
+ connstr="zeromq:endpoint=ipc:///tmp/pdns.0"
+ $testsdir/zeromq-backend.rb &
+ echo $! > pdns-remotebackend.pid
+ ;;
unix)
connstr="unix:path=/tmp/remote.socket"
socat unix-listen:/tmp/remote.socket,fork exec:$testsdir/unix-backend.rb &