]> granicus.if.org Git - pdns/commitdiff
Enable zeromq for remotebackend
authorAki Tuomi <cmouse@desteem.org>
Thu, 28 Nov 2013 13:14:29 +0000 (15:14 +0200)
committerAki Tuomi <cmouse@cmouse.fi>
Mon, 9 Dec 2013 20:14:01 +0000 (22:14 +0200)
27 files changed:
.travis.yml
configure.ac
modules/remotebackend/.gitignore
modules/remotebackend/Gemfile
modules/remotebackend/Gemfile.lock
modules/remotebackend/Makefile.am
modules/remotebackend/OBJECTFILES
modules/remotebackend/OBJECTLIBS
modules/remotebackend/example.rb
modules/remotebackend/regression-tests/Gemfile
modules/remotebackend/regression-tests/Gemfile.lock
modules/remotebackend/regression-tests/backend.rb
modules/remotebackend/regression-tests/http-backend.rb
modules/remotebackend/regression-tests/pipe-backend.rb
modules/remotebackend/regression-tests/zeromq-backend.rb [new file with mode: 0755]
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
modules/remotebackend/test-remotebackend-zeromq.cc [new file with mode: 0644]
modules/remotebackend/testrunner.sh
modules/remotebackend/unittest.rb
modules/remotebackend/unittest_http.rb
modules/remotebackend/unittest_json.rb
modules/remotebackend/unittest_pipe.rb
modules/remotebackend/unittest_post.rb
modules/remotebackend/unittest_zeromq.rb [new file with mode: 0755]
modules/remotebackend/zmqconnector.cc [new file with mode: 0644]
regression-tests/start-test-stop

index 70a510a8fd29d2a649423e851060d3ff8507828e..7a51790a3591005598048819c1c7e7692d19d906 100644 (file)
@@ -3,20 +3,21 @@ compiler:
   - 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
@@ -49,6 +50,10 @@ script:
  - ./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
index 0e4dd1940ea38cae663f71626f6c2991c51892e7..066fac415b38335c9bfc560c3c31748fa8b868a5 100644 (file)
@@ -282,6 +282,21 @@ then
         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]),
index 572d122258c9649eec018f55653b0c46f534ce51..b040bc9e3ea3e16edcfc4d5ef8d75fe80f4a8080 100644 (file)
@@ -4,3 +4,4 @@ test_remotebackend_pipe
 test_remotebackend_unix
 test_remotebackend_json
 test_remotebackend_post
+test_remotebackend_zeromq
index 9eddca48fa7c4c3874f754f1d069a20dd49d918f..70af3719c0ab5b1dd268aa94da40aa24f7fa16f6 100644 (file)
@@ -1,3 +1,5 @@
 source "https://rubygems.org"
 
 gem "webrick"
+gem "zeromqrb"
+gem "sqlite3"
index b77c55326693d59466d8ec51e13c6c08bc97ad6e..44b2bee99727c78a837fc049175c0f949410e016 100644 (file)
@@ -1,10 +1,18 @@
 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
index 7a2d791080298865c48393dcc5b46533ef67d4b0..f7bf4b3d23cfa2ebe7512298bd09b57a105a860d 100644 (file)
@@ -4,8 +4,8 @@ AM_CPPFLAGS=@THREADFLAGS@ $(BOOST_CPPFLAGS) $(LIBCURL_CFLAGS) -I../../pdns/ext/r
 #       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:
@@ -13,13 +13,13 @@ 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
 
@@ -35,33 +35,39 @@ libtestremotebackend_la_SOURCES=../../pdns/dnsbackend.hh ../../pdns/dnsbackend.c
         ../../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)
index c125b8249fa9101ff474dafd22c58549e3775dd4..fa80d5461b2bd8988f158d9218832ba7d8406f9a 100644 (file)
@@ -1 +1 @@
-remotebackend.lo unixconnector.lo httpconnector.lo pipeconnector.lo
+remotebackend.lo unixconnector.lo httpconnector.lo pipeconnector.lo zmqconnector.lo
index 3030c7acf3d25aacaa480b544a440783422ab100..68e356cc0683474a9b223c555926841afa832619 100644 (file)
@@ -1 +1 @@
-$(LIBCURL_LIBS)
+$(LIBCURL_LIBS) $(LIBZMQ_LIBS)
index 3b7f2b43ee2e4956a44f9d6746bb47a5785f2373..777d31dc9ec815ecc9ecad023d125d7dec9ed0b5 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/ruby
 
 require 'rubygems'
+require 'bundler/setup'
 require 'json'
 
 ## this is an example stub for remote backend
index 5d4c4abe215f188fd6a2fbbb22a09883b3a71a48..019fc2a224c7d4da9dd714293021e186cf02fd35 100644 (file)
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
 
 gem 'webrick'
 gem 'sqlite3'
+gem 'zeromqrb'
index 6c21f3dde1557280f4d62d78dd900107cb268cc6..44b2bee99727c78a837fc049175c0f949410e016 100644 (file)
@@ -1,8 +1,13 @@
 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
