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:
Yann Leboulanger 2005-06-22 14:54:02 +00:00
parent a51c63ae35
commit d62b4e1ea2
2 changed files with 19 additions and 10 deletions

View File

@ -127,6 +127,8 @@ class Connection:
self.myVCardID = []
self.bookmarks = []
self.on_purpose = False
self._lastIncome = time.time()
self._natSent = False
self.password = gajim.config.get_per('accounts', name, 'password')
if USE_GPG:
self.gpg = GnuPG.GnuPG()
@ -592,6 +594,10 @@ class Connection:
errcode = iq_obj.getErrorCode()
jid_from = str(iq_obj.getFrom())
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):
if realm == common.xmpp.NS_REGISTER:
@ -670,6 +676,9 @@ class Connection:
con.RegisterHandler('iq', self._PrivateCB, 'result',
common.xmpp.NS_PRIVATE)
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)
gajim.log.debug('Connected to server')
@ -1152,6 +1161,16 @@ class Connection:
return
if self.connected:
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)
except:
gajim.log.debug('error appeared while processing xmpp:')

View File

@ -35,8 +35,6 @@ class Dispatcher(PlugIn):
PlugIn.__init__(self)
DBG_LINE='dispatcher'
self.handlers={}
self._lastIncome = time.time()
self._natSent = False
self._expected={}
self._defaultHandler=None
self._eventHandler=None
@ -110,18 +108,10 @@ class Dispatcher(PlugIn):
1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive;
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)
if self._owner.Connection.pending_data(timeout):
data=self._owner.Connection.receive()
self.Stream.Parse(data)
self._lastIncome = time.time()
self._natSent = False
return len(data)
return '0' # It means that nothing is received but link is alive.