diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2015-04-14 17:24:44 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2015-04-14 19:14:56 +0200 |
commit | c1f23b566b447dbaa4a4ea6942b61128b3161c10 (patch) | |
tree | 2b09723d1cf7bd8a545a9426fc4c727748648275 | |
parent | 45f7cb8bda42512bad70b6262483ac435209d9c3 (diff) | |
download | slixmpp-c1f23b566b447dbaa4a4ea6942b61128b3161c10.tar.gz slixmpp-c1f23b566b447dbaa4a4ea6942b61128b3161c10.tar.bz2 slixmpp-c1f23b566b447dbaa4a4ea6942b61128b3161c10.tar.xz slixmpp-c1f23b566b447dbaa4a4ea6942b61128b3161c10.zip |
XEP-0047: remove now-useless threading locks.
-rw-r--r-- | slixmpp/plugins/xep_0047/ibb.py | 33 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0047/stream.py | 19 |
2 files changed, 17 insertions, 35 deletions
diff --git a/slixmpp/plugins/xep_0047/ibb.py b/slixmpp/plugins/xep_0047/ibb.py index 87cd1f51..aa4e6afc 100644 --- a/slixmpp/plugins/xep_0047/ibb.py +++ b/slixmpp/plugins/xep_0047/ibb.py @@ -1,6 +1,5 @@ import uuid import logging -import threading from slixmpp import Message, Iq from slixmpp.exceptions import XMPPError @@ -30,10 +29,6 @@ class XEP_0047(BasePlugin): def plugin_init(self): self._streams = {} self._pending_streams = {} - self._pending_lock = threading.Lock() - self._stream_lock = threading.Lock() - - self._preauthed_sids_lock = threading.Lock() self._preauthed_sids = {} register_stanza_plugin(Iq, Open) @@ -85,9 +80,8 @@ class XEP_0047(BasePlugin): self._streams[(jid, sid, peer_jid)] = stream def _del_stream(self, jid, sid, peer_jid, data): - with self._stream_lock: - if (jid, sid, peer_jid) in self._streams: - del self._streams[(jid, sid, peer_jid)] + if (jid, sid, peer_jid) in self._streams: + del self._streams[(jid, sid, peer_jid)] def _accept_stream(self, iq): receiver = iq['to'] @@ -105,15 +99,13 @@ class XEP_0047(BasePlugin): return False def _authorized_sid(self, jid, sid, ifrom, iq): - with self._preauthed_sids_lock: - if (jid, sid, ifrom) in self._preauthed_sids: - del self._preauthed_sids[(jid, sid, ifrom)] - return True - return False + if (jid, sid, ifrom) in self._preauthed_sids: + del self._preauthed_sids[(jid, sid, ifrom)] + return True + return False def _preauthorize_sid(self, jid, sid, ifrom, data): - with self._preauthed_sids_lock: - self._preauthed_sids[(jid, sid, ifrom)] = True + self._preauthed_sids[(jid, sid, ifrom)] = True def open_stream(self, jid, block_size=None, sid=None, window=1, use_messages=False, ifrom=None, timeout=None, callback=None): @@ -134,9 +126,6 @@ class XEP_0047(BasePlugin): iq['from'], iq['to'], window, use_messages) - with self._stream_lock: - self._pending_streams[iq['id']] = stream - self._pending_streams[iq['id']] = stream cb = None @@ -151,8 +140,7 @@ class XEP_0047(BasePlugin): def _handle_opened_stream(self, iq): if iq['type'] == 'result': - with self._stream_lock: - stream = self._pending_streams.get(iq['id'], None) + stream = self._pending_streams.get(iq['id'], None) if stream is not None: log.debug('IBB stream (%s) accepted by %s', stream.sid, iq['from']) stream.self_jid = iq['to'] @@ -162,9 +150,8 @@ class XEP_0047(BasePlugin): self.xmpp.event('ibb_stream_start', stream) self.xmpp.event('stream:%s:%s' % (stream.sid, stream.peer_jid), stream) - with self._stream_lock: - if iq['id'] in self._pending_streams: - del self._pending_streams[iq['id']] + if iq['id'] in self._pending_streams: + del self._pending_streams[iq['id']] def _handle_open_request(self, iq): sid = iq['ibb_open']['sid'] diff --git a/slixmpp/plugins/xep_0047/stream.py b/slixmpp/plugins/xep_0047/stream.py index 817f96a1..e15a66be 100644 --- a/slixmpp/plugins/xep_0047/stream.py +++ b/slixmpp/plugins/xep_0047/stream.py @@ -27,9 +27,6 @@ class IBBytestream(object): self.send_seq = -1 self.recv_seq = -1 - self._send_seq_lock = threading.Lock() - self._recv_seq_lock = threading.Lock() - self.stream_started = threading.Event() self.stream_in_closed = threading.Event() self.stream_out_closed = threading.Event() @@ -47,9 +44,8 @@ class IBBytestream(object): raise socket.error data = data[0:self.block_size] self.send_window.acquire() - with self._send_seq_lock: - self.send_seq = (self.send_seq + 1) % 65535 - seq = self.send_seq + self.send_seq = (self.send_seq + 1) % 65535 + seq = self.send_seq if self.use_messages: msg = self.xmpp.Message() msg['to'] = self.peer_jid @@ -87,12 +83,11 @@ class IBBytestream(object): self.close() def _recv_data(self, stanza): - with self._recv_seq_lock: - new_seq = stanza['ibb_data']['seq'] - if new_seq != (self.recv_seq + 1) % 65535: - self.close() - raise XMPPError('unexpected-request') - self.recv_seq = new_seq + new_seq = stanza['ibb_data']['seq'] + if new_seq != (self.recv_seq + 1) % 65535: + self.close() + raise XMPPError('unexpected-request') + self.recv_seq = new_seq data = stanza['ibb_data']['data'] if len(data) > self.block_size: |