Do I need multiple protocols or can I do with the same, for 2 near-identical functions

I am very new to libp2p. Great project.

I am going to send two different message types over the wire to libp2p nodes. Their handling is basically exactly the same - however, their content is different, so the handler will have to unpack into different types.

Does this require a new protocol, and therefore an independent handler? Or can I do this with the same handler (how would the handler in this case evaluate which type it is receiving and therefore be able correctly unpack)?

Happy to provide some code if the description is unclear, but I thought this could be answered conceptually only.

:wave:

Whether to use two or one handler is a matter of taste, or matter of how distinct the two protocols are. I don’t see any performance or other hard technical considerations.

From the limited knowledge I have of your use-case, I would start with two handlers.

1 Like

Thank you, appreciate your suggestion. I am thinking it’s best indeed.