Skip to content

Commit

Permalink
Merge pull request #35 from VwCSXg/close-filedescriptors
Browse files Browse the repository at this point in the history
Close files of engine logger
  • Loading branch information
Kkevsterrr authored Jul 29, 2022
2 parents 2fc5b2f + c248c8b commit 3c1c963
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def __enter__(self):

def __exit__(self, exc_type, exc_value, tb):
"""
Allows the engine to be used as a context manager; simply stops the engine
if enabled.
Allows the engine to be used as a context manager
Stops the engine if enabled and closes loggers.
"""
for handler in self.logger.handlers:
handler.close()
if self.enabled:
self.shutdown_nfqueue()

Expand Down Expand Up @@ -443,29 +445,25 @@ def main(args):
"""
Kicks off the engine with the given arguments.
"""
try:
nat_config = {}
if args.get("sender_ip") and args.get("routing_ip") and args.get("forward_ip"):
nat_config = {"sender_ip" : args["sender_ip"],
"routing_ip" : args["routing_ip"],
"forward_ip" : args["forward_ip"]}

eng = Engine(args["server_port"],
args["strategy"],
environment_id=args["environment_id"],
server_side=args["server_side"],
output_directory=args["output_directory"],
forwarder=nat_config,
log_level=args["log"],
in_queue_num=args["in_queue_num"],
out_queue_num=args["out_queue_num"],
save_seen_packets=args["no_save_packets"],
demo_mode=args["demo_mode"])
eng.initialize_nfqueue()
while True:
time.sleep(0.5)
finally:
eng.shutdown_nfqueue()
nat_config = {}
if args.get("sender_ip") and args.get("routing_ip") and args.get("forward_ip"):
nat_config = {"sender_ip": args["sender_ip"],
"routing_ip": args["routing_ip"],
"forward_ip": args["forward_ip"]}

with Engine(args["server_port"],
args["strategy"],
environment_id=args["environment_id"],
server_side=args["server_side"],
output_directory=args["output_directory"],
forwarder=nat_config,
log_level=args["log"],
in_queue_num=args["in_queue_num"],
out_queue_num=args["out_queue_num"],
save_seen_packets=args["no_save_packets"],
demo_mode=args["demo_mode"]):

threading.Event().wait() # Wait forever


if __name__ == "__main__":
Expand Down

0 comments on commit 3c1c963

Please sign in to comment.