Proposal: change Router and Worker to specify the "self address" #1449
hairyhum
started this conversation in
General & Learning
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context:
Currently
Ockam.Worker.handle_message/2
receives a message which was routed viaOckam.Router.route/1
and expects a first address in theonward_route
to be a "self address", while it also has this address in the worker state.This is an implicit assumption, which might not hold true. That makes message forwarding harder as the worker has to check the address and remove it from the
onward_route
on forwarding.Some internal mechanisms like TCP transport do not use the
Ockam.Router.route/1
, but send the message directly to the worker, which means there is no "self address" in this message. This is inconsistent with the other workers.Proposed change:
Change the
Ockam.Worker.handle_message/2
callback to accept 3 arguments:(routed_address, onward_message, state)
whererouted_address
is the first addres in the onward_route, which was used inOckam.Router.route/1
In most cases when the message was routed to the local worker, this
routed_address
will be the same asaddress
in the worker state.The
onward_message
in this case is a message used inOckam.Router.route/1
, but with therouted_address
removed from theonward_route
.This way the worker doesn't have to deconstruct the
onward_route
, doesn't have to assume that the first element there is the same as itsaddress
in the state and may have the knowledge about the address it was accessed by even if it's different from the stateaddress
.When forwarding a message, the worker would use the
onward_message
without modification to theonward_route
and only needs to update thereturn_route
(and maybe the payload)The API for
Ockam.Router.route/1
would stay the same, whileOckam.Node.send/2
would have to accept theonward_message
as the second argument and pass the first argument as therouted_address
to the worker.The downside here is that the message in
handle_message/3
androute/1
would be different. Also the implementation should choose the format for the erlang message to contain the ockamonward_message
and therouted_address
, which might beOckam.Message
, but thenOckam.Worker
would do the job of deconstructing it.Beta Was this translation helpful? Give feedback.
All reactions