@@ -10,3 +15,4 @@ PLATFORMS
 DEPENDENCIES
   sqlite3
   webrick
+  zeromqrb
index 8f859418094fb44ad43cfa0dd3860058ccd89adf..46daaadf7d4be09f9e2032621fc9984000e8ce9a 100755 (executable)
@@ -1,5 +1,6 @@
-#!/usr/bin/ruby1.9.1
+#!/usr/bin/env ruby
 
+require 'rubygems'
 require 'json'
 require 'sqlite3'
 
index 6581a12fbb60bb8e5b3f190d5ffbc780e20a9ecc..30cda13cc8a2b9cc28721ee3f786572f2d1efef4 100755 (executable)
@@ -1,6 +1,6 @@
-#!/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"
index 27f1213d370f0d5e7e9c856a75df7bac5914ce8c..f9a8467329418c3e499a8492a526c978990e48d8 100755 (executable)
@@ -1,5 +1,6 @@
-#!/usr/bin/ruby1.9.1
-
+#!/usr/bin/env ruby
+require "rubygems"
+require 'bundler/setup'
 require 'json'
 require '../modules/remotebackend/regression-tests/backend'
 
diff --git a/modules/remotebackend/regression-tests/zeromq-backend.rb b/modules/remotebackend/regression-tests/zeromq-backend.rb
new file mode 100755 (executable)
index 0000000..6c14f77
--- /dev/null
@@ -0,0 +1,48 @@
+#!/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
index 98d05821070ba01aca1e33046862d45c1305cebb..a443b729bf872fa4990b6568a28db9b71bf1c628 100644 (file)
@@ -143,6 +143,12 @@ int RemoteBackend::build() {
         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);
index b7bcb624dea90ec0cf6df34b8005718564133495..568b94f9121f3878c0d4fc0d5f7d56587c6cb764 100644 (file)
@@ -18,7 +18,9 @@
 #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); }
 
@@ -79,6 +81,24 @@ class HTTPConnector: public Connector {
 };
 #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:
 
diff --git a/modules/remotebackend/test-remotebackend-zeromq.cc b/modules/remotebackend/test-remotebackend-zeromq.cc
new file mode 100644 (file)
index 0000000..364e97a
--- /dev/null
@@ -0,0 +1,77 @@
+#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
index df312c95a11e39d8031e490be1e5c43d1249e617..1cee260f656c9add0ce22c25539089a5ae401975 100755 (executable)
@@ -2,6 +2,7 @@
 
 webrick_pid=""
 socat_pid=""
+zeromq_pid=""
 socat=/usr/bin/socat
 
 function start_web() {
@@ -32,6 +33,31 @@ function stop_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)"
@@ -92,6 +118,12 @@ case "$mode" in
     rv=$?
     stop_web
   ;;
+  test_remotebackend_zeromq)
+    start_zeromq 
+    ./test_remotebackend_zeromq
+    rv=$?
+    stop_zeromq
+  ;;
   *)
      echo "Usage: $0 test_remotebackend_(pipe|http|post|json)"
   ;;
index c44cf98dd2cca10c70b2f41f1986a5ba942c7e0e..f169a4b3ed3ea59a81d52d8c53f77069c67b7f88 100644 (file)
@@ -1,4 +1,5 @@
 require 'rubygems'
+require 'bundler/setup'
 require 'json'
 
 # define a simple $domain
index e3f32daf7d7f3a59f6db74bb36bbaa4d8af38389..3c7c34d949584b9ab37177f9c70a00e995866e28 100755 (executable)
@@ -1,10 +1,11 @@
 #!/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)
index 73f14fea520e7c324fc5a6a2af6ec327f952e841..54a3e3ba5a9828f45d92a90b1dfd704aad7b7099 100755 (executable)
@@ -1,10 +1,11 @@
 #!/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)
index 35dc30705955baf94f6eb4de58c7cf66371893c6..e95652bfdca865375e2b025d6ca4b0c797d6815d 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
 
 require 'rubygems'
+require 'bundler/setup'
 require 'json'
 require './unittest'
 
index 08ac05e5e4e60bbb9734cc66dd27bc847a81c10a..bf9b7ed93044d2710f4011c71bc573e657feac89 100755 (executable)
@@ -1,10 +1,11 @@
 #!/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)
diff --git a/modules/remotebackend/unittest_zeromq.rb b/modules/remotebackend/unittest_zeromq.rb
new file mode 100755 (executable)
index 0000000..eb9ac0c
--- /dev/null
@@ -0,0 +1,50 @@
+#!/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"
diff --git a/modules/remotebackend/zmqconnector.cc b/modules/remotebackend/zmqconnector.cc
new file mode 100644 (file)
index 0000000..3e96589
--- /dev/null
@@ -0,0 +1,131 @@
+#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
index a8bd46bbea31abf832b47be7de2cd0ff2d472e4f..51e808476cf7913cc39101a2f90949dd73cc2a62 100755 (executable)
@@ -306,8 +306,8 @@ gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3
 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
 
@@ -841,6 +841,11 @@ __EOF__
                                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 &