summaryrefslogtreecommitdiff
path: root/src/leap/common/events
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2013-09-03 11:59:02 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2013-09-03 11:59:02 -0300
commitd367db764444c0befce425189acdf06339d1c566 (patch)
treeb0acf685b74a784565799851b0b18dd86d13faf2 /src/leap/common/events
parent03e5e612103bf129602032065cfe5917b8de8be5 (diff)
parent2c2f1eb7714bf98059b6966e08d01897c5626bd4 (diff)
Merge remote-tracking branch 'kali/bug/fix-exception' into develop
Diffstat (limited to 'src/leap/common/events')
-rw-r--r--src/leap/common/events/client.py31
-rw-r--r--src/leap/common/events/server.py11
2 files changed, 22 insertions, 20 deletions
diff --git a/src/leap/common/events/client.py b/src/leap/common/events/client.py
index 4ae9bff..83f18e0 100644
--- a/src/leap/common/events/client.py
+++ b/src/leap/common/events/client.py
@@ -14,7 +14,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
"""
The client end point of the events mechanism.
@@ -27,18 +26,15 @@ server that it wants to be notified whenever signals of that type are sent by
some other client.
"""
-
import logging
-import threading
from protobuf.socketrpc import RpcService
-from leap.common.events import (
- events_pb2 as proto,
- server,
- daemon,
- mac_auth,
-)
+
+from leap.common.events import events_pb2 as proto
+from leap.common.events import server
+from leap.common.events import daemon
+from leap.common.events import mac_auth
logger = logging.getLogger(__name__)
@@ -118,9 +114,13 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None,
if signal not in registered_callbacks:
registered_callbacks[signal] = []
cbklist = registered_callbacks[signal]
+
+ # TODO should check that the callback has the right
+ # number of arguments.
+
if uid and filter(lambda (x, y): x == uid, cbklist):
if not replace:
- raise CallbackAlreadyRegisteredException()
+ raise CallbackAlreadyRegistered()
else:
registered_callbacks[signal] = filter(lambda(x, y): x != uid,
cbklist)
@@ -133,12 +133,13 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None,
request.mac = ""
service = RpcService(proto.EventsServerService_Stub,
server.SERVER_PORT, 'localhost')
- logger.info(
+ logger.debug(
"Sending registration request to server on port %s: %s",
server.SERVER_PORT,
str(request)[:40])
return service.register(request, callback=reqcbk, timeout=timeout)
+
def unregister(signal, uid=None, reqcbk=None, timeout=1000):
"""
Unregister a callback.
@@ -226,7 +227,7 @@ def signal(signal, content="", mac_method="", mac="", reqcbk=None,
request.mac = mac
service = RpcService(proto.EventsServerService_Stub, server.SERVER_PORT,
'localhost')
- logger.info("Sending signal to server: %s", str(request)[:40])
+ logger.debug("Sending signal to server: %s", str(request)[:40])
return service.signal(request, callback=reqcbk, timeout=timeout)
@@ -251,7 +252,7 @@ def ping(port, reqcbk=None, timeout=1000):
proto.EventsClientService_Stub,
port,
'localhost')
- logger.info("Pinging a client in port %d..." % port)
+ logger.debug("Pinging a client in port %d..." % port)
return service.ping(request, callback=reqcbk, timeout=timeout)
@@ -277,7 +278,7 @@ class EventsClientService(proto.EventsClientService):
:param done: callback to be called when done
:type done: protobuf.socketrpc.server.Callback
"""
- logger.info('Received signal from server: %s...' % str(request)[:40])
+ logger.debug('Received signal from server: %s...' % str(request)[:40])
# run registered callbacks
# TODO: verify authentication using mac in incoming message
@@ -303,7 +304,7 @@ class EventsClientService(proto.EventsClientService):
:param done: callback to be called when done
:type done: protobuf.socketrpc.server.Callback
"""
- logger.info("Received ping request, sending response.")
+ logger.debug("Received ping request, sending response.")
response = proto.EventResponse()
response.status = proto.EventResponse.OK
done.run(response)
diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py
index 861cb4f..dc55551 100644
--- a/src/leap/common/events/server.py
+++ b/src/leap/common/events/server.py
@@ -85,6 +85,7 @@ def ensure_server(port=SERVER_PORT):
logger.info('Launching server on port %d.', port)
return EventsServerDaemon.ensure(port)
+
def process_ping(port, request, response):
"""
Response callback for the ping event.
@@ -100,7 +101,7 @@ def process_ping(port, request, response):
logger.info('A server is already running on port %d.', port)
return
# port is taken, and not by an events server
- logger.info('Port %d is taken by something not an events server.', port)
+ logger.warning('Port %d is taken by something not an events server.', port)
raise PortAlreadyTaken(port)
@@ -125,7 +126,7 @@ def ping(port=SERVER_PORT, reqcbk=None, timeout=1000):
proto.EventsServerService_Stub,
port,
'localhost')
- logger.info("Pinging server in port %d..." % port)
+ logger.debug("Pinging server in port %d..." % port)
return service.ping(request, callback=reqcbk, timeout=timeout)
@@ -196,14 +197,14 @@ class EventsServerService(proto.EventsServerService):
:param done: callback to be called when done
:type done: protobuf.socketrpc.server.Callback
"""
- logger.info('Received signal from client: %s...', str(request)[:40])
+ logger.debug('Received signal from client: %s...', str(request)[:40])
# send signal to all registered clients
# TODO: verify signal auth
if request.event in registered_clients:
for port in registered_clients[request.event]:
def callback(req, resp):
- logger.info("Signal received by " + str(port))
+ logger.debug("Signal received by " + str(port))
service = RpcService(proto.EventsClientService_Stub,
port, 'localhost')
@@ -224,7 +225,7 @@ class EventsServerService(proto.EventsServerService):
:param done: callback to be called when done
:type done: protobuf.socketrpc.server.Callback
"""
- logger.info("Received ping request, sending response.")
+ logger.debug("Received ping request, sending response.")
response = proto.EventResponse()
response.status = proto.EventResponse.OK
done.run(response)