[-]
[+]
|
Changed |
apache2-mod_asn.changes
|
|
[-]
[+]
|
Changed |
apache2-mod_asn.spec
^
|
|
[-]
[+]
|
Deleted |
mod_asn-1.2.tar.gz/docs/_static
^
|
-(directory)
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/asn_get_routeviews.py
^
|
@@ -15,12 +15,14 @@
# mirrored daily from archive.routeviews.org, to save routeviews.org the traffic
url = 'http://mirrorbrain.org/routeviews/%s' % filename
-if not os.path.exists(filename):
- print >>sys.stderr, 'downloading', url
+if os.path.exists(filename) \
+ and (time.time() - os.path.getmtime(filename)) < (60 * 60 * 8):
+ print >>sys.stderr, 'Using existing file, because it is less than 8h old.'
+ print >>sys.stderr, 'Remove it to have it downloaded again.'
+else:
+ print >>sys.stderr, 'Downloading', url
urllib.urlretrieve(url, filename=filename)
-if time.time() - os.path.getmtime(filename) > 60 * 60 * 24 * 7:
- sys.exit('File older than 1 week - remove it to have it downloaded again')
def gen_open(filenames):
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/asn_import.py
^
|
@@ -58,10 +58,12 @@
cursor.execute("begin")
cursor.execute("delete from %s" % tablename)
+ inserted = 0
for line in fileinput.input():
pfx, asnb, asn = line.split()
try:
cursor.execute("INSERT INTO %s VALUES ( %%s, %%s )" % tablename, [pfx, asn])
+ inserted += 1
except psycopg2.IntegrityError, e:
print e
if hasattr(psycopg2, 'errorcodes'):
@@ -75,8 +77,11 @@
raise
sys.exit('insert failed for %s, %s' % (pfx, asn))
- cursor.execute("commit")
- cursor.execute("vacuum analyze %s" % tablename)
+ if inserted > 0:
+ cursor.execute("commit")
+ cursor.execute("vacuum analyze %s" % tablename)
+ else:
+ sys.exit('nothing imported, no change comitted to the database')
import_raw()
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/docs/changes.rst
^
|
@@ -2,7 +2,58 @@
Release Notes/Change History
============================
-Release 1.2 (Jul 27, 2009)
+Release 1.4 (r79, Mar 27, 2010)
+-------------------------------
+
+This release does not bring about significant user-visible changes, but under
+the hood, some optimizations were done.
+
+* For more efficient database connection usage, mod_asn now closes the used
+ connection when its handler quits. Before, a connection with lifetime of the
+ request was acquired; if a long-running handler runs after mod_asn, this
+ could mean that the connection is blocked for other threads until the end of
+ the request. This could occur, for instance, when mod_mirrorbrain ran later,
+ but exited early because a file was supposed to be delivered directly.
+ This was tracked in `issue 44`_.
+
+* Database errors from the lower DBD layer are now resolved to strings, where
+ available. In relation to this: if an IP address is not found it isn't
+ necessarily an error, because it could be a private IP, for instance, which
+ is never present in global routing tables. That case is now logged with
+ NOTICE log level.
+
+* When compiling mod_asn with the Apache Portable Runtime 1.2, different
+ semantics are used to access database rows, couting from 0 instead of from 1. It
+ seemed to work either way (maybe because only a single row is accessed), but
+ hopefully now it is done more correctly and therefore safer in the future.
+ See `issue 29`_ and `issue 7`_ for the context.
+
+
+* In the documentation, the support scripts are now mentioned without their
+ :file:`.py` suffix in the example for data import, which might be less
+ confusing.
+
+.. _`issue 44`: http://mirrorbrain.org/issues/issue44
+.. _`issue 29`: http://mirrorbrain.org/issues/issue29
+.. _`issue 7`: http://mirrorbrain.org/issues/issue7
+
+
+Release 1.3 (r70, Jul 30, 2009)
+-------------------------------
+
+* Bugs in the :program:`asn_get_routeviews` and :program:`asn_import` scripts were fixed:
+
+ - The logic which decided whether to download the routing data snapshot file
+ was fixed. If :program:`asn_get_routeviews` is called and it finds a file
+ which was downloaded less then 8 hours ago, the file is reused. If no file
+ exists or the file is older than 8 hours, it is downloaded again.
+
+ - Deletion of existing entries in the database is now prevented, if not at
+ least one entry has been imported. This fixes a bug where the routing data
+ would be deleted if the script was called with no input.
+
+
+Release 1.2 (Jul 28, 2009)
--------------------------
* :program:`asn_get_routeviews` script:
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/docs/conf.py
^
|
@@ -120,7 +120,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+#html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/docs/installation.rst
^
|
@@ -98,7 +98,7 @@
The data is downloaded and imported into the database with the following
command::
- asn_get_routeviews.py | asn_import.py
+ asn_get_routeviews | asn_import
It is recommendable to run the command as unprivileged user, for safety
reasons (as any network client).
|
[-]
[+]
|
Changed |
mod_asn-1.4.tar.gz/mod_asn.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2008-2009 Peter Poeml <poeml@suse.de> / Novell Inc.
+ * Copyright (c) 2008-2010 Peter Poeml <poeml@mirrorbrain.org> / Novell Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,6 +35,7 @@
#include "http_main.h"
#include "http_protocol.h"
+#include "apr_version.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_dbd.h"
@@ -45,7 +46,7 @@
#define UNSET (-1)
#endif
-#define MOD_ASN_VER "1.2"
+#define MOD_ASN_VER "1.4"
#define VERSION_COMPONENT "mod_asn/"MOD_ASN_VER
/* from ssl/ssl_engine_config.c */
@@ -79,8 +80,9 @@
-/* optional function - look it up once in post_config */
-static ap_dbd_t *(*asn_dbd_acquire_fn)(request_rec*) = NULL;
+/* optional functions - look them up once in post_config */
+static ap_dbd_t *(*asn_dbd_open_fn)(apr_pool_t*, server_rec*) = NULL;
+static void (*asn_dbd_close_fn)(server_rec*, ap_dbd_t*) = NULL;
static void (*asn_dbd_prepare_fn)(server_rec*, const char*, const char*) = NULL;
@@ -113,10 +115,11 @@
asn_dbd_prepare_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_prepare);
if (asn_dbd_prepare_fn == NULL) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
- "[mod_asn] You must load mod_dbd to enable mod_asn functions");
+ "[mod_asn] You must load mod_dbd to enable mod_asn to work");
return HTTP_INTERNAL_SERVER_ERROR;
}
- asn_dbd_acquire_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_acquire);
+ asn_dbd_open_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_open);
+ asn_dbd_close_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_close);
}
/* prepare DBD SQL statements */
@@ -267,7 +270,7 @@
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_asn] No database query prepared!");
return DECLINED;
}
- ap_dbd_t *dbd = asn_dbd_acquire_fn(r);
+ ap_dbd_t *dbd = asn_dbd_open_fn(r->pool, r->server);
if (dbd == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"[mod_asn] Error acquiring database connection");
@@ -278,6 +281,7 @@
statement = apr_hash_get(dbd->prepared, scfg->query_prep, APR_HASH_KEY_STRING);
if (statement == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_asn] Could not get prepared statement!");
+ asn_dbd_close_fn(r->server, dbd);
return DECLINED;
}
@@ -293,6 +297,7 @@
if (!clientip) {
debugLog(r, cfg, "empty client ip... not doing a lookup");
+ asn_dbd_close_fn(r->server, dbd);
return DECLINED;
}
@@ -303,16 +308,30 @@
clientip, NULL) != 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"[mod_asn] Error looking up %s in database", clientip);
+ asn_dbd_close_fn(r->server, dbd);
return DECLINED;
}
+#if (APR_MAJOR_VERSION == 1 && APR_MINOR_VERSION == 2)
+#define DBD_FIRST_ROW 0
+#else
+#define DBD_FIRST_ROW 1
+#endif
/* we care only about the 1st row, because our query uses 'limit 1' */
- rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, 1);
- if (rv != 0) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
- "[mod_asn] Error retrieving row from database for %s",
- clientip);
+ rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, DBD_FIRST_ROW);
+ if (rv != APR_SUCCESS) {
+ if (rv == -1) {
+ /* not an error - might be a private IP, for instance */
+ ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
+ "[mod_asn] IP %s not found", clientip);
+ } else {
+ const char *errmsg = apr_dbd_error(dbd->driver, dbd->handle, rv);
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+ "[mod_asn] Error retrieving row from database for %s: %s",
+ clientip, (errmsg ? errmsg : "[???]"));
+ }
+ asn_dbd_close_fn(r->server, dbd);
return DECLINED;
}
@@ -326,11 +345,12 @@
}
/* clear the cursor by accessing invalid row */
- rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, 2);
+ rv = apr_dbd_get_row(dbd->driver, r->pool, res, &row, DBD_FIRST_ROW + 1);
if (rv != -1) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
"[mod_asn] found one row too much looking up %s",
clientip);
+ asn_dbd_close_fn(r->server, dbd);
return DECLINED;
}
@@ -344,6 +364,7 @@
apr_table_setn(r->err_headers_out, "X-AS", apr_pstrdup(r->pool, as));
}
+ asn_dbd_close_fn(r->server, dbd);
return OK;
}
|