feat: generic BIP terminal control (Simulator BIP pill) (v3.6.0)
BIP was only reachable through the SCP81 listener; cards that use TCP for
other purposes (an applet's OPEN CHANNEL, a push trigger without HTTP OTA)
now get a generic control surface, independent of SCP81.
Server:
- /api/bip/control starts a plain BIP session in three modes: sink
(default; a local TcpDumpServer that accepts the card's channels and only
logs conn/sink-rx/conn-close, never answering; port 0 = ephemeral, the
bound port is reported), passthru (dial the OPEN CHANNEL destination, TCP
client only) and redirect (fixed host:port).
- /api/bip/status returns {owner, bip, listener}; /api/bip/log and
/api/bip/log-clear share the BIP event log with /api/scp81/log.
- The session state is shared with the SCP81 listener and only one session
runs at a time: _bip_session_stop() stops whichever control started it
and the control responses report it as `replaced` (both directions,
SCP81 <-> BIP). State renamed _SCP81_MODE/_TARGET/_LISTENER/_LINK_EVENTS
-> _BIP_* plus _BIP_OWNER.
- TcpDumpServer logs conn-close and counts accepted connections; stop()
joins the accept thread so the port is really free on restart.
- The new control endpoints are blocked during test-script runs.
PWA:
- New Simulator pill BIP (after TR Config): mode select with notes,
Host/Port rules, Start/Stop with a "replaced" notice, status line (mode,
bound address, owner, channels), a Channels box and the shared BIP log
(reuses the SCP81 log renderer, now showing `peer`).
- The SCP81 status line marks a session owned by the BIP pill.
Help EN/RU 8.10, docs/api.md, AGENTS; CAT_TP/UDP recorded as not
implemented.
Tests: tests/test_bip.py (9) and frontend/tests/bip.test.js (6).
600 frontend / 482 Python green; version 3.6.0; sw simple-v273.
This commit is contained in:
@@ -423,6 +423,7 @@ class TcpDumpServer:
|
||||
self.on_log = on_log
|
||||
self.stopped = False
|
||||
self.conns = []
|
||||
self.accepted = 0
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.sock.bind((host, int(port)))
|
||||
@@ -443,11 +444,13 @@ class TcpDumpServer:
|
||||
except OSError:
|
||||
break
|
||||
self.conns.append(conn)
|
||||
self.accepted += 1
|
||||
if self.on_log:
|
||||
self.on_log('conn', peer='%s:%d' % addr[:2])
|
||||
threading.Thread(target=self._conn_loop, args=(conn, addr), daemon=True).start()
|
||||
|
||||
def _conn_loop(self, conn, addr):
|
||||
total = 0
|
||||
try:
|
||||
while not self.stopped:
|
||||
conn.settimeout(0.2)
|
||||
@@ -459,9 +462,12 @@ class TcpDumpServer:
|
||||
break
|
||||
if not data:
|
||||
break
|
||||
total += len(data)
|
||||
if self.on_rx:
|
||||
self.on_rx('%s:%d' % addr[:2], data)
|
||||
finally:
|
||||
if self.on_log:
|
||||
self.on_log('conn-close', peer='%s:%d' % addr[:2], bytes=total)
|
||||
try:
|
||||
conn.close()
|
||||
except OSError:
|
||||
@@ -481,3 +487,11 @@ class TcpDumpServer:
|
||||
except OSError:
|
||||
pass
|
||||
self.conns = []
|
||||
# Wait for the accept loop to leave accept(): a thread blocked in
|
||||
# accept() keeps the listening socket alive for up to its poll
|
||||
# timeout, so the port must be released before stop() returns
|
||||
# (restarting a listener on the same port must not race).
|
||||
try:
|
||||
self.thread.join(timeout=2)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user