-
Notifications
You must be signed in to change notification settings - Fork 314
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
Compile in geoip2 database and avoid external file reading #281
Conversation
+100 kudos, awesome idea |
68d1164
to
6cf482b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is shown for me on each pull request reminder, so I'm putting request changes to hide it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just a note that we will need to remove 'bin/common_package/GeoLite2-Country.mmdb' and all related packaging references. Maybe in separate task.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
It comes a bit important now |
eb26da5
to
4d9a653
Compare
@mysteriumnetwork/core you can all take a look, while its being verified by CI |
@Waldz @vkuznecovas ping. Ready for review |
cmd/flags_location.go
Outdated
@@ -28,8 +28,12 @@ var ( | |||
Usage: "Address (URL form) of ipify service", | |||
Value: "https://api.ipify.org/", | |||
} | |||
locationBuiltInDbFlag = cli.BoolTFlag{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont need this flag, compiled-in should be default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
cmd/di.go
Outdated
di.LocationResolver = location.NewResolverFake(options.Country) | ||
di.LocationResolver = location.NewStaticResolver(options.Country) | ||
case options.BuiltInDb: | ||
di.LocationResolver = location.NewBuiltInResolver() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewBuiltInResolver
should be default resolver if no other option other resolver given
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/location/built_in_resolver.go
Outdated
return "", errors.New("failed to parse IP") | ||
} | ||
|
||
countryRecord, err := r.db.Country(ipObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like duplicated logic, lets DRY with composition:
DBResolver{
db resource
}
BuiltinDBResolver {
Resolver DBResolver
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRYied
core/node/options_location.go
Outdated
Country string | ||
IpifyUrl string | ||
ExternalDb string | ||
BuiltInDb bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If build-in is default, we dont need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Removed
core/location/built_in_resolver.go
Outdated
|
||
// NewBuiltInResolver returns new BuiltInDbResolver | ||
func NewBuiltInResolver() Resolver { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the empty line at the start of the func seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
core/location/built_in_resolver.go
Outdated
|
||
// ResolveCountry maps given ip to country | ||
func (r *BuiltInDbResolver) ResolveCountry(ip string) (string, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the empty line at the start of the func seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
core/location/built_in_resolver.go
Outdated
|
||
country := countryRecord.Country.IsoCode | ||
if country == "" { | ||
country = countryRecord.RegisteredCountry.IsoCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if country = countryRecord.RegisteredCountry.IsoCode; country == "" {
return "", errors.New("failed to resolve country")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I am not sure if this looks more readable :)
2b7555b
to
e4aed78
Compare
@Waldz @vkuznecovas all comments addressed. Ready for re-review |
e4aed78
to
dde38ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, did we try to use existing libraries that allows embedding files into executable binary?
cmd/di.go
Outdated
@@ -43,6 +41,7 @@ import ( | |||
"github.com/mysteriumnetwork/node/services/openvpn" | |||
openvpn_service "github.com/mysteriumnetwork/node/services/openvpn/service" | |||
"github.com/mysteriumnetwork/node/session" | |||
"path/filepath" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look goimports formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin/check_goimports: line 23: goimports: command not found
hm, looks like we have broken goimports
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue for fixing goimports on the CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed code.
core/location/gendb/loader.go
Outdated
|
||
// EncodedDataLoader returns emmbeded database as byte array | ||
func EncodedDataLoader(data string, originalSize int, compressed bool) (decompressed []byte, err error) { | ||
var reader io.Reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be just reader := base64.NewDecoder(base64.RawStdEncoding, strings.NewReader(data))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot. Because of the compressed flag, reader can be further decorated with gzip.Reader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Got your point. It can be just reader := ...
Thanks.
Yea I checked a few embedding libraries, didn't find small and efficient enough, they all were either to big, ugly to use, or not compatible with go generate style integration |
dde38ea
to
3206da2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
core/location/gendb/db_index.go
Outdated
const originalSize = 3303090 | ||
const dbData = "" + dbDataPart0 + dbDataPart1 | ||
|
||
// LoadData returns emmbeded database as byte array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: emmbeded -> embedded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
cmd/flags_location.go
Outdated
@@ -29,9 +29,9 @@ var ( | |||
Value: "https://api.ipify.org/", | |||
} | |||
locationDatabaseFlag = cli.StringFlag{ | |||
Name: "location.database", | |||
Name: "location.db.external", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not change contract
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location.database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
3206da2
to
537a4e3
Compare
@soffokl @vkuznecovas reapprove please |
Idea is to reduce external file dependencies and to build-in as much data/info as possible. First candidate geoip database.
Short summary: