summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Andersson <erik@packy.se>2016-11-22 23:51:17 +0100
committerErik Andersson <erik@packy.se>2016-11-22 23:51:17 +0100
commit09abe2a091672f45ccacd6a90d0f3872b6cb6a00 (patch)
tree10a034ecdb8f876fb3829ef7eafa4c85194c82d3
parent6addd793e745d6a2a65b66249c4f36e763e142e8 (diff)
downloadocelot-09abe2a091672f45ccacd6a90d0f3872b6cb6a00.zip
ocelot-09abe2a091672f45ccacd6a90d0f3872b6cb6a00.tar.gz
ocelot-09abe2a091672f45ccacd6a90d0f3872b6cb6a00.tar.bz2
Ocelot v0.6 (r1)v0.6-r1
-rw-r--r--src/CHANGES29
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in162
-rw-r--r--src/aclocal.m4129
-rw-r--r--src/config.cpp.template2
-rwxr-xr-xsrc/config.guess28
-rw-r--r--src/config.h6
-rwxr-xr-xsrc/config.sub61
-rwxr-xr-xsrc/configure76
-rw-r--r--src/configure.ac4
-rw-r--r--src/db.cpp348
-rw-r--r--src/db.h32
-rwxr-xr-xsrc/depcomp418
-rw-r--r--src/events.cpp26
-rw-r--r--src/events.h3
-rw-r--r--src/logger.cpp34
-rw-r--r--src/logger.h26
-rw-r--r--src/misc_functions.cpp16
-rwxr-xr-xsrc/missing405
-rw-r--r--src/ocelot.cpp36
-rw-r--r--src/ocelot.h16
-rw-r--r--src/schedule.cpp9
-rw-r--r--src/schedule.h3
-rw-r--r--src/site_comm.cpp142
-rw-r--r--src/site_comm.h14
-rw-r--r--src/worker.cpp481
-rw-r--r--src/worker.h8
27 files changed, 1294 insertions, 1222 deletions
diff --git a/src/CHANGES b/src/CHANGES
new file mode 100644
index 0000000..a9df798
--- /dev/null
+++ b/src/CHANGES
@@ -0,0 +1,29 @@
+Date: Wed Feb 6 05:26:58 2013
+
+ Send special data to search engine crawlers (and other odd clients) in an
+ attempt to prevent indexing of announce URLs
+
+Date: Sat Feb 2 18:24:19 2013
+
+ Use a lighter query to update peer records in xbt_files_users if peer data
+ has not changed since its previous announcement
+
+Date: Thu Jan 31
+
+ Expire multiple tokens in a single request to the web server
+
+Date: Sat Nov 17
+
+ Print warning instead of error if someone submits an IPv6 or otherwise
+ invalid address
+
+Date: Sun Oct 7
+
+ Make flush queries slightly less spammy by moving them to the functions
+ that invoke flush threads. This makes Ocelot print all queue lengths every
+ <schedule_interval> seconds. It also fixes the problem where two threads
+ are writing to stdout at the same time
+
+Date: Fri Oct 5
+
+ Put primitive types at the beginning of the peer and torrent structs
diff --git a/src/Makefile.am b/src/Makefile.am
index e83f66d..662452d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = ocelot
-ocelot_SOURCES = config.cpp db.cpp events.cpp logger.cpp misc_functions.cpp ocelot.cpp \
+ocelot_SOURCES = config.cpp db.cpp events.cpp misc_functions.cpp ocelot.cpp \
schedule.cpp site_comm.cpp worker.cpp
AM_CPPFLAGS = -march=native -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fno-ident $(BOOST_CPPFLAGS) -I$(MYSQLPP_INC_DIR) -I$(EV_INCLUDE_DIR)
diff --git a/src/Makefile.in b/src/Makefile.in
index 9fd31ac..ee064f2 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.12.4 from Makefile.am.
+# Makefile.in generated by automake 1.13.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2012 Free Software Foundation, Inc.
@@ -51,9 +51,9 @@ POST_UNINSTALL = :
build_triplet = @build@
bin_PROGRAMS = ocelot$(EXEEXT)
subdir = .
-DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in $(top_srcdir)/configure config.guess \
- config.sub depcomp install-sh missing
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/configure $(am__configure_deps) depcomp \
+ config.guess config.sub install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_boost_base.m4 \
$(top_srcdir)/m4/ax_boost_iostreams.m4 \
@@ -71,21 +71,41 @@ CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_ocelot_OBJECTS = config.$(OBJEXT) db.$(OBJEXT) events.$(OBJEXT) \
- logger.$(OBJEXT) misc_functions.$(OBJEXT) ocelot.$(OBJEXT) \
- schedule.$(OBJEXT) site_comm.$(OBJEXT) worker.$(OBJEXT)
+ misc_functions.$(OBJEXT) ocelot.$(OBJEXT) schedule.$(OBJEXT) \
+ site_comm.$(OBJEXT) worker.$(OBJEXT)
ocelot_OBJECTS = $(am_ocelot_OBJECTS)
am__DEPENDENCIES_1 =
ocelot_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
SOURCES = $(ocelot_SOURCES)
DIST_SOURCES = $(ocelot_SOURCES)
am__can_run_installinfo = \
@@ -93,6 +113,23 @@ am__can_run_installinfo = \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
CSCOPE = cscope
@@ -116,6 +153,7 @@ am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
distcleancheck_listfiles = find . -type f -print
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
@@ -221,7 +259,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4
-ocelot_SOURCES = config.cpp db.cpp events.cpp logger.cpp misc_functions.cpp ocelot.cpp \
+ocelot_SOURCES = config.cpp db.cpp events.cpp misc_functions.cpp ocelot.cpp \
schedule.cpp site_comm.cpp worker.cpp
AM_CPPFLAGS = -march=native -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fno-ident $(BOOST_CPPFLAGS) -I$(MYSQLPP_INC_DIR) -I$(EV_INCLUDE_DIR)
@@ -273,10 +311,11 @@ install-binPROGRAMS: $(bin_PROGRAMS)
fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
- while read p p1; do if test -f $$p; \
- then echo "$$p"; echo "$$p"; else :; fi; \
+ while read p p1; do if test -f $$p \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
done | \
- sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
-e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
sed 'N;N;N;s,\n, ,g' | \
$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
@@ -297,7 +336,8 @@ uninstall-binPROGRAMS:
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
files=`for p in $$list; do echo "$$p"; done | \
sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
- -e 's/$$/$(EXEEXT)/' `; \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
test -n "$$list" || exit 0; \
echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(bindir)" && rm -f $$files
@@ -306,7 +346,7 @@ clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
ocelot$(EXEEXT): $(ocelot_OBJECTS) $(ocelot_DEPENDENCIES) $(EXTRA_ocelot_DEPENDENCIES)
@rm -f ocelot$(EXEEXT)
- $(CXXLINK) $(ocelot_OBJECTS) $(ocelot_LDADD) $(LIBS)
+ $(AM_V_CXXLD)$(CXXLINK) $(ocelot_OBJECTS) $(ocelot_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -317,7 +357,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/db.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/events.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logger.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc_functions.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ocelot.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/schedule.Po@am__quote@
@@ -325,39 +364,28 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/worker.Po@am__quote@
.cpp.o:
-@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
.cpp.obj:
-@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
-
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -369,15 +397,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$unique; \
fi; \
fi
-ctags: CTAGS
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -386,18 +410,16 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
-
cscope: cscope.files
test ! -s cscope.files \
|| $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS)
-
clean-cscope:
-rm -f cscope.files
+cscope.files: clean-cscope cscopelist
+cscopelist: cscopelist-am
-cscope.files: clean-cscope cscopelist
-
-cscopelist: $(HEADERS) $(SOURCES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP)'; \
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
@@ -681,21 +703,21 @@ uninstall-am: uninstall-binPROGRAMS
.MAKE: install-am install-strip
-.PHONY: CTAGS GTAGS all all-am am--refresh check check-am clean \
- clean-binPROGRAMS clean-cscope clean-generic cscope cscopelist \
- ctags dist dist-all dist-bzip2 dist-gzip dist-lzip dist-shar \
- dist-tarZ dist-xz dist-zip distcheck distclean \
- distclean-compile distclean-generic distclean-tags \
- distcleancheck distdir distuninstallcheck dvi dvi-am html \
- html-am info info-am install install-am install-binPROGRAMS \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-pdf \
- install-pdf-am install-ps install-ps-am install-strip \
- installcheck installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-compile \
- mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
- uninstall-am uninstall-binPROGRAMS
+.PHONY: CTAGS GTAGS TAGS all all-am am--refresh check check-am clean \
+ clean-binPROGRAMS clean-cscope clean-generic cscope \
+ cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \
+ dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \
+ distcheck distclean distclean-compile distclean-generic \
+ distclean-tags distcleancheck distdir distuninstallcheck dvi \
+ dvi-am html html-am info info-am install install-am \
+ install-binPROGRAMS install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/src/aclocal.m4 b/src/aclocal.m4
index dbac008..41aeccc 100644
--- a/src/aclocal.m4
+++ b/src/aclocal.m4
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.12.4 -*- Autoconf -*-
+# generated automatically by aclocal 1.13.1 -*- Autoconf -*-
# Copyright (C) 1996-2012 Free Software Foundation, Inc.
@@ -11,6 +11,7 @@
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
+m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
@@ -19,7 +20,7 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
-# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -31,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.12'
+[am__api_version='1.13'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.12.4], [],
+m4_if([$1], [1.13.1], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -50,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.12.4])dnl
+[AM_AUTOMAKE_VERSION([1.13.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -110,7 +111,7 @@ am_aux_dir=`cd $ac_aux_dir && pwd`
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997-2012 Free Software Foundation, Inc.
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -141,7 +142,7 @@ AC_CONFIG_COMMANDS_PRE(
Usually this means the macro was only invoked conditionally.]])
fi])])
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -332,7 +333,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
# Generate code to set up dependency tracking. -*- Autoconf -*-
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -343,7 +344,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
# ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[{
- # Autoconf 2.62 quotes --file arguments for eval, but not when files
+ # Older Autoconf quotes --file arguments for eval, but not when files
# are listed without --file. Let's play safe and only enable the eval
# if we detect the quoting.
case $CONFIG_FILES in
@@ -408,7 +409,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# Do all the work for Automake. -*- Autoconf -*-
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -429,7 +430,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# arguments mandatory, and then we can depend on a new Autoconf
# release and drop the old call support.
AC_DEFUN([AM_INIT_AUTOMAKE],
-[AC_PREREQ([2.62])dnl
+[AC_PREREQ([2.65])dnl
dnl Autoconf wants to disallow AM_ names. We explicitly allow
dnl the ones we care about.
m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
@@ -459,8 +460,7 @@ AC_SUBST([CYGPATH_W])
dnl Distinguish between old-style and new-style calls.
m4_ifval([$2],
[AC_DIAGNOSE([obsolete],
-[$0: two- and three-arguments forms are deprecated. For more info, see:
-http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_INIT_AUTOMAKE-invocation])
+ [$0: two- and three-arguments forms are deprecated.])
m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
AC_SUBST([PACKAGE], [$1])dnl
AC_SUBST([VERSION], [$2])],
@@ -514,18 +514,15 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJC],
[_AM_DEPENDENCIES([OBJC])],
[m4_define([AC_PROG_OBJC],
m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl
-dnl Support for Objective C++ was only introduced in Autoconf 2.65,
-dnl but we still cater to Autoconf 2.62.
-m4_ifdef([AC_PROG_OBJCXX],
-[AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
+AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
[_AM_DEPENDENCIES([OBJCXX])],
[m4_define([AC_PROG_OBJCXX],
- m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])])dnl
+ m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
])
-_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
-dnl The 'parallel-tests' driver may need to know about EXEEXT, so add the
-dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro
-dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_REQUIRE([AM_SILENT_RULES])dnl
+dnl The testsuite driver may need to know about EXEEXT, so add the
+dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This
+dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below.
AC_CONFIG_COMMANDS_PRE(dnl
[m4_provide_if([_AM_COMPILER_EXEEXT],
[AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
@@ -559,7 +556,7 @@ for _am_header in $config_headers :; do
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -580,7 +577,7 @@ if test x"${install_sh}" != xset; then
fi
AC_SUBST([install_sh])])
-# Copyright (C) 2003-2012 Free Software Foundation, Inc.
+# Copyright (C) 2003-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -601,7 +598,7 @@ AC_SUBST([am__leading_dot])])
# Check to see how 'make' treats includes. -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -651,7 +648,7 @@ rm -f confinc confmf
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
-# Copyright (C) 1997-2012 Free Software Foundation, Inc.
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -666,8 +663,8 @@ AC_SUBST($1)])
# AM_MISSING_HAS_RUN
# ------------------
-# Define MISSING if not defined so far and test if it supports --run.
-# If it does, set am_missing_run to use it, otherwise, to nothing.
+# Define MISSING if not defined so far and test if it is modern enough.
+# If it is, set am_missing_run to use it, otherwise, to nothing.
AC_DEFUN([AM_MISSING_HAS_RUN],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
AC_REQUIRE_AUX_FILE([missing])dnl
@@ -680,8 +677,8 @@ if test x"${MISSING+set}" != xset; then
esac
fi
# Use eval to expand $SHELL
-if eval "$MISSING --run true"; then
- am_missing_run="$MISSING --run "
+if eval "$MISSING --is-lightweight"; then
+ am_missing_run="$MISSING "
else
am_missing_run=
AC_MSG_WARN(['missing' script is too old or missing])
@@ -690,7 +687,7 @@ fi
# Helper functions for option handling. -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -721,7 +718,7 @@ AC_DEFUN([_AM_IF_OPTION],
# Check to make sure that the build environment is sane. -*- Autoconf -*-
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -802,7 +799,67 @@ AC_CONFIG_COMMANDS_PRE(
rm -f conftest.file
])
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2009-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_SILENT_RULES([DEFAULT])
+# --------------------------
+# Enable less verbose build rules; with the default set to DEFAULT
+# ("yes" being less verbose, "no" or empty being verbose).
+AC_DEFUN([AM_SILENT_RULES],
+[AC_ARG_ENABLE([silent-rules], [dnl
+AS_HELP_STRING(
+ [--enable-silent-rules],
+ [less verbose build output (undo: "make V=1")])
+AS_HELP_STRING(
+ [--disable-silent-rules],
+ [verbose build output (undo: "make V=0")])dnl
+])
+case $enable_silent_rules in @%:@ (((
+ yes) AM_DEFAULT_VERBOSITY=0;;
+ no) AM_DEFAULT_VERBOSITY=1;;
+ *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);;
+esac
+dnl
+dnl A few 'make' implementations (e.g., NonStop OS and NextStep)
+dnl do not support nested variable expansions.
+dnl See automake bug#9928 and bug#10237.
+am_make=${MAKE-make}
+AC_CACHE_CHECK([whether $am_make supports nested variables],
+ [am_cv_make_support_nested_variables],
+ [if AS_ECHO([['TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+ @$(TRUE)
+.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then
+ am_cv_make_support_nested_variables=yes
+else
+ am_cv_make_support_nested_variables=no
+fi])
+if test $am_cv_make_support_nested_variables = yes; then
+ dnl Using '$V' instead of '$(V)' breaks IRIX make.
+ AM_V='$(V)'
+ AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+ AM_V=$AM_DEFAULT_VERBOSITY
+ AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AC_SUBST([AM_V])dnl
+AM_SUBST_NOTMAKE([AM_V])dnl
+AC_SUBST([AM_DEFAULT_V])dnl
+AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
+AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
+AM_BACKSLASH='\'
+AC_SUBST([AM_BACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
+])
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -830,7 +887,7 @@ fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
-# Copyright (C) 2006-2012 Free Software Foundation, Inc.
+# Copyright (C) 2006-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -849,7 +906,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# Check how to create a tarball. -*- Autoconf -*-
-# Copyright (C) 2004-2012 Free Software Foundation, Inc.
+# Copyright (C) 2004-2013 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/src/config.cpp.template b/src/config.cpp.template
index abc3048..ccd8406 100644
--- a/src/config.cpp.template
+++ b/src/config.cpp.template
@@ -21,6 +21,8 @@ config::config() {
mysql_username = "***";
mysql_password = "***";
+ // Site communication
site_host = "localhost";
site_password = "********************************"; // MUST BE 32 CHARS
+ site_path = ""; // If the site is not running under the domain root
}
diff --git a/src/config.guess b/src/config.guess
index 68194c9..8905e54 100755
--- a/src/config.guess
+++ b/src/config.guess
@@ -2,13 +2,13 @@
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-# 2011, 2012 Free Software Foundation, Inc.
+# 2011, 2012, 2013 Free Software Foundation, Inc.
-timestamp='2012-08-14'
+timestamp='2012-12-30'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
@@ -22,19 +22,17 @@ timestamp='2012-08-14'
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-
-# Originally written by Per Bothner. Please send patches (context
-# diff format) to <config-patches@gnu.org> and include a ChangeLog
-# entry.
+# the same distribution terms that you use for the rest of that
+# program. This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
#
-# This script attempts to guess a canonical system name similar to
-# config.sub. If it succeeds, it prints the system name on stdout, and
-# exits with 0. Otherwise, it exits with 1.
+# Originally written by Per Bothner.
#
# You can get the latest version of this script from:
# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+#
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+
me=`echo "$0" | sed -e 's,.*/,,'`
@@ -55,8 +53,8 @@ GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-Free Software Foundation, Inc.
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012, 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -329,7 +327,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit ;;
- arm:riscos:*:*|arm:RISCOS:*:*)
+ arm*:riscos:*:*|arm*:RISCOS:*:*)
echo arm-unknown-riscos
exit ;;
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
diff --git a/src/config.h b/src/config.h
index 18cc953..d98ef7c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -24,10 +24,12 @@ class config {
std::string mysql_host;
std::string mysql_username;
std::string mysql_password;
-
+
+ // Site communication
std::string site_host;
std::string site_password;
-
+ std::string site_path;
+
config();
};
diff --git a/src/config.sub b/src/config.sub
index ae2965a..de08881 100755
--- a/src/config.sub
+++ b/src/config.sub
@@ -2,23 +2,19 @@
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-# 2011, 2012 Free Software Foundation, Inc.
+# 2011, 2012, 2013 Free Software Foundation, Inc.
-timestamp='2012-08-18'
+timestamp='2013-01-11'
-# This file is (in principle) common to ALL GNU software.
-# The presence of a machine in this file suggests that SOME GNU software
-# can handle that machine. It does not imply ALL GNU software can.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
@@ -26,11 +22,12 @@ timestamp='2012-08-18'
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
+# the same distribution terms that you use for the rest of that
+# program. This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
-# Please send patches to <config-patches@gnu.org>. Submit a context
-# diff and a properly formatted GNU ChangeLog entry.
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
#
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
@@ -74,8 +71,8 @@ version="\
GNU config.sub ($timestamp)
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-Free Software Foundation, Inc.
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012, 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -156,7 +153,7 @@ case $os in
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
- -apple | -axis | -knuth | -cray | -microblaze)
+ -apple | -axis | -knuth | -cray | -microblaze*)
os=
basic_machine=$1
;;
@@ -259,8 +256,10 @@ case $basic_machine in
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
- | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
- | be32 | be64 \
+ | arc \
+ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+ | avr | avr32 \
+ | be32 | be64 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx | dvp \
@@ -273,7 +272,7 @@ case $basic_machine in
| le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
- | maxq | mb | microblaze | mcore | mep | metag \
+ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
@@ -291,6 +290,7 @@ case $basic_machine in
| mipsisa64r2 | mipsisa64r2el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
+ | mipsr5900 | mipsr5900el \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
| moxie \
@@ -389,7 +389,8 @@ case $basic_machine in
| lm32-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
- | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
+ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+ | microblaze-* | microblazeel-* \
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
| mips16-* \
| mips64-* | mips64el-* \
@@ -407,6 +408,7 @@ case $basic_machine in
| mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+ | mipsr5900-* | mipsr5900el-* \
| mipstx39-* | mipstx39el-* \
| mmix-* \
| mt-* \
@@ -788,7 +790,7 @@ case $basic_machine in
basic_machine=ns32k-utek
os=-sysv
;;
- microblaze)
+ microblaze*)
basic_machine=microblaze-xilinx
;;
mingw64)
@@ -1041,7 +1043,11 @@ case $basic_machine in
basic_machine=i586-unknown
os=-pw32
;;
- rdos)
+ rdos | rdos64)
+ basic_machine=x86_64-pc
+ os=-rdos
+ ;;
+ rdos32)
basic_machine=i386-pc
os=-rdos
;;
@@ -1368,7 +1374,7 @@ case $os in
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
- | -sym* | -kopensolaris* \
+ | -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* | -aros* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
@@ -1514,9 +1520,6 @@ case $os in
-aros*)
os=-aros
;;
- -kaos*)
- os=-kaos
- ;;
-zvmoe)
os=-zvmoe
;;
diff --git a/src/configure b/src/configure
index bbf3bbd..1e343a3 100755
--- a/src/configure
+++ b/src/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for ocelot 0.5.
+# Generated by GNU Autoconf 2.69 for ocelot 0.6.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='ocelot'
PACKAGE_TARNAME='ocelot'
-PACKAGE_VERSION='0.5'
-PACKAGE_STRING='ocelot 0.5'
+PACKAGE_VERSION='0.6'
+PACKAGE_STRING='ocelot 0.6'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -664,6 +664,10 @@ CPPFLAGS
LDFLAGS
CXXFLAGS
CXX
+AM_BACKSLASH
+AM_DEFAULT_VERBOSITY
+AM_DEFAULT_V
+AM_V
am__untar
am__tar
AMTAR
@@ -728,6 +732,7 @@ SHELL'
ac_subst_files=''
ac_user_opts='
enable_option_checking
+enable_silent_rules
enable_dependency_tracking
with_boost
with_boost_libdir
@@ -1296,7 +1301,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures ocelot 0.5 to adapt to many kinds of systems.
+\`configure' configures ocelot 0.6 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1365,7 +1370,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of ocelot 0.5:";;
+ short | recursive ) echo "Configuration of ocelot 0.6:";;
esac
cat <<\_ACEOF
@@ -1373,6 +1378,8 @@ Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --enable-silent-rules less verbose build output (undo: "make V=1")
+ --disable-silent-rules verbose build output (undo: "make V=0")
--enable-dependency-tracking
do not reject slow dependency extractors
--disable-dependency-tracking
@@ -1491,7 +1498,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-ocelot configure 0.5
+ocelot configure 0.6
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1827,7 +1834,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by ocelot $as_me 0.5, which was
+It was created by ocelot $as_me 0.6, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -2175,7 +2182,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
-am__api_version='1.12'
+am__api_version='1.13'
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
@@ -2388,8 +2395,8 @@ if test x"${MISSING+set}" != xset; then
esac
fi
# Use eval to expand $SHELL
-if eval "$MISSING --run true"; then
- am_missing_run="$MISSING --run "
+if eval "$MISSING --is-lightweight"; then
+ am_missing_run="$MISSING "
else
am_missing_run=
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
@@ -2629,6 +2636,45 @@ else
fi
rmdir .tst 2>/dev/null
+# Check whether --enable-silent-rules was given.
+if test "${enable_silent_rules+set}" = set; then :
+ enableval=$enable_silent_rules;
+fi
+
+case $enable_silent_rules in # (((
+ yes) AM_DEFAULT_VERBOSITY=0;;
+ no) AM_DEFAULT_VERBOSITY=1;;
+ *) AM_DEFAULT_VERBOSITY=1;;
+esac
+am_make=${MAKE-make}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5
+$as_echo_n "checking whether $am_make supports nested variables... " >&6; }
+if ${am_cv_make_support_nested_variables+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if $as_echo 'TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+ @$(TRUE)
+.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then
+ am_cv_make_support_nested_variables=yes
+else
+ am_cv_make_support_nested_variables=no
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5
+$as_echo "$am_cv_make_support_nested_variables" >&6; }
+if test $am_cv_make_support_nested_variables = yes; then
+ AM_V='$(V)'
+ AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+ AM_V=$AM_DEFAULT_VERBOSITY
+ AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AM_BACKSLASH='\'
+
if test "`cd $srcdir && pwd`" != "`pwd`"; then
# Use -I$(srcdir) only when $(srcdir) != ., so that make's output
# is not polluted with repeated "-I."
@@ -2651,7 +2697,7 @@ fi
# Define the identity of the package.
PACKAGE='ocelot'
- VERSION='0.5'
+ VERSION='0.6'
# Some tools Automake needs.
@@ -2688,7 +2734,7 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
-CXXFLAGS="$CXXFLAGS -std=c++0x -march=native -O2 -fomit-frame-pointer -fno-ident -fvisibility-inlines-hidden -fvisibility=hidden -Wall -iquote -Wl,O1 -Wl,--as-needed"
+CXXFLAGS="$CXXFLAGS -std=c++0x -march=native -O2 -fomit-frame-pointer -fno-ident -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wfatal-errors -iquote -Wl,O1 -Wl,--as-needed"
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -6539,7 +6585,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by ocelot $as_me 0.5, which was
+This file was extended by ocelot $as_me 0.6, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -6596,7 +6642,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-ocelot config.status 0.5
+ocelot config.status 0.6
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
@@ -7146,7 +7192,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
case $ac_file$ac_mode in
"depfiles":C) test x"$AMDEP_TRUE" != x"" || {
- # Autoconf 2.62 quotes --file arguments for eval, but not when files
+ # Older Autoconf quotes --file arguments for eval, but not when files
# are listed without --file. Let's play safe and only enable the eval
# if we detect the quoting.
case $CONFIG_FILES in
diff --git a/src/configure.ac b/src/configure.ac
index 55c9c22..48ec716 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -1,6 +1,6 @@
-AC_INIT(ocelot, 0.5)
+AC_INIT(ocelot, 0.6)
AM_INIT_AUTOMAKE([1.11 no-define foreign])
-CXXFLAGS="$CXXFLAGS -std=c++0x -march=native -O2 -fomit-frame-pointer -fno-ident -fvisibility-inlines-hidden -fvisibility=hidden -Wall -iquote -Wl,O1 -Wl,--as-needed"
+CXXFLAGS="$CXXFLAGS -std=c++0x -march=native -O2 -fomit-frame-pointer -fno-ident -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wfatal-errors -iquote -Wl,O1 -Wl,--as-needed"
AC_PROG_CXX
AC_CONFIG_FILES([Makefile])
diff --git a/src/db.cpp b/src/db.cpp
index 0ef7b45..49a889b 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -14,23 +14,23 @@
#define DB_LOCK_TIMEOUT 50
mysql::mysql(std::string mysql_db, std::string mysql_host, std::string username, std::string password) {
- if(!conn.connect(mysql_db.c_str(), mysql_host.c_str(), username.c_str(), password.c_str(), 0)) {
- std::cout << "Could not connect to MySQL" << std::endl;
- return;
- }
+ if (!conn.connect(mysql_db.c_str(), mysql_host.c_str(), username.c_str(), password.c_str(), 0)) {
+ std::cout << "Could not connect to MySQL" << std::endl;
+ return;
+ }
db = mysql_db, server = mysql_host, db_user = username, pw = password;
- u_active = false; t_active = false; p_active = false; s_active = false; tok_active = false; hist_active = false;
-
- std::cout << "Connected to MySQL" << std::endl;
- update_user_buffer = "";
- update_torrent_buffer = "";
- update_peer_buffer = "";
- update_snatch_buffer = "";
+ u_active = false; t_active = false; p_active = false; s_active = false; tok_active = false;
+ std::cout << "Connected to MySQL" << std::endl;
+ update_user_buffer = "";
+ update_torrent_buffer = "";
+ update_heavy_peer_buffer = "";
+ update_light_peer_buffer = "";
+ update_snatch_buffer = "";
- logger_ptr = logger::get_instance();
std::cout << "Clearing xbt_files_users and resetting peer counts...";
+ std::cout.flush();
clear_peer_data();
std::cout << "done" << std::endl;
}
@@ -53,128 +53,125 @@ void mysql::clear_peer_data() {
}
void mysql::load_torrents(std::unordered_map<std::string, torrent> &torrents) {
- mysqlpp::Query query = conn.query("SELECT ID, info_hash, freetorrent, Snatched FROM torrents ORDER BY ID;");
- if(mysqlpp::StoreQueryResult res = query.store()) {
- mysqlpp::String one("1"); // Hack to get around bug in mysql++3.0.0
- mysqlpp::String two("2");
- size_t num_rows = res.num_rows();
- for(size_t i = 0; i < num_rows; i++) {
- std::string info_hash;
- res[i][1].to_string(info_hash);
-
- torrent t;
- t.id = res[i][0];
- if(res[i][2].compare(one) == 0) {
- t.free_torrent = FREE;
- } else if(res[i][2].compare(two) == 0) {
- t.free_torrent = NEUTRAL;
- } else {
- t.free_torrent = NORMAL;
- }
- t.balance = 0;
- t.completed = res[i][3];
- t.last_selected_seeder = "";
- torrents[info_hash] = t;
- }
- }
+ mysqlpp::Query query = conn.query("SELECT ID, info_hash, freetorrent, Snatched FROM torrents ORDER BY ID;");
+ if (mysqlpp::StoreQueryResult res = query.store()) {
+ mysqlpp::String one("1"); // Hack to get around bug in mysql++3.0.0
+ mysqlpp::String two("2");
+ size_t num_rows = res.num_rows();
+ for (size_t i = 0; i < num_rows; i++) {
+ std::string info_hash;
+ res[i][1].to_string(info_hash);
+
+ torrent t;
+ t.id = res[i][0];
+ if (res[i][2].compare(one) == 0) {
+ t.free_torrent = FREE;
+ } else if (res[i][2].compare(two) == 0) {
+ t.free_torrent = NEUTRAL;
+ } else {
+ t.free_torrent = NORMAL;
+ }
+ t.balance = 0;
+ t.completed = res[i][3];
+ t.last_selected_seeder = "";
+ torrents[info_hash] = t;
+ }
+ }
}
void mysql::load_users(std::unordered_map<std::string, user> &users) {
- mysqlpp::Query query = conn.query("SELECT ID, can_leech, torrent_pass FROM users_main WHERE Enabled='1';");
- if(mysqlpp::StoreQueryResult res = query.store()) {
- size_t num_rows = res.num_rows();
- for(size_t i = 0; i < num_rows; i++) {
- std::string passkey;
- res[i][2].to_string(passkey);
-
- user u;
- u.id = res[i][0];
- u.can_leech = res[i][1];
- users[passkey] = u;
- }
- }
+ mysqlpp::Query query = conn.query("SELECT ID, can_leech, torrent_pass, visible FROM users_main WHERE Enabled='1';");
+ if (mysqlpp::StoreQueryResult res = query.store()) {
+ size_t num_rows = res.num_rows();
+ for (size_t i = 0; i < num_rows; i++) {
+ std::string passkey;
+ res[i][2].to_string(passkey);
+
+ user u;
+ u.id = res[i][0];
+ u.can_leech = res[i][1];
+ u.protect_ip = res[i][3].compare("1") != 0;
+ users[passkey] = u;
+ }
+ }
}
void mysql::load_tokens(std::unordered_map<std::string, torrent> &torrents) {
- mysqlpp::Query query = conn.query("SELECT uf.UserID, t.info_hash FROM users_freeleeches AS uf JOIN torrents AS t ON t.ID = uf.TorrentID WHERE uf.Expired = '0';");
- if (mysqlpp::StoreQueryResult res = query.store()) {
- size_t num_rows = res.num_rows();
- for (size_t i = 0; i < num_rows; i++) {
- std::string info_hash;
- res[i][1].to_string(info_hash);
- std::unordered_map<std::string, torrent>::iterator it = torrents.find(info_hash);
- if (it != torrents.end()) {
- torrent &tor = it->second;
- tor.tokened_users.insert(res[i][0]);
- }
- }
- }
+ mysqlpp::Query query = conn.query("SELECT uf.UserID, t.info_hash FROM users_freeleeches AS uf JOIN torrents AS t ON t.ID = uf.TorrentID WHERE uf.Expired = '0';");
+ if (mysqlpp::StoreQueryResult res = query.store()) {
+ size_t num_rows = res.num_rows();
+ for (size_t i = 0; i < num_rows; i++) {
+ std::string info_hash;
+ res[i][1].to_string(info_hash);
+ std::unordered_map<std::string, torrent>::iterator it = torrents.find(info_hash);
+ if (it != torrents.end()) {
+ torrent &tor = it->second;
+ tor.tokened_users.insert(res[i][0]);
+ }
+ }
+ }
}
void mysql::load_whitelist(std::vector<std::string> &whitelist) {
- mysqlpp::Query query = conn.query("SELECT peer_id FROM xbt_client_whitelist;");
- if(mysqlpp::StoreQueryResult res = query.store()) {
- size_t num_rows = res.num_rows();
- for(size_t i = 0; i<num_rows; i++) {
- whitelist.push_back(res[i][0].c_str());
- }
- }
+ mysqlpp::Query query = conn.query("SELECT peer_id FROM xbt_client_whitelist;");
+ if (mysqlpp::StoreQueryResult res = query.store()) {
+ size_t num_rows = res.num_rows();
+ for (size_t i = 0; i<num_rows; i++) {
+ whitelist.push_back(res[i][0].c_str());
+ }
+ }
}
void mysql::record_token(std::string &record) {
- boost::mutex::scoped_lock lock(user_token_lock);
- if (update_token_buffer != "") {
- update_token_buffer += ",";
- }
- update_token_buffer += record;
+ if (update_token_buffer != "") {
+ update_token_buffer += ",";
+ }
+ update_token_buffer += record;
}
void mysql::record_user(std::string &record) {
- boost::mutex::scoped_lock lock(user_buffer_lock);
- if(update_user_buffer != "") {
- update_user_buffer += ",";
- }
- update_user_buffer += record;
+ if (update_user_buffer != "") {
+ update_user_buffer += ",";
+ }
+ update_user_buffer += record;
}
+
void mysql::record_torrent(std::string &record) {
- boost::mutex::scoped_lock lock(torrent_buffer_lock);
- if(update_torrent_buffer != "") {
- update_torrent_buffer += ",";
- }
- update_torrent_buffer += record;
+ if (update_torrent_buffer != "") {
+ update_torrent_buffer += ",";
+ }
+ update_torrent_buffer += record;
}
+
void mysql::record_peer(std::string &record, std::string &ip, std::string &peer_id, std::string &useragent) {
- boost::mutex::scoped_lock lock(peer_buffer_lock);
- if(update_peer_buffer != "") {
- update_peer_buffer += ",";
- }
- mysqlpp::Query q = conn.query();
- q << record << mysqlpp::quote << ip << ',' << mysqlpp::quote << peer_id << ',' << mysqlpp::quote << useragent << "," << time(NULL) << ')';
-
- update_peer_buffer += q.str();
-}
+ if (update_heavy_peer_buffer != "") {
+ update_heavy_peer_buffer += ",";
+ }
+ mysqlpp::Query q = conn.query();
+ q << record << mysqlpp::quote << ip << ',' << mysqlpp::quote << peer_id << ',' << mysqlpp::quote << useragent << "," << time(NULL) << ')';
-void mysql::record_peer_hist(std::string &record, std::string &peer_id, int tid){
- boost::mutex::scoped_lock (peer_hist_buffer_lock);
- if (update_peer_hist_buffer != "") {
- update_peer_hist_buffer += ",";
+ update_heavy_peer_buffer += q.str();
+}
+void mysql::record_peer(std::string &record, std::string &peer_id) {
+ if (update_light_peer_buffer != "") {
+ update_light_peer_buffer += ",";
}
mysqlpp::Query q = conn.query();
- q << record << ',' << mysqlpp::quote << peer_id << ',' << tid << ',' << time(NULL) << ')';
- update_peer_hist_buffer += q.str();
+ q << record << mysqlpp::quote << peer_id << ',' << time(NULL) << ')';
+
+ update_light_peer_buffer += q.str();
}
void mysql::record_snatch(std::string &record) {
- boost::mutex::scoped_lock lock(mysql::snatch_buffer_lock);
- if(update_snatch_buffer != "") {
- update_snatch_buffer += ",";
- }
- update_snatch_buffer += record;
+ if (update_snatch_buffer != "") {
+ update_snatch_buffer += ",";
+ }
+ update_snatch_buffer += record;
}
bool mysql::all_clear() {
- return (user_queue.size() == 0 && torrent_queue.size() == 0 && peer_queue.size() == 0 && snatch_queue.size() == 0 && token_queue.size() == 0 && peer_hist_queue.size() == 0);
+ return (user_queue.size() == 0 && torrent_queue.size() == 0 && peer_queue.size() == 0 && snatch_queue.size() == 0 && token_queue.size() == 0);
}
void mysql::flush() {
@@ -182,13 +179,16 @@ void mysql::flush() {
flush_torrents();
flush_snatches();
flush_peers();
- flush_peer_hist();
flush_tokens();
}
void mysql::flush_users() {
std::string sql;
- boost::mutex::scoped_lock lock(user_buffer_lock);
+ boost::mutex::scoped_lock lock(user_queue_lock);
+ size_t qsize = user_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "User flush queue size: " << qsize << std::endl;
+ }
if (update_user_buffer == "") {
return;
}
@@ -203,7 +203,11 @@ void mysql::flush_users() {
void mysql::flush_torrents() {
std::string sql;
- boost::mutex::scoped_lock lock(torrent_buffer_lock);
+ boost::mutex::scoped_lock lock(torrent_queue_lock);
+ size_t qsize = torrent_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "Torrent flush queue size: " << qsize << std::endl;
+ }
if (update_torrent_buffer == "") {
return;
}
@@ -223,7 +227,11 @@ void mysql::flush_torrents() {
void mysql::flush_snatches() {
std::string sql;
- boost::mutex::scoped_lock lock(snatch_buffer_lock);
+ boost::mutex::scoped_lock lock(snatch_queue_lock);
+ size_t qsize = snatch_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "Snatch flush queue size: " << qsize << std::endl;
+ }
if (update_snatch_buffer == "" ) {
return;
}
@@ -237,60 +245,62 @@ void mysql::flush_snatches() {
void mysql::flush_peers() {
std::string sql;
- boost::mutex::scoped_lock lock(peer_buffer_lock);
+ boost::mutex::scoped_lock lock(peer_queue_lock);
+ size_t qsize = peer_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "Peer flush queue size: " << qsize << std::endl;
+ }
// because xfu inserts are slow and ram is not infinite we need to
// limit this queue's size
- if (peer_queue.size() >= 1000) {
+ if (qsize >= 1000) {
peer_queue.pop();
}
- if (update_peer_buffer == "") {
+
+ // Nothing to do
+ if (update_light_peer_buffer == "" && update_heavy_peer_buffer == "") {
return;
}
-
- if (peer_queue.size() == 0) {
+
+ if (qsize == 0) {
sql = "SET session sql_log_bin = 0";
peer_queue.push(sql);
sql.clear();
}
-
- sql = "INSERT INTO xbt_files_users (uid,fid,active,uploaded,downloaded,upspeed,downspeed,remaining,corrupt," +
- std::string("timespent,announced,ip,peer_id,useragent,mtime) VALUES ") + update_peer_buffer +
- " ON DUPLICATE KEY UPDATE active=VALUES(active), uploaded=VALUES(uploaded), " +
- "downloaded=VALUES(downloaded), upspeed=VALUES(upspeed), " +
- "downspeed=VALUES(downspeed), remaining=VALUES(remaining), " +
- "corrupt=VALUES(corrupt), timespent=VALUES(timespent), " +
- "announced=VALUES(announced), mtime=VALUES(mtime)";
- peer_queue.push(sql);
- update_peer_buffer.clear();
- if (p_active == false) {
- boost::thread thread(&mysql::do_flush_peers, this);
- }
-}
-void mysql::flush_peer_hist() {
- std::string sql;
- boost::mutex::scoped_lock lock(peer_hist_buffer_lock);
- if (update_peer_hist_buffer == "") {
- return;
+ if (update_heavy_peer_buffer != "") {
+ sql = "INSERT INTO xbt_files_users (uid,fid,active,uploaded,downloaded,upspeed,downspeed,remaining,corrupt," +
+ std::string("timespent,announced,ip,peer_id,useragent,mtime) VALUES ") + update_heavy_peer_buffer +
+ " ON DUPLICATE KEY UPDATE active=VALUES(active), uploaded=VALUES(uploaded), " +
+ "downloaded=VALUES(downloaded), upspeed=VALUES(upspeed), " +
+ "downspeed=VALUES(downspeed), remaining=VALUES(remaining), " +
+ "corrupt=VALUES(corrupt), timespent=VALUES(timespent), " +
+ "announced=VALUES(announced), mtime=VALUES(mtime)";
+ peer_queue.push(sql);
+ update_heavy_peer_buffer.clear();
+ sql.clear();
}
-
- if (peer_hist_queue.size() == 0) {
- sql = "SET session sql_log_bin = 0";
- peer_hist_queue.push(sql);
+ if (update_light_peer_buffer != "") {
+ sql = "INSERT INTO xbt_files_users (fid,timespent,announced,peer_id,mtime) VALUES " +
+ update_light_peer_buffer +
+ " ON DUPLICATE KEY UPDATE upspeed=0, downspeed=0, timespent=VALUES(timespent), " +
+ "announced=VALUES(announced), mtime=VALUES(mtime)";
+ peer_queue.push(sql);
+ update_light_peer_buffer.clear();
sql.clear();
}
- sql = "INSERT IGNORE INTO xbt_peers_history (uid, downloaded, remaining, uploaded, upspeed, downspeed, timespent, peer_id, fid, mtime) VALUES " + update_peer_hist_buffer;
- peer_hist_queue.push(sql);
- update_peer_hist_buffer.clear();
- if (hist_active == false) {
- boost::thread thread(&mysql::do_flush_peer_hist, this);
+ if (p_active == false) {
+ boost::thread thread(&mysql::do_flush_peers, this);
}
}
void mysql::flush_tokens() {
std::string sql;
- boost::mutex::scoped_lock lock(user_token_lock);
+ boost::mutex::scoped_lock lock(token_queue_lock);
+ size_t qsize = token_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "Token flush queue size: " << qsize << std::endl;
+ }
if (update_token_buffer == "") {
return;
}
@@ -316,9 +326,8 @@ void mysql::do_flush_users() {
sleep(3);
continue;
} else {
- boost::mutex::scoped_lock lock(user_buffer_lock);
+ boost::mutex::scoped_lock lock(user_queue_lock);
user_queue.pop();
- std::cout << "Users flushed (" << user_queue.size() << " remain)" << std::endl;
}
}
catch (const mysqlpp::BadQuery &er) {
@@ -357,9 +366,8 @@ void mysql::do_flush_torrents() {
sleep(3);
continue;
} else {
- boost::mutex::scoped_lock lock(torrent_buffer_lock);
+ boost::mutex::scoped_lock lock(torrent_queue_lock);
torrent_queue.pop();
- std::cout << "Torrents flushed (" << torrent_queue.size() << " remain)" << std::endl;
}
}
catch (const mysqlpp::BadQuery &er) {
@@ -394,9 +402,8 @@ void mysql::do_flush_peers() {
sleep(3);
continue;
} else {
- boost::mutex::scoped_lock lock(peer_buffer_lock);
+ boost::mutex::scoped_lock lock(peer_queue_lock);
peer_queue.pop();
- std::cout << "Peers flushed (" << peer_queue.size() << " remain)" << std::endl;
}
}
catch (const mysqlpp::BadQuery &er) {
@@ -418,43 +425,6 @@ void mysql::do_flush_peers() {
p_active = false;
}
-void mysql::do_flush_peer_hist() {
- hist_active = true;
- try {
- mysqlpp::Connection c(db.c_str(), server.c_str(), db_user.c_str(), pw.c_str(), 0);
- while (peer_hist_queue.size() > 0) {
- try {
- std::string sql = peer_hist_queue.front();
- mysqlpp::Query query = c.query(sql);
- if (!query.exec()) {
- std::cout << "Peer history flush failed (" << peer_hist_queue.size() << " remain)" << std::endl;
- sleep(3);
- continue;
- } else {
- boost::mutex::scoped_lock lock(peer_hist_buffer_lock);
- peer_hist_queue.pop();
- std::cout << "Peer history flushed (" << peer_hist_queue.size() << " remain)" << std::endl;
- }
- }
- catch (const mysqlpp::BadQuery &er) {
- std::cerr << "Query error: " << er.what() << " in flush peer history with a qlength: " << peer_hist_queue.front().size() << " queue size: " << peer_hist_queue.size() << std::endl;
- sleep(3);
- continue;
- } catch (const mysqlpp::Exception &er) {
- std::cerr << "Query error: " << er.what() << " in flush peer history with a qlength: " << peer_hist_queue.front().size() << " queue size: " << peer_hist_queue.size() << std::endl;
- sleep(3);
- continue;
- }
- }
- }
- catch (const mysqlpp::Exception &er) {
- std::cerr << "MySQL error in flush_peer_hist: " << er.what() << std::endl;
- hist_active = false;
- return;
- }
- hist_active = false;
-}
-
void mysql::do_flush_snatches() {
s_active = true;
try {
@@ -468,9 +438,8 @@ void mysql::do_flush_snatches() {
sleep(3);
continue;
} else {
- boost::mutex::scoped_lock lock(snatch_buffer_lock);
+ boost::mutex::scoped_lock lock(snatch_queue_lock);
snatch_queue.pop();
- std::cout << "Snatches flushed (" << snatch_queue.size() << " remain)" << std::endl;
}
}
catch (const mysqlpp::BadQuery &er) {
@@ -505,9 +474,8 @@ void mysql::do_flush_tokens() {
sleep(3);
continue;
} else {
- boost::mutex::scoped_lock lock(user_token_lock);
+ boost::mutex::scoped_lock lock(token_queue_lock);
token_queue.pop();
- std::cout << "Tokens flushed (" << token_queue.size() << " remain)" << std::endl;
}
}
catch (const mysqlpp::BadQuery &er) {
diff --git a/src/db.h b/src/db.h
index 397d257..d78a012 100644
--- a/src/db.h
+++ b/src/db.h
@@ -7,53 +7,49 @@
#include <queue>
#include <boost/thread/mutex.hpp>
-#include "logger.h"
-
class mysql {
private:
mysqlpp::Connection conn;
std::string update_user_buffer;
std::string update_torrent_buffer;
- std::string update_peer_buffer;
+ std::string update_heavy_peer_buffer;
+ std::string update_light_peer_buffer;
std::string update_snatch_buffer;
std::string update_token_buffer;
- std::string update_peer_hist_buffer;
std::queue<std::string> user_queue;
std::queue<std::string> torrent_queue;
std::queue<std::string> peer_queue;
std::queue<std::string> snatch_queue;
std::queue<std::string> token_queue;
- std::queue<std::string> peer_hist_queue;
std::string db, server, db_user, pw;
- bool u_active, t_active, p_active, s_active, tok_active, hist_active;
+ bool u_active, t_active, p_active, s_active, tok_active;
// These locks prevent more than one thread from reading/writing the buffers.
// These should be held for the minimum time possible.
- boost::mutex user_buffer_lock;
- boost::mutex torrent_buffer_lock;
- boost::mutex peer_buffer_lock;
- boost::mutex snatch_buffer_lock;
- boost::mutex user_token_lock;
- boost::mutex peer_hist_buffer_lock;
-
+ boost::mutex user_queue_lock;
+ boost::mutex torrent_queue_lock;
+ boost::mutex peer_queue_lock;
+ boost::mutex snatch_queue_lock;
+ boost::mutex token_queue_lock;
+
void do_flush_users();
void do_flush_torrents();
void do_flush_snatches();
void do_flush_peers();
void do_flush_tokens();
- void do_flush_peer_hist();
void flush_users();
void flush_torrents();
void flush_snatches();
void flush_peers();
void flush_tokens();
- void flush_peer_hist();
void clear_peer_data();
public:
+ bool verbose_flush;
+
mysql(std::string mysql_db, std::string mysql_host, std::string username, std::string password);
void load_torrents(std::unordered_map<std::string, torrent> &torrents);
void load_users(std::unordered_map<std::string, user> &users);
@@ -63,17 +59,15 @@ class mysql {
void record_user(std::string &record); // (id,uploaded_change,downloaded_change)
void record_torrent(std::string &record); // (id,seeders,leechers,snatched_change,balance)
void record_snatch(std::string &record); // (uid,fid,tstamp)
- void record_peer(std::string &record, std::string &ip, std::string &peer_id, std::string &useragent); // (uid,fid,active,peerid,useragent,ip,uploaded,downloaded,upspeed,downspeed,left,timespent,announces)
+ void record_peer(std::string &record, std::string &ip, std::string &peer_id, std::string &useragent); // (uid,fid,active,peerid,useragent,ip,uploaded,downloaded,upspeed,downspeed,left,timespent,announces,tstamp)
+ void record_peer(std::string &record, std::string &peer_id); // (fid,peerid,timespent,announces,tstamp)
void record_token(std::string &record);
- void record_peer_hist(std::string &record, std::string &peer_id, int tid);
void flush();
bool all_clear();
boost::mutex torrent_list_mutex;
-
- logger* logger_ptr;
};
#pragma GCC visibility pop
diff --git a/src/depcomp b/src/depcomp
index 0544c68..06b0882 100755
--- a/src/depcomp
+++ b/src/depcomp
@@ -1,9 +1,9 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
-scriptversion=2012-07-12.20; # UTC
+scriptversion=2012-10-18.11; # UTC
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,9 +27,9 @@ scriptversion=2012-07-12.20; # UTC
case $1 in
'')
- echo "$0: No command. Try '$0 --help' for more information." 1>&2
- exit 1;
- ;;
+ echo "$0: No command. Try '$0 --help' for more information." 1>&2
+ exit 1;
+ ;;
-h | --h*)
cat <<\EOF
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
@@ -56,11 +56,65 @@ EOF
;;
esac
+# Get the directory component of the given path, and save it in the
+# global variables '$dir'. Note that this directory component will
+# be either empty or ending with a '/' character. This is deliberate.
+set_dir_from ()
+{
+ case $1 in
+ */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
+ *) dir=;;
+ esac
+}
+
+# Get the suffix-stripped basename of the given path, and save it the
+# global variable '$base'.
+set_base_from ()
+{
+ base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
+}
+
+# If no dependency file was actually created by the compiler invocation,
+# we still have to create a dummy depfile, to avoid errors with the
+# Makefile "include basename.Plo" scheme.
+make_dummy_depfile ()
+{
+ echo "#dummy" > "$depfile"
+}
+
+# Factor out some common post-processing of the generated depfile.
+# Requires the auxiliary global variable '$tmpdepfile' to be set.
+aix_post_process_depfile ()
+{
+ # If the compiler actually managed to produce a dependency file,
+ # post-process it.
+ if test -f "$tmpdepfile"; then
+ # Each line is of the form 'foo.o: dependency.h'.
+ # Do two passes, one to just change these to
+ # $object: dependency.h
+ # and one to simply output
+ # dependency.h:
+ # which is needed to avoid the deleted-header problem.
+ { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
+ sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
+ } > "$depfile"
+ rm -f "$tmpdepfile"
+ else
+ make_dummy_depfile
+ fi
+}
+
# A tabulation character.
tab=' '
# A newline character.
nl='
'
+# Character ranges might be problematic outside the C locale.
+# These definitions help.
+upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+lower=abcdefghijklmnopqrstuvwxyz
+digits=0123456789
+alpha=${upper}${lower}
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
@@ -74,6 +128,9 @@ tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
+# Avoid interferences from the environment.
+gccflag= dashmflag=
+
# Some modes work just like other modes, but use different flags. We
# parameterize here, but still list the modes in the big case below,
# to make depend.m4 easier to write. Note that we *cannot* use a case
@@ -85,32 +142,32 @@ if test "$depmode" = hp; then
fi
if test "$depmode" = dashXmstdout; then
- # This is just like dashmstdout with a different argument.
- dashmflag=-xM
- depmode=dashmstdout
+ # This is just like dashmstdout with a different argument.
+ dashmflag=-xM
+ depmode=dashmstdout
fi
cygpath_u="cygpath -u -f -"
if test "$depmode" = msvcmsys; then
- # This is just like msvisualcpp but w/o cygpath translation.
- # Just convert the backslash-escaped backslashes to single forward
- # slashes to satisfy depend.m4
- cygpath_u='sed s,\\\\,/,g'
- depmode=msvisualcpp
+ # This is just like msvisualcpp but w/o cygpath translation.
+ # Just convert the backslash-escaped backslashes to single forward
+ # slashes to satisfy depend.m4
+ cygpath_u='sed s,\\\\,/,g'
+ depmode=msvisualcpp
fi
if test "$depmode" = msvc7msys; then
- # This is just like msvc7 but w/o cygpath translation.
- # Just convert the backslash-escaped backslashes to single forward
- # slashes to satisfy depend.m4
- cygpath_u='sed s,\\\\,/,g'
- depmode=msvc7
+ # This is just like msvc7 but w/o cygpath translation.
+ # Just convert the backslash-escaped backslashes to single forward
+ # slashes to satisfy depend.m4
+ cygpath_u='sed s,\\\\,/,g'
+ depmode=msvc7
fi
if test "$depmode" = xlc; then
- # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
- gccflag=-qmakedep=gcc,-MF
- depmode=gcc
+ # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
+ gccflag=-qmakedep=gcc,-MF
+ depmode=gcc
fi
case "$depmode" in
@@ -133,8 +190,7 @@ gcc3)
done
"$@"
stat=$?
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
@@ -142,13 +198,17 @@ gcc3)
;;
gcc)
+## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
+## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
+## (see the conditional assignment to $gccflag above).
## There are various ways to get dependency output from gcc. Here's
## why we pick this rather obscure method:
## - Don't want to use -MD because we'd like the dependencies to end
## up in a subdir. Having to rename by hand is ugly.
## (We might end up doing this anyway to support other compilers.)
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
-## -MM, not -M (despite what the docs say).
+## -MM, not -M (despite what the docs say). Also, it might not be
+## supported by the other compilers which use the 'gcc' depmode.
## - Using -M directly means running the compiler twice (even worse
## than renaming).
if test -z "$gccflag"; then
@@ -156,15 +216,14 @@ gcc)
fi
"$@" -Wp,"$gccflag$tmpdepfile"
stat=$?
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
- alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
-## The second -e expression handles DOS-style file names with drive letters.
+ # The second -e expression handles DOS-style file names with drive
+ # letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the "deleted header file" problem.
@@ -173,15 +232,15 @@ gcc)
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
- tr ' ' "$nl" < "$tmpdepfile" |
## Some versions of gcc put a space before the ':'. On the theory
## that the space means something, we add a space to the output as
## well. hp depmode also adds that space, but also prefixes the VPATH
## to the object. Take care to not repeat it in the output.
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
- | sed -e 's/$/ :/' >> "$depfile"
+ tr ' ' "$nl" < "$tmpdepfile" \
+ | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
+ | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
@@ -199,8 +258,7 @@ sgi)
"$@" -MDupdate "$tmpdepfile"
fi
stat=$?
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
@@ -208,7 +266,6 @@ sgi)
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
echo "$object : \\" > "$depfile"
-
# Clip off the initial element (the dependent). Don't try to be
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
@@ -216,19 +273,15 @@ sgi)
# the IRIX cc adds comments like '#:fec' to the end of the
# dependency line.
tr ' ' "$nl" < "$tmpdepfile" \
- | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
- tr "$nl" ' ' >> "$depfile"
+ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
+ | tr "$nl" ' ' >> "$depfile"
echo >> "$depfile"
-
# The second pass generates a dummy entry for each header file.
tr ' ' "$nl" < "$tmpdepfile" \
- | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
- >> "$depfile"
+ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+ >> "$depfile"
else
- # The sourcefile does not contain any dependencies, so just
- # store a dummy comment line, to avoid errors with the Makefile
- # "include basename.Plo" scheme.
- echo "#dummy" > "$depfile"
+ make_dummy_depfile
fi
rm -f "$tmpdepfile"
;;
@@ -246,9 +299,8 @@ aix)
# current directory. Also, the AIX compiler puts '$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+ set_dir_from "$object"
+ set_base_from "$object"
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.u
tmpdepfile2=$base.u
@@ -261,9 +313,7 @@ aix)
"$@" -M
fi
stat=$?
-
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
exit $stat
fi
@@ -272,65 +322,37 @@ aix)
do
test -f "$tmpdepfile" && break
done
- if test -f "$tmpdepfile"; then
- # Each line is of the form 'foo.o: dependent.h'.
- # Do two passes, one to just change these to
- # '$object: dependent.h' and one to simply 'dependent.h:'.
- sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
- else
- # The sourcefile does not contain any dependencies, so just
- # store a dummy comment line, to avoid errors with the Makefile
- # "include basename.Plo" scheme.
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile"
+ aix_post_process_depfile
;;
-icc)
- # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
- # However on
- # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
- # ICC 7.0 will fill foo.d with something like
- # foo.o: sub/foo.c
- # foo.o: sub/foo.h
- # which is wrong. We want
- # sub/foo.o: sub/foo.c
- # sub/foo.o: sub/foo.h
- # sub/foo.c:
- # sub/foo.h:
- # ICC 7.1 will output
- # foo.o: sub/foo.c sub/foo.h
- # and will wrap long lines using '\':
- # foo.o: sub/foo.c ... \
- # sub/foo.h ... \
- # ...
- # tcc 0.9.26 (FIXME still under development at the moment of writing)
- # will emit a similar output, but also prepend the continuation lines
- # with horizontal tabulation characters.
+tcc)
+ # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
+ # FIXME: That version still under development at the moment of writing.
+ # Make that this statement remains true also for stable, released
+ # versions.
+ # It will wrap lines (doesn't matter whether long or short) with a
+ # trailing '\', as in:
+ #
+ # foo.o : \
+ # foo.c \
+ # foo.h \
+ #
+ # It will put a trailing '\' even on the last line, and will use leading
+ # spaces rather than leading tabs (at least since its commit 0394caf7
+ # "Emit spaces for -MD").
"$@" -MD -MF "$tmpdepfile"
stat=$?
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
- # Each line is of the form 'foo.o: dependent.h',
- # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
- # Do two passes, one to just change these to
- # '$object: dependent.h' and one to simply 'dependent.h:'.
- sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \
- < "$tmpdepfile" > "$depfile"
- sed '
- s/[ '"$tab"'][ '"$tab"']*/ /g
- s/^ *//
- s/ *\\*$//
- s/^[^:]*: *//
- /^$/d
- /:$/d
- s/$/ :/
- ' < "$tmpdepfile" >> "$depfile"
+ # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
+ # We have to change lines of the first kind to '$object: \'.
+ sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
+ # And for each line of the second kind, we have to emit a 'dep.h:'
+ # dummy dependency, to avoid the deleted-header problem.
+ sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
rm -f "$tmpdepfile"
;;
@@ -349,34 +371,37 @@ pgcc)
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
+ set_dir_from "$object"
# Use the source, not the object, to determine the base name, since
# that's sadly what pgcc will do too.
- base=`echo "$source" | sed -e 's|^.*/||' -e 's/\.[-_a-zA-Z0-9]*$//'`
- tmpdepfile="$base.d"
+ set_base_from "$source"
+ tmpdepfile=$base.d
# For projects that build the same source file twice into different object
# files, the pgcc approach of using the *source* file root name can cause
# problems in parallel builds. Use a locking strategy to avoid stomping on
# the same $tmpdepfile.
- lockdir="$base.d-lock"
- trap "echo '$0: caught signal, cleaning up...' >&2; rm -rf $lockdir" 1 2 13 15
+ lockdir=$base.d-lock
+ trap "
+ echo '$0: caught signal, cleaning up...' >&2
+ rmdir '$lockdir'
+ exit 1
+ " 1 2 13 15
numtries=100
i=$numtries
- while test $i -gt 0 ; do
+ while test $i -gt 0; do
# mkdir is a portable test-and-set.
- if mkdir $lockdir 2>/dev/null; then
+ if mkdir "$lockdir" 2>/dev/null; then
# This process acquired the lock.
"$@" -MD
stat=$?
# Release the lock.
- rm -rf $lockdir
+ rmdir "$lockdir"
break
else
- ## the lock is being held by a different process,
- ## wait until the winning process is done or we timeout
- while test -d $lockdir && test $i -gt 0; do
+ # If the lock is being held by a different process, wait
+ # until the winning process is done or we timeout.
+ while test -d "$lockdir" && test $i -gt 0; do
sleep 1
i=`expr $i - 1`
done
@@ -402,8 +427,8 @@ pgcc)
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this invocation
# correctly. Breaking it into two sed invocations is a workaround.
- sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
- sed -e 's/$/ :/' >> "$depfile"
+ sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
+ | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
@@ -414,9 +439,8 @@ hp2)
# 'foo.d', which lands next to the object file, wherever that
# happens to be.
# Much of this is similar to the tru64 case; see comments there.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+ set_dir_from "$object"
+ set_base_from "$object"
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir.libs/$base.d
@@ -427,8 +451,7 @@ hp2)
"$@" +Maked
fi
stat=$?
- if test $stat -eq 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
@@ -438,76 +461,61 @@ hp2)
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
- sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+ sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
# Add 'dependent.h:' lines.
sed -ne '2,${
- s/^ *//
- s/ \\*$//
- s/$/:/
- p
- }' "$tmpdepfile" >> "$depfile"
+ s/^ *//
+ s/ \\*$//
+ s/$/:/
+ p
+ }' "$tmpdepfile" >> "$depfile"
else
- echo "#dummy" > "$depfile"
+ make_dummy_depfile
fi
rm -f "$tmpdepfile" "$tmpdepfile2"
;;
tru64)
- # The Tru64 compiler uses -MD to generate dependencies as a side
- # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
- # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
- # dependencies in 'foo.d' instead, so we check for that too.
- # Subdirectories are respected.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-
- if test "$libtool" = yes; then
- # With Tru64 cc, shared objects can also be used to make a
- # static library. This mechanism is used in libtool 1.4 series to
- # handle both shared and static libraries in a single compilation.
- # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
- #
- # With libtool 1.5 this exception was removed, and libtool now
- # generates 2 separate objects for the 2 libraries. These two
- # compilations output dependencies in $dir.libs/$base.o.d and
- # in $dir$base.o.d. We have to check for both files, because
- # one of the two compilations can be disabled. We should prefer
- # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
- # automatically cleaned when .libs/ is deleted, while ignoring
- # the former would cause a distcleancheck panic.
- tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
- tmpdepfile2=$dir$base.o.d # libtool 1.5
- tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
- tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
- "$@" -Wc,-MD
- else
- tmpdepfile1=$dir$base.o.d
- tmpdepfile2=$dir$base.d
- tmpdepfile3=$dir$base.d
- tmpdepfile4=$dir$base.d
- "$@" -MD
- fi
-
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
- exit $stat
- fi
-
- for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
- do
- test -f "$tmpdepfile" && break
- done
- if test -f "$tmpdepfile"; then
- sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
- else
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile"
- ;;
+ # The Tru64 compiler uses -MD to generate dependencies as a side
+ # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
+ # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+ # dependencies in 'foo.d' instead, so we check for that too.
+ # Subdirectories are respected.
+ set_dir_from "$object"
+ set_base_from "$object"
+
+ if test "$libtool" = yes; then
+ # Libtool generates 2 separate objects for the 2 libraries. These
+ # two compilations output dependencies in $dir.libs/$base.o.d and
+ # in $dir$base.o.d. We have to check for both files, because
+ # one of the two compilations can be disabled. We should prefer
+ # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+ # automatically cleaned when .libs/ is deleted, while ignoring
+ # the former would cause a distcleancheck panic.
+ tmpdepfile1=$dir$base.o.d # libtool 1.5
+ tmpdepfile2=$dir.libs/$base.o.d # Likewise.
+ tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
+ "$@" -Wc,-MD
+ else
+ tmpdepfile1=$dir$base.d
+ tmpdepfile2=$dir$base.d
+ tmpdepfile3=$dir$base.d
+ "$@" -MD
+ fi
+
+ stat=$?
+ if test $stat -ne 0; then
+ rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+ exit $stat
+ fi
+
+ for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+ do
+ test -f "$tmpdepfile" && break
+ done
+ # Same post-processing that is required for AIX mode.
+ aix_post_process_depfile
+ ;;
msvc7)
if test "$libtool" = yes; then
@@ -518,8 +526,7 @@ msvc7)
"$@" $showIncludes > "$tmpdepfile"
stat=$?
grep -v '^Note: including file: ' "$tmpdepfile"
- if test "$stat" = 0; then :
- else
+ if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
@@ -596,13 +603,14 @@ dashmstdout)
# in the target name. This is to cope with DOS-style filenames:
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
"$@" $dashmflag |
- sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
+ sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
- tr ' ' "$nl" < "$tmpdepfile" | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+ # Some versions of the HPUX 10.20 sed can't process this sed invocation
+ # correctly. Breaking it into two sed invocations is a workaround.
+ tr ' ' "$nl" < "$tmpdepfile" \
+ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+ | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
@@ -655,10 +663,12 @@ makedepend)
# makedepend may prepend the VPATH from the source file name to the object.
# No need to regex-escape $object, excess matching of '.' is harmless.
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
- sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+ # Some versions of the HPUX 10.20 sed can't process the last invocation
+ # correctly. Breaking it into two sed invocations is a workaround.
+ sed '1,2d' "$tmpdepfile" \
+ | tr ' ' "$nl" \
+ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+ | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile" "$tmpdepfile".bak
;;
@@ -694,10 +704,10 @@ cpp)
esac
done
- "$@" -E |
- sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
- -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
- sed '$ s: \\$::' > "$tmpdepfile"
+ "$@" -E \
+ | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+ | sed '$ s: \\$::' > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
cat < "$tmpdepfile" >> "$depfile"
@@ -729,15 +739,15 @@ msvisualcpp)
shift
;;
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
- set fnord "$@"
- shift
- shift
- ;;
+ set fnord "$@"
+ shift
+ shift
+ ;;
*)
- set fnord "$@" "$arg"
- shift
- shift
- ;;
+ set fnord "$@" "$arg"
+ shift
+ shift
+ ;;
esac
done
"$@" -E 2>/dev/null |
diff --git a/src/events.cpp b/src/events.cpp
index b534a64..07d9ff5 100644
--- a/src/events.cpp
+++ b/src/events.cpp
@@ -14,7 +14,7 @@
//---------- Connection mother - spawns middlemen and lets them deal with the connection
-connection_mother::connection_mother(worker * worker_obj, config * config_obj, mysql * db_obj) : work(worker_obj), conf(config_obj), db(db_obj) {
+connection_mother::connection_mother(worker * worker_obj, config * config_obj, mysql * db_obj, site_comm * sc_obj) : work(worker_obj), conf(config_obj), db(db_obj), sc(sc_obj) {
open_connections = 0;
opened_connections = 0;
@@ -25,7 +25,7 @@ connection_mother::connection_mother(worker * worker_obj, config * config_obj, m
// Stop old sockets from hogging the port
int yes = 1;
- if(setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
+ if (setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
std::cout << "Could not reuse socket" << std::endl;
}
@@ -42,26 +42,26 @@ connection_mother::connection_mother(worker * worker_obj, config * config_obj, m
address.sin_port = htons(conf->port);
// Bind
- if(bind(listen_socket, (sockaddr *) &address, sizeof(address)) == -1) {
+ if (bind(listen_socket, (sockaddr *) &address, sizeof(address)) == -1) {
std::cout << "Bind failed " << errno << std::endl;
}
// Listen
- if(listen(listen_socket, conf->max_connections) == -1) {
+ if (listen(listen_socket, conf->max_connections) == -1) {
std::cout << "Listen failed" << std::endl;
}
// Set non-blocking
int flags = fcntl(listen_socket, F_GETFL);
- if(flags == -1) {
+ if (flags == -1) {
std::cout << "Could not get socket flags" << std::endl;
}
- if(fcntl(listen_socket, F_SETFL, flags | O_NONBLOCK) == -1) {
+ if (fcntl(listen_socket, F_SETFL, flags | O_NONBLOCK) == -1) {
std::cout << "Could not set non-blocking" << std::endl;
}
// Create libev timer
- schedule timer(this, worker_obj, conf, db);
+ schedule timer(this, worker_obj, conf, db, sc);
schedule_event.set<schedule, &schedule::handle>(&timer);
schedule_event.set(conf->schedule_interval, conf->schedule_interval); // After interval, every interval
@@ -74,7 +74,7 @@ connection_mother::connection_mother(worker * worker_obj, config * config_obj, m
void connection_mother::handle_connect(ev::io &watcher, int events_flags) {
// Spawn a new middleman
- if(open_connections < conf->max_middlemen) {
+ if (open_connections < conf->max_middlemen) {
opened_connections++;
new connection_middleman(listen_socket, address, addr_len, work, this, conf);
}
@@ -97,7 +97,7 @@ connection_middleman::connection_middleman(int &listen_socket, sockaddr_in &addr
conf(config_obj), mother (mother_arg), work(new_work), gzip(false) {
connect_sock = accept(listen_socket, (sockaddr *) &address, &addr_len);
- if(connect_sock == -1) {
+ if (connect_sock == -1) {
std::cout << "Accept failed, errno " << errno << ": " << strerror(errno) << std::endl;
mother->increment_open_connections(); // destructor decrements open connections
delete this;
@@ -106,15 +106,15 @@ connection_middleman::connection_middleman(int &listen_socket, sockaddr_in &addr
// Set non-blocking
int flags = fcntl(connect_sock, F_GETFL);
- if(flags == -1) {
+ if (flags == -1) {
std::cout << "Could not get connect socket flags" << std::endl;
}
- if(fcntl(connect_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
+ if (fcntl(connect_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
std::cout << "Could not set non-blocking" << std::endl;
}
// Get their info
- if(getpeername(connect_sock, (sockaddr *) &client_addr, &addr_len) == -1) {
+ if (getpeername(connect_sock, (sockaddr *) &client_addr, &addr_len) == -1) {
//std::cout << "Could not get client info" << std::endl;
}
@@ -143,7 +143,7 @@ void connection_middleman::handle_read(ev::io &watcher, int events_flags) {
memset(buffer, 0, conf->max_read_buffer + 1);
int status = recv(connect_sock, &buffer, conf->max_read_buffer, 0);
- if(status == -1) {
+ if (status == -1) {
delete this;
return;
}
diff --git a/src/events.h b/src/events.h
index d82ca0d..e073ada 100644
--- a/src/events.h
+++ b/src/events.h
@@ -53,13 +53,14 @@ class connection_mother {
worker * work;
config * conf;
mysql * db;
+ site_comm * sc;
ev::timer schedule_event;
unsigned int open_connections;
uint64_t opened_connections;
public:
- connection_mother(worker * worker_obj, config * config_obj, mysql * db_obj);
+ connection_mother(worker * worker_obj, config * config_obj, mysql * db_obj, site_comm * sc_obj);
void increment_open_connections() { open_connections++; }
void decrement_open_connections() { open_connections--; }
diff --git a/src/logger.cpp b/src/logger.cpp
deleted file mode 100644
index 691c6cf..0000000
--- a/src/logger.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "logger.h"
-
-logger* logger::singletonInstance_ = 0;
-
-logger::logger(std::string filename) {
- logger::log_file_.open(filename.c_str(), std::ios::out);
- if(logger::log_file_.is_open()) {
- singletonInstance_ = this;
- }
-}
-
-logger::~logger(void) {
- if(log_file_.is_open()) {
- log_file_.close();
- }
- singletonInstance_ = 0;
-}
-
-logger *logger::get_instance(void) {
- if(singletonInstance_ != 0) {
- return singletonInstance_;
- }
- return NULL;
-}
-
-bool logger::log(std::string msg) {
- boost::mutex::scoped_lock lock(log_lock_);
- if(log_file_.is_open()) {
- log_file_ << msg << std::endl;
- log_file_.flush();
- return true;
- }
- return false;
-}
diff --git a/src/logger.h b/src/logger.h
deleted file mode 100644
index 08f7c2c..0000000
--- a/src/logger.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef OCELOT_LOGGER_H
-#define OCELOT_LOGGER_H
-
-#include <string>
-#include <iostream>
-#include <fstream>
-
-#include <boost/thread/mutex.hpp>
-
-class logger {
-
- public:
- logger(std::string filename);
- virtual ~logger(void);
- bool log(std::string msg);
- static logger* get_instance(void);
-
- protected:
-
- private:
- static logger* singletonInstance_;
- boost::mutex log_lock_;
- std::ofstream log_file_;
-};
-
-#endif
diff --git a/src/misc_functions.cpp b/src/misc_functions.cpp
index 7e6082f..88396d3 100644
--- a/src/misc_functions.cpp
+++ b/src/misc_functions.cpp
@@ -29,24 +29,24 @@ std::string hex_decode(const std::string &in) {
std::string out;
out.reserve(20);
unsigned int in_length = in.length();
- for(unsigned int i = 0; i < in_length; i++) {
+ for (unsigned int i = 0; i < in_length; i++) {
unsigned char x = '0';
- if(in[i] == '%' && (i + 2) < in_length) {
+ if (in[i] == '%' && (i + 2) < in_length) {
i++;
- if(in[i] >= 'a' && in[i] <= 'f') {
+ if (in[i] >= 'a' && in[i] <= 'f') {
x = static_cast<unsigned char>((in[i]-87) << 4);
- } else if(in[i] >= 'A' && in[i] <= 'F') {
+ } else if (in[i] >= 'A' && in[i] <= 'F') {
x = static_cast<unsigned char>((in[i]-55) << 4);
- } else if(in[i] >= '0' && in[i] <= '9') {
+ } else if (in[i] >= '0' && in[i] <= '9') {
x = static_cast<unsigned char>((in[i]-48) << 4);
}
i++;
- if(in[i] >= 'a' && in[i] <= 'f') {
+ if (in[i] >= 'a' && in[i] <= 'f') {
x += static_cast<unsigned char>(in[i]-87);
- } else if(in[i] >= 'A' && in[i] <= 'F') {
+ } else if (in[i] >= 'A' && in[i] <= 'F') {
x += static_cast<unsigned char>(in[i]-55);
- } else if(in[i] >= '0' && in[i] <= '9') {
+ } else if (in[i] >= '0' && in[i] <= '9') {
x += static_cast<unsigned char>(in[i]-48);
}
} else {
diff --git a/src/missing b/src/missing
index 9a55648..cdea514 100755
--- a/src/missing
+++ b/src/missing
@@ -1,10 +1,10 @@
#! /bin/sh
-# Common stub for a few missing GNU programs while installing.
+# Common wrapper for a few potentially missing GNU programs.
-scriptversion=2012-01-06.18; # UTC
+scriptversion=2012-06-26.16; # UTC
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
-# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,61 +29,33 @@ if test $# -eq 0; then
exit 1
fi
-run=:
-sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
-sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
-
-# In the cases where this matters, 'missing' is being run in the
-# srcdir already.
-if test -f configure.ac; then
- configure_ac=configure.ac
-else
- configure_ac=configure.in
-fi
+case $1 in
-msg="missing on your system"
+ --is-lightweight)
+ # Used by our autoconf macros to check whether the available missing
+ # script is modern enough.
+ exit 0
+ ;;
-case $1 in
---run)
- # Try to run requested program, and just exit if it succeeds.
- run=
- shift
- "$@" && exit 0
- # Exit code 63 means version mismatch. This often happens
- # when the user try to use an ancient version of a tool on
- # a file that requires a minimum version. In this case we
- # we should proceed has if the program had been absent, or
- # if --run hadn't been passed.
- if test $? = 63; then
- run=:
- msg="probably too old"
- fi
- ;;
+ --run)
+ # Back-compat with the calling convention used by older automake.
+ shift
+ ;;
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
-Handle 'PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
-error status if there is no known handling for PROGRAM.
+Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
+to PROGRAM being missing or too old.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
- --run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
- aclocal touch file 'aclocal.m4'
- autoconf touch file 'configure'
- autoheader touch file 'config.h.in'
- autom4te touch the output file, or create a stub one
- automake touch all 'Makefile.in' files
- bison create 'y.tab.[ch]', if possible, from existing .[ch]
- flex create 'lex.yy.c', if possible, from existing .c
- help2man touch the output file
- lex create 'lex.yy.c', if possible, from existing .c
- makeinfo touch the output file
- yacc create 'y.tab.[ch]', if possible, from existing .[ch]
+ aclocal autoconf autoheader autom4te automake makeinfo
+ bison yacc flex lex help2man
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
'g' are ignored when checking the name.
@@ -98,228 +70,141 @@ Send bug reports to <bug-automake@gnu.org>."
;;
-*)
- echo 1>&2 "$0: Unknown '$1' option"
+ echo 1>&2 "$0: unknown '$1' option"
echo 1>&2 "Try '$0 --help' for more information"
exit 1
;;
esac
-# normalize program name to check for.
-program=`echo "$1" | sed '
- s/^gnu-//; t
- s/^gnu//; t
- s/^g//; t'`
-
-# Now exit if we have it, but it failed. Also exit now if we
-# don't have it and --version was passed (most likely to detect
-# the program). This is about non-GNU programs, so use $1 not
-# $program.
-case $1 in
- lex*|yacc*)
- # Not GNU programs, they don't have --version.
- ;;
-
- *)
- if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
- # We have it, but it failed.
- exit 1
- elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
- # Could not run --version or --help. This is probably someone
- # running '$TOOL --version' or '$TOOL --help' to check whether
- # $TOOL exists and not knowing $TOOL uses missing.
- exit 1
- fi
- ;;
-esac
-
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case $program in
- aclocal*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'acinclude.m4' or '${configure_ac}'. You might want
- to install the Automake and Perl packages. Grab them from
- any GNU archive site."
- touch aclocal.m4
- ;;
-
- autoconf*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified '${configure_ac}'. You might want to install the
- Autoconf and GNU m4 packages. Grab them from any GNU
- archive site."
- touch configure
- ;;
-
- autoheader*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'acconfig.h' or '${configure_ac}'. You might want
- to install the Autoconf and GNU m4 packages. Grab them
- from any GNU archive site."
- files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
- test -z "$files" && files="config.h"
- touch_files=
- for f in $files; do
- case $f in
- *:*) touch_files="$touch_files "`echo "$f" |
- sed -e 's/^[^:]*://' -e 's/:.*//'`;;
- *) touch_files="$touch_files $f.in";;
- esac
- done
- touch $touch_files
- ;;
-
- automake*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'Makefile.am', 'acinclude.m4' or '${configure_ac}'.
- You might want to install the Automake and Perl packages.
- Grab them from any GNU archive site."
- find . -type f -name Makefile.am -print |
- sed 's/\.am$/.in/' |
- while read f; do touch "$f"; done
- ;;
-
- autom4te*)
- echo 1>&2 "\
-WARNING: '$1' is needed, but is $msg.
- You might have modified some files without having the
- proper tools for further handling them.
- You can get '$1' as part of Autoconf from any GNU
- archive site."
-
- file=`echo "$*" | sed -n "$sed_output"`
- test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
- if test -f "$file"; then
- touch $file
- else
- test -z "$file" || exec >$file
- echo "#! /bin/sh"
- echo "# Created by GNU Automake missing as a replacement of"
- echo "# $ $@"
- echo "exit 0"
- chmod +x $file
- exit 1
- fi
- ;;
-
- bison*|yacc*)
- echo 1>&2 "\
-WARNING: '$1' $msg. You should only need it if
- you modified a '.y' file. You may need the Bison package
- in order for those modifications to take effect. You can get
- Bison from any GNU archive site."
- rm -f y.tab.c y.tab.h
- if test $# -ne 1; then
- eval LASTARG=\${$#}
- case $LASTARG in
- *.y)
- SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
- if test -f "$SRCFILE"; then
- cp "$SRCFILE" y.tab.c
- fi
- SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
- if test -f "$SRCFILE"; then
- cp "$SRCFILE" y.tab.h
- fi
- ;;
- esac
- fi
- if test ! -f y.tab.h; then
- echo >y.tab.h
- fi
- if test ! -f y.tab.c; then
- echo 'main() { return 0; }' >y.tab.c
- fi
- ;;
-
- lex*|flex*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified a '.l' file. You may need the Flex package
- in order for those modifications to take effect. You can get
- Flex from any GNU archive site."
- rm -f lex.yy.c
- if test $# -ne 1; then
- eval LASTARG=\${$#}
- case $LASTARG in
- *.l)
- SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
- if test -f "$SRCFILE"; then
- cp "$SRCFILE" lex.yy.c
- fi
- ;;
- esac
- fi
- if test ! -f lex.yy.c; then
- echo 'main() { return 0; }' >lex.yy.c
- fi
- ;;
-
- help2man*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified a dependency of a manual page. You may need the
- Help2man package in order for those modifications to take
- effect. You can get Help2man from any GNU archive site."
-
- file=`echo "$*" | sed -n "$sed_output"`
- test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
- if test -f "$file"; then
- touch $file
- else
- test -z "$file" || exec >$file
- echo ".ab help2man is required to generate this page"
- exit $?
- fi
- ;;
-
- makeinfo*)
- echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified a '.texi' or '.texinfo' file, or any other file
- indirectly affecting the aspect of the manual. The spurious
- call might also be the consequence of using a buggy 'make' (AIX,
- DU, IRIX). You might want to install the Texinfo package or
- the GNU make package. Grab either from any GNU archive site."
- # The file to touch is that specified with -o ...
- file=`echo "$*" | sed -n "$sed_output"`
- test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
- if test -z "$file"; then
- # ... or it is the one specified with @setfilename ...
- infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
- file=`sed -n '
- /^@setfilename/{
- s/.* \([^ ]*\) *$/\1/
- p
- q
- }' $infile`
- # ... or it is derived from the source name (dir/f.texi becomes f.info)
- test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
- fi
- # If the file does not exist, the user really needs makeinfo;
- # let's fail without touching anything.
- test -f $file || exit 1
- touch $file
- ;;
+# Run the given program, remember its exit status.
+"$@"; st=$?
+
+# If it succeeded, we are done.
+test $st -eq 0 && exit 0
+
+# Also exit now if we it failed (or wasn't found), and '--version' was
+# passed; such an option is passed most likely to detect whether the
+# program is present and works.
+case $2 in --version|--help) exit $st;; esac
+
+# Exit code 63 means version mismatch. This often happens when the user
+# tries to use an ancient version of a tool on a file that requires a
+# minimum version.
+if test $st -eq 63; then
+ msg="probably too old"
+elif test $st -eq 127; then
+ # Program was missing.
+ msg="missing on your system"
+else
+ # Program was found and executed, but failed. Give up.
+ exit $st
+fi
- *)
- echo 1>&2 "\
-WARNING: '$1' is needed, and is $msg.
- You might have modified some files without having the
- proper tools for further handling them. Check the 'README' file,
- it often tells you about the needed prerequisites for installing
- this package. You may also peek at any GNU archive site, in case
- some other package would contain this missing '$1' program."
- exit 1
+perl_URL=http://www.perl.org/
+flex_URL=http://flex.sourceforge.net/
+gnu_software_URL=http://www.gnu.org/software
+
+program_details ()
+{
+ case $1 in
+ aclocal|automake)
+ echo "The '$1' program is part of the GNU Automake package:"
+ echo "<$gnu_software_URL/automake>"
+ echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
+ echo "<$gnu_software_URL/autoconf>"
+ echo "<$gnu_software_URL/m4/>"
+ echo "<$perl_URL>"
+ ;;
+ autoconf|autom4te|autoheader)
+ echo "The '$1' program is part of the GNU Autoconf package:"
+ echo "<$gnu_software_URL/autoconf/>"
+ echo "It also requires GNU m4 and Perl in order to run:"
+ echo "<$gnu_software_URL/m4/>"
+ echo "<$perl_URL>"
+ ;;
+ esac
+}
+
+give_advice ()
+{
+ # Normalize program name to check for.
+ normalized_program=`echo "$1" | sed '
+ s/^gnu-//; t
+ s/^gnu//; t
+ s/^g//; t'`
+
+ printf '%s\n' "'$1' is $msg."
+
+ configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
+ case $normalized_program in
+ autoconf*)
+ echo "You should only need it if you modified 'configure.ac',"
+ echo "or m4 files included by it."
+ program_details 'autoconf'
+ ;;
+ autoheader*)
+ echo "You should only need it if you modified 'acconfig.h' or"
+ echo "$configure_deps."
+ program_details 'autoheader'
+ ;;
+ automake*)
+ echo "You should only need it if you modified 'Makefile.am' or"
+ echo "$configure_deps."
+ program_details 'automake'
+ ;;
+ aclocal*)
+ echo "You should only need it if you modified 'acinclude.m4' or"
+ echo "$configure_deps."
+ program_details 'aclocal'
+ ;;
+ autom4te*)
+ echo "You might have modified some maintainer files that require"
+ echo "the 'automa4te' program to be rebuilt."
+ program_details 'autom4te'
+ ;;
+ bison*|yacc*)
+ echo "You should only need it if you modified a '.y' file."
+ echo "You may want to install the GNU Bison package:"
+ echo "<$gnu_software_URL/bison/>"
+ ;;
+ lex*|flex*)
+ echo "You should only need it if you modified a '.l' file."
+ echo "You may want to install the Fast Lexical Analyzer package:"
+ echo "<$flex_URL>"
+ ;;
+ help2man*)
+ echo "You should only need it if you modified a dependency" \
+ "of a man page."
+ echo "You may want to install the GNU Help2man package:"
+ echo "<$gnu_software_URL/help2man/>"
;;
-esac
-
-exit 0
+ makeinfo*)
+ echo "You should only need it if you modified a '.texi' file, or"
+ echo "any other file indirectly affecting the aspect of the manual."
+ echo "You might want to install the Texinfo package:"
+ echo "<$gnu_software_URL/texinfo/>"
+ echo "The spurious makeinfo call might also be the consequence of"
+ echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
+ echo "want to install GNU make:"
+ echo "<$gnu_software_URL/make/>"
+ ;;
+ *)
+ echo "You might have modified some files without having the proper"
+ echo "tools for further handling them. Check the 'README' file, it"
+ echo "often tells you about the needed prerequisites for installing"
+ echo "this package. You may also peek at any GNU archive site, in"
+ echo "case some other package contains this missing '$1' program."
+ ;;
+ esac
+}
+
+give_advice "$1" | sed -e '1s/^/WARNING: /' \
+ -e '2,$s/^/ /' >&2
+
+# Propagate the correct exit status (expected to be 127 for a program
+# not found, 63 for a program that failed due to version mismatch).
+exit $st
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
diff --git a/src/ocelot.cpp b/src/ocelot.cpp
index b7a484d..ea0b5c8 100644
--- a/src/ocelot.cpp
+++ b/src/ocelot.cpp
@@ -4,14 +4,10 @@
#include "worker.h"
#include "events.h"
#include "schedule.h"
-#include "logger.h"
#include "site_comm.h"
-static mysql *db_ptr;
static connection_mother *mother;
static worker *work;
-static logger *log_ptr;
-static site_comm *sc_ptr;
static void sig_handler(int sig)
{
@@ -21,42 +17,50 @@ static void sig_handler(int sig)
}
}
-int main() {
+int main(int argc, char **argv) {
+ // we don't use printf so make cout/cerr a little bit faster
+ std::ios_base::sync_with_stdio(false);
+
config conf;
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
- log_ptr = new logger("debug.log");
+ bool verbose = false;
+ for (int i = argc; i > 1; i--) {
+ if (!strcmp(argv[1], "-v")) {
+ verbose = true;
+ }
+ }
mysql db(conf.mysql_db, conf.mysql_host, conf.mysql_username, conf.mysql_password);
- db_ptr = &db;
+ db.verbose_flush = verbose;
site_comm sc(conf);
- sc_ptr = &sc;
-
+ sc.verbose_flush = verbose;
+
std::vector<std::string> whitelist;
db.load_whitelist(whitelist);
std::cout << "Loaded " << whitelist.size() << " clients into the whitelist" << std::endl;
- if(whitelist.size() == 0) {
+ if (whitelist.size() == 0) {
std::cout << "Assuming no whitelist desired, disabling" << std::endl;
}
-
+
std::unordered_map<std::string, user> users_list;
db.load_users(users_list);
std::cout << "Loaded " << users_list.size() << " users" << std::endl;
-
+
std::unordered_map<std::string, torrent> torrents_list;
db.load_torrents(torrents_list);
std::cout << "Loaded " << torrents_list.size() << " torrents" << std::endl;
db.load_tokens(torrents_list);
-
+
// Create worker object, which handles announces and scrapes and all that jazz
- work = new worker(torrents_list, users_list, whitelist, &conf, &db, sc);
-
+ work = new worker(torrents_list, users_list, whitelist, &conf, &db, &sc);
+
// Create connection mother, which binds to its socket and handles the event stuff
- mother = new connection_mother(work, &conf, &db);
+ mother = new connection_mother(work, &conf, &db, &sc);
return 0;
}
diff --git a/src/ocelot.h b/src/ocelot.h
index dcf949b..8310c99 100644
--- a/src/ocelot.h
+++ b/src/ocelot.h
@@ -10,19 +10,18 @@
typedef struct {
int userid;
- std::string peer_id;
-// std::string user_agent;
- std::string ip_port;
- std::string ip;
unsigned int port;
int64_t uploaded;
int64_t downloaded;
int64_t corrupt;
- uint64_t left;
+ int64_t left;
time_t last_announced;
time_t first_announced;
unsigned int announces;
bool visible;
+ bool invalid_ip;
+ std::string ip_port;
+ std::string ip;
} peer;
typedef std::map<std::string, peer> peer_list;
@@ -35,16 +34,17 @@ typedef struct {
int64_t balance;
int completed;
freetype free_torrent;
- std::map<std::string, peer> seeders;
- std::map<std::string, peer> leechers;
+ time_t last_flushed;
+ peer_list seeders;
+ peer_list leechers;
std::string last_selected_seeder;
std::set<int> tokened_users;
- time_t last_flushed;
} torrent;
typedef struct {
int id;
bool can_leech;
+ bool protect_ip;
} user;
enum {
diff --git a/src/schedule.cpp b/src/schedule.cpp
index b33d1c8..eb79b4b 100644
--- a/src/schedule.cpp
+++ b/src/schedule.cpp
@@ -6,7 +6,7 @@
#include "schedule.h"
-schedule::schedule(connection_mother * mother_obj, worker* worker_obj, config* conf_obj, mysql * db_obj) : mother(mother_obj), work(worker_obj), conf(conf_obj), db(db_obj) {
+schedule::schedule(connection_mother * mother_obj, worker* worker_obj, config* conf_obj, mysql * db_obj, site_comm * sc_obj) : mother(mother_obj), work(worker_obj), conf(conf_obj), db(db_obj), sc(sc_obj) {
counter = 0;
last_opened_connections = 0;
@@ -15,13 +15,13 @@ schedule::schedule(connection_mother * mother_obj, worker* worker_obj, config* c
//---------- Schedule - gets called every schedule_interval seconds
void schedule::handle(ev::timer &watcher, int events_flags) {
- if(counter % 20 == 0) {
+ if (counter % 20 == 0) {
std::cout << "Schedule run #" << counter << " - open: " << mother->get_open_connections() << ", opened: "
<< mother->get_opened_connections() << ", speed: "
<< ((mother->get_opened_connections()-last_opened_connections)/conf->schedule_interval) << "/s" << std::endl;
}
- if ((work->get_status() == CLOSING) && db->all_clear()) {
+ if ((work->get_status() == CLOSING) && db->all_clear() && sc->all_clear()) {
std::cout << "all clear, shutting down" << std::endl;
exit(0);
}
@@ -29,10 +29,11 @@ void schedule::handle(ev::timer &watcher, int events_flags) {
last_opened_connections = mother->get_opened_connections();
db->flush();
+ sc->flush_tokens();
time_t cur_time = time(NULL);
- if(cur_time > next_reap_peers) {
+ if (cur_time > next_reap_peers) {
work->reap_peers();
next_reap_peers = cur_time + conf->reap_peers_interval;
}
diff --git a/src/schedule.h b/src/schedule.h
index 7c87e9b..57d92e3 100644
--- a/src/schedule.h
+++ b/src/schedule.h
@@ -8,12 +8,13 @@ class schedule {
worker * work;
config * conf;
mysql * db;
+ site_comm * sc;
uint64_t last_opened_connections;
int counter;
time_t next_flush;
time_t next_reap_peers;
public:
- schedule(connection_mother * mother_obj, worker * worker_obj, config* conf_obj, mysql * db_obj);
+ schedule(connection_mother * mother_obj, worker * worker_obj, config* conf_obj, mysql * db_obj, site_comm * sc_obj);
void handle(ev::timer &watcher, int events_flags);
};
diff --git a/src/site_comm.cpp b/src/site_comm.cpp
index 5294d01..0df4b5c 100644
--- a/src/site_comm.cpp
+++ b/src/site_comm.cpp
@@ -2,7 +2,12 @@
#include <istream>
#include <ostream>
#include <string>
+#include <sstream>
+#include <queue>
#include <boost/asio.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
#include "config.h"
#include "site_comm.h"
@@ -12,64 +17,105 @@ using boost::asio::ip::tcp;
site_comm::site_comm(config &config)
{
conf = config;
+ t_active = false;
}
-bool site_comm::expire_token(int torrent, int user)
+bool site_comm::all_clear() {
+ return (token_queue.size() == 0);
+}
+
+void site_comm::expire_token(int torrent, int user)
+{
+ std::stringstream token_pair;
+ token_pair << user << ':' << torrent;
+ if (expire_token_buffer != "") {
+ expire_token_buffer += ",";
+ }
+ expire_token_buffer += token_pair.str();
+ if (expire_token_buffer.length() > 350) {
+ std::cout << "Flushing overloaded token buffer" << std::endl;
+ boost::mutex::scoped_lock lock(expire_queue_lock);
+ token_queue.push(expire_token_buffer);
+ expire_token_buffer.clear();
+ }
+}
+
+void site_comm::flush_tokens()
+{
+ boost::mutex::scoped_lock lock(expire_queue_lock);
+ size_t qsize = token_queue.size();
+ if (verbose_flush || qsize > 0) {
+ std::cout << "Token expire queue size: " << qsize << std::endl;
+ }
+ if (expire_token_buffer == "") {
+ return;
+ }
+ token_queue.push(expire_token_buffer);
+ expire_token_buffer.clear();
+ if (t_active == false) {
+ boost::thread thread(&site_comm::do_flush_tokens, this);
+ }
+}
+
+void site_comm::do_flush_tokens()
{
+ t_active = true;
try {
- boost::asio::io_service io_service;
-
- tcp::resolver resolver(io_service);
- tcp::resolver::query query(conf.site_host, "http");
- tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
- tcp::resolver::iterator end;
-
- tcp::socket socket(io_service);
- boost::system::error_code error = boost::asio::error::host_not_found;
- while (error && endpoint_iterator != end) {
- socket.close();
- socket.connect(*endpoint_iterator++, error);
- }
- if (error) {
- throw boost::system::system_error(error);
- }
+ while (token_queue.size() > 0) {
+ boost::asio::io_service io_service;
- boost::asio::streambuf request;
- std::ostream request_stream(&request);
- request_stream << "GET /tools.php?key=" << conf.site_password << "&type=expiretoken&action=ocelot&torrentid=" << torrent << "&userid=" << user << " HTTP/1.0\r\n";
- request_stream << "Host: " << conf.site_host << "\r\n";
- request_stream << "Accept: */*\r\n";
- request_stream << "Connection: close\r\n\r\n";
-
- boost::asio::write(socket, request);
-
- boost::asio::streambuf response;
- boost::asio::read_until(socket, response, "\r\n");
-
- std::istream response_stream(&response);
- std::string http_version;
- response_stream >> http_version;
- unsigned int status_code;
- response_stream >> status_code;
- std::string status_message;
- std::getline(response_stream, status_message);
-
- if (!response_stream || http_version.substr(0, 5) != "HTTP/") {
- std::cout << "Invalid response" << std::endl;
- return false;
- }
+ tcp::resolver resolver(io_service);
+ tcp::resolver::query query(conf.site_host, "http");
+ tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
+ tcp::resolver::iterator end;
+
+ tcp::socket socket(io_service);
+ boost::system::error_code error = boost::asio::error::host_not_found;
+ while (error && endpoint_iterator != end) {
+ socket.close();
+ socket.connect(*endpoint_iterator++, error);
+ }
+ if (error) {
+ throw boost::system::system_error(error);
+ }
+
+ boost::asio::streambuf request;
+ std::ostream request_stream(&request);
+ request_stream << "GET " << conf.site_path << "/tools.php?key=" << conf.site_password;
+ request_stream << "&type=expiretoken&action=ocelot&tokens=" << token_queue.front() << " HTTP/1.0\r\n";
+ request_stream << "Host: " << conf.site_host << "\r\n";
+ request_stream << "Accept: */*\r\n";
+ request_stream << "Connection: close\r\n\r\n";
+
+ boost::asio::write(socket, request);
+
+ boost::asio::streambuf response;
+ boost::asio::read_until(socket, response, "\r\n");
+
+ std::istream response_stream(&response);
+ std::string http_version;
+ response_stream >> http_version;
+ unsigned int status_code;
+ response_stream >> status_code;
+ std::string status_message;
+ std::getline(response_stream, status_message);
+
+ if (!response_stream || http_version.substr(0, 5) != "HTTP/") {
+ std::cout << "Invalid response" << std::endl;
+ continue;
+ }
- if (status_code == 200) {
- return true;
- } else {
- std::cout << "Response returned with status code " << status_code << " when trying to expire a token!" << std::endl;;
- return false;
+ if (status_code == 200) {
+ boost::mutex::scoped_lock lock(expire_queue_lock);
+ token_queue.pop();
+ } else {
+ std::cout << "Response returned with status code " << status_code << " when trying to expire a token!" << std::endl;;
+ }
}
} catch (std::exception &e) {
std::cout << "Exception: " << e.what() << std::endl;
- return false;
}
- return true;
+ t_active = false;
}
site_comm::~site_comm()
diff --git a/src/site_comm.h b/src/site_comm.h
index 0741059..c9b36e9 100644
--- a/src/site_comm.h
+++ b/src/site_comm.h
@@ -5,6 +5,8 @@
#include <ostream>
#include <string>
#include <boost/asio.hpp>
+#include <queue>
+#include <boost/thread/mutex.hpp>
#include "config.h"
@@ -13,10 +15,18 @@ using boost::asio::ip::tcp;
class site_comm {
private:
config conf;
-
+ boost::mutex expire_queue_lock;
+ std::string expire_token_buffer;
+ std::queue<std::string> token_queue;
+ bool t_active;
+
public:
+ bool verbose_flush;
site_comm(config &conf);
- bool expire_token(int torrent, int user);
+ bool all_clear();
+ void expire_token(int torrent, int user);
+ void flush_tokens();
+ void do_flush_tokens();
~site_comm();
};
#endif
diff --git a/src/worker.cpp b/src/worker.cpp
index 7f0203f..4f473c6 100644
--- a/src/worker.cpp
+++ b/src/worker.cpp
@@ -29,7 +29,8 @@
#include <boost/iostreams/filter/gzip.hpp>
//---------- Worker - does stuff with input
-worker::worker(torrent_list &torrents, user_list &users, std::vector<std::string> &_whitelist, config * conf_obj, mysql * db_obj, site_comm &sc) : torrents_list(torrents), users_list(users), whitelist(_whitelist), conf(conf_obj), db(db_obj), s_comm(sc) {
+worker::worker(torrent_list &torrents, user_list &users, std::vector<std::string> &_whitelist, config * conf_obj, mysql * db_obj, site_comm * sc) : torrents_list(torrents), users_list(users), whitelist(_whitelist), conf(conf_obj), db(db_obj), s_comm(sc)
+{
status = OPEN;
}
bool worker::signal(int sig) {
@@ -46,103 +47,113 @@ bool worker::signal(int sig) {
}
std::string worker::work(std::string &input, std::string &ip, bool &gzip) {
unsigned int input_length = input.length();
-
+
//---------- Parse request - ugly but fast. Using substr exploded.
- if(input_length < 60) { // Way too short to be anything useful
+ if (input_length < 60) { // Way too short to be anything useful
return error("GET string too short");
}
-
- size_t pos = 5; // skip GET /
-
+
+ size_t pos = 5; // skip 'GET /'
+
// Get the passkey
std::string passkey;
passkey.reserve(32);
- if(input[37] != '/') {
+ if (input[37] != '/') {
+ /* This didn't work as intended. We want the crawler to download the meta tag
+ if (input.substr(5, 10) == "robots.txt") {
+ // Let's just hope that no crawler has a / at pos 37
+ return "User-agent: *\nDisallow: /";
+ }*/
return error("Malformed announce");
}
-
- for(; pos < 37; pos++) {
+
+ for (; pos < 37; pos++) {
passkey.push_back(input[pos]);
}
-
+
pos = 38;
-
+
// Get the action
enum action_t {
INVALID = 0, ANNOUNCE, SCRAPE, UPDATE
};
action_t action = INVALID;
-
- switch(input[pos]) {
+
+ switch (input[pos]) {
case 'a':
action = ANNOUNCE;
- pos += 9;
+ pos += 8;
break;
case 's':
action = SCRAPE;
- pos += 7;
+ pos += 6;
break;
case 'u':
action = UPDATE;
- pos += 7;
+ pos += 6;
break;
}
- if(action == INVALID) {
+ if (action == INVALID) {
return error("invalid action");
}
+ if (input[pos] != '?') {
+ // No parameters given. Probably means we're not talking to a torrent client
+ return "<html><head><meta name=\"robots\" content=\"noindex, nofollow\" /></head><body>Nothing to see here</body></html>";
+ }
+
if ((status != OPEN) && (action != UPDATE)) {
return error("The tracker is temporarily unavailable.");
}
-
+
// Parse URL params
std::list<std::string> infohashes; // For scrape only
-
+
std::map<std::string, std::string> params;
std::string key;
std::string value;
bool parsing_key = true; // true = key, false = value
-
- for(; pos < input_length; ++pos) {
- if(input[pos] == '=') {
+
+ pos++; // Skip the '?'
+ for (; pos < input_length; ++pos) {
+ if (input[pos] == '=') {
parsing_key = false;
- } else if(input[pos] == '&' || input[pos] == ' ') {
+ } else if (input[pos] == '&' || input[pos] == ' ') {
parsing_key = true;
- if(action == SCRAPE && key == "info_hash") {
+ if (action == SCRAPE && key == "info_hash") {
infohashes.push_back(value);
} else {
-
params[key] = value;
}
key.clear();
value.clear();
- if(input[pos] == ' ') {
+ if (input[pos] == ' ') {
break;
}
} else {
- if(parsing_key) {
+ if (parsing_key) {
key.push_back(input[pos]);
} else {
value.push_back(input[pos]);
}
}
}
-
- pos += 10; // skip HTTP/1.1 - should probably be +=11, but just in case a client doesn't send \r
-
+
+ pos += 10; // skip 'HTTP/1.1' - should probably be +=11, but just in case a client doesn't send \r
+
// Parse headers
std::map<std::string, std::string> headers;
parsing_key = true;
bool found_data = false;
-
- for(; pos < input_length; ++pos) {
- if(input[pos] == ':') {
+
+ for (; pos < input_length; ++pos) {
+ if (input[pos] == ':') {
parsing_key = false;
++pos; // skip space after :
- } else if(input[pos] == '\n' || input[pos] == '\r') {
+ } else if (input[pos] == '\n' || input[pos] == '\r') {
parsing_key = true;
-
- if(found_data) {
+
+ if (found_data) {
found_data = false; // dodge for getting around \r\n or just \n
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
headers[key] = value;
@@ -151,38 +162,38 @@ std::string worker::work(std::string &input, std::string &ip, bool &gzip) {
}
} else {
found_data = true;
- if(parsing_key) {
+ if (parsing_key) {
key.push_back(input[pos]);
} else {
value.push_back(input[pos]);
}
}
}
-
-
-
- if(action == UPDATE) {
- if(passkey == conf->site_password) {
+
+
+
+ if (action == UPDATE) {
+ if (passkey == conf->site_password) {
return update(params);
} else {
return error("Authentication failure");
}
}
-
+
// Either a scrape or an announce
-
+
user_list::iterator u = users_list.find(passkey);
- if(u == users_list.end()) {
+ if (u == users_list.end()) {
return error("Passkey not found");
}
-
- if(action == ANNOUNCE) {
+
+ if (action == ANNOUNCE) {
boost::mutex::scoped_lock lock(db->torrent_list_mutex);
// Let's translate the infohash into something nice
// info_hash is a url encoded (hex) base 20 number
std::string info_hash_decoded = hex_decode(params["info_hash"]);
torrent_list::iterator tor = torrents_list.find(info_hash_decoded);
- if(tor == torrents_list.end()) {
+ if (tor == torrents_list.end()) {
boost::mutex::scoped_lock lock(del_reasons_lock);
auto msg = del_reasons.find(info_hash_decoded);
if (msg != del_reasons.end()) {
@@ -210,55 +221,73 @@ std::string worker::error(std::string err) {
return output;
}
-std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::string> &params, std::map<std::string, std::string> &headers, std::string &ip, bool &gzip){
- time_t cur_time = time(NULL);
-
- if(params["compact"] != "1") {
+std::string worker::warning(std::string msg) {
+ std::string output = "15:warning message";
+ output += inttostr(msg.length());
+ output += ':';
+ output += msg;
+ return output;
+}
+
+std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::string> &params, std::map<std::string, std::string> &headers, std::string &ip, bool &gzip) {
+ cur_time = time(NULL);
+
+ if (params["compact"] != "1") {
return error("Your client does not support compact announces");
}
-
+
int64_t left = strtolonglong(params["left"]);
int64_t uploaded = std::max((int64_t)0, strtolonglong(params["uploaded"]));
int64_t downloaded = std::max((int64_t)0, strtolonglong(params["downloaded"]));
int64_t corrupt = strtolonglong(params["corrupt"]);
-
+
+ int snatches = 0; // This is the value that gets sent to the database on a snatch
+ int active = 1; // This is the value that marks a peer as active/inactive in the database
bool inserted = false; // If we insert the peer as opposed to update
bool update_torrent = false; // Whether or not we should update the torrent in the DB
bool completed_torrent = false; // Whether or not the current announcement is a snatch
+ bool stopped_torrent = false; // Was the torrent just stopped?
bool expire_token = false; // Whether or not to expire a token after torrent completion
-
+ bool peer_changed = false; // Whether or not the peer is new or has changed since the last announcement
+
std::map<std::string, std::string>::const_iterator peer_id_iterator = params.find("peer_id");
- if(peer_id_iterator == params.end()) {
+ if (peer_id_iterator == params.end()) {
return error("No peer ID");
}
std::string peer_id = peer_id_iterator->second;
peer_id = hex_decode(peer_id);
-
- if(whitelist.size() > 0) {
+
+ if (whitelist.size() > 0) {
bool found = false; // Found client in whitelist?
- for(unsigned int i = 0; i < whitelist.size(); i++) {
- if(peer_id.find(whitelist[i]) == 0) {
+ for (unsigned int i = 0; i < whitelist.size(); i++) {
+ if (peer_id.find(whitelist[i]) == 0) {
found = true;
break;
}
}
- if(!found) {
+ if (!found) {
return error("Your client is not on the whitelist");
}
}
- if(params["event"] == "completed") {
+ if (params["event"] == "completed") {
+ // Don't update <snatches> here as we may decide to use other conditions later on
completed_torrent = true;
+ } else if (params["event"] == "stopped") {
+ stopped_torrent = true;
+ peer_changed = true;
+ update_torrent = true;
+ active = 0;
}
-
+
peer * p;
peer_list::iterator i;
// Insert/find the peer in the torrent list
- if(left > 0) {
+ if (left > 0) {
i = tor.leechers.find(peer_id);
- if(i == tor.leechers.end()) {
+ if (i == tor.leechers.end()) {
peer new_peer;
- std::pair<peer_list::iterator, bool> insert
+ std::pair<peer_list::iterator, bool> insert
= tor.leechers.insert(std::pair<std::string, peer>(peer_id, new_peer));
p = &(insert.first->second);
@@ -266,9 +295,9 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
} else {
p = &i->second;
}
- } else if(completed_torrent) {
+ } else if (completed_torrent) {
i = tor.leechers.find(peer_id);
- if(i == tor.leechers.end()) {
+ if (i == tor.leechers.end()) {
peer new_peer;
std::pair<peer_list::iterator, bool> insert
= tor.seeders.insert(std::pair<std::string, peer>(peer_id, new_peer));
@@ -280,13 +309,13 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
}
} else {
i = tor.seeders.find(peer_id);
- if(i == tor.seeders.end()) {
+ if (i == tor.seeders.end()) {
i = tor.leechers.find(peer_id);
- if(i == tor.leechers.end()) {
+ if (i == tor.leechers.end()) {
peer new_peer;
std::pair<peer_list::iterator, bool> insert
= tor.seeders.insert(std::pair<std::string, peer>(peer_id, new_peer));
-
+
p = &(insert.first->second);
inserted = true;
} else {
@@ -294,70 +323,66 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
std::pair<peer_list::iterator, bool> insert
= tor.seeders.insert(std::pair<std::string, peer>(peer_id, *p));
tor.leechers.erase(peer_id);
- if(downloaded > 0) {
+ if (downloaded > 0) {
std::cout << "Found unreported snatch from user " << u.id << " on torrent " << tor.id << std::endl;
}
p = &(insert.first->second);
-// completed_torrent = true; // Not sure if we want to do this. Might cause massive spam for broken clients (e.g. µTorrent 3)
+ peer_changed = true;
+// completed_torrent = true; // Not sure if we want to do this. Will cause massive spam for weird clients (e.g. µTorrent 3 and Deluge)
}
} else {
p = &i->second;
}
-
+
tor.last_seeded = cur_time;
}
-
- // Update the peer
- p->left = left;
- p->visible = user_is_visible(&u);
+
int64_t upspeed = 0;
int64_t downspeed = 0;
- int64_t real_uploaded_change = 0;
- int64_t real_downloaded_change = 0;
-
- if(inserted || params["event"] == "started") {
+ if (inserted || params["event"] == "started") {
//New peer on this torrent
update_torrent = true;
p->userid = u.id;
- p->peer_id = peer_id;
p->first_announced = cur_time;
p->last_announced = 0;
p->uploaded = uploaded;
p->downloaded = downloaded;
p->corrupt = corrupt;
p->announces = 1;
- } else if(uploaded < p->uploaded || downloaded < p->downloaded) {
+ peer_changed = true;
+ } else if (uploaded < p->uploaded || downloaded < p->downloaded) {
p->announces++;
p->uploaded = uploaded;
p->downloaded = downloaded;
+ peer_changed = true;
} else {
int64_t uploaded_change = 0;
int64_t downloaded_change = 0;
int64_t corrupt_change = 0;
p->announces++;
-
- if(uploaded != p->uploaded) {
+
+ if (uploaded != p->uploaded) {
uploaded_change = uploaded - p->uploaded;
- real_uploaded_change = uploaded_change;
p->uploaded = uploaded;
}
- if(downloaded != p->downloaded) {
+ if (downloaded != p->downloaded) {
downloaded_change = downloaded - p->downloaded;
- real_downloaded_change = downloaded_change;
p->downloaded = downloaded;
}
- if(corrupt != p->corrupt) {
+ if (corrupt != p->corrupt) {
corrupt_change = corrupt - p->corrupt;
p->corrupt = corrupt;
tor.balance -= corrupt_change;
update_torrent = true;
}
- if(uploaded_change || downloaded_change) {
+ peer_changed = peer_changed || uploaded_change || downloaded_change || corrupt_change;
+
+ if (uploaded_change || downloaded_change) {
tor.balance += uploaded_change;
tor.balance -= downloaded_change;
update_torrent = true;
-
- if(cur_time > p->last_announced) {
+
+ if (cur_time > p->last_announced) {
upspeed = uploaded_change / (cur_time - p->last_announced);
downspeed = downloaded_change / (cur_time - p->last_announced);
}
@@ -365,8 +390,8 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
if (tor.free_torrent == NEUTRAL) {
downloaded_change = 0;
uploaded_change = 0;
- } else if(tor.free_torrent == FREE || sit != tor.tokened_users.end()) {
- if(sit != tor.tokened_users.end()) {
+ } else if (tor.free_torrent == FREE || sit != tor.tokened_users.end()) {
+ if (sit != tor.tokened_users.end()) {
expire_token = true;
std::stringstream record;
record << '(' << u.id << ',' << tor.id << ',' << downloaded_change << ')';
@@ -375,9 +400,8 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
}
downloaded_change = 0;
}
-
- if(uploaded_change || downloaded_change) {
-
+
+ if (uploaded_change || downloaded_change) {
std::stringstream record;
record << '(' << u.id << ',' << uploaded_change << ',' << downloaded_change << ')';
std::string record_str = record.str();
@@ -385,155 +409,184 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
}
}
}
- p->last_announced = cur_time;
-
+ p->left = left;
+
std::map<std::string, std::string>::const_iterator param_ip = params.find("ip");
- if(param_ip != params.end()) {
+ if (param_ip != params.end()) {
ip = param_ip->second;
} else {
param_ip = params.find("ipv4");
- if(param_ip != params.end()) {
+ if (param_ip != params.end()) {
ip = param_ip->second;
}
}
-
+
unsigned int port = strtolong(params["port"]);
// Generate compact ip/port string
- if(inserted || port != p->port || ip != p->ip) {
+ if (inserted || port != p->port || ip != p->ip) {
p->port = port;
p->ip = ip;
p->ip_port = "";
char x = 0;
- for(size_t pos = 0, end = ip.length(); pos < end; pos++) {
- if(ip[pos] == '.') {
+ bool invalid_ip = false;
+ for (size_t pos = 0, end = ip.length(); pos < end; pos++) {
+ if (ip[pos] == '.') {
p->ip_port.push_back(x);
x = 0;
continue;
- } else if(!isdigit(ip[pos])) {
- return error("Unexpected character in IP address. Only IPv4 is currently supported");
+ } else if (!isdigit(ip[pos])) {
+ invalid_ip = true;
+ break;
}
x = x * 10 + ip[pos] - '0';
}
- p->ip_port.push_back(x);
- p->ip_port.push_back(port >> 8);
- p->ip_port.push_back(port & 0xFF);
- if(p->ip_port.length() != 6) {
- return error("Specified IP address is of a bad length");
+ if (!invalid_ip) {
+ p->ip_port.push_back(x);
+ p->ip_port.push_back(port >> 8);
+ p->ip_port.push_back(port & 0xFF);
}
+ if (p->ip_port.length() != 6) {
+ p->ip_port.clear();
+ invalid_ip = true;
+ }
+ p->invalid_ip = invalid_ip;
}
-
+
+ // Update the peer
+ p->last_announced = cur_time;
+ p->visible = peer_is_visible(&u, p);
+
+ // Add peer data to the database
+ std::stringstream record;
+ if (peer_changed) {
+ record << '(' << u.id << ',' << tor.id << ',' << active << ',' << uploaded << ',' << downloaded << ',' << upspeed << ',' << downspeed << ',' << left << ',' << corrupt << ',' << (cur_time - p->first_announced) << ',' << p->announces << ',';
+ std::string record_str = record.str();
+ std::string record_ip;
+ if (u.protect_ip) {
+ record_ip = "";
+ } else {
+ record_ip = ip;
+ }
+ db->record_peer(record_str, record_ip, peer_id, headers["user-agent"]);
+ } else {
+ record << '(' << tor.id << ',' << (cur_time - p->first_announced) << ',' << p->announces << ',';
+ std::string record_str = record.str();
+ db->record_peer(record_str, peer_id);
+ }
+
// Select peers!
unsigned int numwant;
std::map<std::string, std::string>::const_iterator param_numwant = params.find("numwant");
- if(param_numwant == params.end()) {
+ if (param_numwant == params.end()) {
numwant = 50;
} else {
numwant = std::min(50l, strtolong(param_numwant->second));
}
- int snatches = 0;
- int active = 1;
- if(params["event"] == "stopped") {
- update_torrent = true;
- active = 0;
+ if (stopped_torrent) {
numwant = 0;
-
- if(left > 0) {
- if(tor.leechers.erase(peer_id) == 0) {
+ if (left > 0) {
+ if (tor.leechers.erase(peer_id) == 0) {
std::cout << "Tried and failed to remove seeder from torrent " << tor.id << std::endl;
}
} else {
- if(tor.seeders.erase(peer_id) == 0) {
+ if (tor.seeders.erase(peer_id) == 0) {
std::cout << "Tried and failed to remove leecher from torrent " << tor.id << std::endl;
}
}
- } else if(completed_torrent) {
+ } else if (completed_torrent) {
snatches = 1;
update_torrent = true;
tor.completed++;
-
+
std::stringstream record;
- record << '(' << u.id << ',' << tor.id << ',' << cur_time << ", '" << ip << "')";
+ std::string record_ip;
+ if (u.protect_ip) {
+ record_ip = "";
+ } else {
+ record_ip = ip;
+ }
+ record << '(' << u.id << ',' << tor.id << ',' << cur_time << ", '" << record_ip << "')";
std::string record_str = record.str();
db->record_snatch(record_str);
-
+
// User is a seeder now!
- if(!inserted) {
+ if (!inserted) {
tor.seeders.insert(std::pair<std::string, peer>(peer_id, *p));
tor.leechers.erase(peer_id);
}
- if(expire_token) {
- (&s_comm)->expire_token(tor.id, u.id);
+ if (expire_token) {
+ s_comm->expire_token(tor.id, u.id);
tor.tokened_users.erase(u.id);
}
// do cache expire
- } else if(!u.can_leech && left > 0) {
+ } else if (!u.can_leech && left > 0) {
numwant = 0;
}
std::string peers;
- if(numwant > 0) {
+ if (numwant > 0) {
peers.reserve(numwant*6);
unsigned int found_peers = 0;
- if(left > 0) { // Show seeders to leechers first
- if(tor.seeders.size() > 0) {
+ if (left > 0) { // Show seeders to leechers first
+ if (tor.seeders.size() > 0) {
// We do this complicated stuff to cycle through the seeder list, so all seeders will get shown to leechers
-
+
// Find out where to begin in the seeder list
peer_list::const_iterator i;
- if(tor.last_selected_seeder == "") {
+ if (tor.last_selected_seeder == "") {
i = tor.seeders.begin();
} else {
i = tor.seeders.find(tor.last_selected_seeder);
- if(i == tor.seeders.end() || ++i == tor.seeders.end()) {
+ if (i == tor.seeders.end() || ++i == tor.seeders.end()) {
i = tor.seeders.begin();
}
}
-
+
// Find out where to end in the seeder list
peer_list::const_iterator end;
- if(i == tor.seeders.begin()) {
+ if (i == tor.seeders.begin()) {
end = tor.seeders.end();
} else {
end = i;
- if(--end == tor.seeders.begin()) {
+ if (--end == tor.seeders.begin()) {
end++;
i++;
}
}
-
+
// Add seeders
while(i != end && found_peers < numwant) {
- if(i == tor.seeders.end()) {
+ if (i == tor.seeders.end()) {
i = tor.seeders.begin();
}
// Don't show users themselves
- if (i->second.userid == p->userid) {
+ if (i->second.userid == p->userid || !i->second.visible) {
i++;
continue;
}
peers.append(i->second.ip_port);
found_peers++;
- tor.last_selected_seeder = i->second.peer_id;
+ tor.last_selected_seeder = i->first;
i++;
}
}
- if(found_peers < numwant && tor.leechers.size() > 1) {
- for(peer_list::const_iterator i = tor.leechers.begin(); i != tor.leechers.end() && found_peers < numwant; i++) {
+ if (found_peers < numwant && tor.leechers.size() > 1) {
+ for (peer_list::const_iterator i = tor.leechers.begin(); i != tor.leechers.end() && found_peers < numwant; i++) {
// Don't show users themselves or leech disabled users
- if(i->second.ip_port == p->ip_port || i->second.userid == p->userid || !i->second.visible) {
+ if (i->second.ip_port == p->ip_port || i->second.userid == p->userid || !i->second.visible) {
continue;
}
found_peers++;
peers.append(i->second.ip_port);
}
-
+
}
- } else if(tor.leechers.size() > 0) { // User is a seeder, and we have leechers!
- for(peer_list::const_iterator i = tor.leechers.begin(); i != tor.leechers.end() && found_peers < numwant; i++) {
+ } else if (tor.leechers.size() > 0) { // User is a seeder, and we have leechers!
+ for (peer_list::const_iterator i = tor.leechers.begin(); i != tor.leechers.end() && found_peers < numwant; i++) {
// Don't show users themselves or leech disabled users
- if(i->second.userid == p->userid || !i->second.visible) {
+ if (i->second.userid == p->userid || !i->second.visible) {
continue;
}
found_peers++;
@@ -542,7 +595,7 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
}
}
- if(update_torrent || tor.last_flushed + 3600 < cur_time) {
+ if (update_torrent || tor.last_flushed + 3600 < cur_time) {
tor.last_flushed = cur_time;
std::stringstream record;
@@ -551,19 +604,7 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
db->record_torrent(record_str);
}
- std::stringstream record;
- record << '(' << u.id << ',' << tor.id << ',' << active << ',' << uploaded << ',' << downloaded << ',' << upspeed << ',' << downspeed << ',' << left << ',' << corrupt << ',' << (cur_time - p->first_announced) << ',' << p->announces << ',';
- std::string record_str = record.str();
- db->record_peer(record_str, ip, peer_id, headers["user-agent"]);
-
- if (real_uploaded_change > 0 || real_downloaded_change > 0) {
- record.str("");
- record << '(' << u.id << ',' << downloaded << ',' << left << ',' << uploaded << ',' << upspeed << ',' << downspeed << ',' << (cur_time - p->first_announced);
- record_str = record.str();
- db->record_peer_hist(record_str, peer_id, tor.id);
- }
-
- if(!u.can_leech && left > 0) {
+ if (!u.can_leech && left > 0) {
return error("Access denied, leeching forbidden");
}
@@ -579,13 +620,16 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
response += "e12:min intervali";
response += inttostr(conf->announce_interval);
response += "e5:peers";
- if(peers.length() == 0) {
+ if (peers.length() == 0) {
response += "0:";
} else {
response += inttostr(peers.length());
response += ":";
response += peers;
}
+ if (p->invalid_ip) {
+ response += warning("Illegal character found in IP address. IPv6 is not supported");
+ }
response += "e";
/* gzip compression actually makes announce returns larger from our
@@ -607,16 +651,16 @@ std::string worker::announce(torrent &tor, user &u, std::map<std::string, std::s
std::string worker::scrape(const std::list<std::string> &infohashes, std::map<std::string, std::string> &headers, bool &gzip) {
std::string output = "d5:filesd";
- for(std::list<std::string>::const_iterator i = infohashes.begin(); i != infohashes.end(); i++) {
+ for (std::list<std::string>::const_iterator i = infohashes.begin(); i != infohashes.end(); i++) {
std::string infohash = *i;
infohash = hex_decode(infohash);
-
+
torrent_list::iterator tor = torrents_list.find(infohash);
- if(tor == torrents_list.end()) {
+ if (tor == torrents_list.end()) {
continue;
}
torrent *t = &(tor->second);
-
+
output += inttostr(infohash.length());
output += ':';
output += infohash;
@@ -646,7 +690,7 @@ std::string worker::scrape(const std::list<std::string> &infohashes, std::map<st
//TODO: Restrict to local IPs
std::string worker::update(std::map<std::string, std::string> &params) {
- if(params["action"] == "change_passkey") {
+ if (params["action"] == "change_passkey") {
std::string oldpasskey = params["oldpasskey"];
std::string newpasskey = params["newpasskey"];
user_list::iterator i = users_list.find(oldpasskey);
@@ -657,14 +701,14 @@ std::string worker::update(std::map<std::string, std::string> &params) {
users_list.erase(oldpasskey);
std::cout << "Changed passkey from " << oldpasskey << " to " << newpasskey << " for user " << i->second.id << std::endl;
}
- } else if(params["action"] == "add_torrent") {
+ } else if (params["action"] == "add_torrent") {
torrent t;
t.id = strtolong(params["id"]);
std::string info_hash = params["info_hash"];
info_hash = hex_decode(info_hash);
- if(params["freetorrent"] == "0") {
+ if (params["freetorrent"] == "0") {
t.free_torrent = NORMAL;
- } else if(params["freetorrent"] == "1") {
+ } else if (params["freetorrent"] == "1") {
t.free_torrent = FREE;
} else {
t.free_torrent = NEUTRAL;
@@ -674,13 +718,13 @@ std::string worker::update(std::map<std::string, std::string> &params) {
t.last_selected_seeder = "";
torrents_list[info_hash] = t;
std::cout << "Added torrent " << t.id<< ". FL: " << t.free_torrent << " " << params["freetorrent"] << std::endl;
- } else if(params["action"] == "update_torrent") {
+ } else if (params["action"] == "update_torrent") {
std::string info_hash = params["info_hash"];
info_hash = hex_decode(info_hash);
freetype fl;
- if(params["freetorrent"] == "0") {
+ if (params["freetorrent"] == "0") {
fl = NORMAL;
- } else if(params["freetorrent"] == "1") {
+ } else if (params["freetorrent"] == "1") {
fl = FREE;
} else {
fl = NEUTRAL;
@@ -692,19 +736,19 @@ std::string worker::update(std::map<std::string, std::string> &params) {
} else {
std::cout << "Failed to find torrent " << info_hash << " to FL " << fl << std::endl;
}
- } else if(params["action"] == "update_torrents") {
+ } else if (params["action"] == "update_torrents") {
// Each decoded infohash is exactly 20 characters long.
std::string info_hashes = params["info_hashes"];
info_hashes = hex_decode(info_hashes);
freetype fl;
- if(params["freetorrent"] == "0") {
+ if (params["freetorrent"] == "0") {
fl = NORMAL;
- } else if(params["freetorrent"] == "1") {
+ } else if (params["freetorrent"] == "1") {
fl = FREE;
} else {
fl = NEUTRAL;
}
- for(unsigned int pos = 0; pos < info_hashes.length(); pos += 20) {
+ for (unsigned int pos = 0; pos < info_hashes.length(); pos += 20) {
std::string info_hash = info_hashes.substr(pos, 20);
auto torrent_it = torrents_list.find(info_hash);
if (torrent_it != torrents_list.end()) {
@@ -714,7 +758,7 @@ std::string worker::update(std::map<std::string, std::string> &params) {
std::cout << "Failed to find torrent " << info_hash << " to FL " << fl << std::endl;
}
}
- } else if(params["action"] == "add_token") {
+ } else if (params["action"] == "add_token") {
std::string info_hash = hex_decode(params["info_hash"]);
int user_id = atoi(params["userid"].c_str());
auto torrent_it = torrents_list.find(info_hash);
@@ -723,7 +767,7 @@ std::string worker::update(std::map<std::string, std::string> &params) {
} else {
std::cout << "Failed to find torrent to add a token for user " << user_id << std::endl;
}
- } else if(params["action"] == "remove_token") {
+ } else if (params["action"] == "remove_token") {
std::string info_hash = hex_decode(params["info_hash"]);
int user_id = atoi(params["userid"].c_str());
auto torrent_it = torrents_list.find(info_hash);
@@ -732,7 +776,7 @@ std::string worker::update(std::map<std::string, std::string> &params) {
} else {
std::cout << "Failed to find torrent " << info_hash << " to remove token for user " << user_id << std::endl;
}
- } else if(params["action"] == "delete_torrent") {
+ } else if (params["action"] == "delete_torrent") {
std::string info_hash = params["info_hash"];
info_hash = hex_decode(info_hash);
int reason = -1;
@@ -752,68 +796,78 @@ std::string worker::update(std::map<std::string, std::string> &params) {
} else {
std::cout << "Failed to find torrent " << info_hash << " to delete " << std::endl;
}
- } else if(params["action"] == "add_user") {
+ } else if (params["action"] == "add_user") {
std::string passkey = params["passkey"];
unsigned int id = strtolong(params["id"]);
user u;
u.id = id;
u.can_leech = 1;
+ if (params["visible"] == "0") {
+ u.protect_ip = 1;
+ } else {
+ u.protect_ip = 0;
+ }
users_list[passkey] = u;
std::cout << "Added user " << id << std::endl;
- } else if(params["action"] == "remove_user") {
+ } else if (params["action"] == "remove_user") {
std::string passkey = params["passkey"];
users_list.erase(passkey);
std::cout << "Removed user " << passkey << std::endl;
- } else if(params["action"] == "remove_users") {
+ } else if (params["action"] == "remove_users") {
// Each passkey is exactly 32 characters long.
std::string passkeys = params["passkeys"];
- for(unsigned int pos = 0; pos < passkeys.length(); pos += 32){
+ for (unsigned int pos = 0; pos < passkeys.length(); pos += 32) {
std::string passkey = passkeys.substr(pos, 32);
users_list.erase(passkey);
std::cout << "Removed user " << passkey << std::endl;
}
- } else if(params["action"] == "update_user") {
+ } else if (params["action"] == "update_user") {
std::string passkey = params["passkey"];
bool can_leech = true;
- if(params["can_leech"] == "0") {
+ bool protect_ip = false;
+ if (params["can_leech"] == "0") {
can_leech = false;
}
+ if (params["visible"] == "0") {
+ protect_ip = true;
+ }
user_list::iterator i = users_list.find(passkey);
if (i == users_list.end()) {
std::cout << "No user with passkey " << passkey << " found when attempting to change leeching status!" << std::endl;
} else {
+ users_list[passkey].protect_ip = protect_ip;
users_list[passkey].can_leech = can_leech;
std::cout << "Updated user " << passkey << std::endl;
}
- } else if(params["action"] == "add_whitelist") {
+ } else if (params["action"] == "add_whitelist") {
std::string peer_id = params["peer_id"];
whitelist.push_back(peer_id);
std::cout << "Whitelisted " << peer_id << std::endl;
- } else if(params["action"] == "remove_whitelist") {
+ } else if (params["action"] == "remove_whitelist") {
std::string peer_id = params["peer_id"];
- for(unsigned int i = 0; i < whitelist.size(); i++) {
- if(whitelist[i].compare(peer_id) == 0) {
+ for (unsigned int i = 0; i < whitelist.size(); i++) {
+ if (whitelist[i].compare(peer_id) == 0) {
whitelist.erase(whitelist.begin() + i);
break;
}
}
std::cout << "De-whitelisted " << peer_id << std::endl;
- } else if(params["action"] == "edit_whitelist") {
+ } else if (params["action"] == "edit_whitelist") {
std::string new_peer_id = params["new_peer_id"];
std::string old_peer_id = params["old_peer_id"];
- for(unsigned int i = 0; i < whitelist.size(); i++) {
- if(whitelist[i].compare(old_peer_id) == 0) {
+ for (unsigned int i = 0; i < whitelist.size(); i++) {
+ if (whitelist[i].compare(old_peer_id) == 0) {
whitelist.erase(whitelist.begin() + i);
break;
}
}
whitelist.push_back(new_peer_id);
std::cout << "Edited whitelist item from " << old_peer_id << " to " << new_peer_id << std::endl;
- } else if(params["action"] == "update_announce_interval") {
+ } else if (params["action"] == "update_announce_interval") {
unsigned int interval = strtolong(params["new_announce_interval"]);
conf->announce_interval = interval;
std::cout << "Edited announce interval to " << interval << std::endl;
- } else if(params["action"] == "info_torrent") {
+ } else if (params["action"] == "info_torrent") {
std::string info_hash_hex = params["info_hash"];
std::string info_hash = hex_decode(info_hash_hex);
std::cout << "Info for torrent '" << info_hash_hex << "'" << std::endl;
@@ -834,16 +888,15 @@ void worker::reap_peers() {
}
void worker::do_reap_peers() {
- db->logger_ptr->log("Began worker::do_reap_peers()");
std::cout << "Starting peer reaper" << std::endl;
- time_t cur_time = time(NULL);
+ cur_time = time(NULL);
unsigned int reaped = 0;
- std::unordered_map<std::string, torrent>::iterator i = torrents_list.begin();
- for(; i != torrents_list.end(); i++) {
- std::map<std::string, peer>::iterator p = i->second.leechers.begin();
- std::map<std::string, peer>::iterator del_p;
+ torrent_list::iterator i = torrents_list.begin();
+ for (; i != torrents_list.end(); i++) {
+ peer_list::iterator p = i->second.leechers.begin();
+ peer_list::iterator del_p;
while(p != i->second.leechers.end()) {
- if(p->second.last_announced + conf->peers_timeout < cur_time) {
+ if (p->second.last_announced + conf->peers_timeout < cur_time) {
del_p = p;
p++;
boost::mutex::scoped_lock lock(db->torrent_list_mutex);
@@ -855,7 +908,7 @@ void worker::do_reap_peers() {
}
p = i->second.seeders.begin();
while(p != i->second.seeders.end()) {
- if(p->second.last_announced + conf->peers_timeout < cur_time) {
+ if (p->second.last_announced + conf->peers_timeout < cur_time) {
del_p = p;
p++;
boost::mutex::scoped_lock lock(db->torrent_list_mutex);
@@ -867,7 +920,6 @@ void worker::do_reap_peers() {
}
}
std::cout << "Reaped " << reaped << " peers" << std::endl;
- db->logger_ptr->log("Completed worker::do_reap_peers()");
}
void worker::do_reap_del_reasons()
@@ -892,7 +944,7 @@ void worker::do_reap_del_reasons()
std::string worker::get_del_reason(int code)
{
- switch(code) {
+ switch (code) {
case DUPE:
return "Dupe";
break;
@@ -968,9 +1020,8 @@ std::string worker::get_del_reason(int code)
}
}
-bool worker::user_is_visible(user *u) {
- if(!u->can_leech) {
- return false;
- }
- return true;
+/* Peers should be invisible if they are a leecher without
+ download privs or their IP is invalid */
+bool worker::peer_is_visible(user *u, peer *p) {
+ return (p->left == 0 || u->can_leech) && !p->invalid_ip;
}
diff --git a/src/worker.h b/src/worker.h
index 2d6dff1..6d9969f 100644
--- a/src/worker.h
+++ b/src/worker.h
@@ -23,15 +23,17 @@ class worker {
void do_reap_peers();
void do_reap_del_reasons();
tracker_status status;
- site_comm s_comm;
+ time_t cur_time;
+ site_comm * s_comm;
std::string get_del_reason(int code);
boost::mutex del_reasons_lock;
- bool user_is_visible(user *u);
+ bool peer_is_visible(user *u, peer *p);
public:
- worker(torrent_list &torrents, user_list &users, std::vector<std::string> &_whitelist, config * conf_obj, mysql * db_obj, site_comm &sc);
+ worker(torrent_list &torrents, user_list &users, std::vector<std::string> &_whitelist, config * conf_obj, mysql * db_obj, site_comm * sc);
std::string work(std::string &input, std::string &ip, bool &gzip);
std::string error(std::string err);
+ std::string warning(std::string err);
std::string announce(torrent &tor, user &u, std::map<std::string, std::string> &params, std::map<std::string, std::string> &headers, std::string &ip, bool &gzip);
std::string scrape(const std::list<std::string> &infohashes, std::map<std::string, std::string> &headers, bool &gzip);
std::string update(std::map<std::string, std::string> &params);