()
| 184 | } |
| 185 | |
| 186 | func initNode() (cleanupFunc func(), server *rpc.Server, err error) { |
| 187 | var d string |
| 188 | if d, err = ioutil.TempDir("", "db_test_"); err != nil { |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | // init conf |
| 193 | _, testFile, _, _ := runtime.Caller(0) |
| 194 | pubKeyStoreFile := filepath.Join(d, PubKeyStorePath) |
| 195 | utils.RemoveAll(pubKeyStoreFile + "*") |
| 196 | clientPubKeyStoreFile := filepath.Join(d, PubKeyStorePath+"_c") |
| 197 | utils.RemoveAll(clientPubKeyStoreFile + "*") |
| 198 | dupConfFile := filepath.Join(d, "config.yaml") |
| 199 | confFile := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/config.yaml") |
| 200 | if err = utils.DupConf(confFile, dupConfFile); err != nil { |
| 201 | return |
| 202 | } |
| 203 | privateKeyPath := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/private.key") |
| 204 | |
| 205 | conf.GConf, _ = conf.LoadConfig(dupConfFile) |
| 206 | // reset the once |
| 207 | route.Once.Reset() |
| 208 | route.InitKMS(clientPubKeyStoreFile) |
| 209 | |
| 210 | var dht *route.DHTService |
| 211 | |
| 212 | // init dht |
| 213 | dht, err = route.NewDHTService(pubKeyStoreFile, new(consistent.KMSStorage), true) |
| 214 | if err != nil { |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | // init rpc |
| 219 | if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil { |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | // init private key |
| 224 | masterKey := []byte("") |
| 225 | if err = server.InitRPCServer(conf.GConf.ListenAddr, privateKeyPath, masterKey); err != nil { |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | // start server |
| 230 | go server.Serve() |
| 231 | |
| 232 | cleanupFunc = func() { |
| 233 | os.RemoveAll(d) |
| 234 | server.Listener.Close() |
| 235 | server.Stop() |
| 236 | // clear the connection pool |
| 237 | rpc.GetSessionPoolInstance().Close() |
| 238 | } |
| 239 | |
| 240 | return |
| 241 | } |
no test coverage detected