nim-libp2p/libp2p/protocols/pubsub
Eric Mastro 3b718baa97
feat: allow msgIdProvider to fail (#688)
* feat: allow msgIdProvider to fail

Closes: #642.

Changes the return type of the msgIdProvider to `Result[MessageID, string]` so that message id generation can fail.

String error type was chosen as this `msgIdProvider` mainly because the failed message id generation drops the message and logs the error provided. Because `msgIdProvider` can be externally provided by library consumers, an enum didn’t make sense and a object seemed to be overkill. Exceptions could have been used as well, however, in this case, Result ergonomics were warranted and prevented wrapping quite a large block of code in try/except.

The `defaultMsgIdProvider` function previously allowed message id generation to fail silently for use in the tests: when seqno or source peerid were not valid, the message id generated was based on a hash of the message data and topic ids. The silent failing was moved to the `defaultMsgIdProvider` used only in the tests so that it could not fail silently in applications.

Unit tests were added for the `defaultMsgIdProvider`.

* Change MsgIdProvider error type to ValidationResult
2022-02-21 16:04:17 +01:00
..
gossipsub Fixes for style check (#676) 2021-12-16 11:05:20 +01:00
rpc feat: allow msgIdProvider to fail (#688) 2022-02-21 16:04:17 +01:00
errors.nim feat: allow msgIdProvider to fail (#688) 2022-02-21 16:04:17 +01:00
floodsub.nim feat: allow msgIdProvider to fail (#688) 2022-02-21 16:04:17 +01:00
gossipsub.nim feat: allow msgIdProvider to fail (#688) 2022-02-21 16:04:17 +01:00
mcache.nim fix peer score accumulation (#541) 2021-03-09 13:22:52 +01:00
peertable.nim Fixes for style check (#676) 2021-12-16 11:05:20 +01:00
pubsub.nim feat: allow msgIdProvider to fail (#688) 2022-02-21 16:04:17 +01:00
pubsubpeer.nim Fixes for style check (#676) 2021-12-16 11:05:20 +01:00
timedcache.nim adding raises defect across the codebase (#572) 2021-05-21 10:27:01 -06:00