func receiveEnvelopeFromPeer(dhtHandler DHTHandler, stream network.Stream) (*aea.Envelope, error) {
	lerror, _, _, _ := dhtHandler.GetLoggers()
	streamPipe := utils.StreamPipe{Stream: stream}

	aeaEnvelope, err := acn.ReadEnvelopeMessage(streamPipe)
	if err != nil {
		lerror(err).Msg("while handling acn envelope message")
		return nil, err
	}

	envel := &aea.Envelope{}
	err = proto.Unmarshal(aeaEnvelope.Envelope, envel)
	if err != nil {
		lerror(err).Msg("while deserializing acn aea envelope message")
		ignore(acn.SendAcnError(
			streamPipe,
			"while deserializing acn aea envelope message",
			acn.ERROR_DECODE,
		))
		return nil, err
	}

	remotePubkey, err := utils.FetchAIPublicKeyFromPubKey(stream.Conn().RemotePublicKey())
	ignore(err)
	status, err := dhtnode.IsValidProofOfRepresentation(
		aeaEnvelope.Record,
		aeaEnvelope.Record.Address,
		remotePubkey,
	)
	if err != nil || status.Code != acn.SUCCESS {
		if err == nil {
			err = errors.New(status.Code.String() + ":" + strings.Join(status.Msgs, ":"))
		}
		lerror(err).Msg("incoming envelope PoR is not valid")
		ignore(acn.SendAcnError(streamPipe, "incoming envelope PoR is not valid", status.Code))
		return nil, err
	}
	return envel, nil
}
//read ACN message, decode envelope, check PoR
read ACN message, decode envelope, check PoR
// read ACN message decode envelope check PoR
func receiveEnvelopeFromPeer(dhtHandler DHTHandler, stream network.Stream) (*aea.Envelope, error) {
	lerror, _, _, _ := dhtHandler.GetLoggers()
	streamPipe := utils.StreamPipe{Stream: stream}
	aeaEnvelope, err := acn.ReadEnvelopeMessage(streamPipe)
	if err != nil {
		lerror(err).Msg("while handling acn envelope message")
		return nil, err
	}
	envel := &aea.Envelope{}
	err = proto.Unmarshal(aeaEnvelope.Envelope, envel)
	if err != nil {
		lerror(err).Msg("while deserializing acn aea envelope message")
		ignore(acn.SendAcnError(
			streamPipe,
			"while deserializing acn aea envelope message",
			acn.ERROR_DECODE,
		))
		return nil, err
	}
	remotePubkey, err := utils.FetchAIPublicKeyFromPubKey(stream.Conn().RemotePublicKey())
	ignore(err)
	status, err := dhtnode.IsValidProofOfRepresentation(
		aeaEnvelope.Record,
		aeaEnvelope.Record.Address,
		remotePubkey,
	)
	if err != nil || status.Code != acn.SUCCESS {
		if err == nil {
			err = errors.New(status.Code.String() + ":" + strings.Join(status.Msgs, ":"))
		}
		lerror(err).Msg("incoming envelope PoR is not valid")
		ignore(acn.SendAcnError(streamPipe, "incoming envelope PoR is not valid", status.Code))
		return nil, err
	}
	return envel, nil
}
func receiveEnvelopeFromPeer ( dhtHandler DHTHandler , stream network . Stream ) ( * aea . Envelope , error ) { lerror , _ , _ , _ := dhtHandler . GetLoggers ( ) streamPipe := utils . StreamPipe { Stream : stream } aeaEnvelope , err := acn . ReadEnvelopeMessage ( streamPipe ) if err != nil { lerror ( err ) . Msg ( " " ) return nil , err } envel := & aea . Envelope { } err = proto . Unmarshal ( aeaEnvelope . Envelope , envel ) if err != nil { lerror ( err ) . Msg ( " " ) ignore ( acn . SendAcnError ( streamPipe , " " , acn . ERROR_DECODE , ) ) return nil , err } remotePubkey , err := utils . FetchAIPublicKeyFromPubKey ( stream . Conn ( ) . RemotePublicKey ( ) ) ignore ( err ) status , err := dhtnode . IsValidProofOfRepresentation ( aeaEnvelope . Record , aeaEnvelope . Record . Address , remotePubkey , ) if err != nil || status . Code != acn . SUCCESS { if err == nil { err = errors . New ( status . Code . String ( ) + " " + strings . Join ( status . Msgs , " " ) ) } lerror ( err ) . Msg ( " " ) ignore ( acn . SendAcnError ( streamPipe , " " , status . Code ) ) return nil , err } return envel , nil }
read ACN message, decode envelope, check PoR
read ACN message decode envelope check PoR