- for msg in msgs:
- if proto_of_message(msg) == LOGIN.PROTO: # Could do blindly...
- self.by_imei[clnt.imei] = clnt
- result.append((clnt.imei, msg))
+ for when, peeraddr, packet in msgs:
+ assert clnt.pmod is not None
+ if clnt.imei is None:
+ imei = clnt.pmod.imei_from_packet(packet)
+ if imei is not None:
+ log.info("LOGIN from fd %d (IMEI %s)", fd, imei)
+ clnt.imei = imei
+ oldclnt = self.by_imei.get(clnt.imei)
+ if oldclnt is not None:
+ log.info(
+ "Orphaning fd %d with the same IMEI",
+ oldclnt.sock.fileno(),
+ )
+ oldclnt.imei = None
+ self.by_imei[clnt.imei] = clnt
+ else:
+ log.warning(
+ "Login message from %s: %s, but client imei unfilled",
+ peeraddr,
+ packet,
+ )
+ result.append((clnt.pmod, clnt.imei, when, peeraddr, packet))
+ log.debug(
+ "Received from %s (IMEI %s): %s",
+ peeraddr,
+ clnt.imei,
+ packet.hex(),
+ )