()
| 42 | ) |
| 43 | |
| 44 | func initNode() (server *mux.Server, direct *rpc.Server, err error) { |
| 45 | var masterKey []byte |
| 46 | if !conf.GConf.UseTestMasterKey { |
| 47 | // read master key |
| 48 | fmt.Print("Type in Master key to continue: ") |
| 49 | masterKey, err = terminal.ReadPassword(syscall.Stdin) |
| 50 | if err != nil { |
| 51 | fmt.Printf("Failed to read Master Key: %v", err) |
| 52 | } |
| 53 | fmt.Println("") |
| 54 | } |
| 55 | |
| 56 | if err = kms.InitLocalKeyPair(conf.GConf.PrivateKeyFile, masterKey); err != nil { |
| 57 | log.WithError(err).Error("init local key pair failed") |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | log.Info("init routes") |
| 62 | |
| 63 | // init kms routing |
| 64 | route.InitKMS(conf.GConf.PubKeyStoreFile) |
| 65 | |
| 66 | err = mux.RegisterNodeToBP(30 * time.Second) |
| 67 | if err != nil { |
| 68 | log.Fatalf("register node to BP failed: %v", err) |
| 69 | } |
| 70 | |
| 71 | // init server |
| 72 | utils.RemoveAll(conf.GConf.PubKeyStoreFile + "*") |
| 73 | if server, err = createServer( |
| 74 | conf.GConf.PrivateKeyFile, masterKey, conf.GConf.ListenAddr); err != nil { |
| 75 | log.WithError(err).Error("create server failed") |
| 76 | return |
| 77 | } |
| 78 | if direct, err = createDirectServer( |
| 79 | conf.GConf.PrivateKeyFile, masterKey, conf.GConf.ListenDirectAddr); err != nil { |
| 80 | log.WithError(err).Error("create direct server failed") |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | func createServer(privateKeyPath string, masterKey []byte, listenAddr string) (server *mux.Server, err error) { |
| 88 | server = mux.NewServer() |
no test coverage detected