Skip to content

Commit

Permalink
chore: Refactor JSONRPCServer and server builder
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Nov 13, 2023
1 parent ac54c24 commit efc2ab5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
19 changes: 3 additions & 16 deletions pkg/relayer/proxy/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ type jsonRPCServer struct {
// service is the service that the server is responsible for.
service *sharedtypes.Service

// serverEndpoint is the advertised endpoint configuration that the server uses to
// listen for incoming relay requests.
serverEndpoint *sharedtypes.SupplierEndpoint

// proxiedServiceEndpoint is the address of the proxied service that the server relays requests to.
proxiedServiceEndpoint url.URL

Expand All @@ -43,22 +39,13 @@ type jsonRPCServer struct {
// a RelayServer that listens to incoming RelayRequests.
func NewJSONRPCServer(
service *sharedtypes.Service,
supplierEndpoint *sharedtypes.SupplierEndpoint,
supplierEndpointHost string,
proxiedServiceEndpoint url.URL,
servedRelaysProducer chan<- *types.Relay,
proxy relayer.RelayerProxy,
) relayer.RelayServer {
// TODO_IN_THIS_COMMIT: refactor / rename / simplify
url, err := url.Parse(supplierEndpoint.Url)
if err != nil {
panic(err)
}
supplierEndpointHost := url.Host

return &jsonRPCServer{
service: service,
serverEndpoint: supplierEndpoint,
// server: &http.Server{Addr: supplierEndpoint.Url},
service: service,
server: &http.Server{Addr: supplierEndpointHost},
relayerProxy: proxy,
proxiedServiceEndpoint: proxiedServiceEndpoint,
Expand Down Expand Up @@ -121,7 +108,7 @@ func (jsrv *jsonRPCServer) ServeHTTP(writer http.ResponseWriter, request *http.R
relay.Res.Meta.SessionHeader.ApplicationAddress,
relay.Res.Meta.SessionHeader.Service.Id,
relay.Res.Meta.SessionHeader.SessionStartBlockHeight,
jsrv.serverEndpoint.Url,
jsrv.server.Addr,
)

// Emit the relay to the servedRelays observable.
Expand Down
9 changes: 8 additions & 1 deletion pkg/relayer/proxy/server_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proxy
import (
"context"
"log"
"net/url"

"github.com/pokt-network/poktroll/pkg/relayer"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
Expand Down Expand Up @@ -42,6 +43,12 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
var serviceEndpoints []relayer.RelayServer

for _, endpoint := range serviceConfig.Endpoints {
url, err := url.Parse(endpoint.Url)
if err != nil {
return err
}
supplierEndpointHost := url.Host

var server relayer.RelayServer

log.Printf(
Expand All @@ -54,7 +61,7 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
case sharedtypes.RPCType_JSON_RPC:
server = NewJSONRPCServer(
service,
endpoint,
supplierEndpointHost,
proxiedServicesEndpoints,
rp.servedRelaysPublishCh,
rp,
Expand Down

0 comments on commit efc2ab5

Please sign in to comment.