github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/cmd/bootstrap_mobile_provider.go (about) 1 //go:build (ios || android) && mobile_provider 2 3 /* 4 * Copyright (C) 2018 The "MysteriumNetwork/node" Authors. 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package cmd 21 22 import ( 23 "fmt" 24 "net" 25 "os" 26 "time" 27 28 "github.com/rs/zerolog/log" 29 30 "github.com/gin-gonic/gin" 31 "github.com/mysteriumnetwork/node/config" 32 "github.com/mysteriumnetwork/node/consumer/entertainment" 33 "github.com/mysteriumnetwork/node/core/node" 34 "github.com/mysteriumnetwork/node/services" 35 "github.com/mysteriumnetwork/node/tequilapi" 36 tequilapi_client "github.com/mysteriumnetwork/node/tequilapi/client" 37 tequilapi_endpoints "github.com/mysteriumnetwork/node/tequilapi/endpoints" 38 "github.com/mysteriumnetwork/node/ui" 39 uinoop "github.com/mysteriumnetwork/node/ui/noop" 40 "github.com/mysteriumnetwork/node/ui/versionmanager" 41 "github.com/mysteriumnetwork/node/utils" 42 ) 43 44 func (di *Dependencies) bootstrapTequilapi(nodeOptions node.Options, listener net.Listener) (tequilapi.APIServer, error) { 45 log.Debug().Msg("bootstrapTequilapi - I am here!") 46 log.Debug().Msg("nodeOptions.TequilapiEnabled - " + fmt.Sprint(nodeOptions.TequilapiEnabled)) 47 if !nodeOptions.TequilapiEnabled { 48 return tequilapi.NewNoopAPIServer(), nil 49 } 50 tequilaApiClient := tequilapi_client.NewClient(nodeOptions.TequilapiAddress, nodeOptions.TequilapiPort) 51 52 return tequilapi.NewServer( 53 listener, 54 nodeOptions, 55 di.JWTAuthenticator, 56 []func(engine *gin.Engine) error{ 57 func(e *gin.Engine) error { 58 if err := tequilapi_endpoints.AddRoutesForSSE(e, di.StateKeeper, di.EventBus); err != nil { 59 return err 60 } 61 return nil 62 }, 63 func(e *gin.Engine) error { 64 if config.GetBool(config.FlagPProfEnable) { 65 tequilapi_endpoints.AddRoutesForPProf(e) 66 } 67 return nil 68 }, 69 func(e *gin.Engine) error { 70 e.GET("/healthcheck", tequilapi_endpoints.HealthCheckEndpointFactory(time.Now, os.Getpid).HealthCheck) 71 return nil 72 }, 73 tequilapi_endpoints.AddRouteForStop(utils.SoftKiller(di.Shutdown)), 74 tequilapi_endpoints.AddRoutesForAuthentication(di.Authenticator, di.JWTAuthenticator, di.SSOMystnodes), 75 tequilapi_endpoints.AddRoutesForIdentities(di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, di.ConsumerBalanceTracker, di.AddressProvider, di.HermesChannelRepository, di.BCHelper, di.Transactor, di.BeneficiaryProvider, di.IdentityMover, di.BeneficiaryAddressStorage, di.HermesMigrator), 76 tequilapi_endpoints.AddRoutesForConnection(di.MultiConnectionManager, di.StateKeeper, di.ProposalRepository, di.IdentityRegistry, di.EventBus, di.AddressProvider), 77 tequilapi_endpoints.AddRoutesForSessions(di.SessionStorage), 78 tequilapi_endpoints.AddRoutesForConnectionLocation(di.IPResolver, di.LocationResolver, di.LocationResolver), 79 tequilapi_endpoints.AddRoutesForProposals(di.ProposalRepository, di.PricingHelper, di.LocationResolver, di.FilterPresetStorage, di.NATProber), 80 tequilapi_endpoints.AddRoutesForService(di.ServicesManager, services.JSONParsersByType, di.ProposalRepository, tequilaApiClient), 81 tequilapi_endpoints.AddRoutesForAccessPolicies(di.HTTPClient, config.GetString(config.FlagAccessPolicyAddress)), 82 tequilapi_endpoints.AddRoutesForNAT(di.StateKeeper, di.NATProber), 83 tequilapi_endpoints.AddRoutesForNodeUI(versionmanager.NewVersionManager(di.UIServer, di.HTTPClient, di.uiVersionConfig)), 84 tequilapi_endpoints.AddRoutesForNode(di.NodeStatusTracker, di.NodeStatsTracker), 85 tequilapi_endpoints.AddRoutesForTransactor(di.IdentityRegistry, di.Transactor, di.Affiliator, di.HermesPromiseSettler, di.SettlementHistoryStorage, di.AddressProvider, di.BeneficiaryProvider, di.BeneficiarySaver, di.PilvytisAPI), 86 tequilapi_endpoints.AddRoutesForAffiliator(di.Affiliator), 87 tequilapi_endpoints.AddRoutesForConfig, 88 tequilapi_endpoints.AddRoutesForMMN(di.MMN, di.SSOMystnodes, di.Authenticator), 89 tequilapi_endpoints.AddRoutesForFeedback(di.Reporter), 90 tequilapi_endpoints.AddRoutesForConnectivityStatus(di.SessionConnectivityStatusStorage), 91 tequilapi_endpoints.AddRoutesForDocs, 92 tequilapi_endpoints.AddRoutesForCurrencyExchange(di.PilvytisAPI), 93 tequilapi_endpoints.AddRoutesForPilvytis(di.PilvytisAPI, di.PilvytisOrderIssuer, di.LocationResolver), 94 tequilapi_endpoints.AddRoutesForTerms, 95 tequilapi_endpoints.AddEntertainmentRoutes(entertainment.NewEstimator( 96 config.FlagPaymentPriceGiB.Value, 97 config.FlagPaymentPriceHour.Value, 98 )), 99 tequilapi_endpoints.AddRoutesForValidator, 100 }, 101 ) 102 } 103 104 func (di *Dependencies) bootstrapUIServer(options node.Options) (err error) { 105 log.Debug().Msg("bootstrapUIServer - I am here!") 106 log.Debug().Msg("options.UI.UIEnabled - " + fmt.Sprint(options.UI.UIEnabled)) 107 if !options.UI.UIEnabled { 108 di.UIServer = uinoop.NewServer() 109 return nil 110 } 111 112 bindAddress := options.UI.UIBindAddress 113 if bindAddress == "" { 114 bindAddress, err = di.IPResolver.GetOutboundIP() 115 if err != nil { 116 return err 117 } 118 bindAddress = bindAddress + ",127.0.0.1" 119 } 120 di.UIServer = ui.NewServer(bindAddress, options.UI.UIPort, options.TequilapiAddress, options.TequilapiPort, di.JWTAuthenticator, di.HTTPClient, di.uiVersionConfig) 121 return nil 122 } 123 124 func (di *Dependencies) bootstrapNodeUIVersionConfig(_ node.Options) error { 125 noopCfg, _ := versionmanager.NewNoOpVersionConfig() 126 di.uiVersionConfig = noopCfg 127 return nil 128 }