05nelsonm / kmp-tor

Kotlin Multiplatform Library for embedding Tor into your applications
Apache License 2.0
33 stars 5 forks source link

Add `RuntimeEvent.LISTENERS` #398

Closed 05nelsonm closed 4 months ago

05nelsonm commented 4 months ago

Event observers should be notified of listener addresses opened by tor

05nelsonm commented 4 months ago

Getting the unix listeners to work properly is challenging b/c the notice for closure is ???:0 so unsure which one it is that is closing... There are 4 scenarios which tor will react differently to, all of which need to be accounted for to appropriately remove/add the appropriate listeners.

Scenario 1 ``` // ### CONF_CHANGED while Network.Enabled //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:40.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:40.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:40.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:40.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorState[fid=6E96…6985, daemon=On{0%}, network=Enabled] //DisableNetwork=0 //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:41.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:41.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock" OnionTrafficOnly GroupWritable //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock" //TorProcess[fid=6E96…6985]@554336724 May 25 09:25:41.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorState[fid=6E96…6985, daemon=On{5%}, network=Enabled] ```
Scenario 2 ``` // ### CONF_CHANGED while Network.Disabled //TorState[fid=6E96…6985, daemon=On{10%}, network=Enabled] //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:07.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:07.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:07.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:07.000 [notice] DisableNetwork is set. Tor will not make or accept non-control network connections. Shutting down all existing connections. //TorState[fid=6E96…6985, daemon=On{10%}, network=Disabled] //DisableNetwork=1 //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:08.000 [notice] DisableNetwork is set. Tor will not make or accept non-control network connections. Shutting down all existing connections. //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock" OnionTrafficOnly GroupWritable //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock" //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:08.000 [notice] Delaying directory fetches: DisableNetwork is set. //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:09.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:09.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:09.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorProcess[fid=6E96…6985]@1381828853 May 25 09:36:09.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorState[fid=6E96…6985, daemon=On{10%}, network=Enabled] ```
Scenario 3 ``` // ### CONF_CHANGED (with Network.Enabled -> Network.Disabled change) while Network.Enabled //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorState[fid=6E96…6985, daemon=On{0%}, network=Enabled] //DisableNetwork=0 //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:13.000 [notice] DisableNetwork is set. Tor will not make or accept non-control network connections. Shutting down all existing connections. //TorState[fid=6E96…6985, daemon=On{0%}, network=Disabled] //DisableNetwork=1 //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock" OnionTrafficOnly GroupWritable //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock" //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:14.000 [notice] Delaying directory fetches: DisableNetwork is set. //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:14.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:14.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:14.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorProcess[fid=6E96…6985]@2129779619 May 25 09:42:14.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorState[fid=6E96…6985, daemon=On{0%}, network=Enabled] ```
Scenario 2 ``` // ### CONF_CHANGED (with Network.Disabled -> Network.Enabled change) while Network.Disabled //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:24.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:24.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks1.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:24.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:24.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorState[fid=6E96…6985, daemon=On{0%}, network=Enabled] //DisableNetwork=0 //TorState[fid=6E96…6985, daemon=On{5%}, network=Enabled] //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:25.000 [notice] Bootstrapped 5% (conn): Connecting to a relay //TorState[fid=6E96…6985, daemon=On{10%}, network=Enabled] //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:25.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:25.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:25.000 [notice] Closing no-longer-configured Socks listener on ???:0 //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:25.000 [notice] DisableNetwork is set. Tor will not make or accept non-control network connections. Shutting down all existing connections. //TorState[fid=6E96…6985, daemon=On{10%}, network=Disabled] //DisableNetwork=1 //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Opening Socks listener on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Opened Socks listener connection (ready) on /tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock //TorState[fid=6E96…6985, daemon=On{10%}, network=Enabled] //DisableNetwork=0 //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks2.sock" OnionTrafficOnly GroupWritable //__SocksPort=unix:"/tmp/kmp_tor_test/obs_conn_no_net/work/socks3.sock" //TorState[fid=6E96…6985, daemon=On{14%}, network=Enabled] //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay //TorState[fid=6E96…6985, daemon=On{15%}, network=Enabled] //TorProcess[fid=6E96…6985]@1552207275 May 25 11:10:26.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done //TorState[fid=6E96…6985, daemon=On{75%}, network=Enabled] ```
05nelsonm commented 4 months ago

Also, if only unix sockets are open and a config change occurs whereby only a TCP port is expressed, all unix socket listeners are closed. The config change needs to also include ports, (not just unix paths) in order to trigger closures.