add content-addressed message id utility

This commit is contained in:
Alex Stokes 2020-02-27 12:13:17 -08:00
parent ef666267bd
commit 857cc29d27
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086

View File

@ -1,4 +1,6 @@
import base64
import functools
import hashlib
import logging
import time
from typing import (
@ -52,6 +54,10 @@ def get_peer_and_seqno_msg_id(msg: rpc_pb2.Message) -> bytes:
return msg.seqno + msg.from_id
def get_content_addressed_msg_id(msg: rpc_pb2.Message) -> bytes:
return base64.b64encode(hashlib.sha256(msg.data).digest())
class TopicValidator(NamedTuple):
validator: ValidatorFn
is_async: bool