Skip to content

Commit

Permalink
sshtunnel: generate self.info for logging and debugging (compatibilit…
Browse files Browse the repository at this point in the history
…y for #231)
  • Loading branch information
pahaz committed May 14, 2023
1 parent af17d66 commit cd1be32
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sshtunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"""

import os
import random
import string
import sys
import socket
import getpass
Expand Down Expand Up @@ -257,6 +259,11 @@ def _remove_none_values(dictionary):
return list(map(dictionary.pop,
[i for i in dictionary if dictionary[i] is None]))


def generate_random_string(length):
letters = string.ascii_letters + string.digits
return ''.join(random.choice(letters) for _ in range(length))

########################
# #
# Errors #
Expand Down Expand Up @@ -331,6 +338,9 @@ def _redirect(self, chan):
self.request.sendall(data)

def handle(self):
uid = generate_random_string(5)
self.info = '#{0} <-- {1}'.format(uid, self.client_address or
self.server.local_address)
src_address = self.request.getpeername()
if not isinstance(src_address, tuple):
src_address = ('dummy', 12345)
Expand Down

0 comments on commit cd1be32

Please sign in to comment.