From a401f88d26117de5e1857e90ea9c37c7fc6a766f Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Tue, 28 Jun 2022 09:47:49 +0200 Subject: [PATCH] feat: add configuration for graphql server port --- gql/dummy.go | 5 +++-- gql/dummy_test.go | 5 +++-- gql/server.go | 9 ++++----- node/config/def.go | 4 ++++ node/config/doc_gen.go | 14 ++++++++++++++ node/config/types.go | 6 ++++++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gql/dummy.go b/gql/dummy.go index 6fdc6941c..d2b9982b3 100644 --- a/gql/dummy.go +++ b/gql/dummy.go @@ -11,9 +11,10 @@ import ( const DummyDealsDir = "/tmp/dummy" const DummyDealsPrefix = "dummy" -var DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, httpPort) +var DummyDealsBase string -func serveDummyDeals(mux *http.ServeMux) error { +func serveDummyDeals(mux *http.ServeMux, port int) error { + DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, port) dpath := "/" + DummyDealsPrefix + "/" if err := os.MkdirAll(DummyDealsDir, 0755); err != nil { return fmt.Errorf("failed to mk directory %s for dummy deals: %w", DummyDealsDir, err) diff --git a/gql/dummy_test.go b/gql/dummy_test.go index f658a5743..77bbb095f 100644 --- a/gql/dummy_test.go +++ b/gql/dummy_test.go @@ -19,9 +19,10 @@ func TestDummyServer(t *testing.T) { ctx := context.Background() mux := http.NewServeMux() - listenAddr := fmt.Sprintf(":%d", httpPort) + port := 8080 + listenAddr := fmt.Sprintf(":%d", port) t.Logf("server listening on %s\n", listenAddr) - err := serveDummyDeals(mux) + err := serveDummyDeals(mux, port) rq.NoError(err) srv := &http.Server{Addr: listenAddr, Handler: mux} diff --git a/gql/server.go b/gql/server.go index d4242243f..b6114c7ef 100644 --- a/gql/server.go +++ b/gql/server.go @@ -21,8 +21,6 @@ import ( var log = logging.Logger("gql") -const httpPort = 8080 - type Server struct { resolver *resolver srv *http.Server @@ -47,13 +45,14 @@ func (s *Server) Start(ctx context.Context) error { } // Serve dummy deals - err = serveDummyDeals(mux) + port := int(s.resolver.cfg.Graphql.Port) + err = serveDummyDeals(mux, port) if err != nil { return err } // GraphQL handler (GUI for making GraphQL queries) - mux.HandleFunc("/graphiql", graphiql(httpPort)) + mux.HandleFunc("/graphiql", graphiql(port)) // Allow resolving directly to fields (instead of requiring resolvers to // have a method for every GraphQL field) @@ -73,7 +72,7 @@ func (s *Server) Start(ctx context.Context) error { } wsHandler := graphqlws.NewHandlerFunc(schema, queryHandler, wsOpts...) - listenAddr := fmt.Sprintf(":%d", httpPort) + listenAddr := fmt.Sprintf(":%d", port) s.srv = &http.Server{Addr: listenAddr, Handler: mux} fmt.Printf("Graphql server listening on %s\n", listenAddr) mux.Handle("/graphql/subscription", &corsHandler{wsHandler}) diff --git a/node/config/def.go b/node/config/def.go index a67f4e9c7..84f2c1db7 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -63,6 +63,10 @@ func DefaultBoost() *Boost { ParallelFetchLimit: 10, }, + Graphql: GraphqlConfig{ + Port: 8080, + }, + Dealmaking: DealmakingConfig{ ConsiderOnlineStorageDeals: true, ConsiderOfflineStorageDeals: true, diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index 2f30b9f96..57d02e589 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -55,6 +55,12 @@ your node if metadata log is disabled`, Comment: ``, }, + { + Name: "Graphql", + Type: "GraphqlConfig", + + Comment: ``, + }, { Name: "LotusDealmaking", Type: "lotus_config.DealmakingConfig", @@ -262,6 +268,14 @@ see https://docs.filecoin.io/mine/lotus/miner-configuration/#using-filters-for-f Comment: `The maximum fee to pay when sending the AddBalance message (used by legacy markets)`, }, }, + "GraphqlConfig": []DocField{ + { + Name: "Port", + Type: "uint64", + + Comment: `The port that the graphql server listens on`, + }, + }, "LotusDealmakingConfig": []DocField{ { Name: "PieceCidBlocklist", diff --git a/node/config/types.go b/node/config/types.go index e041a6da4..bf7d43baa 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -41,6 +41,7 @@ type Boost struct { SectorIndexApiInfo string Dealmaking DealmakingConfig Wallets WalletsConfig + Graphql GraphqlConfig // Lotus configs LotusDealmaking lotus_config.DealmakingConfig @@ -69,6 +70,11 @@ type WalletsConfig struct { PledgeCollateral string } +type GraphqlConfig struct { + // The port that the graphql server listens on + Port uint64 +} + type LotusDealmakingConfig struct { // A list of Data CIDs to reject when making deals PieceCidBlocklist []cid.Cid