mirror of
				https://github.com/PurpleI2P/i2pd-tools.git
				synced 2025-11-04 08:30:47 +00:00 
			
		
		
		
	update logic
This commit is contained in:
		
							parent
							
								
									d0e76fa6eb
								
							
						
					
					
						commit
						fb77e988e5
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -7,7 +7,7 @@ class Filter:
 | 
			
		|||
    
 | 
			
		||||
    def process(self, info):
 | 
			
		||||
        """
 | 
			
		||||
        process an info and return True if it should be added to blocklist
 | 
			
		||||
        process an info and return a string representation of a reason to add to blocklist
 | 
			
		||||
        any other return value will cause this info to NOT be added to blocklist
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -22,11 +22,12 @@ class FloodfillFilter(Filter):
 | 
			
		|||
    def process(self, info):
 | 
			
		||||
        caps = util.getcaps(info)
 | 
			
		||||
        if not caps:
 | 
			
		||||
            return False
 | 
			
		||||
            return 
 | 
			
		||||
        if b'f' not in caps:
 | 
			
		||||
            return False
 | 
			
		||||
            return 
 | 
			
		||||
        h = util.getaddress(info)
 | 
			
		||||
        if h not in self._floodfills:
 | 
			
		||||
            self._floodfills[h] = 0
 | 
			
		||||
        self._floodfills[h] += 1
 | 
			
		||||
        return self._floodfills[h] > self.fmax
 | 
			
		||||
        if self._floodfills[h] > self.fmax:
 | 
			
		||||
            return '{} > {} floodfills per ip'.format(self._floodfills[h], self.fmax)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,8 +12,9 @@ class BaddieProcessor:
 | 
			
		|||
    def hook(self, entry):
 | 
			
		||||
        now = datetime.datetime.now()
 | 
			
		||||
        for f in self._filters:
 | 
			
		||||
            if f.process(entry) is True:
 | 
			
		||||
                self.add_baddie(entry, 'detected by {} on {}'.format(f.name, now.strftime("%c").replace(":",'-')))
 | 
			
		||||
            reason = f.process(entry)
 | 
			
		||||
            if reason is not None:
 | 
			
		||||
                self.add_baddie(entry, 'detected by {} on {} ({})'.format(f.name, now.strftime("%c").replace(":",'-'), reason))
 | 
			
		||||
 | 
			
		||||
    def add_baddie(self, entry, reason):
 | 
			
		||||
        addr = util.getaddress(entry).decode('ascii')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue