Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- # # Copyright (C) 2012 Bro <bro.development@gmail.com> # # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with # the additional special exception to link portions of this program with the OpenSSL library. # See LICENSE for more details. #
except ImportError: import deluge.rencode as rencode
""" Data messages are transfered using very a simple protocol. Data messages are transfered with a header containing the length of the data to be transfered (payload).
"""
""" Transfer the data.
The data will be serialized and compressed before being sent. First a header is sent - containing the length of the compressed payload to come as a signed integer. After the header, the payload is transfered.
:param data: data to be transfered in a data structure serializable by rencode.
""" # Store length as a signed integer (using 4 bytes). "!" denotes network byte order.
""" This method is called whenever data is received.
:param data: a message as transfered by transfer_message, or a part of such a messsage.
Global variables: _buffer - contains the data received _message_length - the length of the payload of the current message.
"""
# We have a complete packet # Remove message data from buffer else:
""" Handle the start of a new message. This method is called only when the beginning of the buffer contains data from a new message (i.e. the header).
""" # Read the first bytes of the message (MESSAGE_HEADER_SIZE bytes) # Extract the length stored as a signed integer (using 4 bytes) raise Exception("Message length is negative: %d" % self._message_length) # Remove the header from the buffer
""" Handles a complete message as it is transfered on the network.
:param data: a zlib compressed string encoded with rencode.
"""
""" Returns the number of bytes received.
:returns: the number of bytes received :rtype: int
"""
""" Returns the number of bytes sent.
:returns: the number of bytes sent :rtype: int
""" return self._bytes_sent
"""Override this method to receive the complete message""" pass |