XEP-0047: remove now-useless threading locks.
This commit is contained in:
parent
45f7cb8bda
commit
c1f23b566b
2 changed files with 17 additions and 35 deletions
|
@ -1,6 +1,5 @@
|
||||||
import uuid
|
import uuid
|
||||||
import logging
|
import logging
|
||||||
import threading
|
|
||||||
|
|
||||||
from slixmpp import Message, Iq
|
from slixmpp import Message, Iq
|
||||||
from slixmpp.exceptions import XMPPError
|
from slixmpp.exceptions import XMPPError
|
||||||
|
@ -30,10 +29,6 @@ class XEP_0047(BasePlugin):
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self._streams = {}
|
self._streams = {}
|
||||||
self._pending_streams = {}
|
self._pending_streams = {}
|
||||||
self._pending_lock = threading.Lock()
|
|
||||||
self._stream_lock = threading.Lock()
|
|
||||||
|
|
||||||
self._preauthed_sids_lock = threading.Lock()
|
|
||||||
self._preauthed_sids = {}
|
self._preauthed_sids = {}
|
||||||
|
|
||||||
register_stanza_plugin(Iq, Open)
|
register_stanza_plugin(Iq, Open)
|
||||||
|
@ -85,9 +80,8 @@ class XEP_0047(BasePlugin):
|
||||||
self._streams[(jid, sid, peer_jid)] = stream
|
self._streams[(jid, sid, peer_jid)] = stream
|
||||||
|
|
||||||
def _del_stream(self, jid, sid, peer_jid, data):
|
def _del_stream(self, jid, sid, peer_jid, data):
|
||||||
with self._stream_lock:
|
if (jid, sid, peer_jid) in self._streams:
|
||||||
if (jid, sid, peer_jid) in self._streams:
|
del self._streams[(jid, sid, peer_jid)]
|
||||||
del self._streams[(jid, sid, peer_jid)]
|
|
||||||
|
|
||||||
def _accept_stream(self, iq):
|
def _accept_stream(self, iq):
|
||||||
receiver = iq['to']
|
receiver = iq['to']
|
||||||
|
@ -105,15 +99,13 @@ class XEP_0047(BasePlugin):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _authorized_sid(self, jid, sid, ifrom, iq):
|
def _authorized_sid(self, jid, sid, ifrom, iq):
|
||||||
with self._preauthed_sids_lock:
|
if (jid, sid, ifrom) in self._preauthed_sids:
|
||||||
if (jid, sid, ifrom) in self._preauthed_sids:
|
del self._preauthed_sids[(jid, sid, ifrom)]
|
||||||
del self._preauthed_sids[(jid, sid, ifrom)]
|
return True
|
||||||
return True
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def _preauthorize_sid(self, jid, sid, ifrom, data):
|
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,
|
def open_stream(self, jid, block_size=None, sid=None, window=1, use_messages=False,
|
||||||
ifrom=None, timeout=None, callback=None):
|
ifrom=None, timeout=None, callback=None):
|
||||||
|
@ -134,9 +126,6 @@ class XEP_0047(BasePlugin):
|
||||||
iq['from'], iq['to'], window,
|
iq['from'], iq['to'], window,
|
||||||
use_messages)
|
use_messages)
|
||||||
|
|
||||||
with self._stream_lock:
|
|
||||||
self._pending_streams[iq['id']] = stream
|
|
||||||
|
|
||||||
self._pending_streams[iq['id']] = stream
|
self._pending_streams[iq['id']] = stream
|
||||||
|
|
||||||
cb = None
|
cb = None
|
||||||
|
@ -151,8 +140,7 @@ class XEP_0047(BasePlugin):
|
||||||
|
|
||||||
def _handle_opened_stream(self, iq):
|
def _handle_opened_stream(self, iq):
|
||||||
if iq['type'] == 'result':
|
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:
|
if stream is not None:
|
||||||
log.debug('IBB stream (%s) accepted by %s', stream.sid, iq['from'])
|
log.debug('IBB stream (%s) accepted by %s', stream.sid, iq['from'])
|
||||||
stream.self_jid = iq['to']
|
stream.self_jid = iq['to']
|
||||||
|
@ -162,9 +150,8 @@ class XEP_0047(BasePlugin):
|
||||||
self.xmpp.event('ibb_stream_start', stream)
|
self.xmpp.event('ibb_stream_start', stream)
|
||||||
self.xmpp.event('stream:%s:%s' % (stream.sid, stream.peer_jid), stream)
|
self.xmpp.event('stream:%s:%s' % (stream.sid, stream.peer_jid), stream)
|
||||||
|
|
||||||
with self._stream_lock:
|
if iq['id'] in self._pending_streams:
|
||||||
if iq['id'] in self._pending_streams:
|
del self._pending_streams[iq['id']]
|
||||||
del self._pending_streams[iq['id']]
|
|
||||||
|
|
||||||
def _handle_open_request(self, iq):
|
def _handle_open_request(self, iq):
|
||||||
sid = iq['ibb_open']['sid']
|
sid = iq['ibb_open']['sid']
|
||||||
|
|
|
@ -27,9 +27,6 @@ class IBBytestream(object):
|
||||||
self.send_seq = -1
|
self.send_seq = -1
|
||||||
self.recv_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_started = threading.Event()
|
||||||
self.stream_in_closed = threading.Event()
|
self.stream_in_closed = threading.Event()
|
||||||
self.stream_out_closed = threading.Event()
|
self.stream_out_closed = threading.Event()
|
||||||
|
@ -47,9 +44,8 @@ class IBBytestream(object):
|
||||||
raise socket.error
|
raise socket.error
|
||||||
data = data[0:self.block_size]
|
data = data[0:self.block_size]
|
||||||
self.send_window.acquire()
|
self.send_window.acquire()
|
||||||
with self._send_seq_lock:
|
self.send_seq = (self.send_seq + 1) % 65535
|
||||||
self.send_seq = (self.send_seq + 1) % 65535
|
seq = self.send_seq
|
||||||
seq = self.send_seq
|
|
||||||
if self.use_messages:
|
if self.use_messages:
|
||||||
msg = self.xmpp.Message()
|
msg = self.xmpp.Message()
|
||||||
msg['to'] = self.peer_jid
|
msg['to'] = self.peer_jid
|
||||||
|
@ -87,12 +83,11 @@ class IBBytestream(object):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def _recv_data(self, stanza):
|
def _recv_data(self, stanza):
|
||||||
with self._recv_seq_lock:
|
new_seq = stanza['ibb_data']['seq']
|
||||||
new_seq = stanza['ibb_data']['seq']
|
if new_seq != (self.recv_seq + 1) % 65535:
|
||||||
if new_seq != (self.recv_seq + 1) % 65535:
|
self.close()
|
||||||
self.close()
|
raise XMPPError('unexpected-request')
|
||||||
raise XMPPError('unexpected-request')
|
self.recv_seq = new_seq
|
||||||
self.recv_seq = new_seq
|
|
||||||
|
|
||||||
data = stanza['ibb_data']['data']
|
data = stanza['ibb_data']['data']
|
||||||
if len(data) > self.block_size:
|
if len(data) > self.block_size:
|
||||||
|
|
Loading…
Reference in a new issue