Skip to content
Snippets Groups Projects
Commit d1aa4157 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added SSLRpcServer

parent 91fc5eec
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,6 @@
from __future__ import absolute_import
from sjrpc.server.simple import (RpcServer, )
from sjrpc.server.simple import (RpcServer, SSLRpcServer)
__all__ = ('RpcServer', )
__all__ = ('RpcServer', 'SSLRpcServer')
......@@ -42,19 +42,24 @@ class RpcServer(object):
sock.listen(5)
return cls(sock, *args, **kwargs)
def _wrap(self, sock):
'''
Wrap the socket into the :class:`RpcConnection` and return it.
'''
return RpcConnection(sock, self.loop, *self._conn_args, **self._conn_kw)
def _handle(self, watcher, revents):
while True:
try:
sock, address = self._sock.accept()
except socket.error as err:
if err.args[0] in self.NONBLOCKING_ERRORS:
if err.errno in self.NONBLOCKING_ERRORS:
break
else:
raise #FIXME
self.logger.info('New incoming connection from %s:%s', *address)
conn = RpcConnection(sock, self.loop,
*self._conn_args, **self._conn_kw)
conn = self._wrap(sock)
self.register(conn)
#
......@@ -97,3 +102,23 @@ class RpcServer(object):
for client in self._clients.copy():
self.unregister(client, shutdown=True)
self.loop.stop(pyev.EVBREAK_ALL)
class SSLRpcServer(RpcServer):
'''
SSL version of the RpcServer.
'''
def __init__(self, sock, certfile, keyfile, loop=None, *args, **kwargs):
super(SSLRpcServer, self).__init__(sock, loop, *args, **kwargs)
self._certfile = certfile
self._keyfile = keyfile
def _wrap(self, sock):
sock = ssl.wrap_socket(sock, server_side=True,
keyfile=self._keyfile,
certfile=self._certfile,
ssl_version=ssl.PROTOCOL_TLSv1,
do_handshake_on_connect=True)
return super(SSLRpcServer, self)._wrap(sock)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment