core: MitogenProtocol.is_privileged was not set in children

Follow the previous unidirectional routing fix, now errors are occurring
where they should not.
This commit is contained in:
David Wilson 2019-08-09 17:10:04 +01:00
parent 83a86a2ce1
commit 2ee0e07037
2 changed files with 27 additions and 11 deletions

View File

@ -1937,18 +1937,28 @@ class MitogenProtocol(Protocol):
:class:`Protocol` implementing mitogen's :ref:`stream protocol
<stream-protocol>`.
"""
#: If not :data:`None`, :class:`Router` stamps this into
#: :attr:`Message.auth_id` of every message received on this stream.
auth_id = None
#: If not :data:`False`, indicates the stream has :attr:`auth_id` set and
#: its value is the same as :data:`mitogen.context_id` or appears in
#: :data:`mitogen.parent_ids`.
is_privileged = False
def __init__(self, router, remote_id):
def __init__(self, router, remote_id, auth_id=None,
local_id=None, parent_ids=None):
self._router = router
self.remote_id = remote_id
#: If not :data:`None`, :class:`Router` stamps this into
#: :attr:`Message.auth_id` of every message received on this stream.
self.auth_id = auth_id
if parent_ids is None:
parent_ids = mitogen.parent_ids
if local_id is None:
local_id = mitogen.context_id
self.is_privileged = (
(remote_id in parent_ids) or
auth_id in ([local_id] + parent_ids)
)
self.sent_modules = set(['mitogen', 'mitogen.core'])
self._input_buf = collections.deque()
self._input_buf_len = 0
@ -2800,8 +2810,8 @@ class Router(object):
broker_exit_msg = 'Broker has exitted'
no_route_msg = 'no route to %r, my ID is %r'
unidirectional_msg = (
'routing mode prevents forward of message from context %d via '
'context %d'
'routing mode prevents forward of message from context %d to '
'context %d via context %d'
)
def __init__(self, broker):
@ -3152,7 +3162,9 @@ class Router(object):
(in_stream.protocol.is_privileged or
out_stream.protocol.is_privileged):
self._maybe_send_dead(msg, self.unidirectional_msg,
in_stream.protocol.remote_id, out_stream.protocol.remote_id)
in_stream.protocol.remote_id,
out_stream.protocol.remote_id,
mitogen.context_id)
return
out_stream.protocol._send(msg)
@ -3641,7 +3653,12 @@ class ExternalContext(object):
os.close(in_fd)
out_fp = os.fdopen(os.dup(self.config.get('out_fd', 1)), 'wb', 0)
self.stream = MitogenProtocol.build_stream(self.router, parent_id)
self.stream = MitogenProtocol.build_stream(
self.router,
parent_id,
local_id=self.config['context_id'],
parent_ids=self.config['parent_ids']
)
self.stream.accept(in_fp, out_fp)
self.stream.name = 'parent'
self.stream.receive_side.keep_alive = False

View File

@ -162,10 +162,9 @@ class Listener(mitogen.core.Protocol):
stream = mitogen.core.MitogenProtocol.build_stream(
router=self._router,
remote_id=context_id,
auth_id=mitogen.context_id,
)
stream.name = u'unix_client.%d' % (pid,)
stream.protocol.auth_id = mitogen.context_id
stream.protocol.is_privileged = True
stream.accept(sock, sock)
LOG.debug('listener: accepted connection from PID %d: %s',
pid, stream.name)