Skip to content

Commit

Permalink
De-ISS-ize RequestReceiver
Browse files Browse the repository at this point in the history
Remove hardcoded dependencies of RequestReceiver on ISS.
  • Loading branch information
xosmig committed Jul 25, 2022
1 parent 2047aaf commit fd287d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/deploytest/testreplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (tr *TestReplica) Run(ctx context.Context) error {
}

// Create a RequestReceiver for request coming over the network.
requestReceiver := requestreceiver.NewRequestReceiver(node, logging.Decorate(tr.Config.Logger, "ReqRec: "))
requestReceiver := requestreceiver.NewRequestReceiver(node, "iss", logging.Decorate(tr.Config.Logger, "ReqRec: "))
p, err := strconv.Atoi(tr.ID.Pb())
if err != nil {
return fmt.Errorf("error converting node ID %s: %w", tr.ID, err)
Expand Down
13 changes: 9 additions & 4 deletions pkg/requestreceiver/requestreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/mir/pkg/events"
"github.com/filecoin-project/mir/pkg/logging"
"github.com/filecoin-project/mir/pkg/pb/requestpb"
t "github.com/filecoin-project/mir/pkg/types"
)

type RequestReceiver struct {
Expand All @@ -27,6 +28,9 @@ type RequestReceiver struct {
// The Node to which to submit the received requests.
node *mir.Node

// The ID of the module to which to submit the received requests.
moduleID t.ModuleID

// The gRPC server used by this networking module.
grpcServer *grpc.Server

Expand All @@ -45,15 +49,16 @@ type RequestReceiver struct {
// The returned RequestReceiver is not yet running (able to receive requests).
// This needs to be done explicitly by calling the Start() method.
// For the requests to be processed by passed Node, the Node must also be running.
func NewRequestReceiver(node *mir.Node, logger logging.Logger) *RequestReceiver {
func NewRequestReceiver(node *mir.Node, moduleID t.ModuleID, logger logging.Logger) *RequestReceiver {
// If no logger was given, only write errors to the console.
if logger == nil {
logger = logging.ConsoleErrorLogger
}

return &RequestReceiver{
node: node,
logger: logger,
node: node,
moduleID: moduleID,
logger: logger,
}
}

Expand Down Expand Up @@ -83,7 +88,7 @@ func (rr *RequestReceiver) Listen(srv RequestReceiver_ListenServer) error {

// Submit the request to the Node.
if srErr := rr.node.InjectEvents(srv.Context(), events.ListOf(events.NewClientRequests(
"iss",
rr.moduleID,
[]*requestpb.Request{req},
))); srErr != nil {

Expand Down
2 changes: 1 addition & 1 deletion samples/chat-demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func run() error {
// Create a request receiver and start receiving requests.
// Note that the RequestReceiver is _not_ part of the Node as its module.
// It is external to the Node and only submits requests it receives to the node.
reqReceiver := requestreceiver.NewRequestReceiver(node, logger)
reqReceiver := requestreceiver.NewRequestReceiver(node, "iss", logger)
if err := reqReceiver.Start(reqReceiverBasePort + ownID); err != nil {
return fmt.Errorf("could not start request receiver: %w", err)
}
Expand Down

0 comments on commit fd287d2

Please sign in to comment.