()
| 45 | } |
| 46 | |
| 47 | func main() { |
| 48 | //log.SetLevel(log.DebugLevel) |
| 49 | conf.GConf, _ = conf.LoadConfig(os.Args[1]) |
| 50 | log.Debugf("GConf: %#v", conf.GConf) |
| 51 | |
| 52 | // Init Key Management System |
| 53 | route.InitKMS(conf.GConf.PubKeyStoreFile) |
| 54 | |
| 55 | // Register DHT service |
| 56 | server, err := rpc.NewServerWithService(rpc.ServiceMap{ |
| 57 | "Test": NewTestService(), |
| 58 | }) |
| 59 | if err != nil { |
| 60 | log.Fatal(err) |
| 61 | } |
| 62 | |
| 63 | // Init RPC server with an empty master key, which is not recommend |
| 64 | addr := conf.GConf.ListenAddr |
| 65 | masterKey := []byte("") |
| 66 | server.InitRPCServer(addr, conf.GConf.PrivateKeyFile, masterKey) |
| 67 | |
| 68 | // Start Node RPC server |
| 69 | go server.Serve() |
| 70 | |
| 71 | pClient := rpc.NewPersistentCaller(conf.GConf.BP.NodeID) |
| 72 | // Register Node public key, addr to Tracker(BP) |
| 73 | for _, n := range conf.GConf.KnownNodes { |
| 74 | reqA := &proto.PingReq{ |
| 75 | Node: n, |
| 76 | } |
| 77 | respA := new(proto.PingResp) |
| 78 | err = pClient.Call("DHT.Ping", reqA, respA) |
| 79 | if err != nil { |
| 80 | log.Fatal(err) |
| 81 | } |
| 82 | log.Debugf("respA: %v", respA) |
| 83 | } |
| 84 | |
| 85 | // Read target node and connect to it |
| 86 | scanner := bufio.NewScanner(os.Stdin) |
| 87 | fmt.Print("Input target node ID: ") |
| 88 | scanner.Scan() |
| 89 | if scanner.Err() == nil { |
| 90 | target := proto.NodeID(strings.TrimSpace(scanner.Text())) |
| 91 | pc := rpc.NewPersistentCaller(target) |
| 92 | log.Debugf("connecting to %s", scanner.Text()) |
| 93 | |
| 94 | fmt.Print("Input msg: ") |
| 95 | for scanner.Scan() { |
| 96 | input := scanner.Text() |
| 97 | log.Debugf("get input %s", input) |
| 98 | repSimple := new(string) |
| 99 | err = pc.Call("Test.Talk", input, repSimple) |
| 100 | if err != nil { |
| 101 | log.Fatal(err) |
| 102 | } |
| 103 | log.Infof("resp msg: %s", *repSimple) |
| 104 | } |
nothing calls this directly
no test coverage detected