def connection_made(self): self.buffer = "A" * self.conf.get("net.stream.chunk", 32768) MEASURER.register_stream(self) duration = self.conf.get("net.stream.duration", 10) if duration >= 0: POLLER.sched(duration, self._do_close) if self.kind == "discard": self.start_recv() elif self.kind == "chargen": self.start_send(self.buffer) elif self.kind == "echo": self.start_recv() else: self.close()
def main(args): CONFIG.register_descriptions({ "net.stream.certfile": "Set SSL certfile path", "net.stream.ipv6": "Enable IPv6", "net.stream.key": "Set key for ARC4", "net.stream.obfuscate": "Enable scrambling with ARC4", "net.stream.secure": "Enable SSL", "net.stream.server_side": "Enable SSL server-side mode", "net.stream.rcvbuf": "Set sock recv buffer (0 = use default)", "net.stream.sndbuf": "Set sock send buffer (0 = use default)", }) CONFIG.register_descriptions({ "net.stream.address": "Set client or server address", "net.stream.chunk": "Chunk written by each write", "net.stream.clients": "Set number of client connections", "net.stream.daemonize": "Enable daemon behavior", "net.stream.duration": "Set duration of a test", "net.stream.listen": "Enable server mode", "net.stream.port": "Set client or server port", "net.stream.proto": "Set proto (chargen, discard, or echo)", }) common.main("net.stream", "TCP bulk transfer test", args) conf = CONFIG.copy() if not conf["net.stream.address"]: if not conf["net.stream.listen"]: conf["net.stream.address"] = "neubot.blupixel.net" else: conf["net.stream.address"] = "0.0.0.0" if not (conf["net.stream.listen"] and conf["net.stream.daemonize"]): MEASURER.start() endpoint = (conf["net.stream.address"], conf["net.stream.port"]) if not conf["net.stream.proto"]: if conf["net.stream.listen"]: conf["net.stream.proto"] = "chargen" else: conf["net.stream.proto"] = "discard" elif conf["net.stream.proto"] not in ("chargen", "discard", "echo"): common.write_help(sys.stderr, "net.stream", "TCP bulk transfer test") sys.exit(1) handler = GenericHandler(POLLER) handler.configure(conf, MEASURER) if conf["net.stream.listen"]: if conf["net.stream.daemonize"]: system.change_dir() system.go_background() LOG.redirect() system.drop_privileges(LOG.error) conf["net.stream.server_side"] = True handler.listen(endpoint) POLLER.loop() sys.exit(0) handler.connect(endpoint, count=conf["net.stream.clients"]) POLLER.loop() sys.exit(0)