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

Method handleMessage

src/Connection/Connection.py:442–480  ·  view source on GitHub ↗
(self, message)

Source from the content-addressed store, hash-verified

440
441 # Handle incoming message
442 def handleMessage(self, message):
443 cmd = message["cmd"]
444
445 self.last_message_time = time.time()
446 self.last_cmd_recv = cmd
447 if cmd == "response": # New style response
448 if message["to"] in self.waiting_requests:
449 if self.last_send_time and len(self.waiting_requests) == 1:
450 ping = time.time() - self.last_send_time
451 self.last_ping_delay = ping
452 self.waiting_requests[message["to"]]["evt"].set(message) # Set the response to event
453 del self.waiting_requests[message["to"]]
454 elif message["to"] == 0: # Other peers handshake
455 ping = time.time() - self.start_time
456 if config.debug_socket:
457 self.log("Handshake response: %s, ping: %s" % (message, ping))
458 self.last_ping_delay = ping
459 # Server switched to crypt, lets do it also if not crypted already
460 if message.get("crypt") and not self.sock_wrapped:
461 self.crypt = message["crypt"]
462 server = (self.type == "in")
463 self.log("Crypt out connection using: %s (server side: %s, ping: %.3fs)..." % (self.crypt, server, ping))
464 self.sock = CryptConnection.manager.wrapSocket(self.sock, self.crypt, server, cert_pin=self.cert_pin)
465 self.sock.do_handshake()
466 self.sock_wrapped = True
467
468 if not self.sock_wrapped and self.cert_pin:
469 self.close("Crypt connection error: Socket not encrypted, but certificate pin present")
470 return
471
472 self.setHandshake(message)
473 else:
474 self.log("Unknown response: %s" % message)
475 elif cmd:
476 self.server.num_recv += 1
477 if cmd == "handshake":
478 self.handleHandshake(message)
479 else:
480 self.server.handleRequest(self, message)
481
482 # Incoming handshake set request
483 def handleHandshake(self, message):

Callers 2

messageLoopMethod · 0.95
all.jsFile · 0.45

Calls 7

logMethod · 0.95
closeMethod · 0.95
setHandshakeMethod · 0.95
handleHandshakeMethod · 0.95
wrapSocketMethod · 0.80
getMethod · 0.45
handleRequestMethod · 0.45

Tested by

no test coverage detected