Esempio n. 1
0
//处理查找节点请求
func (this *NodeManager) FindNodeReq(c server.Controller, msg net.GetPacket) {
	findNode := new(message.FindNodeReq)
	proto.Unmarshal(msg.Date, findNode)
	nodeStore := c.GetAttribute("peerNode").(*peerNode.NodeStore)

	targetNode := nodeStore.Get(findNode.GetFindId())
	// fmt.Println("查找到:", targetNode.NodeId.String())
	rspMsg := message.FindNodeRsp{
		NodeId:  proto.String(targetNode.NodeId.String()),
		FindId:  findNode.FindId,
		Addr:    proto.String(targetNode.Addr),
		IsProxy: proto.Bool(!targetNode.IsSuper),
		TcpPort: proto.Int32(int32(targetNode.TcpPort)),
		UdpPort: proto.Int32(int32(targetNode.UdpPort)),
	}

	resultBytes, _ := proto.Marshal(&rspMsg)
	c.GetNet().Send(msg.ConnId, message.FindNodeRspNum, resultBytes)
}