def manageUpdateProbes(cls, action): """Update your list of probes with this set of probes :param action: UpdateProbes action instance """ assert isinstance(action, a.UpdateProbes) cls.logger.info("Joined overlay size %s", len(action.getProbeList())) if action.echo is not None: Client.send(Hello(action.echo, list(ProbeStorage.getAllOtherProbes()), Identification.PROBE_ID)) cls.logger.info("Sent echo to %s", action.echo) for probe in action.getProbeList(): # don't re-add ourselves to the local DHT if probe.getId() != Identification.PROBE_ID: ProbeStorage.addProbe(ProbeStorage.newProbe(probe.getId(), probe.getIp()))
def manageUpdateProbes(cls, action): """Update your list of probes with this set of probes :param action: UpdateProbes action instance """ assert isinstance(action, a.UpdateProbes) cls.logger.info("Joined overlay size %s", len(action.getProbeList())) if action.echo is not None: Client.send( Hello(action.echo, list(ProbeStorage.getAllOtherProbes()), Identification.PROBE_ID)) cls.logger.info("Sent echo to %s", action.echo) for probe in action.getProbeList(): # don't re-add ourselves to the local DHT if probe.getId() != Identification.PROBE_ID: ProbeStorage.addProbe( ProbeStorage.newProbe(probe.getId(), probe.getIp()))
def manageAddToOverlay(cls, action): assert isinstance(action, a.AddToOverlay) cls.logger.ddebug("Add probe to overlay") try: probeId = Retry.retry(times=Consts.GET_REMOTE_ID_RETRY, interval=Consts.GET_REMOVE_ID_RETRY_INTERVAL, failure=ProbeConnectionException, eraise=ProbeConnectionException)( Client.getRemoteId)(action.probeIp) # probeId = Client.getRemoteId(action.probeIp) cls.logger.info("Adding probe %s at %s to overlay", probeId, action.probeIp) addMessage = Add(Identification.PROBE_ID, probeId, action.probeIp) #use action directly because of timing issues selfAddAction = a.Add( action.probeIp, probeId, Hello(probeId, list(ProbeStorage.getAllOtherProbes()), Identification.PROBE_ID, echo=Identification.PROBE_ID if action.mergeOverlays else None)) # selfAddMessage = copy.deepcopy(addMessage) # selfAddAction.hello = Hello(probeId, # list(ProbeStorage.getAllOtherProbes()), # Identification.PROBE_ID, # echo = Identification.PROBE_ID if action.mergeOverlays else None) # Do broadcast before adding the probe so that it doesn't receive unnecessary message # addMessage = m.Add(Identification.PROBE_ID, probeId, message.targetIp, hello=True) # print(ProbeStorage.getIdAllOtherProbes()) Client.broadcast(addMessage) #treat message after so that the new guy does not receive bogus add message #treat the add for this addToOverlay before any other AddToOverlay # import calls.messagetoaction as MTA cls.addTask(selfAddAction) #try to fix adding host too quickly Scheduler.addToOverlay() cls.logger.debug("Probe %s added to overlay", probeId) except ProbeConnectionException as e: cls.logger.warning("Adding probe failed %s : %s", action.probeIp, e)
def manageAddToOverlay(cls, action): assert isinstance(action, a.AddToOverlay) cls.logger.ddebug("Add probe to overlay") try: probeId = Retry.retry(times = Consts.GET_REMOTE_ID_RETRY, interval = Consts.GET_REMOVE_ID_RETRY_INTERVAL, failure = ProbeConnectionException, eraise = ProbeConnectionException)(Client.getRemoteId)(action.probeIp) # probeId = Client.getRemoteId(action.probeIp) cls.logger.info("Adding probe %s at %s to overlay", probeId, action.probeIp) addMessage = Add(Identification.PROBE_ID, probeId, action.probeIp) #use action directly because of timing issues selfAddAction = a.Add(action.probeIp, probeId, Hello(probeId, list(ProbeStorage.getAllOtherProbes()), Identification.PROBE_ID, echo = Identification.PROBE_ID if action.mergeOverlays else None) ) # selfAddMessage = copy.deepcopy(addMessage) # selfAddAction.hello = Hello(probeId, # list(ProbeStorage.getAllOtherProbes()), # Identification.PROBE_ID, # echo = Identification.PROBE_ID if action.mergeOverlays else None) # Do broadcast before adding the probe so that it doesn't receive unnecessary message # addMessage = m.Add(Identification.PROBE_ID, probeId, message.targetIp, hello=True) # print(ProbeStorage.getIdAllOtherProbes()) Client.broadcast(addMessage) #treat message after so that the new guy does not receive bogus add message #treat the add for this addToOverlay before any other AddToOverlay # import calls.messagetoaction as MTA cls.addTask(selfAddAction) #try to fix adding host too quickly Scheduler.addToOverlay() cls.logger.debug("Probe %s added to overlay", probeId) except ProbeConnectionException as e: cls.logger.warning("Adding probe failed %s : %s", action.probeIp, e)
def getAllOtherProbes(cls): return ProbeStorage.getAllOtherProbes()