Exemple #1
0
func (w *Worker) GetPeers(query *conn.Query, reply *conn.Reply) error {
	//gob.Register(pList)
	var network bytes.Buffer
	enc := gob.NewEncoder(&network)
	err := enc.Encode(peers)
	if err != nil {
		glog.Fatalf("encode:", err)
	}

	reply.Data = network.Bytes()
	return nil
}
Exemple #2
0
func (w *Worker) GetMasterIP(query *conn.Query, reply *conn.Reply) error {
	buf := bytes.NewBuffer(query.Data)
	dec := gob.NewDecoder(buf)
	var v helloRPC
	err := dec.Decode(&v)
	if err != nil {
		glog.Fatal("decode:", err)
	}

	if _, ok := pools[v.Id]; !ok {
		go connectWith(v.Addr)
	}
	reply.Data = []byte(peers[cur_node.raft.Status().Lead])
	fmt.Println("In Hello")
	return nil
}
Exemple #3
0
func (w *Worker) Hello(query *conn.Query, reply *conn.Reply) error {
	buf := bytes.NewBuffer(query.Data)
	dec := gob.NewDecoder(buf)
	var v helloRPC
	err := dec.Decode(&v)
	if err != nil {
		glog.Fatal("decode:", err)
	}

	if _, ok := pools[v.Id]; !ok {
		go connectWith(v.Addr)
	}
	reply.Data = []byte(strconv.Itoa(int(cur_node.id)))

	fmt.Println("In Hello")
	return nil
}
Exemple #4
0
func (w *Worker) Ping(query *conn.Query, reply *conn.Reply) error {
	reply.Data = []byte("reachable")
	return nil
}