mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-03-22 12:20:07 +08:00
rename Equals -> Equal, add some comments
This commit is contained in:
parent
c8a9a5eafe
commit
cf19665533
@ -109,6 +109,7 @@ func (e *SignedEnvelope) Payload() []byte {
|
|||||||
return e.payload
|
return e.payload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marshal returns a byte slice containing a serailized protobuf representation of a SignedEnvelope.
|
||||||
func (e *SignedEnvelope) Marshal() ([]byte, error) {
|
func (e *SignedEnvelope) Marshal() ([]byte, error) {
|
||||||
key, err := PublicKeyToProto(e.publicKey)
|
key, err := PublicKeyToProto(e.publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,7 +124,10 @@ func (e *SignedEnvelope) Marshal() ([]byte, error) {
|
|||||||
return proto.Marshal(&msg)
|
return proto.Marshal(&msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SignedEnvelope) Equals(other *SignedEnvelope) bool {
|
// Equal returns true if the other SignedEnvelope has the same
|
||||||
|
// public key, payload, payload type, and signature. This
|
||||||
|
// implies that they were also created with the same domain string.
|
||||||
|
func (e *SignedEnvelope) Equal(other *SignedEnvelope) bool {
|
||||||
return e.publicKey.Equals(other.publicKey) &&
|
return e.publicKey.Equals(other.publicKey) &&
|
||||||
bytes.Compare(e.payloadType, other.payloadType) == 0 &&
|
bytes.Compare(e.payloadType, other.payloadType) == 0 &&
|
||||||
bytes.Compare(e.payload, other.payload) == 0 &&
|
bytes.Compare(e.payload, other.payload) == 0 &&
|
||||||
|
@ -45,7 +45,7 @@ func TestEnvelopeHappyPath(t *testing.T) {
|
|||||||
t.Error("payload of envelope does not match input")
|
t.Error("payload of envelope does not match input")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !envelope.Equals(deserialized) {
|
if !envelope.Equal(deserialized) {
|
||||||
t.Error("round-trip serde results in unequal envelope structures")
|
t.Error("round-trip serde results in unequal envelope structures")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ type AddrBook interface {
|
|||||||
|
|
||||||
// AddCertifiedAddrs adds addresses from a routing.RoutingState record
|
// AddCertifiedAddrs adds addresses from a routing.RoutingState record
|
||||||
// contained in a serialized SignedEnvelope.
|
// contained in a serialized SignedEnvelope.
|
||||||
AddCertifiedAddrs(envelopeBytes []byte, ttl time.Duration) error
|
AddCertifiedAddrs(envelope []byte, ttl time.Duration) error
|
||||||
|
|
||||||
// SetAddr calls mgr.SetAddrs(p, addr, ttl)
|
// SetAddr calls mgr.SetAddrs(p, addr, ttl)
|
||||||
SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)
|
SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)
|
||||||
|
Loading…
Reference in New Issue
Block a user