Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Application Specific RPC Inspector #509

Merged
merged 26 commits into from
Dec 1, 2022
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c93e47a
Update go.mod
yhassanzadeh13 Oct 19, 2022
19b4efd
Refactor GossipSub Construction (#1)
yhassanzadeh13 Oct 28, 2022
7c7c05a
decouples options
yhassanzadeh13 Nov 8, 2022
c557ad4
Merge remote-tracking branch 'libp2p/master' into yahya/gossipsub-rou…
yhassanzadeh13 Nov 8, 2022
5f71a48
fixes conflict
yhassanzadeh13 Nov 8, 2022
1c1c946
reverts back module
yhassanzadeh13 Nov 8, 2022
ab8365c
fixes peer score helper
yhassanzadeh13 Nov 8, 2022
5e7a682
Adds send control message to gossipsub router (#2)
yhassanzadeh13 Nov 10, 2022
b897e22
adjusts libp2p version (#3)
yhassanzadeh13 Nov 10, 2022
1c91995
Merge branch 'yahya/gossipsub-router-interface'
yhassanzadeh13 Nov 10, 2022
60457b3
Update go.mod (#4)
yhassanzadeh13 Nov 10, 2022
6f0858c
adds app specific rpc handler
yhassanzadeh13 Nov 24, 2022
3d47fa1
Create ci.yml (#5)
yhassanzadeh13 Nov 24, 2022
a94ddf3
Create Makefile (#7)
yhassanzadeh13 Nov 24, 2022
26f8d34
Revert "Merge branch 'yahya/gossipsub-router-interface'" (#6)
yhassanzadeh13 Nov 24, 2022
2e13ee8
Merge branch 'master' into yahya/adds-rpc-inspector
yhassanzadeh13 Nov 24, 2022
1c99052
Update ci.yml (#9)
yhassanzadeh13 Nov 24, 2022
352d747
Merge branch 'master' into yahya/adds-rpc-inspector
yhassanzadeh13 Nov 24, 2022
40950fe
Revert "Merge branch 'master' into yahya/adds-rpc-inspector"
yhassanzadeh13 Nov 24, 2022
586c5cb
Merge remote-tracking branch 'origin/yahya/adds-rpc-inspector' into y…
yhassanzadeh13 Nov 24, 2022
221ca50
Revert "Merge remote-tracking branch 'origin/yahya/adds-rpc-inspector…
yhassanzadeh13 Nov 24, 2022
653294a
Revert "Merge branch 'master' into yahya/adds-rpc-inspector"
yhassanzadeh13 Nov 24, 2022
37df80c
moves app specific inspector to pubsub
yhassanzadeh13 Nov 25, 2022
7f56708
removes option from gossipsub
yhassanzadeh13 Nov 25, 2022
e23f9ea
moves app specific rpc inspector up
yhassanzadeh13 Nov 25, 2022
776d859
refactors app specific to return an error
yhassanzadeh13 Nov 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ type PubSub struct {
protoMatchFunc ProtocolMatchFn

ctx context.Context

// appSpecificRpcInspector is an auxiliary that may be set by the application to inspect incoming RPCs prior to
// processing them. The inspector is invoked on an accepted RPC right prior to handling it.
// The return value of the inspector function is a boolean indicating whether the RPC should be processed or not.
appSpecificRpcInspector func(peer.ID, *RPC) bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets return a loggable error to provide some context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// PubSubRouter is the message router component of PubSub.
Expand Down Expand Up @@ -527,6 +532,13 @@ func WithSeenMessagesTTL(ttl time.Duration) Option {
}
}

func WithAppSpecificRpcInspector(inspector func(peer.ID, *RPC) bool) Option {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, lets make a type alias for the user inspector fun, returning error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return func(ps *PubSub) error {
ps.appSpecificRpcInspector = inspector
return nil
}
}

// processLoop handles all inputs arriving on the channels
func (p *PubSub) processLoop(ctx context.Context) {
defer func() {
Expand Down Expand Up @@ -1005,6 +1017,14 @@ func (p *PubSub) notifyLeave(topic string, pid peer.ID) {
}

func (p *PubSub) handleIncomingRPC(rpc *RPC) {
// pass the rpc through app specific validation (if any available).
if p.appSpecificRpcInspector != nil {
// check if the RPC is allowed by the external inspector
if accept := p.appSpecificRpcInspector(rpc.from, rpc); !accept {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If err := ....; err != nil {
  Log.Debugf(...)
  return
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return // reject the RPC
}
}

p.tracer.RecvRPC(rpc)

subs := rpc.GetSubscriptions()
Expand Down