Skip to content

Commit 776d859

Browse files
committed
refactors app specific to return an error
1 parent e23f9ea commit 776d859

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pubsub.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ type PubSub struct {
173173

174174
// appSpecificRpcInspector is an auxiliary that may be set by the application to inspect incoming RPCs prior to
175175
// 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
178179
}
179180

180181
// PubSubRouter is the message router component of PubSub.
@@ -532,7 +533,7 @@ func WithSeenMessagesTTL(ttl time.Duration) Option {
532533
}
533534
}
534535

535-
func WithAppSpecificRpcInspector(inspector func(peer.ID, *RPC) bool) Option {
536+
func WithAppSpecificRpcInspector(inspector func(peer.ID, *RPC) error) Option {
536537
return func(ps *PubSub) error {
537538
ps.appSpecificRpcInspector = inspector
538539
return nil
@@ -1020,7 +1021,8 @@ func (p *PubSub) handleIncomingRPC(rpc *RPC) {
10201021
// pass the rpc through app specific validation (if any available).
10211022
if p.appSpecificRpcInspector != nil {
10221023
// 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)
10241026
return // reject the RPC
10251027
}
10261028
}

0 commit comments

Comments
 (0)