Skip to content

Commit

Permalink
brittspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robey Pointer committed Apr 14, 2010
1 parent bf3a87f commit d268594
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions paramiko/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Packetizer (object):
# they should probably be lower.
REKEY_PACKETS = pow(2, 30)
REKEY_BYTES = pow(2, 30)

def __init__(self, socket):
self.__socket = socket
self.__logger = None
Expand All @@ -68,14 +68,14 @@ def __init__(self, socket):
self.__need_rekey = False
self.__init_count = 0
self.__remainder = ''

# used for noticing when to re-key:
self.__sent_bytes = 0
self.__sent_packets = 0
self.__received_bytes = 0
self.__received_packets = 0
self.__received_packets_overflow = 0

# current inbound/outbound ciphering:
self.__block_size_out = 8
self.__block_size_in = 8
Expand All @@ -99,13 +99,13 @@ def __init__(self, socket):
self.__keepalive_interval = 0
self.__keepalive_last = time.time()
self.__keepalive_callback = None

def set_log(self, log):
"""
Set the python log object to use for logging.
"""
self.__logger = log

def set_outbound_cipher(self, block_engine, block_size, mac_engine, mac_size, mac_key):
"""
Switch outbound data cipher.
Expand All @@ -122,7 +122,7 @@ def set_outbound_cipher(self, block_engine, block_size, mac_engine, mac_size, ma
if self.__init_count == 3:
self.__init_count = 0
self.__need_rekey = False

def set_inbound_cipher(self, block_engine, block_size, mac_engine, mac_size, mac_key):
"""
Switch inbound data cipher.
Expand All @@ -140,26 +140,26 @@ def set_inbound_cipher(self, block_engine, block_size, mac_engine, mac_size, mac
if self.__init_count == 3:
self.__init_count = 0
self.__need_rekey = False

def set_outbound_compressor(self, compressor):
self.__compress_engine_out = compressor

def set_inbound_compressor(self, compressor):
self.__compress_engine_in = compressor

def close(self):
self.__closed = True
self.__socket.close()

def set_hexdump(self, hexdump):
self.__dump_packets = hexdump

def get_hexdump(self):
return self.__dump_packets

def get_mac_size_in(self):
return self.__mac_size_in

def get_mac_size_out(self):
return self.__mac_size_out

Expand All @@ -168,11 +168,11 @@ def need_rekey(self):
Returns C{True} if a new set of keys needs to be negotiated. This
will be triggered during a packet read or write, so it should be
checked after every read or write, or at least after every few.
@return: C{True} if a new set of keys needs to be negotiated
"""
return self.__need_rekey

def set_keepalive(self, interval, callback):
"""
Turn on/off the callback keepalive. If C{interval} seconds pass with
Expand All @@ -182,11 +182,11 @@ def set_keepalive(self, interval, callback):
self.__keepalive_interval = interval
self.__keepalive_callback = callback
self.__keepalive_last = time.time()

def read_all(self, n, check_rekey=False):
"""
Read as close to N bytes as possible, blocking as long as necessary.
@param n: number of bytes to read
@type n: int
@return: the data read
Expand Down Expand Up @@ -262,7 +262,7 @@ def write_all(self, out):
break
out = out[n:]
return

def readline(self, timeout):
"""
Read a line from the socket. We assume no data is pending after the
Expand All @@ -277,7 +277,7 @@ def readline(self, timeout):
if (len(buf) > 0) and (buf[-1] == '\r'):
buf = buf[:-1]
return buf

def send_message(self, data):
"""
Write a block of data using the current cipher, as an SSH block.
Expand Down Expand Up @@ -328,7 +328,7 @@ def read_message(self):
"""
Only one thread should ever be in this function (no other locking is
done).
@raise SSHException: if the packet is mangled
@raise NeedRekeyException: if the transport should rekey
"""
Expand Down Expand Up @@ -369,7 +369,7 @@ def read_message(self):
msg = Message(payload[1:])
msg.seqno = self.__sequence_number_in
self.__sequence_number_in = (self.__sequence_number_in + 1) & 0xffffffffL

# check for rekey
self.__received_bytes += packet_size + self.__mac_size_in + 4
self.__received_packets += 1
Expand Down Expand Up @@ -398,8 +398,8 @@ def read_message(self):


########## protected


def _log(self, level, msg):
if self.__logger is None:
return
Expand All @@ -418,7 +418,7 @@ def _check_keepalive(self):
if now > self.__keepalive_last + self.__keepalive_interval:
self.__keepalive_callback()
self.__keepalive_last = now

def _py22_read_all(self, n, out):
while n > 0:
r, w, e = select.select([self.__socket], [], [], 0.1)
Expand Down

0 comments on commit d268594

Please sign in to comment.