()
| 192 | } |
| 193 | |
| 194 | func initNode() (cleanupFunc func(), tempDir string, server *rpc.Server, err error) { |
| 195 | if tempDir, err = ioutil.TempDir("", "db_test_"); err != nil { |
| 196 | return |
| 197 | } |
| 198 | log.WithField("d", tempDir).Debug("created temp dir") |
| 199 | |
| 200 | // init conf |
| 201 | _, testFile, _, _ := runtime.Caller(0) |
| 202 | pubKeyStoreFile := filepath.Join(tempDir, PubKeyStorePath+"_dht") |
| 203 | utils.RemoveAll(pubKeyStoreFile + "*") |
| 204 | clientPubKeyStoreFile := filepath.Join(tempDir, PubKeyStorePath+"_c") |
| 205 | utils.RemoveAll(clientPubKeyStoreFile + "*") |
| 206 | dupConfFile := filepath.Join(tempDir, "config.yaml") |
| 207 | confFile := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/config.yaml") |
| 208 | if err = utils.DupConf(confFile, dupConfFile); err != nil { |
| 209 | return |
| 210 | } |
| 211 | privateKeyPath := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/private.key") |
| 212 | conf.GConf, _ = conf.LoadConfig(dupConfFile) |
| 213 | log.Debugf("GConf: %#v", conf.GConf) |
| 214 | _, err = utils.CopyFile(privateKeyPath, conf.GConf.PrivateKeyFile) |
| 215 | if err != nil { |
| 216 | log.WithFields(log.Fields{ |
| 217 | "from": privateKeyPath, |
| 218 | "to": conf.GConf.PrivateKeyFile, |
| 219 | }).WithError(err).Fatal("copy private key failed") |
| 220 | return |
| 221 | } |
| 222 | // reset the once |
| 223 | route.Once.Reset() |
| 224 | route.InitKMS(clientPubKeyStoreFile) |
| 225 | |
| 226 | var dht *route.DHTService |
| 227 | |
| 228 | // init dht |
| 229 | dht, err = route.NewDHTService(pubKeyStoreFile, new(consistent.KMSStorage), true) |
| 230 | if err != nil { |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | // init rpc |
| 235 | if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil { |
| 236 | return |
| 237 | } |
| 238 | |
| 239 | // register fake chain service |
| 240 | if err = server.RegisterService(route.BlockProducerRPCName, &stubBPService{}); err != nil { |
| 241 | return |
| 242 | } |
| 243 | |
| 244 | // init private key |
| 245 | masterKey := []byte("") |
| 246 | if err = server.InitRPCServer(conf.GConf.ListenAddr, privateKeyPath, masterKey); err != nil { |
| 247 | return |
| 248 | } |
| 249 | |
| 250 | // start server |
| 251 | go server.Serve() |
no test coverage detected