MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / ping

Method ping

src/Peer/Peer.py:238–258  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

236
237 # Send a ping request
238 def ping(self):
239 response_time = None
240 for retry in range(1, 3): # Retry 3 times
241 s = time.time()
242 with gevent.Timeout(10.0, False): # 10 sec timeout, don't raise exception
243 res = self.request("ping")
244
245 if res and "body" in res and res["body"] == b"Pong!":
246 response_time = time.time() - s
247 break # All fine, exit from for loop
248 # Timeout reached or bad response
249 self.onConnectionError("Ping timeout")
250 self.connect()
251 time.sleep(1)
252
253 if response_time:
254 self.log("Ping: %.3f" % response_time)
255 else:
256 self.log("Ping failed")
257 self.last_ping = response_time
258 return response_time
259
260 # Request peer exchange from peer
261 def pex(self, site=None, need_num=5):

Callers 5

peerPingMethod · 0.95
testPingMethod · 0.45
testUpdateMethod · 0.45
testIpv6Method · 0.45
testPingMethod · 0.45

Calls 4

requestMethod · 0.95
onConnectionErrorMethod · 0.95
connectMethod · 0.95
logMethod · 0.95

Tested by 4

testPingMethod · 0.36
testUpdateMethod · 0.36
testIpv6Method · 0.36
testPingMethod · 0.36