xep_0065: Remove the last useless threading locks.

This commit is contained in:
Emmanuel Gil Peyrot 2015-08-22 13:53:04 +01:00 committed by Emmanuel Gil Peyrot
parent 488c433555
commit dc7fef1064

View file

@ -1,6 +1,5 @@
import asyncio import asyncio
import logging import logging
import threading
import socket import socket
from hashlib import sha1 from hashlib import sha1
@ -33,9 +32,6 @@ class XEP_0065(BasePlugin):
self._proxies = {} self._proxies = {}
self._sessions = {} self._sessions = {}
self._sessions_lock = threading.Lock()
self._preauthed_sids_lock = threading.Lock()
self._preauthed_sids = {} self._preauthed_sids = {}
self.xmpp.register_handler( self.xmpp.register_handler(
@ -76,7 +72,6 @@ class XEP_0065(BasePlugin):
log.warning('Received unknown SOCKS5 proxy: %s', proxy) log.warning('Received unknown SOCKS5 proxy: %s', proxy)
return return
with self._sessions_lock:
try: try:
self._sessions[sid] = (yield from self._connect_proxy( self._sessions[sid] = (yield from self._connect_proxy(
self._get_dest_sha1(sid, self.xmpp.boundjid, to), self._get_dest_sha1(sid, self.xmpp.boundjid, to),
@ -212,7 +207,6 @@ class XEP_0065(BasePlugin):
# TODO: close properly the connection to the other proxies. # TODO: close properly the connection to the other proxies.
iq = iq.reply() iq = iq.reply()
with self._sessions_lock:
self._sessions[sid] = conn self._sessions[sid] = conn
iq['socks']['sid'] = sid iq['socks']['sid'] = sid
iq['socks']['streamhost_used']['jid'] = used_streamhost iq['socks']['streamhost_used']['jid'] = used_streamhost
@ -239,7 +233,6 @@ class XEP_0065(BasePlugin):
except socket.error: except socket.error:
pass pass
# Though this should not be neccessary remove the closed session anyway # Though this should not be neccessary remove the closed session anyway
with self._sessions_lock:
if sid in self._sessions: if sid in self._sessions:
log.warn(('SOCKS5 session with sid = "%s" was not ' + log.warn(('SOCKS5 session with sid = "%s" was not ' +
'removed from _sessions by sock.close()') % sid) 'removed from _sessions by sock.close()') % sid)
@ -249,7 +242,6 @@ class XEP_0065(BasePlugin):
"""Closes all proxy sockets.""" """Closes all proxy sockets."""
for sid, sock in self._sessions.items(): for sid, sock in self._sessions.items():
sock.close() sock.close()
with self._sessions_lock:
self._sessions = {} self._sessions = {}
def _connect_proxy(self, dest, proxy, proxy_port): def _connect_proxy(self, dest, proxy, proxy_port):
@ -277,7 +269,6 @@ class XEP_0065(BasePlugin):
return self.auto_accept return self.auto_accept
def _authorized_sid(self, jid, sid, ifrom, iq): def _authorized_sid(self, jid, sid, ifrom, iq):
with self._preauthed_sids_lock:
log.debug('>>> authed sids: %s', self._preauthed_sids) log.debug('>>> authed sids: %s', self._preauthed_sids)
log.debug('>>> lookup: %s %s %s', jid, sid, ifrom) log.debug('>>> lookup: %s %s %s', jid, sid, ifrom)
if (jid, sid, ifrom) in self._preauthed_sids: if (jid, sid, ifrom) in self._preauthed_sids:
@ -287,5 +278,4 @@ class XEP_0065(BasePlugin):
def _preauthorize_sid(self, jid, sid, ifrom, data): def _preauthorize_sid(self, jid, sid, ifrom, data):
log.debug('>>>> %s %s %s %s', jid, sid, ifrom, data) log.debug('>>>> %s %s %s %s', jid, sid, ifrom, data)
with self._preauthed_sids_lock:
self._preauthed_sids[(jid, sid, ifrom)] = True self._preauthed_sids[(jid, sid, ifrom)] = True