@@ -173,8 +173,9 @@ type PubSub struct {
173
173
174
174
// appSpecificRpcInspector is an auxiliary that may be set by the application to inspect incoming RPCs prior to
175
175
// processing them. The inspector is invoked on an accepted RPC right prior to handling it.
176
- // The return value of the inspector function is a boolean indicating whether the RPC should be processed or not.
177
- appSpecificRpcInspector func (peer.ID , * RPC ) bool
176
+ // The return value of the inspector function is an error indicating whether the RPC should be processed or not.
177
+ // If the error is nil, the RPC is processed as usual. If the error is non-nil, the RPC is dropped.
178
+ appSpecificRpcInspector func (peer.ID , * RPC ) error
178
179
}
179
180
180
181
// PubSubRouter is the message router component of PubSub.
@@ -532,7 +533,7 @@ func WithSeenMessagesTTL(ttl time.Duration) Option {
532
533
}
533
534
}
534
535
535
- func WithAppSpecificRpcInspector (inspector func (peer.ID , * RPC ) bool ) Option {
536
+ func WithAppSpecificRpcInspector (inspector func (peer.ID , * RPC ) error ) Option {
536
537
return func (ps * PubSub ) error {
537
538
ps .appSpecificRpcInspector = inspector
538
539
return nil
@@ -1020,7 +1021,8 @@ func (p *PubSub) handleIncomingRPC(rpc *RPC) {
1020
1021
// pass the rpc through app specific validation (if any available).
1021
1022
if p .appSpecificRpcInspector != nil {
1022
1023
// check if the RPC is allowed by the external inspector
1023
- if accept := p .appSpecificRpcInspector (rpc .from , rpc ); ! accept {
1024
+ if err := p .appSpecificRpcInspector (rpc .from , rpc ); err != nil {
1025
+ log .Debugf ("application-specific inspection failed, rejecting incoming rpc: %s" , err )
1024
1026
return // reject the RPC
1025
1027
}
1026
1028
}
0 commit comments