mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-02-13 18:33:22 +00:00
* move constants & core's func to @waku/utils * setup @waku/relay * use @waku/relay for create * address: principal review * fix: size-limit * move all constants to @waku/core * move TopicOnlyDecoder to relay * merge: master * fix: tests * Move constants out of core (#1340) * update package.lock * change constants folder into a ts file * use dependency version as * instead of version number * add constants import from @waku/core * add empty changelog file for relay --------- Co-authored-by: fryorcraken.eth <110212804+fryorcraken@users.noreply.github.com>
36 lines
1019 B
TypeScript
36 lines
1019 B
TypeScript
import type { PeerId } from "@libp2p/interface-peer-id";
|
|
import type { Message } from "@libp2p/interface-pubsub";
|
|
import { TopicValidatorResult } from "@libp2p/interface-pubsub";
|
|
import { proto_message as proto } from "@waku/proto";
|
|
import debug from "debug";
|
|
|
|
const log = debug("waku:relay");
|
|
|
|
export function messageValidator(
|
|
peer: PeerId,
|
|
message: Message
|
|
): TopicValidatorResult {
|
|
const startTime = performance.now();
|
|
log(`validating message from ${peer} received on ${message.topic}`);
|
|
let result = TopicValidatorResult.Accept;
|
|
|
|
try {
|
|
const protoMessage = proto.WakuMessage.decode(message.data);
|
|
|
|
if (
|
|
!protoMessage.contentTopic ||
|
|
!protoMessage.contentTopic.length ||
|
|
!protoMessage.payload ||
|
|
!protoMessage.payload.length
|
|
) {
|
|
result = TopicValidatorResult.Reject;
|
|
}
|
|
} catch (e) {
|
|
result = TopicValidatorResult.Reject;
|
|
}
|
|
|
|
const endTime = performance.now();
|
|
log(`Validation time (must be <100ms): ${endTime - startTime}ms`);
|
|
return result;
|
|
}
|