changeset 963f8a6b18da in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=963f8a6b18da description: coding standards
diffstat:
src/common/jingle_ft.py | 31 +++---------------------------- src/common/jingle_ftstates.py | 19 +++++++------------ src/common/socks5.py | 40 ++++++---------------------------------- src/dialogs.py | 4 ++-- 4 files changed, 18 insertions(+), 76 deletions(-)
diffs (truncated from 569 to 300 lines):
diff -r e00cf699baf7 -r 963f8a6b18da src/common/jingle_ft.py --- a/src/common/jingle_ft.py Thu Aug 23 22:11:21 2012 +0200 +++ b/src/common/jingle_ft.py Thu Aug 23 17:45:38 2012 -0400 @@ -50,9 +50,7 @@ def __init__(self, session, transport=None, file_props=None, use_security=False): JingleContent.__init__(self, session, transport) - log.info("transport value: %s" % transport) - # events we might be interested in self.callbacks['session-initiate'] += [self.__on_session_initiate] self.callbacks['session-initiate-sent'] += [ @@ -68,31 +66,25 @@ self.callbacks['transport-reject'] += [self.__on_transport_reject] self.callbacks['transport-info'] += [self.__on_transport_info] self.callbacks['iq-result'] += [self.__on_iq_result] - self.use_security = use_security - self.file_props = file_props if file_props is None: self.weinitiate = False else: self.weinitiate = True - if self.file_props is not None: self.file_props.sender = session.ourjid self.file_props.receiver = session.peerjid self.file_props.session_type = 'jingle' self.file_props.session_sid = session.sid self.file_props.transfered_size = [] - log.info("FT request: %s" % file_props) - if transport is None: self.transport = JingleTransportSocks5() self.transport.set_connection(session.connection) self.transport.set_file_props(self.file_props) self.transport.set_our_jid(session.ourjid) log.info('ourjid: %s' % session.ourjid) - self.session = session self.media = 'file' self.nominated_cand = {} @@ -128,6 +120,7 @@ # Delete this after file_props refactoring this shouldn't be necesary self.session.file_hash = self.file_props.hash_ self.session.hash_algo = self.file_props.algo + def __on_session_initiate_sent(self, stanza, content, error, action): # Calculate file_hash in a new thread # if we haven't sent the hash already. @@ -142,7 +135,6 @@ checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER) self.session.__session_info(checksum )
- def _calcHash(self): # Caculates the hash and returns a xep-300 hash stanza if self.session.hash_algo == None: @@ -155,7 +147,7 @@ h = xmpp.Hashes() hash_ = h.calculateHash(self.session.hash_algo, file_) # DEBUG - #hash_ = '1294809248109223' + hash_ = '1294809248109223' if not hash_: # Hash alogrithm not supported return @@ -169,8 +161,6 @@ security = content.getTag('security') if not security: # responder can not verify our fingerprint self.use_security = False - - if self.state == STATE_TRANSPORT_REPLACE: # We ack the session accept response = stanza.buildReply('result') @@ -179,13 +169,11 @@ # We send the file self.__state_changed(STATE_TRANSFERING) raise xmpp.NodeProcessed - self.file_props.streamhosts = self.transport.remote_candidates for host in self.file_props.streamhosts: host['initiator'] = self.session.initiator host['target'] = self.session.responder host['sid'] = self.file_props.sid - response = stanza.buildReply('result') response.delChild(response.getQuery()) con.connection.send(response) @@ -218,7 +206,6 @@
def __on_transport_info(self, stanza, content, error, action): log.info("__on_transport_info") - if content.getTag('transport').getTag('candidate-error'): self.nominated_cand['peer-cand'] = False if self.state == STATE_CAND_SENT: @@ -244,7 +231,6 @@ gajim.socks5queue.send_file(self.file_props, self.session.connection.name, 'client') return - args = {'content' : content, 'sendCand' : False} if self.state == STATE_CAND_SENT: @@ -257,8 +243,6 @@ else: self.__state_changed(STATE_CAND_RECEIVED, args)
- - def __on_iq_result(self, stanza, content, error, action): log.info("__on_iq_result")
@@ -277,12 +261,10 @@ def __transport_setup(self, stanza=None, content=None, error=None, action=None): # Sets up a few transport specific things for the file transfer - if self.transport.type_ == TransportType.IBB: # No action required, just set the state to transfering self.state = STATE_TRANSFERING
- def on_connect(self, streamhost): """ send candidate-used stanza @@ -292,7 +274,6 @@ return args = {'streamhost' : streamhost, 'sendCand' : True} - self.nominated_cand['our-cand'] = streamhost self.__sendCand(args)
@@ -313,19 +294,15 @@ self.file_props.hash_ = hash_id
def _listen_host(self): - receiver = self.file_props.receiver sender = self.file_props.sender sha_str = helpers.get_auth_sha(self.file_props.sid, sender, receiver) self.file_props.sha_str = sha_str - port = gajim.config.get('file_transfers_port') - fingerprint = None if self.use_security: fingerprint = 'server' - if self.weinitiate: listener = gajim.socks5queue.start_listener(port, sha_str, self._store_socks5_sid, self.file_props, @@ -334,10 +311,10 @@ listener = gajim.socks5queue.start_listener(port, sha_str, self._store_socks5_sid, self.file_props, fingerprint=fingerprint, typ='receiver') - if not listener: # send error message, notify the user return + def isOurCandUsed(self): ''' If this method returns true then the candidate we nominated will be @@ -348,10 +325,8 @@ return True if self.nominated_cand['our-cand'] == False: return False - peer_pr = int(self.nominated_cand['peer-cand']['priority']) our_pr = int(self.nominated_cand['our-cand']['priority']) - if peer_pr != our_pr: return our_pr > peer_pr else: diff -r e00cf699baf7 -r 963f8a6b18da src/common/jingle_ftstates.py --- a/src/common/jingle_ftstates.py Thu Aug 23 22:11:21 2012 +0200 +++ b/src/common/jingle_ftstates.py Thu Aug 23 17:45:38 2012 -0400 @@ -16,6 +16,7 @@ from jingle_transport import * from common.socks5 import Socks5ReceiverClient, Socks5SenderClient
+ class JingleFileTransferStates: ''' This class implements the state machine design pattern @@ -64,27 +65,22 @@ # Send candidate used streamhost = args['streamhost'] self.jft.nominated_cand['our-cand'] = streamhost - content = xmpp.Node('content') content.setAttr('creator', 'initiator') content.setAttr('name', self.jft.name) - transport = xmpp.Node('transport') transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM) transport.setAttr('sid', self.jft.transport.sid) - candidateused = xmpp.Node('candidate-used') candidateused.setAttr('cid', streamhost['cid']) - transport.addChild(node=candidateused) content.addChild(node=transport) - self.jft.session.send_transport_info(content)
- def action(self, args=None): self._sendCand(args)
+ class StateCandReceived(JingleFileTransferStates): ''' This state happens when we receive a candidate. @@ -111,6 +107,7 @@ def action(self, args=None): self._recvCand(args)
+ class StateCandSentAndRecv( StateCandSent, StateCandReceived): ''' This state happens when we have received and sent the candidates. @@ -124,6 +121,7 @@ else: self._recvCand(args)
+ class StateTransportReplace(JingleFileTransferStates): ''' This state initiates transport replace @@ -132,6 +130,7 @@ def action(self, args=None): self.jft.session.transport_replace()
+ class StateTransfering(JingleFileTransferStates): ''' This state will start the transfer depeding on the type of transport @@ -146,14 +145,12 @@ def __start_SOCK5_transfer(self): # It tells wether we start the transfer as client or server mode = None - if self.jft.isOurCandUsed(): mode = 'client' streamhost_used = self.jft.nominated_cand['our-cand'] else: mode = 'server' streamhost_used = self.jft.nominated_cand['peer-cand'] - if streamhost_used['type'] == 'proxy': self.jft.file_props.is_a_proxy = True # This needs to be changed when requesting @@ -164,7 +161,6 @@ self.jft.file_props.proxy_sender = streamhost_used['target'] self.jft.file_props.proxy_receiver = streamhost_used[ 'initiator'] - # This needs to be changed when requesting if not self.jft.weinitiate and streamhost_used['type'] == 'proxy': r = gajim.socks5queue.readers @@ -172,7 +168,6 @@ if r[reader].host == streamhost_used['host'] and \ r[reader].connected: return - # This needs to be changed when requesting if self.jft.weinitiate and streamhost_used['type'] == 'proxy': s = gajim.socks5queue.senders @@ -180,7 +175,6 @@ if s[sender].host == streamhost_used['host'] and \ s[sender].connected: return - if streamhost_used['type'] == 'proxy': self.jft.file_props.streamhost_used = True streamhost_used['sid'] = self.jft.file_props.sid @@ -188,7 +182,6 @@ self.jft.file_props.streamhosts.append(streamhost_used) self.jft.file_props.proxyhosts = [] self.jft.file_props.proxyhosts.append(streamhost_used) - # This needs to be changed when requesting if self.jft.weinitiate: gajim.socks5queue.idx += 1 @@ -224,3 +217,5 @@
elif self.jft.transport.type_ == TransportType.SOCKS5: self.__start_SOCK5_transfer() + + diff -r e00cf699baf7 -r 963f8a6b18da src/common/socks5.py