def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchHBBACKALIVE: received [%s] FrameSet from address %s" % (FrameSetTypes.get(fstype)[0], origaddr)) reporter = self.droneinfo.find(origaddr) # System receiving the MARTIAN FrameSet alivesrcaddr = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.IPPORT: alivesrcaddr = frame.getnetaddr() break alivesrc = self.droneinfo.find(alivesrcaddr) # Source of HBBACKALIVE event if CMAdb.debug: CMAdb.log.debug("DispatchHBBACKALIVE: received [%s] FrameSet from %s/%s about %s/%s" % (FrameSetTypes.get(fstype)[0], reporter, origaddr, alivesrc, alivesrcaddr)) if alivesrc.status != 'up': if alivesrc.reason == 'HBSHUTDOWN': # Just bad timing. All is well... return CMAdb.log.info('DispatchHBBACKALIVE: %s had been erroneously marked %s; reason %s' % (alivesrc, alivesrc.status, alivesrc.reason)) alivesrc.status='up' alivesrc.reason='HBBACKALIVE' CMAdb.cdb.TheOneRing.join(alivesrc) AssimEvent(alivesrc, AssimEvent.OBJUP)
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug( "DispatchHBBACKALIVE: received [%s] FrameSet from address %s" % (FrameSetTypes.get(fstype)[0], origaddr)) reporter = self.droneinfo.find( origaddr) # System receiving the MARTIAN FrameSet alivesrcaddr = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.IPPORT: alivesrcaddr = frame.getnetaddr() break alivesrc = self.droneinfo.find( alivesrcaddr) # Source of HBBACKALIVE event if CMAdb.debug: CMAdb.log.debug( "DispatchHBBACKALIVE: received [%s] FrameSet from %s/%s about %s/%s" % (FrameSetTypes.get(fstype)[0], reporter, origaddr, alivesrc, alivesrcaddr)) if alivesrc.status != 'up': if alivesrc.reason == 'HBSHUTDOWN': # Just bad timing. All is well... return CMAdb.log.info( 'DispatchHBBACKALIVE: %s had been erroneously marked %s; reason %s' % (alivesrc, alivesrc.status, alivesrc.reason)) alivesrc.status = 'up' alivesrc.reason = 'HBBACKALIVE' CMAdb.cdb.TheOneRing.join(alivesrc) AssimEvent(alivesrc, AssimEvent.OBJUP)
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug( "DispatchHBMARTIAN: received [%s] FrameSet from address %s " % (FrameSetTypes.get(fstype)[0], origaddr)) reporter = self.droneinfo.find( origaddr) # System receiving the MARTIAN FrameSet martiansrcaddr = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.IPPORT: martiansrcaddr = frame.getnetaddr() break martiansrc = self.droneinfo.find( martiansrcaddr) # Source of MARTIAN event if CMAdb.debug: CMAdb.log.debug( "DispatchHBMARTIAN: received [%s] FrameSet from %s/%s about %s/%s" % (FrameSetTypes.get(fstype)[0], reporter, origaddr, martiansrc, martiansrcaddr)) if martiansrc.status != 'up': if martiansrc.reason == 'HBSHUTDOWN': # Just bad timing. All is well... return CMAdb.log.info( 'DispatchHBMARTIAN: %s had been erroneously marked %s; reason %s' % (martiansrc, martiansrc.status, martiansrc.reason)) if CMAdb.debug: CMAdb.log.info( 'DispatchHBMARTIAN: telling %s/%s to stop sending to %s/%s (%s case)' % (martiansrc, martiansrcaddr, reporter, origaddr, martiansrc.status)) martiansrc.status = 'up' martiansrc.reason = 'HBMARTIAN' martiansrc.send_hbmsg(martiansrcaddr, FrameSetTypes.STOPSENDEXPECTHB, (origaddr, )) CMAdb.cdb.TheOneRing.join(martiansrc) AssimEvent(martiansrc, AssimEvent.OBJUP) return # OK, it's alive... if CMAdb.cdb.TheOneRing.are_partners(reporter, martiansrc): if CMAdb.debug: CMAdb.log.debug( 'DispatchHBMARTIAN: Ignoring msg from %s about %s' % (reporter, martiansrc)) else: if CMAdb.debug: CMAdb.log.info( 'DispatchHBMARTIAN: telling %s/%s to stop sending to %s/%s (%s case)' % (martiansrc, martiansrcaddr, reporter, origaddr, martiansrc.status)) # This probably isn't necessary in most cases, but it doesn't hurt anything. # If the offender is just slow to update, he'll catch up... martiansrc.send_hbmsg(martiansrcaddr, FrameSetTypes.STOPSENDEXPECTHB, (origaddr, ))
def dispatch(self, origaddr, frameset): 'Dummy dispatcher for base class DispatchTarget - for unhandled pyFrameSets' self = self # Make pylint happy... fstype = frameset.get_framesettype() CMAdb.log.info("Received unhandled FrameSet of type [%s] from [%s]" % (FrameSetTypes.get(fstype)[0], str(origaddr))) print ("Received unhandled FrameSet of type [%d:%s] from [%s]" % (fstype, FrameSetTypes.get(fstype)[0], str(origaddr))) for frame in frameset.iter(): frametype = frame.frametype() print "\tframe type [%s]: [%s]" \ % (FrameTypes.get(frametype)[1], str(frame))
def dispatch(self, origaddr, frameset): 'Dummy dispatcher for base class DispatchTarget - for unhandled pyFrameSets' self = self # Make pylint happy... fstype = frameset.get_framesettype() CMAdb.log.info("Received unhandled FrameSet of type [%s] from [%s]" % (FrameSetTypes.get(fstype)[0], str(origaddr))) print("Received unhandled FrameSet of type [%d:%s] from [%s]" % (fstype, FrameSetTypes.get(fstype)[0], str(origaddr))) for frame in frameset.iter(): frametype = frame.frametype() print "\tframe type [%s]: [%s]" \ % (FrameTypes.get(frametype)[1], str(frame))
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchSWDISCOVER: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], str(origaddr))) wallclock = None interface = None designation = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: designation = frame.getstr() elif frametype == FrameTypes.INTERFACE: interface = frame.getstr() elif frametype == FrameTypes.WALLCLOCK: wallclock = frame.getint() elif frametype == FrameTypes.PKTDATA: if wallclock is None or interface is None or designation is None: raise ValueError('Incomplete Switch Discovery Packet') pktstart = frame.framevalue() pktend = frame.frameend() switchjson = pySwitchDiscovery.decode_discovery(designation, interface , wallclock, pktstart, pktend) if CMAdb.debug: CMAdb.log.debug('Got Link discovery info from %s: %s' \ % (interface, str(switchjson))) drone = self.droneinfo.find(designation) drone.logjson(origaddr, str(switchjson)) break
def dispatch(self, origaddr, frameset): json = None fstype = frameset.get_framesettype() print >>sys.stderr,"DispatchSTARTUP: received [%s] FrameSet from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if frametype == FrameTypes.JSDISCOVER: json = frame.getstr() fs = CMAlib.create_setconfig(self.config) #print 'Telling them to heartbeat themselves.' #fs2 = CMAlib.create_sendexpecthb(self.config, FrameSetTypes.SENDEXPECTHB #, origaddr) #print 'Sending SetConfig frameset to %s' % origaddr #self.io.sendframesets(origaddr, (fs,fs2)) self.io.sendframesets(origaddr, fs) #print 'ADDING DRONE for system %s' % sysname DroneInfo.add(sysname, self.io, 'STARTUP packet') drone = DroneInfo.find(sysname) drone.startaddr = origaddr if json is not None: drone.logjson(json) TheOneRing.join(drone)
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchSWDISCOVER: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], str(origaddr))) wallclock = None interface = None designation = None instance = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: designation = frame.getstr() elif frametype == FrameTypes.INTERFACE: interface = frame.getstr() elif frametype == FrameTypes.DISCNAME: instance = frame.getstr() elif frametype == FrameTypes.WALLCLOCK: wallclock = frame.getint() elif frametype == FrameTypes.PKTDATA: if wallclock is None or interface is None or designation is None: raise ValueError('Incomplete Switch Discovery Packet') pktstart = frame.framevalue() pktend = frame.frameend() if instance is None: instance = '_switch_%s' % interface switchjson = pySwitchDiscovery.decode_discovery(designation, interface , instance, wallclock, pktstart, pktend) if CMAdb.debug: CMAdb.log.debug('Got Link discovery info from %s: %s' \ % (interface, str(switchjson))) drone = self.droneinfo.find(designation) drone.logjson(origaddr, str(switchjson)) break
def _process_exception(e, origaddr, frameset): 'Handle an exception from our message dispatcher' # Darn! Got an exception - let's try and put everything useful into the # logs in a legible way trace = sys.exc_info()[2] # we ignore the etype and evalue returns from sys.exc_info tblist = traceback.extract_tb(trace, 20) fstype = frameset.get_framesettype() fstypename = FrameSetTypes.get(fstype)[0] print >> sys.stderr, ('MessageDispatcher exception [%s] occurred' % (e)) CMAdb.log.critical('MessageDispatcher exception [%s] occurred while' ' handling [%s] FrameSet from %s' % (e, fstypename, origaddr)) lines = str(frameset).splitlines() CMAdb.log.info('FrameSet Contents follows (%d lines):' % len(lines)) for line in lines: CMAdb.log.info(line.expandtabs()) CMAdb.log.info('======== Begin %s Message %s Exception Traceback ========' % (fstypename, e)) for tb in tblist: (filename, line, funcname, text) = tb filename = os.path.basename(filename) CMAdb.log.info('%s.%s:%s: %s'% (filename, line, funcname, text)) CMAdb.log.info('======== End %s Message %s Exception Traceback ========' % (fstypename, e)) if CMAdb.store is not None: CMAdb.log.critical("Aborting Neo4j transaction %s" % CMAdb.store) CMAdb.store.abort() if CMAdb.transaction is not None: CMAdb.log.critical("Aborting network transaction %s" % CMAdb.transaction.tree) CMAdb.transaction = None
def dispatch(self, origaddr, frameset): 'Dispatch function for HBSHUTDOWN FrameSets' fstype = frameset.get_framesettype() fsname = FrameSetTypes.get(fstype)[0] for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: hostname = frame.getstr() fromdrone = self.droneinfo.find(hostname, port=origaddr.port()) if fromdrone is not None: CMAdb.log.info( "System %s at %s reports graceful shutdown." % (hostname, str(origaddr))) print >> sys.stderr, ( "System %s at %s reports graceful shutdown." % (hostname, str(origaddr))) fromdrone.death_report('dead', fsname, origaddr, frameset) else: CMAdb.log.error( "DispatchHBSHUTDOWN: received %s FrameSet from unknown drone %s at [%s]" % (fsname, hostname, str(origaddr))) return CMAdb.log.error( "DispatchHBSHUTDOWN: received invalid %s FrameSet from drone at [%s]" % (fsname, str(origaddr))) CMAdb.log.error("DispatchHBSHUTDOWN: invalid FrameSet: %s", str(frameset))
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchJSDISCOVERY: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], repr(origaddr))) sysname = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if frametype == FrameTypes.JSDISCOVER: json = frame.getstr() jsonconfig = pyConfigContext(init=json) #print 'JSON received: ', json if sysname is None: sysname = jsonconfig.getstring('host') drone = self.droneinfo.find(sysname) #print >> sys.stderr, 'FOUND DRONE for %s IS: %s' % (sysname, drone) #print >> sys.stderr, 'LOGGING JSON FOR DRONE for %s IS: %s' % (drone, json) child = drone.find_child_system_from_json(jsonconfig) #if child is not drone: # print >> sys.stderr, ('>>>>>>>>>>>>>>>>>>>LOGGED child system Discovery %s: %s' # % (str(child), json)) child.logjson(origaddr, json) sysname = None
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug( "DispatchJSDISCOVERY: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], repr(origaddr))) sysname = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if frametype == FrameTypes.JSDISCOVER: json = frame.getstr() jsonconfig = pyConfigContext(init=json) #print 'JSON received: ', json if sysname is None: sysname = jsonconfig.getstring('host') drone = self.droneinfo.find(sysname) #print >> sys.stderr, 'FOUND DRONE for %s IS: %s' % (sysname, drone) #print >> sys.stderr, 'LOGGING JSON FOR DRONE for %s IS: %s' % (drone, json) child = drone.find_child_system_from_json(jsonconfig) #if child is not drone: # print >> sys.stderr, ('>>>>>>>>>>>>>>>>>>>LOGGED child system Discovery %s: %s' # % (str(child), json)) child.logjson(origaddr, json) sysname = None
def dispatch(self, origaddr, frameset): json = None fstype = frameset.get_framesettype() print >>sys.stderr,"DispatchSTARTUP: received [%s] FrameSet from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype=frame.frametype() if frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if frametype == FrameTypes.JSDISCOVER: json = frame.getstr() fs = CMAlib.create_setconfig(self.config) #print 'Telling them to heartbeat themselves.' #fs2 = CMAlib.create_sendexpecthb(self.config, FrameSetTypes.SENDEXPECTHB #, origaddr) #print 'Sending SetConfig frameset to %s' % origaddr #self.io.sendframesets(origaddr, (fs,fs2)) self.io.sendframesets(origaddr, fs) #print 'ADDING DRONE for system %s' % sysname DroneInfo.add(sysname, self.io, 'STARTUP packet') drone = DroneInfo.find(sysname) drone.startaddr=origaddr if json is not None: drone.logjson(json) TheOneRing.join(drone)
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() print "Received FrameSet of type [%s] from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype=frame.frametype() print "\tframe type [%s]: [%s]" \ % (FrameTypes.get(frametype)[1], str(frame))
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() print "Received FrameSet of type [%s] from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype = frame.frametype() print "\tframe type [%s]: [%s]" \ % (FrameTypes.get(frametype)[1], str(frame))
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchHBMARTIAN: received [%s] FrameSet from address %s " % (FrameSetTypes.get(fstype)[0], origaddr)) reporter = self.droneinfo.find(origaddr) # System receiving the MARTIAN FrameSet martiansrcaddr = None for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.IPPORT: martiansrcaddr = frame.getnetaddr() break martiansrc = self.droneinfo.find(martiansrcaddr) # Source of MARTIAN event if CMAdb.debug: CMAdb.log.debug("DispatchHBMARTIAN: received [%s] FrameSet from %s/%s about %s/%s" % (FrameSetTypes.get(fstype)[0], reporter, origaddr, martiansrc, martiansrcaddr)) if martiansrc.status != 'up': if martiansrc.reason == 'HBSHUTDOWN': # Just bad timing. All is well... return CMAdb.log.info('DispatchHBMARTIAN: %s had been erroneously marked %s; reason %s' % (martiansrc, martiansrc.status, martiansrc.reason)) if CMAdb.debug: CMAdb.log.info('DispatchHBMARTIAN: telling %s/%s to stop sending to %s/%s (%s case)' % (martiansrc, martiansrcaddr, reporter, origaddr, martiansrc.status)) martiansrc.status='up' martiansrc.reason='HBMARTIAN' martiansrc.send_hbmsg(martiansrcaddr, FrameSetTypes.STOPSENDEXPECTHB, (origaddr,)) CMAdb.cdb.TheOneRing.join(martiansrc) AssimEvent(martiansrc, AssimEvent.OBJUP) return # OK, it's alive... if CMAdb.cdb.TheOneRing.are_partners(reporter, martiansrc): if CMAdb.debug: CMAdb.log.debug('DispatchHBMARTIAN: Ignoring msg from %s about %s' % (reporter, martiansrc)) else: if CMAdb.debug: CMAdb.log.info('DispatchHBMARTIAN: telling %s/%s to stop sending to %s/%s (%s case)' % (martiansrc, martiansrcaddr, reporter, origaddr, martiansrc.status)) # This probably isn't necessary in most cases, but it doesn't hurt anything. # If the offender is just slow to update, he'll catch up... martiansrc.send_hbmsg(martiansrcaddr, FrameSetTypes.STOPSENDEXPECTHB, (origaddr,))
def dispatch(self, origaddr, frameset): 'Dispatch function for HBDEAD FrameSets' json = None fstype = frameset.get_framesettype() fromdrone = DroneInfo.find(origaddr) print>>sys.stderr, "DispatchHBDEAD: received [%s] FrameSet from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype=frame.frametype() if frametype == FrameTypes.IPADDR: deaddrone = DroneInfo.find(frame.getnetaddr()) deaddrone.death_report('dead', 'HBDEAD packet', origaddr, frameset)
def dispatch(self, origaddr, frameset): 'Dispatch function for HBDEAD FrameSets' json = None fstype = frameset.get_framesettype() fromdrone = DroneInfo.find(origaddr) print>>sys.stderr, "DispatchHBDEAD: received [%s] FrameSet from [%s]" \ % (FrameSetTypes.get(fstype)[0], str(origaddr)) for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.IPADDR: deaddrone = DroneInfo.find(frame.getnetaddr()) deaddrone.death_report('dead', 'HBDEAD packet', origaddr, frameset)
def register(classtoregister): '''Register the given class in DispatchTarget.dispatchtable This function is intended to be used as a decorator. This is requires that the class being registered be named Dispatch{name-of-message-being-dispatched} ''' cname = classtoregister.__name__ if not cname.startswith('Dispatch'): raise(ValueError('Dispatch class names must start with "Dispatch"')) msgname = cname[8:] # This is kinda cool! DispatchTarget.dispatchtable[FrameSetTypes.get(msgname)[0]] = classtoregister() return classtoregister
def dispatch(self, origaddr, frameset): fstype = frameset.get_framesettype() if CMAdb.debug: CMAdb.log.debug("DispatchRSCOPREPLY: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], str(origaddr))) for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.RSCJSONREPLY: obj = pyConfigContext(frame.getstr()) MonitorAction.logchange(origaddr, obj) return CMAdb.log.critical('RSCOPREPLY message from %s did not have a RSCJSONREPLY field' % (str(origaddr)))
def dispatch(self, origaddr, frameset): 'Dispatch a Frameset where it will get handled.' self.dispatchcount += 1 CMAdb.transaction = Transaction(encryption_required=self.encryption_required) # W0703 == Too general exception catching... # pylint: disable=W0703 try: self._try_dispatch_action(origaddr, frameset) if (self.dispatchcount % 100) == 1: self._check_memory_usage() except Exception as e: self._process_exception(e, origaddr, frameset) # We want to ack the packet even in the failed case - retries are unlikely to help # and we need to avoid getting stuck in a loop retrying it forever... if CMAdb.debug: fstypename = FrameSetTypes.get(frameset.get_framesettype())[0] CMAdb.log.debug('MessageDispatcher - ACKing %s message from %s' % (fstypename, origaddr)) self.io.ackmessage(origaddr, frameset)
def dispatch(self, origaddr, frameset): 'Dispatch a Frameset where it will get handled.' self.dispatchcount += 1 CMAdb.transaction = Transaction( encryption_required=self.encryption_required) # W0703 == Too general exception catching... # pylint: disable=W0703 try: self._try_dispatch_action(origaddr, frameset) if (self.dispatchcount % 100) == 1: self._check_memory_usage() except Exception as e: self._process_exception(e, origaddr, frameset) # We want to ack the packet even in the failed case - retries are unlikely to help # and we need to avoid getting stuck in a loop retrying it forever... if CMAdb.debug: fstypename = FrameSetTypes.get(frameset.get_framesettype())[0] CMAdb.log.debug('MessageDispatcher - ACKing %s message from %s' % (fstypename, origaddr)) self.io.ackmessage(origaddr, frameset)
def dispatch(self, origaddr, frameset): 'Dispatch function for HBSHUTDOWN FrameSets' fstype = frameset.get_framesettype() fsname = FrameSetTypes.get(fstype)[0] for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.HOSTNAME: hostname = frame.getstr() fromdrone = self.droneinfo.find(hostname, port=origaddr.port()) if fromdrone is not None: CMAdb.log.info("System %s at %s reports graceful shutdown." % (hostname, str(origaddr))) print >> sys.stderr, ("System %s at %s reports graceful shutdown." % (hostname, str(origaddr))) fromdrone.death_report('dead', fsname, origaddr, frameset) else: CMAdb.log.error( "DispatchHBSHUTDOWN: received %s FrameSet from unknown drone %s at [%s]" % (fsname, hostname, str(origaddr))) return CMAdb.log.error("DispatchHBSHUTDOWN: received invalid %s FrameSet from drone at [%s]" % (fsname, str(origaddr))) CMAdb.log.error("DispatchHBSHUTDOWN: invalid FrameSet: %s", str(frameset))
def _process_exception(e, origaddr, frameset): 'Handle an exception from our message dispatcher' # Darn! Got an exception - let's try and put everything useful into the # logs in a legible way trace = sys.exc_info()[2] # we ignore the etype and evalue returns from sys.exc_info tblist = traceback.extract_tb(trace, 20) fstype = frameset.get_framesettype() fstypename = FrameSetTypes.get(fstype)[0] print >> sys.stderr, ('MessageDispatcher exception [%s] occurred' % (e)) CMAdb.log.critical('MessageDispatcher exception [%s] occurred while' ' handling [%s] FrameSet from %s' % (e, fstypename, origaddr)) lines = str(frameset).splitlines() CMAdb.log.info('FrameSet Contents follows (%d lines):' % len(lines)) for line in lines: CMAdb.log.info(line.expandtabs()) CMAdb.log.info( '======== Begin %s Message %s Exception Traceback ========' % (fstypename, e)) for tb in tblist: (filename, line, funcname, text) = tb filename = os.path.basename(filename) CMAdb.log.info('%s.%s:%s: %s' % (filename, line, funcname, text)) CMAdb.log.info( '======== End %s Message %s Exception Traceback ========' % (fstypename, e)) if CMAdb.store is not None: CMAdb.log.critical("Aborting Neo4j transaction %s" % CMAdb.store) CMAdb.store.abort() if CMAdb.transaction is not None: CMAdb.log.critical("Aborting network transaction %s" % CMAdb.transaction.tree) CMAdb.transaction = None
def dispatch(self, origaddr, frameset): json = None addrstr = repr(origaddr) fstype = frameset.get_framesettype() localtime = None listenaddr = None keyid = None pubkey = None keysize = None #print >> sys.stderr, ("DispatchSTARTUP: received [%s] FrameSet from [%s]" #% (FrameSetTypes.get(fstype)[0], addrstr)) if CMAdb.debug: CMAdb.log.debug( "DispatchSTARTUP: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], addrstr)) if not self.io.connactive(origaddr): self.io.closeconn(DEFAULT_FSP_QID, origaddr) CMAdb.transaction.post_transaction_packets.append( FrameSetTypes.ACKSTARTUP) for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.WALLCLOCK: localtime = str(frame.getint()) elif frametype == FrameTypes.IPPORT: listenaddr = frame.getnetaddr() elif frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if sysname == CMAdb.nodename: if origaddr.islocal(): CMAdb.log.info( "Received STARTUP from local system (%s)" % addrstr) else: addresses = ['127.0.0.1', '::ffff:127.0.0.1', '::1'] for address in addresses: localhost = pyNetAddr(address) self.io.addalias(localhost, origaddr) CMAdb.log.info("Aliasing %s to %s" % (localhost, origaddr)) elif frametype == FrameTypes.JSDISCOVER: json = frame.getstr() #print >> sys.stderr, 'GOT JSDISCOVER JSON: [%s] (strlen:%s,framelen:%s)' \ #% (json, len(json), frame.framelen()) elif frametype == FrameTypes.KEYID: keyid = frame.getstr() elif frametype == FrameTypes.PUBKEYCURVE25519: pubkey = frame.framevalue() keysize = frame.framelen() joininfo = pyConfigContext(init=json) origaddr, isNAT = self.validate_source_ip(sysname, origaddr, joininfo, listenaddr) CMAdb.log.info( 'Drone %s registered from address %s (%s) port %s, key_id %s' % (sysname, origaddr, addrstr, origaddr.port(), keyid)) drone = self.droneinfo.add(sysname, 'STARTUP packet', port=origaddr.port(), primary_ip_addr=str(origaddr)) drone.listenaddr = str(listenaddr) # Seems good to hang onto this... drone.isNAT = isNAT # ditto... if CMAdb.debug: CMAdb.log.debug('DRONE select_ip() result: %s' % (drone.select_ip())) CMAdb.log.debug('DRONE listenaddr: %s' % (drone.listenaddr)) CMAdb.log.debug('DRONE port: %s (%s)' % (drone.port, type(drone.port))) # Did they give us the crypto info we need? if keyid is None or pubkey is None: if CMAdb.debug: CMAdb.log.debug( 'Drone %s registered with keyid %s and pubkey provided: %s' % (self, keyid, pubkey is not None)) else: if drone.key_id == '': if not keyid.startswith(sysname + "@@"): CMAdb.log.warning( "Drone %s wants to register with key_id %s -- permitted.", sysname, keyid) if not cryptcurve25519_save_public_key(keyid, pubkey, keysize): raise ValueError( "Drone %s public key (key_id %s, %d bytes) is invalid." % (sysname, keyid, keysize)) elif drone.key_id != keyid: raise ValueError( "Drone %s tried to register with key_id %s instead of %s." % (sysname, keyid, drone.key_id)) drone.set_crypto_identity(keyid=keyid) pyCryptFrame.dest_set_key_id(origaddr, keyid) # # THIS IS HERE BECAUSE OF A PROTOCOL BUG... # @FIXME Protocol bug when starting up a connection if our first (this) packet gets lost, # then the protocol doesn't retransmit it. # More specifically, it seems to clear it out of the queue. # This might be CMA bug or a protocol bug. It's not clear... # The packet goes into the queue, but if that packet is lost in transmission, then when # we come back around here, it's not in the queue any more, even though it # definitely wasn't ACKed. # Once this is fixed, this "add_packet" call needs to go *after* the 'if' statement below. # CMAdb.transaction.add_packet(origaddr, FrameSetTypes.SETCONFIG, (str(self.config), ), FrameTypes.CONFIGJSON) if (localtime is not None): if (drone.lastjoin == localtime): CMAdb.log.warning('Drone %s [%s] sent duplicate STARTUP' % (sysname, origaddr)) if CMAdb.debug: self.io.log_conn(origaddr) return drone.lastjoin = localtime #print >> sys.stderr, 'DRONE from find: ', drone, type(drone), drone.port drone.startaddr = str(origaddr) if json is not None: drone.logjson(origaddr, json) if CMAdb.debug: CMAdb.log.debug('Joining TheOneRing: %s / %s / %s' % (drone, type(drone), drone.port)) CMAdb.cdb.TheOneRing.join(drone) if CMAdb.debug: CMAdb.log.debug('Requesting Discovery from %s' % str(drone)) discovery_params = [] for agent in self.config['initial_discovery']: params = ConfigFile.agent_params(self.config, 'discovery', agent, sysname) params['agent'] = agent params['instance'] = '_init_%s' % agent discovery_params.append(params) # Discover the permissions of all the lists of files we're configured to ask about # Note that there are several lists to keep the amount of data in any one list # down to a somewhat more reasonable level. 'fileattrs' output is really verbose for pathlist_name in self.config['perm_discovery_lists']: paths = self.config[pathlist_name] params = ConfigFile.agent_params(self.config, 'discovery', 'fileattrs', sysname) params['agent'] = 'fileattrs' params['instance'] = pathlist_name params['parameters'] = {'ASSIM_filelist': paths} discovery_params.append(params) if CMAdb.debug: CMAdb.log.debug('Discovery details: %s' % str(discovery_params)) for item in discovery_params: CMAdb.log.debug('Discovery item details: %s' % str(item)) drone.request_discovery(discovery_params) AssimEvent(drone, AssimEvent.OBJUP)
def dispatch(self, origaddr, frameset): json = None addrstr = repr(origaddr) fstype = frameset.get_framesettype() localtime = None listenaddr = None keyid = None pubkey = None keysize = None #print >> sys.stderr, ("DispatchSTARTUP: received [%s] FrameSet from [%s]" #% (FrameSetTypes.get(fstype)[0], addrstr)) if CMAdb.debug: CMAdb.log.debug("DispatchSTARTUP: received [%s] FrameSet from [%s]" % (FrameSetTypes.get(fstype)[0], addrstr)) if not self.io.connactive(origaddr): self.io.closeconn(DEFAULT_FSP_QID, origaddr) CMAdb.transaction.post_transaction_packets.append(FrameSetTypes.ACKSTARTUP) for frame in frameset.iter(): frametype = frame.frametype() if frametype == FrameTypes.WALLCLOCK: localtime = str(frame.getint()) elif frametype == FrameTypes.IPPORT: listenaddr = frame.getnetaddr() elif frametype == FrameTypes.HOSTNAME: sysname = frame.getstr() if sysname == CMAdb.nodename: if origaddr.islocal(): CMAdb.log.info("Received STARTUP from local system (%s)" % addrstr) else: addresses = ['127.0.0.1', '::ffff:127.0.0.1', '::1' ] for address in addresses: localhost = pyNetAddr(address) self.io.addalias(localhost, origaddr) CMAdb.log.info("Aliasing %s to %s" % (localhost, origaddr)) elif frametype == FrameTypes.JSDISCOVER: json = frame.getstr() #print >> sys.stderr, 'GOT JSDISCOVER JSON: [%s] (strlen:%s,framelen:%s)' \ #% (json, len(json), frame.framelen()) elif frametype == FrameTypes.KEYID: keyid = frame.getstr() elif frametype == FrameTypes.PUBKEYCURVE25519: pubkey = frame.framevalue() keysize = frame.framelen() joininfo = pyConfigContext(init=json) origaddr, isNAT = self.validate_source_ip(sysname, origaddr, joininfo, listenaddr) CMAdb.log.info('Drone %s registered from address %s (%s) port %s, key_id %s' % (sysname, origaddr, addrstr, origaddr.port(), keyid)) drone = self.droneinfo.add(sysname, 'STARTUP packet', port=origaddr.port() , primary_ip_addr=str(origaddr)) drone.listenaddr = str(listenaddr) # Seems good to hang onto this... drone.isNAT = isNAT # ditto... # Did they give us the crypto info we need? if keyid is None or pubkey is None: if CMAdb.debug: CMAdb.log.debug('Drone %s registered with keyid %s and pubkey provided: %s' % (self, keyid, pubkey is not None)) else: if drone.key_id == '': if not keyid.startswith(sysname + "@@"): CMAdb.log.warning("Drone %s wants to register with key_id %s -- permitted." , sysname, keyid) if not cryptcurve25519_save_public_key(keyid, pubkey, keysize): raise ValueError("Drone %s public key (key_id %s, %d bytes) is invalid." % (sysname, keyid, keysize)) elif drone.key_id != keyid: raise ValueError("Drone %s tried to register with key_id %s instead of %s." % (sysname, keyid, drone.key_id)) drone.set_crypto_identity(keyid=keyid) pyCryptFrame.dest_set_key_id(origaddr, keyid) # # THIS IS HERE BECAUSE OF A PROTOCOL BUG... # @FIXME Protocol bug when starting up a connection if our first (this) packet gets lost, # then the protocol doesn't retransmit it. # More specifically, it seems to clear it out of the queue. # This might be CMA bug or a protocol bug. It's not clear... # The packet goes into the queue, but if that packet is lost in transmission, then when # we come back around here, it's not in the queue any more, even though it # definitely wasn't ACKed. # Once this is fixed, this "add_packet" call needs to go *after* the 'if' statement below. # CMAdb.transaction.add_packet(origaddr, FrameSetTypes.SETCONFIG, (str(self.config), ) , FrameTypes.CONFIGJSON) if (localtime is not None): if (drone.lastjoin == localtime): CMAdb.log.warning('Drone %s [%s] sent duplicate STARTUP' % (sysname, origaddr)) if CMAdb.debug: self.io.log_conn(origaddr) return drone.lastjoin = localtime #print >> sys.stderr, 'DRONE from find: ', drone, type(drone), drone.port drone.startaddr = str(origaddr) if json is not None: drone.logjson(origaddr, json) if CMAdb.debug: CMAdb.log.debug('Joining TheOneRing: %s / %s / %s' % (drone, type(drone), drone.port)) CMAdb.cdb.TheOneRing.join(drone) if CMAdb.debug: CMAdb.log.debug('Requesting Discovery from %s' % str(drone)) discovery_params = [] for agent in self.config['initial_discovery']: params = ConfigFile.agent_params(self.config, 'discovery', agent, sysname) params['agent'] = agent params['instance'] = '_init_%s' % agent discovery_params.append(params) # Discover the permissions of all the lists of files we're configured to ask about # Note that there are several lists to keep the amount of data in any one list # down to a somewhat more reasonable level. 'fileattrs' output is really verbose for pathlist_name in self.config['perm_discovery_lists']: paths = self.config[pathlist_name] params = ConfigFile.agent_params(self.config, 'discovery', 'fileattrs', sysname) params['agent'] = 'fileattrs' params['instance'] = pathlist_name params['parameters'] = {'ASSIM_filelist': paths} discovery_params.append(params) if CMAdb.debug: CMAdb.log.debug('Discovery details: %s' % str(discovery_params)) drone.request_discovery(discovery_params) AssimEvent(drone, AssimEvent.OBJUP)