diff -uNr a/logotron/MANIFEST.TXT b/logotron/MANIFEST.TXT --- a/logotron/MANIFEST.TXT bdf6b32e0e6b692ece0e85d364bd94b8b62c06872bbf7395c436b8a274ce14f61a83b63f1f10425fecb1a99dcb24d31f1efdb9aa2e6e5be44b3317bd34ef762b +++ b/logotron/MANIFEST.TXT 26d2049579dcd28d250b14db6dcdd9c979af1da5a468130bdad63962cbb916172b23bdda6b41411598a4977a62bb9d1c8dc62d8de4d1b24d3e27b324ca9a254e @@ -12,3 +12,4 @@ 596907 sept_fixes asciilifeform "Several small improvements to bot and reader." 597604 active_disconnect bvt "Close current connection before opening a new one. Disable Nagle's algorithm. s/Listen/Receive/." 597688 sept_errata asciilifeform "Fixed coarse mistake in reader.py" +597858 detect_disconnect asciilifeform "Adjustable detector of bot disconnection." diff -uNr a/logotron/README.txt b/logotron/README.txt --- a/logotron/README.txt 1f4326cf8d7a7ac9ccd54da9ccc56b4c5eef008245933a2905a87978aabdb27d438c8bdd2430275ae75c5ce2a4d335df9fbd1f671a69d046b12f7cf2f57b4ae9 +++ b/logotron/README.txt 706c15fc1eb5be1fdad3d80321da88590cdc33518d0ea2c004de17f948b7ad07c190374a3e118c5d254c2731a280b52b4030ad2998808104410a35eab05cd825 @@ -118,3 +118,21 @@ trilema;1937941;1569445079;diana_coman;wb BingoBoingo ! Still needs a variant of 'eater' that will eat these. + +############### +Oct. 4 Update: +############### + +(1) WWW: Removed ill-conceived 'Tape' knob. +(2) Bot: Added silent-disconnection detector. + +Now requires the following value in bot config e.g.: + +[irc] +disc_t = 180 + +This represents the currently-recommended interval: 3 minutes. +If inactivity on the incoming line (incl. pingism) exceeds this interval, +a disconnection is forced. The normal reconnection routine will execute. + +To disable forced disconnects, set disc_t to zero. diff -uNr a/logotron/bot.py b/logotron/bot.py --- a/logotron/bot.py eda2c9e8930f8207a7588763084768f494b4cad89c6cccec07e9c7412ae8ce238a07b970a7f937048b7cae1f5d7d92cf67ed88e9802a7694ce0cb274d9a81dd3 +++ b/logotron/bot.py 80d24124b12055c919f68583a83445477d13680db62960b9ac57a6d7ca066f52973e9fc1bc3f80ecf6b541d0784cfbfa10195792f2a9d786c57143720584f88a @@ -14,7 +14,7 @@ ############################################################################## # Version. If changing this program, always set this to same # as in MANIFEST -Ver = 597604 +Ver = 597858 ############################################################################## @@ -66,6 +66,7 @@ Pass = cfg.get("irc", "pass") Channels = [x.strip() for x in cfg.get("irc", "chans").split(',')] Join_Delay = int(cfg.get("irc", "join_t")) + Discon_TO = int(cfg.get("irc", "disc_t")) Prefix = cfg.get("control", "prefix") # DBism: DB_Name = cfg.get("db", "db_name") @@ -129,6 +130,9 @@ # Used to compute 'uptime' time_last_conn = datetime.now() +# Used to monitor disconnection timeout +time_last_recv = datetime.now() + # Socket will be here: sock = None; @@ -244,6 +248,7 @@ def irc(): global connected global time_last_conn + global time_last_recv global sock # Initialize a socket @@ -274,8 +279,15 @@ while connected: try: data = sock.recv(Buf_Size) + time_last_recv = datetime.now() # Received anything -- reset timer except socket.timeout as e: logging.debug("Receive timed out") + # Determine whether the connection has timed out: + since_recv = (datetime.now() - time_last_recv).seconds + if since_recv > Discon_TO: + logging.info("Exceeded %d seconds of silence " % Discon_TO + + "from server: disconnecting!") + deinit_socket() continue except socket.error as e: logging.warning("Receive socket error, disconnecting.") diff -uNr a/logotron/nsabot.conf b/logotron/nsabot.conf --- a/logotron/nsabot.conf 61c5df75c043b567b3f5fc2150c4d7c1d31b6fd04a356cfc9280728f88d71c739d4a6b425c3edcc1b8be55aa2fd4ba589e8fe9405060299e2e876a5169d1c0d6 +++ b/logotron/nsabot.conf b94d71536f35de90b931ffc0d485ff22d643576548e60a3b4bacb3e6a8e9f463ae4a219d7d71067dd780b83e41d35a9493b18213d3d6c5dca96538e3995ecfbd @@ -19,6 +19,9 @@ # How long to wait for fleanode to ack auth of nick before joining chans join_t = 20 +# Force-disconnect after this many seconds of complete (incl. 0 PINGs) silence +disc_t = 180 + # Verbose barf of irc tx/rx irc_dbg = 0 diff -uNr a/logotron/reader.py b/logotron/reader.py --- a/logotron/reader.py 433cb3b45ebe59d30a4e2c8ce965bb756e34196f1fc14256620d4a9226ef5ad6e3b707e33d40bf6faebecf18178a0e6f982d48d17924585fa103eb9cc99532d4 +++ b/logotron/reader.py 02094c29071dd57d190922d14909d064afdecda6f03288d7f80887f87b189c6cf9f708bc271da3e9e0cb26d1a5345cb93518f3d9edbcacda6ea8a451929bd8e9 @@ -447,49 +447,6 @@ return Response(res, mimetype='text/plain') -# "Tape" is a raw log containing entried from ALL logged chans: -@app.route('/tape') -def tape(): - res = "" - - # Get start and end indices: - idx_start = request.args.get('istart', default = 0, type = int) - idx_end = request.args.get('iend', default = 0, type = int) - - # Malformed bounds? - if idx_start > idx_end: - return Response("EGGOG: Start must precede End!", - mimetype='text/plain') - - # Demanded too many in one burst ? - if (idx_end - idx_start) > Max_Raw_Ln : - return Response("EGGOG: May request Max. of %s Lines !" % Max_Raw_Ln, - mimetype='text/plain') - - # Get the loglines from DB - lines = query_db( - '''select * from loglines where - idx between %s and %s order by idx asc;''', - [idx_start, idx_end], one=False) - - # Retrieve raw lines in Tape format: - for l in lines: - action = "" - speaker = "%s;" % l['speaker'] - if l['self']: - action = "*;" - speaker = "%s " % l['speaker'] - res += "%s;%s;%s;%s%s%s\n" % (l['chan'], - l['idx'], - l['t'].strftime('%s'), - action, - speaker, - l['payload']) - - # Return plain text: - return Response(res, mimetype='text/plain') - - Name_Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-" def sanitize_speaker(s):