Пример #1
0
/*
	注册一个域名帐号
	@name     姓名
	@email    邮箱
	@domain   网络唯一标识
*/
func CreateAccount(name, email, domain string) {
	//连接网络并得到一个idinfo
	idInfo, err := GetId(nodeStore.NewIdInfo(name, email, domain, Str_zaro))
	if err == nil {
		Init_IdInfo = *idInfo
	} else {
		fmt.Println("从网络中获得idinfo失败")
		return
	}
}
Пример #2
0
//接收
//name   自己的名称
//@return  remoteName   对方服务器的名称
func (this *Auth) RecvKey(conn net.Conn, name string) (remoteName string, err error) {
	/*
		获取对方的名称
	*/
	if remoteName, err = GetNameForConn(conn); err != nil {
		return
	}
	/*
		开始验证对方客户端名称
	*/
	clientIdInfo := new(nodeStore.IdInfo)
	json.Unmarshal([]byte(remoteName), clientIdInfo)
	/*
		这是新节点,需要给他生成一个id
	*/
	if clientIdInfo.Id == Str_zaro {
		//生成id之前先检查这个id是否存在
		// fmt.Println("在网络中注册一个域名:", clientIdInfo.Domain)
		targetId := utils.GetHashForDomain(clientIdInfo.Domain)
		msgOne := &msgcenter.Message{
			TargetId:   targetId,
			ProtoId:    msgcenter.MSGID_findDomain,
			CreateTime: time.Now().Unix(),
			Sender:     nodeStore.ParseId(nodeStore.GetRootIdInfoString()),
			Content:    []byte(clientIdInfo.Domain),
			Accurate:   false,
		}
		msgOne.Hash = msgcenter.GetHash(msgOne)
		ret := <-msgcenter.SendTimeOutMsg(msgOne, time.Second*10)
		if ret == "timeout" {
			err = errors.New("查询域名超时")
			return
		}
		if ret == "true" {
			err = errors.New("这个域名已经被注册了")
			return
		}

		*clientIdInfo = nodeStore.NewIdInfo(clientIdInfo.Name, clientIdInfo.Email, clientIdInfo.Domain, nodeStore.ParseId(name))
		//给服务器发送生成的id
		newName := string(clientIdInfo.Build())
		conn.Write(GetBytesForName(newName))
		err = errors.New("给新节点分配一个idinfo")
		return
	}

	/*
		验证成功后,向对方发送自己的名称
	*/
	//得到对方名称
	conn.Write(GetBytesForName(name))
	return
}
Пример #3
0
func main() {
	fmt.Println(zaro, "\n", len(zaro))

	idInfo, err := nodeStore.NewIdInfo("prestonTao", "*****@*****.**", "mandela", zaro)
	if err != nil {
		fmt.Println(err)
		panic("create id error")
	}
	fmt.Println(idInfo)
	private := idInfo.Build()
	file, _ := os.Create("idinfo.json")
	file.Write(private)
	file.Close()

}