1
0

First message on an interface is server.version (#4407)

- Use server.ping to ping (valid as of protocol version 1.2) rather
  than server.version (deprecated as a ping)
- Ping every 5 mins rather than every 1 minute.  By default servers
  don't consider a connection stale until 10 minutes of inactivity.
- Remove unused last_request member of interface

Port of c3f26e59db
This commit is contained in:
Neil
2018-06-05 19:41:41 +09:00
committed by ghost43
parent f0daf2d37b
commit e0a6b082d2
2 changed files with 8 additions and 16 deletions

View File

@@ -260,9 +260,7 @@ class Interface(util.PrintError):
self.debug = False
self.unsent_requests = []
self.unanswered_requests = {}
# Set last ping to zero to ensure immediate ping
self.last_request = time.time()
self.last_ping = 0
self.last_send = time.time()
self.closed_remotely = False
def diagnostic_name(self):
@@ -294,6 +292,7 @@ class Interface(util.PrintError):
def send_requests(self):
'''Sends queued requests. Returns False on failure.'''
self.last_send = time.time()
make_dict = lambda m, p, i: {'method': m, 'params': p, 'id': i}
n = self.num_requests()
wire_requests = self.unsent_requests[0:n]
@@ -310,14 +309,8 @@ class Interface(util.PrintError):
return True
def ping_required(self):
'''Maintains time since last ping. Returns True if a ping should
be sent.
'''
now = time.time()
if now - self.last_ping > 60:
self.last_ping = now
return True
return False
'''Returns True if a ping should be sent.'''
return time.time() - self.last_send > 300
def has_timed_out(self):
'''Returns True if the interface has timed out.'''