def WorkerProc(self, fnKillSignalled, userData):
        lastUpdate = 0
        interval = Configuration.get().GetConnectionUpdateInterval()

        buffer = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        buffer = buffer + "<Oscar Type=\"ConnectionInformation\">"
        buffer = buffer + "<Version>1.0</Version>"
        buffer = buffer + "<OscarVersion>" + VersionMgr.ReadVer(
        ) + "</OscarVersion>"
        buffer = buffer + "<ID>" + Configuration.get().GetID() + "</ID>"
        buffer = buffer + "<Port>" + str(Configuration.get(
        ).GetDownstreamConnection().getPort()) + "</Port>"
        buffer = buffer + "</Oscar>"

        #<?xml version="1.0" encoding="utf-8"?>
        #<Oscar Type="ConnectionInformation">
        #    <Version>1.0</Version>
        #    <ID>Foo</Foo>
        #    <Port>Port</Port>
        #</Oscar>

        while not fnKillSignalled(
        ):  # run until signalled to end - call passed function to check for the signal
            if lastUpdate < Time.GetCurrMS() - interval:
                TargetManager.GetTargetManager().BroadcastDownstream(
                    buffer, True, None
                )  # send Connection Data to all downstream things (Oscars & Marvins)
                lastUpdate = Time.GetCurrMS()

                Configuration.get().RescanTargets()

            else:
                Sleep.Sleep(0.25)
                TargetManager.GetTargetManager(
                ).CheckForRemovalOfDynamicMarvins()
 def Stop(self):
     if False == self.IsRunning():
         Log.getLogger().error("Tried to stop Thread [" + self.__ID +
                               "] that is not running.")
         return
     self.SignalStop()
     while False == self.IsStopped():
         Sleep.Sleep(.01)
Example #3
0
    def HandleIncomingWatchdogPacket(self,node,rawData,fromAddr):
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="WatchdogTimer">
        #    <Version>1.0</Version>
        #    <MarvinVersion>17.12.22</MarvinVersion>
        #    <UniqueID>3236</UniqueID>
        #    <Port>5000</Port>
        #</Marvin>

        Statistics.GetStatistics().OnPacketReceivedFromDownstream(rawData)
        try:
            _ = node.getElementsByTagName('Version')[0].firstChild.nodeValue 
            IP = fromAddr[0].lower()
            Port = node.getElementsByTagName('Port')[0].firstChild.nodeValue
            UniqueID = node.getElementsByTagName('UniqueID')[0].firstChild.nodeValue

        except Exception as _:
            Statistics.GetStatistics().OnMalformedPacketReceived("Received invalid Marvin WatchdogTimer  Packet : " + rawData)
            return

        try:
            marvinVersion = node.getElementsByTagName('MarvinVersion')[0].firstChild.nodeValue 

        except Exception:
            marvinVersion='Unknown'

        Key = IP + ":" + Port
        objTarget = TargetManager.GetTargetManager().GetDownstreamTarget(Key)  

        if None == objTarget:
            objTarget = TargetManager.GetTargetManager().GetDownstreamTargetEx(IP,Port)  # if using DNS, do lookup based on real IP, not DNS name

        if None == objTarget:
            Sleep.Sleep(50) #give it another shot, other thread may be doing a DNS resolution            
            objTarget = TargetManager.GetTargetManager().GetDownstreamTargetEx(IP,Port)  # if using DNS, do lookup based on real IP, not DNS name

        if None == objTarget:
            Log.getLogger().warning("Received Marvin Watchdog for unknown downstream Target: " +IP+":"+Port + " Version: " + marvinVersion)
            return
        
        if objTarget.getType() != ConnectionType.Marvin and objTarget.getType() != ConnectionType.DynamicMarvin : # would not know what this is until you hear back (could be another Oscar)
            objTarget.Type = ConnectionType.Marvin
            Log.getLogger().info("Connection established with Marvin Target: "+ IP + ":" + Port + " Version: " + marvinVersion)

        try:
            _ = node.getElementsByTagName('RefreshRequested')[0].firstChild.nodeValue 
            objTarget.ReArmRefreshRequest(UniqueID)  # Asked to refresh!

        except Exception as _:
            pass

        objTarget.StrokeWatchdogTimer()
    def StopAllThreads(self):
        for key in self.__threadList:
            objThread = self.__threadList[key]
            if True == objThread.IsRunning():
                objThread.SignalStop()

        allDone = False
        while False == allDone:
            allDone = True
            for key in self.__threadList:
                objThread = self.__threadList[key]
                if True == objThread.IsRunning():
                    allDone = False
                else:
                    objThread.ReportStopped()

            Sleep.Sleep(.01) # sleep for 100ms
    def WatchdogProc(self, fnKillSignalled, userData):
        lastUpdate = 0
        interval = Configuration.get().GetTimeoutPeriod(
        ) * 0.25  # send a watchdog at 4x rate of timeout

        buffer = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        buffer = buffer + "<Oscar Type=\"WatchdogTimer\">"
        buffer = buffer + "<Version>1.0</Version>"
        buffer = buffer + "<Port>" + str(
            Configuration.get().GetUpstreamConnection().getPort()) + "</Port>"
        buffer = buffer + "</Oscar>"

        while not fnKillSignalled(
        ):  # run until signalled to end - call passed function to check for the signal
            if lastUpdate < Time.GetCurrMS() - interval:
                TargetManager.GetTargetManager().BroadcastUpstreamToType(
                    buffer, ConnectionType.UpstreamOscar
                )  # send heartbeat to all upstream Oscars
                lastUpdate = Time.GetCurrMS()

            Sleep.Sleep(0.25)  #snooze for 250 ms