@@ -213,9 +213,10 @@ type RouterReady func(rt PubSubRouter, topic string) (bool, error)
213
213
type ProvideKey func () (crypto.PrivKey , peer.ID )
214
214
215
215
type PublishOptions struct {
216
- ready RouterReady
217
- customKey ProvideKey
218
- local bool
216
+ ready RouterReady
217
+ customKey ProvideKey
218
+ local bool
219
+ validatorData any
219
220
}
220
221
221
222
type PubOpt func (pub * PublishOptions ) error
@@ -308,7 +309,7 @@ func (t *Topic) Publish(ctx context.Context, data []byte, opts ...PubOpt) error
308
309
}
309
310
}
310
311
311
- return t .p .val .PushLocal (& Message {m , "" , t .p .host .ID (), nil , pub .local })
312
+ return t .p .val .PushLocal (& Message {m , "" , t .p .host .ID (), pub . validatorData , pub .local })
312
313
}
313
314
314
315
// WithReadiness returns a publishing option for only publishing when the router is ready.
@@ -332,6 +333,15 @@ func WithLocalPublication(local bool) PubOpt {
332
333
}
333
334
}
334
335
336
+ // WithValidatorData returns a publishing option to set custom validator data for the message.
337
+ // This allows users to avoid deserialization of the message data when validating the message locally.
338
+ func WithValidatorData (data any ) PubOpt {
339
+ return func (pub * PublishOptions ) error {
340
+ pub .validatorData = data
341
+ return nil
342
+ }
343
+ }
344
+
335
345
// WithSecretKeyAndPeerId returns a publishing option for providing a custom private key and its corresponding peer ID
336
346
// This option is useful when we want to send messages from "virtual", never-connectable peers in the network
337
347
func WithSecretKeyAndPeerId (key crypto.PrivKey , pid peer.ID ) PubOpt {
0 commit comments