コード例 #1
0
ファイル: client.go プロジェクト: ProjectNiwl/sagiri
// ListNeighs lists the public keys of the neighbors of the node
func (clnt *Client) ListNeighs() ([]natrium.EdDSAPublic, error) {
	req := textprot.TextReq{
		Verb: "NEIGH_LIST",
	}
	resp, err := clnt.execCmd(req)
	var ninf textprot.NeighInfo
	err = ninf.FromString(resp.Blob)
	if err != nil {
		clnt.sok.Close()
		return nil, ErrBadSocket
	}
	// do the checks
	pubkey := directory.DefaultProvider("").PublicKey()
	err = pubkey.Verify(ninf.Json.HashValue(), ninf.Signat)
	if err != nil {
		clnt.sok.Close() // this server is really bad, go away now
		return nil, ErrBadCrypto
	}
	if ninf.Json.Expires < int(time.Now().Unix()) ||
		subtle.ConstantTimeCompare(clnt.CurrentPublic(), ninf.Json.IssuedTo) != 1 {
		clnt.sok.Close()
		return nil, ErrBadCrypto
	}
	// return the val
	var toret []natrium.EdDSAPublic
	for _, v := range ninf.Json.NeighList {
		toret = append(toret, natrium.EdDSAPublic(v))
	}
	return toret, nil
}
コード例 #2
0
ファイル: do_NEIGH_PUSH.go プロジェクト: ProjectNiwl/sagiri
func (ns *NodeState) do_NEIGH_PUSH(sok io.ReadWriteCloser, req textprot.TextReq) (err error) {
	var info textprot.NeighInfo
	err = info.FromString(req.Blob)
	if err != nil {
		return
	}
	// validate info
	sanctum := directory.DefaultProvider("").PublicKey()
	err = sanctum.Verify(info.Json.HashValue(), info.Signat)
	if err != nil {
		return
	}
	if subtle.ConstantTimeCompare(info.Json.IssuedTo, ns.client.GetPrivate().PublicKey()) != 1 {
		return errors.New("core2core: somebody pushed me a NEIGH_PUSH to the wrong person")
	}
	// pull more info from the directory
	neiz, err := ns.provider.JoinEdge(ns.client)
	if err != nil {
		return
	}
	// return okay
	err = (&textprot.TextReq{Verb: "OKAY"}).WriteTo(sok)
	if err != nil {
		return
	}
	// commit into data structure
	ns.Lock()
	defer ns.Unlock()
	ns.fulNeighs = neiz
	ns.sigNeighs = info
	return
}