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

Improve: Adjust the configuration file #206

Merged
merged 7 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Improve: Optimize the configuration of aria2_candidate_dirs
  • Loading branch information
sonic committed Jan 30, 2023
commit df19122c3063227173d5cb1cd4d500a7e9e0a801
3 changes: 3 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ const (

MARKET_VERSION_1 = "1.1"
MARKET_VERSION_2 = "1.2"

DEFAULT_GRAPHQL_PORT = 8080
DEFAULT_API_PORT = 1288
)
44 changes: 41 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"swan-provider/common/constants"
"time"

"github.com/BurntSushi/toml"
Expand All @@ -22,6 +23,16 @@ type Configuration struct {
Market market `toml:"market"`
}

type ConfigurationBak struct {
Port int `toml:"port"`
Release bool `toml:"release"`
Lotus lotus `toml:"lotus"`
Aria2 aria2Bak `toml:"aria2"`
Main main `toml:"main"`
Bid bid `toml:"bid"`
Market market `toml:"market"`
}

type lotus struct {
ClientApiUrl string `toml:"client_api_url"`
ClientApiToken string `toml:"client_api_token"`
Expand All @@ -31,12 +42,22 @@ type lotus struct {

type aria2 struct {
Aria2DownloadDir string `toml:"aria2_download_dir"`
Aria2CandidateDirs []string `toml:"aria2_candidate_dirs"`
Aria2Host string `toml:"aria2_host"`
Aria2Port int `toml:"aria2_port"`
Aria2Secret string `toml:"aria2_secret"`
Aria2AutoDeleteCarFile bool `toml:"aria2_auto_delete_car_file"`
Aria2MaxDownloadingTasks int `toml:"aria2_max_downloading_tasks"`
Aria2CandidateDirs []string `toml:"aria2_candidate_dirs"`
}

type aria2Bak struct {
Aria2DownloadDir string `toml:"aria2_download_dir"`
Aria2Host string `toml:"aria2_host"`
Aria2Port int `toml:"aria2_port"`
Aria2Secret string `toml:"aria2_secret"`
Aria2AutoDeleteCarFile bool `toml:"aria2_auto_delete_car_file"`
Aria2MaxDownloadingTasks int `toml:"aria2_max_downloading_tasks"`
Aria2CandidateDirs string `toml:"aria2_candidate_dirs"`
}

type main struct {
Expand Down Expand Up @@ -87,7 +108,12 @@ func InitConfig() {
logs.GetLogger().Info("Your config file is:", configFile)

if metaData, err := toml.DecodeFile(configFile, &config); err != nil {
logs.GetLogger().Fatal("error:", err)
var configBak *ConfigurationBak
if _, err = toml.DecodeFile(configFile, &configBak); err == nil {
config.Aria2.Aria2CandidateDirs = strings.Split(configBak.Aria2.Aria2CandidateDirs, ",")
} else {
logs.GetLogger().Fatal("error:", err)
}
} else {
if !requiredFieldsAreGiven(metaData) {
logs.GetLogger().Fatal("required fields not given")
Expand All @@ -96,6 +122,8 @@ func InitConfig() {
config.Market.Repo = filepath.Join(basePath, "boost")
config.Market.BoostLog = filepath.Join(basePath, "boost.log")

println("Aria2CandidateDirs:", config.Aria2.Aria2CandidateDirs)

fullNodeApi, err := ChangeToFull(config.Lotus.ClientApiUrl, config.Lotus.ClientApiToken)
if err != nil {
logs.GetLogger().Fatal(err)
Expand Down Expand Up @@ -181,8 +209,18 @@ func GetRpcInfoByFile(configPath string) (string, string, error) {
if _, err := toml.DecodeFile(configPath, &config); err != nil {
return "", "", err
}

var rpcUrl string
splits := strings.Split(config.API.ListenAddress, "/")
rpcUrl := fmt.Sprintf("127.0.0.1:%s", splits[4])
if len(splits) == 0 {
rpcUrl = fmt.Sprintf("127.0.0.1:%d", constants.DEFAULT_API_PORT)
} else {
rpcUrl = fmt.Sprintf("127.0.0.1:%s", splits[4])
}

if config.Graphql.Port == 0 {
config.Graphql.Port = constants.DEFAULT_GRAPHQL_PORT
}
graphqlUrl := fmt.Sprintf("http://127.0.0.1:%d/graphql/query", config.Graphql.Port)
return rpcUrl, graphqlUrl, nil
}
Expand Down
1 change: 0 additions & 1 deletion service/aria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ func (aria2Service *Aria2Service) StartDownload(aria2Client *client.Aria2Client,
logs.GetLogger().Error(err)
break
}
logs.GetLogger().Infof("taskname: %s,deal2Download: %+v", *deal2Download.TaskName, deal2Download)

if _, err := uuid.Parse(deal2Download.DealCid); err == nil {
dealResp, err := hqlClient.GetDealByUuid(deal2Download.DealCid)
Expand Down