2021-11-18 18:40:19 +00:00
|
|
|
#!/usr/bin/env python
|
2017-09-15 06:24:41 +00:00
|
|
|
"""
|
|
|
|
Print the size of a typical SSH command line and the bootstrap code sent to new
|
|
|
|
contexts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import inspect
|
2018-08-18 13:17:41 +00:00
|
|
|
import sys
|
2017-09-15 06:24:41 +00:00
|
|
|
import zlib
|
|
|
|
|
2017-09-21 11:38:57 +00:00
|
|
|
import mitogen.fakessh
|
2019-02-10 22:38:26 +00:00
|
|
|
import mitogen.fork
|
2017-09-15 06:24:41 +00:00
|
|
|
import mitogen.master
|
2018-05-29 12:00:29 +00:00
|
|
|
import mitogen.minify
|
2018-02-12 10:02:59 +00:00
|
|
|
import mitogen.parent
|
2018-05-29 17:14:29 +00:00
|
|
|
import mitogen.select
|
2018-04-24 21:41:47 +00:00
|
|
|
import mitogen.service
|
2017-09-15 06:24:41 +00:00
|
|
|
import mitogen.ssh
|
|
|
|
import mitogen.sudo
|
|
|
|
|
2018-02-16 01:56:47 +00:00
|
|
|
router = mitogen.master.Router()
|
2018-03-24 13:09:59 +00:00
|
|
|
context = mitogen.parent.Context(router, 0)
|
Refactor Stream, introduce quasi-asynchronous connect, much more
Split Stream into many, many classes
* mitogen.parent.Connection: Handles connection setup logic only.
* Maintain references to stdout and stderr streams.
* Manages TimerList timer to cancel connection attempt after
deadline
* Blocking setup code replaced by async equivalents running on the
broker
* mitogen.parent.Options: Tracks connection-specific options. This
keeps the connection class small, but more importantly, it is
generic to the future desire to build and execute command lines
without starting a full connection.
* mitogen.core.Protocol: Handles program behaviour relating to events
on a stream. Protocol performs no IO of its own, instead deferring
it to Stream and Side. This makes testing much easier, and means
libssh can reimplement Stream and Side to reuse MitogenProtocol
* mitogen.core.MitogenProtocol: Guts of the old Mitogen stream
implementtion
* mitogen.core.BufferedWriter: Guts of the old Mitogen buffered
transmit implementation, made generic
* mitogen.core.DelineatedProtocol: Guts of the old IoLogger, knows how
to split up input and pass it on to a
on_line_received()/on_partial_line_received() callback.
* mitogen.parent.BootstrapProtocol: Asynchronous equivalent of the old
blocking connect code. Waits for various prompts (MITO001 etc) and
writes the bootstrap using a BufferedWriter. On success, switches
the stream to MitogenProtocol.
* mitogen.core.Message: move encoding parts of MitogenProtocol out to
Message (where it belongs) and write a bunch of new tests for
pickling.
* The bizarre Stream.construct() is gone now, Option.__init__ is its
own constructor. Should fix many LGTM errors.
* Update all connection methods: Every connection method is updated to
use async logic, defining protocols as required to handle interactive
prompts like in SSH or su. Add new real integration tests for at least
doas and su.
* Eliminate manual fd management: File descriptors are trapped in file
objects at their point of origin, and Side is updated to use file
objects rather than raw descriptors. This eliminates a whole class of
bugs where unrelated FDs could be closed by the wrong component. Now
an FD's open/closed status is fused to it everywhere in the library.
* Halve file descriptor usage: now FD open/close state is tracked by
its file object, we don't need to duplicate FDs everywhere so that
receive/transmit side can be closed independently. Instead both sides
back on to the same file object. Closes #26, Closes #470.
* Remove most uses of dup/dup2: Closes #256. File descriptors are
trapped in a common file object and shared among classes. The
remaining few uses for dup/dup2 are as close to minimal as possible.
* Introduce mitogen.parent.Process: uniform interface for subprocesses
created either via mitogen.fork or the subprocess module. Remove all
the crap where we steal a pid from subprocess guts. Now we use
subprocess to manage its processes as it should be. Closes #169 by
using the new Timers facility to poll for a slow-to-exit subprocess.
* Fix su password race: Closes #363. DelineatedProtocol naturally
retries partially received lines, preventing the cause of the original
race.
* Delete old blocking IO utility functions
iter_read()/write_all()/discard_until().
Closes #26
Closes #147
Closes #169
Closes #256
Closes #363
Closes #419
Closes #470
2019-03-12 01:15:27 +00:00
|
|
|
options = mitogen.ssh.Options(max_message_size=0, hostname='foo')
|
|
|
|
conn = mitogen.ssh.Connection(options, router)
|
2019-07-28 10:20:39 +00:00
|
|
|
conn.context = context
|
2017-09-15 06:24:41 +00:00
|
|
|
|
Refactor Stream, introduce quasi-asynchronous connect, much more
Split Stream into many, many classes
* mitogen.parent.Connection: Handles connection setup logic only.
* Maintain references to stdout and stderr streams.
* Manages TimerList timer to cancel connection attempt after
deadline
* Blocking setup code replaced by async equivalents running on the
broker
* mitogen.parent.Options: Tracks connection-specific options. This
keeps the connection class small, but more importantly, it is
generic to the future desire to build and execute command lines
without starting a full connection.
* mitogen.core.Protocol: Handles program behaviour relating to events
on a stream. Protocol performs no IO of its own, instead deferring
it to Stream and Side. This makes testing much easier, and means
libssh can reimplement Stream and Side to reuse MitogenProtocol
* mitogen.core.MitogenProtocol: Guts of the old Mitogen stream
implementtion
* mitogen.core.BufferedWriter: Guts of the old Mitogen buffered
transmit implementation, made generic
* mitogen.core.DelineatedProtocol: Guts of the old IoLogger, knows how
to split up input and pass it on to a
on_line_received()/on_partial_line_received() callback.
* mitogen.parent.BootstrapProtocol: Asynchronous equivalent of the old
blocking connect code. Waits for various prompts (MITO001 etc) and
writes the bootstrap using a BufferedWriter. On success, switches
the stream to MitogenProtocol.
* mitogen.core.Message: move encoding parts of MitogenProtocol out to
Message (where it belongs) and write a bunch of new tests for
pickling.
* The bizarre Stream.construct() is gone now, Option.__init__ is its
own constructor. Should fix many LGTM errors.
* Update all connection methods: Every connection method is updated to
use async logic, defining protocols as required to handle interactive
prompts like in SSH or su. Add new real integration tests for at least
doas and su.
* Eliminate manual fd management: File descriptors are trapped in file
objects at their point of origin, and Side is updated to use file
objects rather than raw descriptors. This eliminates a whole class of
bugs where unrelated FDs could be closed by the wrong component. Now
an FD's open/closed status is fused to it everywhere in the library.
* Halve file descriptor usage: now FD open/close state is tracked by
its file object, we don't need to duplicate FDs everywhere so that
receive/transmit side can be closed independently. Instead both sides
back on to the same file object. Closes #26, Closes #470.
* Remove most uses of dup/dup2: Closes #256. File descriptors are
trapped in a common file object and shared among classes. The
remaining few uses for dup/dup2 are as close to minimal as possible.
* Introduce mitogen.parent.Process: uniform interface for subprocesses
created either via mitogen.fork or the subprocess module. Remove all
the crap where we steal a pid from subprocess guts. Now we use
subprocess to manage its processes as it should be. Closes #169 by
using the new Timers facility to poll for a slow-to-exit subprocess.
* Fix su password race: Closes #363. DelineatedProtocol naturally
retries partially received lines, preventing the cause of the original
race.
* Delete old blocking IO utility functions
iter_read()/write_all()/discard_until().
Closes #26
Closes #147
Closes #169
Closes #256
Closes #363
Closes #419
Closes #470
2019-03-12 01:15:27 +00:00
|
|
|
print('SSH command size: %s' % (len(' '.join(conn.get_boot_command())),))
|
2019-08-10 13:52:24 +00:00
|
|
|
print('Bootstrap (mitogen.core) size: %s (%.2fKiB)' % (
|
Refactor Stream, introduce quasi-asynchronous connect, much more
Split Stream into many, many classes
* mitogen.parent.Connection: Handles connection setup logic only.
* Maintain references to stdout and stderr streams.
* Manages TimerList timer to cancel connection attempt after
deadline
* Blocking setup code replaced by async equivalents running on the
broker
* mitogen.parent.Options: Tracks connection-specific options. This
keeps the connection class small, but more importantly, it is
generic to the future desire to build and execute command lines
without starting a full connection.
* mitogen.core.Protocol: Handles program behaviour relating to events
on a stream. Protocol performs no IO of its own, instead deferring
it to Stream and Side. This makes testing much easier, and means
libssh can reimplement Stream and Side to reuse MitogenProtocol
* mitogen.core.MitogenProtocol: Guts of the old Mitogen stream
implementtion
* mitogen.core.BufferedWriter: Guts of the old Mitogen buffered
transmit implementation, made generic
* mitogen.core.DelineatedProtocol: Guts of the old IoLogger, knows how
to split up input and pass it on to a
on_line_received()/on_partial_line_received() callback.
* mitogen.parent.BootstrapProtocol: Asynchronous equivalent of the old
blocking connect code. Waits for various prompts (MITO001 etc) and
writes the bootstrap using a BufferedWriter. On success, switches
the stream to MitogenProtocol.
* mitogen.core.Message: move encoding parts of MitogenProtocol out to
Message (where it belongs) and write a bunch of new tests for
pickling.
* The bizarre Stream.construct() is gone now, Option.__init__ is its
own constructor. Should fix many LGTM errors.
* Update all connection methods: Every connection method is updated to
use async logic, defining protocols as required to handle interactive
prompts like in SSH or su. Add new real integration tests for at least
doas and su.
* Eliminate manual fd management: File descriptors are trapped in file
objects at their point of origin, and Side is updated to use file
objects rather than raw descriptors. This eliminates a whole class of
bugs where unrelated FDs could be closed by the wrong component. Now
an FD's open/closed status is fused to it everywhere in the library.
* Halve file descriptor usage: now FD open/close state is tracked by
its file object, we don't need to duplicate FDs everywhere so that
receive/transmit side can be closed independently. Instead both sides
back on to the same file object. Closes #26, Closes #470.
* Remove most uses of dup/dup2: Closes #256. File descriptors are
trapped in a common file object and shared among classes. The
remaining few uses for dup/dup2 are as close to minimal as possible.
* Introduce mitogen.parent.Process: uniform interface for subprocesses
created either via mitogen.fork or the subprocess module. Remove all
the crap where we steal a pid from subprocess guts. Now we use
subprocess to manage its processes as it should be. Closes #169 by
using the new Timers facility to poll for a slow-to-exit subprocess.
* Fix su password race: Closes #363. DelineatedProtocol naturally
retries partially received lines, preventing the cause of the original
race.
* Delete old blocking IO utility functions
iter_read()/write_all()/discard_until().
Closes #26
Closes #147
Closes #169
Closes #256
Closes #363
Closes #419
Closes #470
2019-03-12 01:15:27 +00:00
|
|
|
len(conn.get_preamble()),
|
|
|
|
len(conn.get_preamble()) / 1024.0,
|
2018-04-17 16:40:45 +00:00
|
|
|
))
|
2019-08-10 13:52:24 +00:00
|
|
|
print('')
|
|
|
|
|
2018-08-18 13:17:41 +00:00
|
|
|
if '--dump' in sys.argv:
|
Refactor Stream, introduce quasi-asynchronous connect, much more
Split Stream into many, many classes
* mitogen.parent.Connection: Handles connection setup logic only.
* Maintain references to stdout and stderr streams.
* Manages TimerList timer to cancel connection attempt after
deadline
* Blocking setup code replaced by async equivalents running on the
broker
* mitogen.parent.Options: Tracks connection-specific options. This
keeps the connection class small, but more importantly, it is
generic to the future desire to build and execute command lines
without starting a full connection.
* mitogen.core.Protocol: Handles program behaviour relating to events
on a stream. Protocol performs no IO of its own, instead deferring
it to Stream and Side. This makes testing much easier, and means
libssh can reimplement Stream and Side to reuse MitogenProtocol
* mitogen.core.MitogenProtocol: Guts of the old Mitogen stream
implementtion
* mitogen.core.BufferedWriter: Guts of the old Mitogen buffered
transmit implementation, made generic
* mitogen.core.DelineatedProtocol: Guts of the old IoLogger, knows how
to split up input and pass it on to a
on_line_received()/on_partial_line_received() callback.
* mitogen.parent.BootstrapProtocol: Asynchronous equivalent of the old
blocking connect code. Waits for various prompts (MITO001 etc) and
writes the bootstrap using a BufferedWriter. On success, switches
the stream to MitogenProtocol.
* mitogen.core.Message: move encoding parts of MitogenProtocol out to
Message (where it belongs) and write a bunch of new tests for
pickling.
* The bizarre Stream.construct() is gone now, Option.__init__ is its
own constructor. Should fix many LGTM errors.
* Update all connection methods: Every connection method is updated to
use async logic, defining protocols as required to handle interactive
prompts like in SSH or su. Add new real integration tests for at least
doas and su.
* Eliminate manual fd management: File descriptors are trapped in file
objects at their point of origin, and Side is updated to use file
objects rather than raw descriptors. This eliminates a whole class of
bugs where unrelated FDs could be closed by the wrong component. Now
an FD's open/closed status is fused to it everywhere in the library.
* Halve file descriptor usage: now FD open/close state is tracked by
its file object, we don't need to duplicate FDs everywhere so that
receive/transmit side can be closed independently. Instead both sides
back on to the same file object. Closes #26, Closes #470.
* Remove most uses of dup/dup2: Closes #256. File descriptors are
trapped in a common file object and shared among classes. The
remaining few uses for dup/dup2 are as close to minimal as possible.
* Introduce mitogen.parent.Process: uniform interface for subprocesses
created either via mitogen.fork or the subprocess module. Remove all
the crap where we steal a pid from subprocess guts. Now we use
subprocess to manage its processes as it should be. Closes #169 by
using the new Timers facility to poll for a slow-to-exit subprocess.
* Fix su password race: Closes #363. DelineatedProtocol naturally
retries partially received lines, preventing the cause of the original
race.
* Delete old blocking IO utility functions
iter_read()/write_all()/discard_until().
Closes #26
Closes #147
Closes #169
Closes #256
Closes #363
Closes #419
Closes #470
2019-03-12 01:15:27 +00:00
|
|
|
print(zlib.decompress(conn.get_preamble()))
|
2018-08-18 13:17:41 +00:00
|
|
|
exit()
|
|
|
|
|
2017-09-15 06:24:41 +00:00
|
|
|
|
2018-03-30 10:05:03 +00:00
|
|
|
print(
|
2019-02-10 14:13:22 +00:00
|
|
|
' '
|
2018-03-30 10:05:03 +00:00
|
|
|
' '
|
|
|
|
' Original '
|
|
|
|
' '
|
|
|
|
' Minimized '
|
|
|
|
' '
|
|
|
|
' Compressed '
|
|
|
|
)
|
|
|
|
|
2017-09-15 06:24:41 +00:00
|
|
|
for mod in (
|
2018-02-12 10:02:59 +00:00
|
|
|
mitogen.parent,
|
2019-02-10 14:13:22 +00:00
|
|
|
mitogen.fork,
|
2017-09-15 06:24:41 +00:00
|
|
|
mitogen.ssh,
|
|
|
|
mitogen.sudo,
|
2018-05-29 17:14:29 +00:00
|
|
|
mitogen.select,
|
2018-05-29 12:00:29 +00:00
|
|
|
mitogen.service,
|
2017-09-21 11:38:57 +00:00
|
|
|
mitogen.fakessh,
|
2018-05-29 12:00:29 +00:00
|
|
|
mitogen.master,
|
2018-03-30 10:05:03 +00:00
|
|
|
):
|
|
|
|
original = inspect.getsource(mod)
|
|
|
|
original_size = len(original)
|
2018-05-29 12:00:29 +00:00
|
|
|
minimized = mitogen.minify.minimize_source(original)
|
2018-03-30 10:05:03 +00:00
|
|
|
minimized_size = len(minimized)
|
2019-08-10 16:20:46 +00:00
|
|
|
compressed = zlib.compress(minimized.encode(), 9)
|
2018-03-30 10:05:03 +00:00
|
|
|
compressed_size = len(compressed)
|
|
|
|
print(
|
2019-02-10 14:13:22 +00:00
|
|
|
'%-25s'
|
2018-03-30 10:05:03 +00:00
|
|
|
' '
|
|
|
|
'%5i %4.1fKiB'
|
|
|
|
' '
|
|
|
|
'%5i %4.1fKiB %.1f%%'
|
|
|
|
' '
|
|
|
|
'%5i %4.1fKiB %.1f%%'
|
|
|
|
% (
|
|
|
|
mod.__name__,
|
|
|
|
original_size,
|
|
|
|
original_size / 1024.0,
|
|
|
|
minimized_size,
|
|
|
|
minimized_size / 1024.0,
|
|
|
|
100 * minimized_size / float(original_size),
|
|
|
|
compressed_size,
|
|
|
|
compressed_size / 1024.0,
|
|
|
|
100 * compressed_size / float(original_size),
|
|
|
|
))
|