Changes methods that do not reference the instance to static methods

This commit is contained in:
vieira 2017-11-07 22:23:44 +00:00 committed by Brian May
parent ad676029c7
commit 112931dd2c
4 changed files with 31 additions and 18 deletions

View File

@ -35,7 +35,8 @@ class BaseMethod(object):
def set_firewall(self, firewall): def set_firewall(self, firewall):
self.firewall = firewall self.firewall = firewall
def get_supported_features(self): @staticmethod
def get_supported_features():
result = Features() result = Features()
result.ipv6 = False result.ipv6 = False
result.udp = False result.udp = False
@ -43,10 +44,12 @@ class BaseMethod(object):
result.user = False result.user = False
return result return result
def get_tcp_dstip(self, sock): @staticmethod
def get_tcp_dstip(sock):
return original_dst(sock) return original_dst(sock)
def recv_udp(self, udp_listener, bufsize): @staticmethod
def recv_udp(udp_listener, bufsize):
debug3('Accept UDP using recvfrom.\n') debug3('Accept UDP using recvfrom.\n')
data, srcip = udp_listener.recvfrom(bufsize) data, srcip = udp_listener.recvfrom(bufsize)
return (srcip, None, data) return (srcip, None, data)
@ -77,7 +80,8 @@ class BaseMethod(object):
def restore_firewall(self, port, family, udp, user): def restore_firewall(self, port, family, udp, user):
raise NotImplementedError() raise NotImplementedError()
def firewall_command(self, line): @staticmethod
def firewall_command(line):
return False return False

View File

@ -66,7 +66,8 @@ class Generic(object):
pfctl('-e') pfctl('-e')
_pf_context['started_by_sshuttle'] += 1 _pf_context['started_by_sshuttle'] += 1
def disable(self, anchor): @staticmethod
def disable(anchor):
pfctl('-a %s -F all' % anchor) pfctl('-a %s -F all' % anchor)
if _pf_context['started_by_sshuttle'] == 1: if _pf_context['started_by_sshuttle'] == 1:
pfctl('-d') pfctl('-d')
@ -98,11 +99,13 @@ class Generic(object):
port = socket.ntohs(self._get_natlook_port(pnl.rdxport)) port = socket.ntohs(self._get_natlook_port(pnl.rdxport))
return (ip, port) return (ip, port)
def _add_natlook_ports(self, pnl, src_port, dst_port): @staticmethod
def _add_natlook_ports(pnl, src_port, dst_port):
pnl.sxport = socket.htons(src_port) pnl.sxport = socket.htons(src_port)
pnl.dxport = socket.htons(dst_port) pnl.dxport = socket.htons(dst_port)
def _get_natlook_port(self, xport): @staticmethod
def _get_natlook_port(xport):
return xport return xport
def add_anchors(self, anchor, status=None): def add_anchors(self, anchor, status=None):
@ -129,18 +132,22 @@ class Generic(object):
'I', self.PF_CHANGE_ADD_TAIL), 4) # action = PF_CHANGE_ADD_TAIL 'I', self.PF_CHANGE_ADD_TAIL), 4) # action = PF_CHANGE_ADD_TAIL
ioctl(pf_get_dev(), pf.DIOCCHANGERULE, pr) ioctl(pf_get_dev(), pf.DIOCCHANGERULE, pr)
def _inet_version(self, family): @staticmethod
def _inet_version(family):
return b'inet' if family == socket.AF_INET else b'inet6' return b'inet' if family == socket.AF_INET else b'inet6'
def _lo_addr(self, family): @staticmethod
def _lo_addr(family):
return b'127.0.0.1' if family == socket.AF_INET else b'::1' return b'127.0.0.1' if family == socket.AF_INET else b'::1'
def add_rules(self, anchor, rules): @staticmethod
def add_rules(anchor, rules):
assert isinstance(rules, bytes) assert isinstance(rules, bytes)
debug3("rules:\n" + rules.decode("ASCII")) debug3("rules:\n" + rules.decode("ASCII"))
pfctl('-a %s -f /dev/stdin' % anchor, rules) pfctl('-a %s -f /dev/stdin' % anchor, rules)
def has_skip_loopback(self): @staticmethod
def has_skip_loopback():
return b'skip' in pfctl('-s Interfaces -i lo -v')[0] return b'skip' in pfctl('-s Interfaces -i lo -v')[0]

View File

@ -175,7 +175,8 @@ class DnsProxy(Handler):
self.to_nameserver = self._addrinfo(peer, port) self.to_nameserver = self._addrinfo(peer, port)
self.try_send() self.try_send()
def _addrinfo(self, peer, port): @staticmethod
def _addrinfo(peer, port):
if int(port) == 0: if int(port) == 0:
port = 53 port = 53
family, _, _, _, sockaddr = socket.getaddrinfo(peer, port)[0] family, _, _, _, sockaddr = socket.getaddrinfo(peer, port)[0]

View File

@ -200,7 +200,8 @@ class SockWrapper:
_, e = sys.exc_info()[:2] _, e = sys.exc_info()[:2]
self.seterr('nowrite: %s' % e) self.seterr('nowrite: %s' % e)
def too_full(self): @staticmethod
def too_full():
return False # fullness is determined by the socket's select() state return False # fullness is determined by the socket's select() state
def uwrite(self, buf): def uwrite(self, buf):