summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavaL <ayoyo@thoughtworks.com>2016-06-02 10:51:33 +0200
committerNavaL <ayoyo@thoughtworks.com>2016-06-02 10:51:33 +0200
commit45adea860ceaf23cfabdaf6a22d13c4650550bb3 (patch)
tree55edd7e02d776373d249422d75cbd9b68316ad99
parent6b528c26a05f1c3f969a9896328be408bcfd6064 (diff)
Revert "added custom c extension to set mutex locking for openssl rand generation"
This reverts commit 6b528c26a05f1c3f969a9896328be408bcfd6064.
-rw-r--r--service/extension/extension.c106
-rw-r--r--service/pixelated/application.py29
-rw-r--r--service/setup.py5
3 files changed, 1 insertions, 139 deletions
diff --git a/service/extension/extension.c b/service/extension/extension.c
deleted file mode 100644
index 4b695d72..00000000
--- a/service/extension/extension.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#include "Python.h"
-
-#include "openssl/crypto.h"
-#include "stdio.h"
-
-static PyObject *SpamError;
-
-static PyObject *IdCallback;
-static PyObject *LockingCallback;
-
-
-//--------------------------
-
-static void locking_function(int mode, int n, const char * file, int line)
-{
- PyObject *arglist;
- PyObject *result;
-
- printf("Enter locking_function\n");
-
- arglist = Py_BuildValue("(i, i, s, i)", mode, n, file, line);
- result = PyObject_CallObject(LockingCallback, arglist);
-// if(mode & CRYPTO_LOCK)
-//
-// result = PyObject_CallObject(IdCallback, arglist);
-// else
-// a--;
-
- Py_DECREF(arglist);
- Py_DECREF(result);
-
- printf("Leave locking_function\n");
-}
-
-static unsigned long id_function(void)
-{
- PyObject *arglist;
- PyObject *result;
- int value;
-
- arglist = Py_BuildValue(NULL);
- result = PyObject_CallObject(IdCallback, arglist);
-
- if (!PyArg_ParseTuple(result, "i", &value))
- return 0;
-
- Py_DECREF(arglist);
- Py_DECREF(result);
-
- return ((unsigned long)value);
-}
-
-
-
-//--------------------------
-
-
-
-static PyObject *
-spam_system(PyObject *self, PyObject *args)
-{
- const char *command;
- int sts;
-
- if (!PyArg_ParseTuple(args, "s", &command))
- return NULL;
- sts = system(command);
- if (sts < 0) {
- PyErr_SetString(SpamError, "System command failed");
- return NULL;
- }
- return PyLong_FromLong(sts);
-}
-
-static PyObject * enable_mutexes(PyObject *self, PyObject *args) {
- PyObject *pIdCallback, *pLockingCallback;
-
- if (!PyArg_UnpackTuple(args, "enable_mutexes", 2, 2, &pIdCallback, &pLockingCallback)) {
- return NULL;
- }
- IdCallback = pIdCallback;
- LockingCallback = pLockingCallback;
-
- CRYPTO_set_id_callback(id_function);
- CRYPTO_set_locking_callback(locking_function);
-
- printf("Enabled mutexes\n");
-
- Py_RETURN_NONE;
-}
-
-
-static PyMethodDef SpamMethods[] = {
- {"system", spam_system, METH_VARARGS,
- "Execute a shell command."},
- {"enable_mutexes", enable_mutexes, METH_VARARGS,
- "Enable mutexes for openssl"},
- {NULL, NULL, 0, NULL} /* Sentinel */
-};
-
-
-PyMODINIT_FUNC
-initfoobar(void)
-{
- (void) Py_InitModule("foobar", SpamMethods);
-}
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 8b128cd3..ce1e0258 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -40,10 +40,6 @@ from pixelated.resources.root_resource import RootResource
log = logging.getLogger(__name__)
-from multiprocessing import Lock
-from threading import current_thread
-import foobar
-
class ServicesFactory(object):
@@ -140,33 +136,8 @@ def _create_service_factory(args):
else:
return ServicesFactory(UserAgentMode(is_single_user=False))
-CRYPTO_LOCK=1
-CRYPTO_UNLOCK=2
-CRYPTO_READ=4
-CRYPTO_WRITE=8
-
-
-def idfunc():
- return current_thread().ident
-
-
-locks = [Lock(), Lock(), Lock(), Lock(), Lock(),Lock(), Lock(), Lock(), Lock(), Lock()]
-
-
-def lockfunc(mode, n, file, line):
- if mode & CRYPTO_LOCK == CRYPTO_LOCK:
- print "acquire lock %d" % n
- locks[n].acquire()
- elif mode & CRYPTO_UNLOCK == CRYPTO_UNLOCK:
- print "release lock %d" % n
- locks[n].release()
- else:
- print "unexpected call with mode %d and n %d" % (mode, n)
-
def initialize():
- foobar.enable_mutexes(idfunc, lockfunc)
-
log.info('Starting the Pixelated user agent')
args = arguments.parse_user_agent_args()
logger.init(debug=args.debug)
diff --git a/service/setup.py b/service/setup.py
index b04e86c7..53a8f715 100644
--- a/service/setup.py
+++ b/service/setup.py
@@ -14,7 +14,6 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-from setuptools import Extension
from setuptools import setup
import os
@@ -56,6 +55,4 @@ setup(name='pixelated-user-agent',
'pixelated-register = pixelated.register:initialize'
]
},
- include_package_data=True,
- ext_modules=[
- Extension("foobar", ["extension/extension.c"], libraries=["crypto"])])
+ include_package_data=True)