本文整理汇总了Python中filter.Filter.tc_del_filter方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.tc_del_filter方法的具体用法?Python Filter.tc_del_filter怎么用?Python Filter.tc_del_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filter.Filter
的用法示例。
在下文中一共展示了Filter.tc_del_filter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TShapper
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import tc_del_filter [as 别名]
#.........这里部分代码省略.........
def update(self):
#cprint("Update", 'white')
if self.USE_SNMP:
updated_devices = self.get_devices_adresses_from_snmp()
else:
updated_devices = self.get_devices_adresses()
for device_mac, ips in updated_devices.items():
self.update_device(device_mac, ips)
self.clean_old_devices()
if len(self.devices) > self.max_devices['Number']:
self.max_devices['Number'] = len(self.devices)
self.max_devices['Time'] = datetime.now()
cprint("Current Clients/Max:"+str(len(self.devices))+"/"+\
str(self.max_devices['Number'])+" at "+\
str(self.max_devices['Time'])+" TokensUsed:"+\
str(self.N_TOKENS - len(self.tokens))+" ActiveFilters:"+\
str(self.active_filters)+self.get_speed(), 'green')
def clean_old_devices(self):
for device_mac, obj in self.devices.items():
if (datetime.now() - obj["last_seen"]).total_seconds() > self.OLD_DEVICES_TIMEOUT:
#obj = self.devices[device_mac]
token = obj["token"]
#Delete Filters
for ip in obj["ips"]:
self.filter.tc_del_filter(token, ip, obj)
self.active_filters -= 2
#Delete Class
self.filter.tc_del_class(token, obj)
del self.devices[device_mac]
self.release_token(token)
def update_device(self, device_mac, ips):
#Add new Device
if device_mac not in self.devices.keys():
obj = { "mac":device_mac,
"token":self.get_token(),
"ips":ips,
"last_seen":datetime.now(),
"prefs": { "lan": dict(), "wan": dict() }
}
self.devices[device_mac] = obj
self.filter.tc_add_device(obj)
for ip in ips:
self.filter.tc_add_filter(obj['token'], ip, obj)
self.active_filters += 2
#Modify Existing Device Rules
else:
old_ips = set(self.devices[device_mac]["ips"])
discovered_ips = set(ips)
ips_to_delete = old_ips - discovered_ips
ips_to_add = discovered_ips - old_ips