diff options
author | bendikro <bendikro@gmail.com> | 2012-06-18 20:28:32 +0200 |
---|---|---|
committer | bendikro <bendikro@gmail.com> | 2012-07-02 02:09:14 +0200 |
commit | 8e7432e71c80a47c96bf48c07535ec1991efe1d9 (patch) | |
tree | 1acd39b2ac5b90cab88f3ed471ce2b827716efd5 /deluge/core/rpcserver.py | |
parent | 5dc6dbf216f1e02992761d7ad10cc911b5c416e0 (diff) | |
download | deluge-8e7432e71c80a47c96bf48c07535ec1991efe1d9.tar.gz deluge-8e7432e71c80a47c96bf48c07535ec1991efe1d9.tar.bz2 deluge-8e7432e71c80a47c96bf48c07535ec1991efe1d9.zip |
Added a protocol for the network traffic between client and daemon.
Implemented a protocol layer above twisted.internet.protocol.Protocol
which guarantees correct transfer of RPC messages. The network messages
are transfered with a header containing the length of the message.
Diffstat (limited to 'deluge/core/rpcserver.py')
-rw-r--r-- | deluge/core/rpcserver.py | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index b9cfba378..3ecbd39e8 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -60,6 +60,8 @@ from deluge.core.authmanager import (AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT, from deluge.error import (DelugeError, NotAuthorizedError, WrappedException, _ClientSideRecreateError, IncompatibleClient) +from deluge.transfer import DelugeTransferProtocol + RPC_RESPONSE = 1 RPC_ERROR = 2 RPC_EVENT = 3 @@ -134,54 +136,34 @@ class ServerContextFactory(object): ctx.use_privatekey_file(os.path.join(ssl_dir, "daemon.pkey")) return ctx -class DelugeRPCProtocol(Protocol): - __buffer = None +class DelugeRPCProtocol(DelugeTransferProtocol): - def dataReceived(self, data): + def message_received(self, request): """ - This method is called whenever data is received from a client. The + This method is called whenever a message is received from a client. The only message that a client sends to the server is a RPC Request message. If the RPC Request message is valid, then the method is called in :meth:`dispatch`. - - :param data: the data from the client. It should be a zlib compressed - rencoded string. - :type data: str + + :param request: the request from the client. + :type data: tuple """ - if self.__buffer: - # We have some data from the last dataReceived() so lets prepend it - data = self.__buffer + data - self.__buffer = None - - while data: - dobj = zlib.decompressobj() - try: - request = rencode.loads(dobj.decompress(data)) - except Exception, e: - #log.debug("Received possible invalid message (%r): %s", data, e) - # This could be cut-off data, so we'll save this in the buffer - # and try to prepend it on the next dataReceived() - self.__buffer = data - return - else: - data = dobj.unused_data - - if type(request) is not tuple: - log.debug("Received invalid message: type is not tuple") - return + if type(request) is not tuple: + log.debug("Received invalid message: type is not tuple") + return - if len(request) < 1: - log.debug("Received invalid message: there are no items") - return + if len(request) < 1: + log.debug("Received invalid message: there are no items") + return - for call in request: - if len(call) != 4: - log.debug("Received invalid rpc request: number of items " - "in request is %s", len(call)) - continue - #log.debug("RPCRequest: %s", format_request(call)) - reactor.callLater(0, self.dispatch, *call) + for call in request: + if len(call) != 4: + log.debug("Received invalid rpc request: number of items " + "in request is %s", len(call)) + continue + #log.debug("RPCRequest: %s", format_request(call)) + reactor.callLater(0, self.dispatch, *call) def sendData(self, data): """ @@ -192,7 +174,7 @@ class DelugeRPCProtocol(Protocol): :type data: object """ - self.transport.write(zlib.compress(rencode.dumps(data))) + self.transfer_message(data) def connectionMade(self): """ |