def heartbeat(self, t):
        t_gone = self.heartbeat_max_silence - t
        for nid in (self.channels_in | self.channels_out):
            if self.last_seen[nid] <= t_gone:
                if nid in self.channels_out:
                    self.channels_out.remove(nid)
                if nid in self.channels_in:
                    self.channels_in.remove(nid)
                yield Disconnect, nid2addr(nid)
                yield RELAY_NODEDOWN_CHECKS(self, nid)
                if self.is_relay or not self.cl_avail_relays:
                    yield NODEDOWN(self, nid)
                elif nid in self.cl_avail_relays:
                    self._handle_relay_down(nid)
                    yield NODEDOWN(self, nid)
                else:
                    relay_nid = random.choice(self.cl_avail_relays.keys())
                    self.cl_avail_relays[relay_nid].add(nid)
                    self.cl_relayees[nid] = relay_nid
                    yield RelayConnect, (IN if relay_nid in self.channels_in else OUT), relay_nid, nid
            else:
                if self._needs_ping(nid, t):
                    yield Ping, (IN if nid in self.channels_in else OUT), nid, self._next_version()
        yield NextBeat, self.heartbeat_interval
dataset/ETHPy150Open eallik/spinoff/spinoff/remoting/hublogic.py/HubLogic.heartbeat/swapped operands of `-`