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

Fix the bug that does not read geoip and geosite in config file #359

Merged
merged 3 commits into from Jun 4, 2021
Merged

Fix the bug that does not read geoip and geosite in config file #359

merged 3 commits into from Jun 4, 2021

Conversation

ghost
Copy link

@ghost ghost commented Jun 3, 2021

Hi everyone,

I noticed that the current GetAssetLocation, LoadIP and LoadSite will ignore geoip and geosite items in the routing config.

Therefore here is my proposal on this section that:

  1. When the user specify an absolute path, it is used;
  2. When the user specify a relative path, follow the current routine to have it joint with the value specified in environment variable or (if that is not available) program directory.
  3. There should be a functionality that allow relative path joint with the directory in which the config file is, but it may possibly conflict with current rule (that join relative path with the program file), so it requires further discussion on implementation.

I am looking forward to your ideas and feedback.

Regards,
Chinese White Dolphin

@Loyalsoldier
Copy link
Collaborator

Let me fix this.

@Loyalsoldier
Copy link
Collaborator

I read the docs and check the original code again, and find out that this is a feature, not a bug. It's designed purposely to load geoip and geosite files just from program dir or TROJAN_GO_LOCATION_ASSET env dir.

I think this PR can be closed.

@ghost
Copy link
Author

ghost commented Jun 4, 2021

I read the docs and check the original code again, and find out that this is a feature, not a bug. It's designed purposely to load geoip and geosite files just from program dir or TROJAN_GO_LOCATION_ASSET env dir.

I think this PR can be closed.

Hi @Loyalsoldier,

Here in https://p4gefau1t.github.io/trojan-go/basic/full-config/ said that

"geoip": "$PROGRAM_DIR$/geoip.dat",
"geosite": "$PROGRAM_DIR$/geosite.dat"

and

geoip和geosite字段指geoip和geosite数据库文件路径,默认使用程序所在目录的geoip.dat和geosite.dat。也可以通过指定环境变量TROJAN_GO_LOCATION_ASSET指定工作目录。
GeoIP and Geosite fields refer to GeoIP and GEOSITE database file paths, the default usage of the geoip.dat and geosite.dat of the directory where the program is located. You can also specify a working directory by specifying the environment variable Trojan_GO_Location_asset. 

I am not sure about the translation (from Google), but if my understanding is correct, in the doc there is a feature to allow users to specify a custom path of geoip/geosite files without using environment variable.

I am looking forward to your ideas and feedback.

Regards,
Chinese White Dolphin

@Loyalsoldier
Copy link
Collaborator

Oh, my mistake.

@Loyalsoldier Loyalsoldier reopened this Jun 4, 2021
@Loyalsoldier
Copy link
Collaborator

GetAssetLocation func should changed to:

func GetAssetLocation(file string) string {
	if filepath.IsAbs(file) {
		return file
	}
	if loc := os.Getenv("TROJAN_GO_LOCATION_ASSET"); loc != "" {
		absPath, err := filepath.Abs(loc)
		if err != nil {
			log.Fatal(err)
		}
		log.Debugf("env set: TROJAN_GO_LOCATION_ASSET=%s", absPath)
		return filepath.Join(absPath, file)
	}
	return filepath.Join(GetProgramDir(), file)
}

Because there is a chance that TROJAN_GO_LOCATION_ASSET be a relative path.

@Loyalsoldier Loyalsoldier merged commit 07fec5e into p4gefau1t:master Jun 4, 2021
@ghost ghost deleted the patch-1 branch June 6, 2021 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant