Skip to content

Commit 2ee0e07

Browse files
committed
core: MitogenProtocol.is_privileged was not set in children
Follow the previous unidirectional routing fix, now errors are occurring where they should not.
1 parent 83a86a2 commit 2ee0e07

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

mitogen/core.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,18 +1937,28 @@ class MitogenProtocol(Protocol):
19371937
:class:`Protocol` implementing mitogen's :ref:`stream protocol
19381938
<stream-protocol>`.
19391939
"""
1940-
#: If not :data:`None`, :class:`Router` stamps this into
1941-
#: :attr:`Message.auth_id` of every message received on this stream.
1942-
auth_id = None
1943-
19441940
#: If not :data:`False`, indicates the stream has :attr:`auth_id` set and
19451941
#: its value is the same as :data:`mitogen.context_id` or appears in
19461942
#: :data:`mitogen.parent_ids`.
19471943
is_privileged = False
19481944

1949-
def __init__(self, router, remote_id):
1945+
def __init__(self, router, remote_id, auth_id=None,
1946+
local_id=None, parent_ids=None):
19501947
self._router = router
19511948
self.remote_id = remote_id
1949+
#: If not :data:`None`, :class:`Router` stamps this into
1950+
#: :attr:`Message.auth_id` of every message received on this stream.
1951+
self.auth_id = auth_id
1952+
1953+
if parent_ids is None:
1954+
parent_ids = mitogen.parent_ids
1955+
if local_id is None:
1956+
local_id = mitogen.context_id
1957+
1958+
self.is_privileged = (
1959+
(remote_id in parent_ids) or
1960+
auth_id in ([local_id] + parent_ids)
1961+
)
19521962
self.sent_modules = set(['mitogen', 'mitogen.core'])
19531963
self._input_buf = collections.deque()
19541964
self._input_buf_len = 0
@@ -2800,8 +2810,8 @@ class Router(object):
28002810
broker_exit_msg = 'Broker has exitted'
28012811
no_route_msg = 'no route to %r, my ID is %r'
28022812
unidirectional_msg = (
2803-
'routing mode prevents forward of message from context %d via '
2804-
'context %d'
2813+
'routing mode prevents forward of message from context %d to '
2814+
'context %d via context %d'
28052815
)
28062816

28072817
def __init__(self, broker):
@@ -3152,7 +3162,9 @@ def _async_route(self, msg, in_stream=None):
31523162
(in_stream.protocol.is_privileged or
31533163
out_stream.protocol.is_privileged):
31543164
self._maybe_send_dead(msg, self.unidirectional_msg,
3155-
in_stream.protocol.remote_id, out_stream.protocol.remote_id)
3165+
in_stream.protocol.remote_id,
3166+
out_stream.protocol.remote_id,
3167+
mitogen.context_id)
31563168
return
31573169

31583170
out_stream.protocol._send(msg)
@@ -3641,7 +3653,12 @@ def _setup_master(self):
36413653
os.close(in_fd)
36423654

36433655
out_fp = os.fdopen(os.dup(self.config.get('out_fd', 1)), 'wb', 0)
3644-
self.stream = MitogenProtocol.build_stream(self.router, parent_id)
3656+
self.stream = MitogenProtocol.build_stream(
3657+
self.router,
3658+
parent_id,
3659+
local_id=self.config['context_id'],
3660+
parent_ids=self.config['parent_ids']
3661+
)
36453662
self.stream.accept(in_fp, out_fp)
36463663
self.stream.name = 'parent'
36473664
self.stream.receive_side.keep_alive = False

mitogen/unix.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,9 @@ def on_accept_client(self, sock):
162162
stream = mitogen.core.MitogenProtocol.build_stream(
163163
router=self._router,
164164
remote_id=context_id,
165+
auth_id=mitogen.context_id,
165166
)
166167
stream.name = u'unix_client.%d' % (pid,)
167-
stream.protocol.auth_id = mitogen.context_id
168-
stream.protocol.is_privileged = True
169168
stream.accept(sock, sock)
170169
LOG.debug('listener: accepted connection from PID %d: %s',
171170
pid, stream.name)

0 commit comments

Comments
 (0)