Changeset 453:3cb368c406cb

Show
Ignore:
Timestamp:
08/01/08 15:56:55 (5 months ago)
Author:
"Brian Warner <warner@lothar.com>"
branch:
default
Message:

gatherer: use getRemoteTubID instead of sanitizing the received tubid string

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r452 r453  
    55        not sure this is a good idea, but it fixes the immediate problem 
    66        I'm dealing with. 
     7        * foolscap/logging/gatherer.py: use "tubid_s" instead of "nodeid_s" 
     8        (IncidentGathererService.remote_logport): use getRemoteTubID() 
     9        instead of trying to sanitize the tubid we receive, since we 
     10        use it as a directory name 
    711 
    812        * foolscap/test/test_logging.py (IncidentGatherer.test_emit): add 
  • foolscap/logging/gatherer.py

    r450 r453  
    294294    implements(RILogObserver) 
    295295 
    296     def __init__(self, basedir, nodeid_s, gatherer, publisher, stdout): 
     296    def __init__(self, basedir, tubid_s, gatherer, publisher, stdout): 
    297297        if not os.path.isdir(basedir): 
    298298            os.makedirs(basedir) 
    299299        self.basedir = filepath.FilePath(basedir) 
    300         self.nodeid_s = nodeid_s # printable string 
     300        self.tubid_s = tubid_s # printable string 
    301301        self.gatherer = gatherer 
    302302        self.publisher = publisher 
     
    314314            pass 
    315315        print >>self.stdout, "connected to %s, last known incident is %s" \ 
    316               % (self.nodeid_s, latest) 
     316              % (self.tubid_s, latest) 
    317317        # now subscribe to everything since then 
    318318        d = self.publisher.callRemote("subscribe_to_incidents", self, 
     
    339339        # we need to record the relative pathname of the savefile, for use by 
    340340        # the classifiers (they write it into their output files) 
    341         rel_fn = os.path.join("incidents", self.nodeid_s, name) + ".flog.bz2" 
     341        rel_fn = os.path.join("incidents", self.tubid_s, name) + ".flog.bz2" 
    342342        self.save_incident(abs_fn, incident) 
    343343        self.update_latest(name) 
    344         self.gatherer.new_incident(abs_fn, rel_fn, self.nodeid_s, incident) 
     344        self.gatherer.new_incident(abs_fn, rel_fn, self.tubid_s, incident) 
    345345 
    346346    def save_incident(self, filename, incident): 
     
    351351        pickle.dump(h, f) 
    352352        for e in events: 
    353             wrapper = {"from": self.nodeid_s, 
     353            wrapper = {"from": self.tubid_s, 
    354354                       "rx_time": now, 
    355355                       "d": e} 
     
    417417        print >>stdout, "No classified/ directory: reclassifying stored incidents" 
    418418        # now classify all stored incidents 
    419         for nodeid_s in os.listdir(indir): 
    420             nodedir = os.path.join(indir, nodeid_s) 
     419        for tubid_s in os.listdir(indir): 
     420            nodedir = os.path.join(indir, tubid_s) 
    421421            for fn in os.listdir(nodedir): 
    422422                if fn.startswith("incident-"): 
    423423                    abs_fn = os.path.join(nodedir, fn) 
    424424                    incident = self.load_incident(abs_fn) 
    425                     rel_fn = os.path.join("incidents", nodeid_s, fn) 
    426                     self.classify_incident(rel_fn, nodeid_s, incident) 
     425                    rel_fn = os.path.join("incidents", tubid_s, fn) 
     426                    self.classify_incident(rel_fn, tubid_s, incident) 
    427427 
    428428    def load_incident(self, abs_fn): 
     
    441441 
    442442    def remote_logport(self, nodeid, publisher): 
    443         # nodeid is actually a printable string 
    444         tubid_s = nodeid 
    445         if not base32.is_base32(tubid_s): 
    446             # we must check it to exclude .. and / and other nasties 
    447             raise BadTubID("%s is not a valid base32-encoded Tub ID" % tubid_s) 
     443        # we ignore nodeid (which is a printable string), and get the tubid 
     444        # (or its <unauth> name) from the publisher remoteReference. 
     445        # getRemoteTubID() protects us from .. and / and other nasties. 
     446        tubid_s = publisher.getRemoteTubID() 
    448447        basedir = os.path.join(self.basedir, "incidents", tubid_s) 
    449448        stdout = self.stdout or sys.stdout 
     
    453452        return d # mostly for testing 
    454453 
    455     def new_incident(self, abs_fn, rel_fn, nodeid_s, incident): 
     454    def new_incident(self, abs_fn, rel_fn, tubid_s, incident): 
    456455        stdout = self.stdout or sys.stdout 
    457456        print >>stdout, "NEW INCIDENT", rel_fn 
    458         self.classify_incident(rel_fn, nodeid_s, incident) 
    459  
    460     def classify_incident(self, rel_fn, nodeid_s, incident): 
     457        self.classify_incident(rel_fn, tubid_s, incident) 
     458 
     459    def classify_incident(self, rel_fn, tubid_s, incident): 
    461460        categories = set() 
    462461        for f in self.classifiers: 
    463             c = f(nodeid_s, incident) 
     462            c = f(tubid_s, incident) 
    464463            if c: # allow the classifier to return None, or [], or ["foo"] 
    465464                if isinstance(c, str):