NAT Timeout packet are now sent from connection.py so they will be configurable and won't be sent while we connect to a server
This commit is contained in:
parent
a51c63ae35
commit
d62b4e1ea2
|
@ -127,6 +127,8 @@ class Connection:
|
||||||
self.myVCardID = []
|
self.myVCardID = []
|
||||||
self.bookmarks = []
|
self.bookmarks = []
|
||||||
self.on_purpose = False
|
self.on_purpose = False
|
||||||
|
self._lastIncome = time.time()
|
||||||
|
self._natSent = False
|
||||||
self.password = gajim.config.get_per('accounts', name, 'password')
|
self.password = gajim.config.get_per('accounts', name, 'password')
|
||||||
if USE_GPG:
|
if USE_GPG:
|
||||||
self.gpg = GnuPG.GnuPG()
|
self.gpg = GnuPG.GnuPG()
|
||||||
|
@ -592,6 +594,10 @@ class Connection:
|
||||||
errcode = iq_obj.getErrorCode()
|
errcode = iq_obj.getErrorCode()
|
||||||
jid_from = str(iq_obj.getFrom())
|
jid_from = str(iq_obj.getFrom())
|
||||||
self.dispatch('ERROR_ANSWER', (jid_from, errmsg, errcode))
|
self.dispatch('ERROR_ANSWER', (jid_from, errmsg, errcode))
|
||||||
|
|
||||||
|
def _StanzaArrivedCB(self, con, obj):
|
||||||
|
self._lastIncome = time.time()
|
||||||
|
self._natSent = False
|
||||||
|
|
||||||
def _event_dispatcher(self, realm, event, data):
|
def _event_dispatcher(self, realm, event, data):
|
||||||
if realm == common.xmpp.NS_REGISTER:
|
if realm == common.xmpp.NS_REGISTER:
|
||||||
|
@ -670,6 +676,9 @@ class Connection:
|
||||||
con.RegisterHandler('iq', self._PrivateCB, 'result',
|
con.RegisterHandler('iq', self._PrivateCB, 'result',
|
||||||
common.xmpp.NS_PRIVATE)
|
common.xmpp.NS_PRIVATE)
|
||||||
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
||||||
|
con.RegisterHandler('iq', self._StanzaArrivedCB)
|
||||||
|
con.RegisterHandler('presence', self._StanzaArrivedCB)
|
||||||
|
con.RegisterHandler('message', self._StanzaArrivedCB)
|
||||||
con.RegisterEventHandler(self._event_dispatcher)
|
con.RegisterEventHandler(self._event_dispatcher)
|
||||||
|
|
||||||
gajim.log.debug('Connected to server')
|
gajim.log.debug('Connected to server')
|
||||||
|
@ -1152,6 +1161,16 @@ class Connection:
|
||||||
return
|
return
|
||||||
if self.connected:
|
if self.connected:
|
||||||
try:
|
try:
|
||||||
|
if time.time() > (self._lastIncome + 60) and not self._natSent:
|
||||||
|
# we received nothing since 1 minute
|
||||||
|
hostname = gajim.config.get_per('accounts', self.name,
|
||||||
|
'hostname')
|
||||||
|
iq = common.xmpp.Iq('get', common.xmpp.NS_LAST, to = hostname)
|
||||||
|
self.connection.send(iq)
|
||||||
|
self._natSent = True
|
||||||
|
if time.time() > self._lastIncome + 105: #1 min + 45 sec for answer
|
||||||
|
self.connection.disconnect()
|
||||||
|
return
|
||||||
self.connection.Process(timeout)
|
self.connection.Process(timeout)
|
||||||
except:
|
except:
|
||||||
gajim.log.debug('error appeared while processing xmpp:')
|
gajim.log.debug('error appeared while processing xmpp:')
|
||||||
|
|
|
@ -35,8 +35,6 @@ class Dispatcher(PlugIn):
|
||||||
PlugIn.__init__(self)
|
PlugIn.__init__(self)
|
||||||
DBG_LINE='dispatcher'
|
DBG_LINE='dispatcher'
|
||||||
self.handlers={}
|
self.handlers={}
|
||||||
self._lastIncome = time.time()
|
|
||||||
self._natSent = False
|
|
||||||
self._expected={}
|
self._expected={}
|
||||||
self._defaultHandler=None
|
self._defaultHandler=None
|
||||||
self._eventHandler=None
|
self._eventHandler=None
|
||||||
|
@ -110,18 +108,10 @@ class Dispatcher(PlugIn):
|
||||||
1) length of processed data if some data were processed;
|
1) length of processed data if some data were processed;
|
||||||
2) '0' string if no data were processed but link is alive;
|
2) '0' string if no data were processed but link is alive;
|
||||||
3) 0 (zero) if underlying connection is closed."""
|
3) 0 (zero) if underlying connection is closed."""
|
||||||
if (time.time() > self._lastIncome + 60) and not self._natSent: #1 min
|
|
||||||
iq = Iq('get', NS_LAST, to=self._owner.Server)
|
|
||||||
self.send(iq)
|
|
||||||
self._natSent = True
|
|
||||||
if time.time() > self._lastIncome + 105: #1 min + 45 sec for answer
|
|
||||||
self._owner.disconnected()
|
|
||||||
for handler in self._cycleHandlers: handler(self)
|
for handler in self._cycleHandlers: handler(self)
|
||||||
if self._owner.Connection.pending_data(timeout):
|
if self._owner.Connection.pending_data(timeout):
|
||||||
data=self._owner.Connection.receive()
|
data=self._owner.Connection.receive()
|
||||||
self.Stream.Parse(data)
|
self.Stream.Parse(data)
|
||||||
self._lastIncome = time.time()
|
|
||||||
self._natSent = False
|
|
||||||
return len(data)
|
return len(data)
|
||||||
return '0' # It means that nothing is received but link is alive.
|
return '0' # It means that nothing is received but link is alive.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue