@@ -39,7 +39,7 @@ import (
3939 faultsRpc "github.com/textileio/powergate/index/faults/rpc"
4040 "github.com/textileio/powergate/index/miner"
4141 minerRpc "github.com/textileio/powergate/index/miner/rpc"
42- "github.com/textileio/powergate/iplocation/ip2location "
42+ "github.com/textileio/powergate/iplocation/maxmind "
4343 "github.com/textileio/powergate/lotus"
4444 pgnet "github.com/textileio/powergate/net"
4545 pgnetlotus "github.com/textileio/powergate/net/lotus"
@@ -67,15 +67,15 @@ var (
6767type Server struct {
6868 ds datastore.TxnDatastore
6969
70- ip2l * ip2location. IP2Location
71- ai * ask.Runner
72- mi * miner.Index
73- fi * faults.Index
74- dm * deals.Module
75- wm * wallet.Module
76- rm * reputation.Module
77- nm pgnet.Module
78- hm * health.Module
70+ mm * maxmind. MaxMind
71+ ai * ask.Runner
72+ mi * miner.Index
73+ fi * faults.Index
74+ dm * deals.Module
75+ wm * wallet.Module
76+ rm * reputation.Module
77+ nm pgnet.Module
78+ hm * health.Module
7979
8080 ffsManager * manager.Manager
8181 sched * scheduler.Scheduler
@@ -105,6 +105,7 @@ type Config struct {
105105 GrpcWebProxyAddress string
106106 RepoPath string
107107 GatewayHostAddr string
108+ MaxMindDBFolder string
108109}
109110
110111// NewServer starts and returns a new server with the given configuration.
@@ -150,12 +151,15 @@ func NewServer(conf Config) (*Server, error) {
150151 return nil , fmt .Errorf ("opening datastore on repo: %s" , err )
151152 }
152153
153- ip2l := ip2location .New ([]string {"./ip2location-ip4.bin" })
154+ mm , err := maxmind .New (filepath .Join (conf .MaxMindDBFolder , "./GeoLite2-City.mmdb" ))
155+ if err != nil {
156+ return nil , fmt .Errorf ("opening maxmind database: %s" , err )
157+ }
154158 ai , err := ask .New (txndstr .Wrap (ds , "index/ask" ), c )
155159 if err != nil {
156160 return nil , fmt .Errorf ("creating ask index: %s" , err )
157161 }
158- mi , err := miner .New (txndstr .Wrap (ds , "index/miner" ), c , fchost , ip2l )
162+ mi , err := miner .New (txndstr .Wrap (ds , "index/miner" ), c , fchost , mm )
159163 if err != nil {
160164 return nil , fmt .Errorf ("creating miner index: %s" , err )
161165 }
@@ -173,7 +177,7 @@ func NewServer(conf Config) (*Server, error) {
173177 }
174178 pm := paychLotus .New (c )
175179 rm := reputation .New (txndstr .Wrap (ds , "reputation" ), mi , si , ai )
176- nm := pgnetlotus .New (c , ip2l )
180+ nm := pgnetlotus .New (c , mm )
177181 hm := health .New (nm )
178182
179183 ipfs , err := httpapi .NewApi (conf .IpfsAPIAddr )
@@ -205,7 +209,7 @@ func NewServer(conf Config) (*Server, error) {
205209 s := & Server {
206210 ds : ds ,
207211
208- ip2l : ip2l ,
212+ mm : mm ,
209213
210214 ai : ai ,
211215 mi : mi ,
@@ -403,5 +407,7 @@ func (s *Server) Close() {
403407 log .Errorf ("closing gateway: %s" , err )
404408 }
405409 s .closeLotus ()
406- s .ip2l .Close ()
410+ if err := s .mm .Close (); err != nil {
411+ log .Errorf ("closing maxmind: %s" , err )
412+ }
407413}
0 commit comments