mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2024-12-27 23:40:11 +08:00
move protobuf files; adjust imports everywhere.
This commit is contained in:
parent
9a771f9d94
commit
d17a62c365
@ -4,7 +4,7 @@ GO = $(PB:.proto=.pb.go)
|
|||||||
all: $(GO)
|
all: $(GO)
|
||||||
|
|
||||||
%.pb.go: %.proto
|
%.pb.go: %.proto
|
||||||
protoc --proto_path=$(GOPATH)/src:. --gogofaster_out=. $<
|
protoc --proto_path=$(PWD)/../..:. --gogofaster_out=. $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.pb.go
|
rm -f *.pb.go
|
||||||
|
@ -2,6 +2,8 @@ syntax = "proto2";
|
|||||||
|
|
||||||
package crypto.pb;
|
package crypto.pb;
|
||||||
|
|
||||||
|
option go_package = "github.com/libp2p/go-libp2p-core/crypto/pb";
|
||||||
|
|
||||||
enum KeyType {
|
enum KeyType {
|
||||||
RSA = 0;
|
RSA = 0;
|
||||||
Ed25519 = 1;
|
Ed25519 = 1;
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
pool "github.com/libp2p/go-buffer-pool"
|
pool "github.com/libp2p/go-buffer-pool"
|
||||||
"github.com/libp2p/go-libp2p-core/crypto"
|
"github.com/libp2p/go-libp2p-core/crypto"
|
||||||
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
|
pb "github.com/libp2p/go-libp2p-core/record/pb"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/multiformats/go-varint"
|
"github.com/multiformats/go-varint"
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package record
|
package record_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
|
|
||||||
. "github.com/libp2p/go-libp2p-core/crypto"
|
|
||||||
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
|
|
||||||
"github.com/libp2p/go-libp2p-core/test"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
crypto "github.com/libp2p/go-libp2p-core/crypto"
|
||||||
|
. "github.com/libp2p/go-libp2p-core/record"
|
||||||
|
pb "github.com/libp2p/go-libp2p-core/record/pb"
|
||||||
|
"github.com/libp2p/go-libp2p-core/test"
|
||||||
|
|
||||||
|
"github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Make an envelope, verify & open it, marshal & unmarshal it
|
// Make an envelope, verify & open it, marshal & unmarshal it
|
||||||
@ -16,7 +18,7 @@ func TestEnvelopeHappyPath(t *testing.T) {
|
|||||||
payload = []byte("happy hacking")
|
payload = []byte("happy hacking")
|
||||||
domain = "libp2p-testing"
|
domain = "libp2p-testing"
|
||||||
payloadType = []byte("/libp2p/testdata")
|
payloadType = []byte("/libp2p/testdata")
|
||||||
priv, pub, err = test.RandTestKeyPair(Ed25519, 256)
|
priv, pub, err = test.RandTestKeyPair(crypto.Ed25519, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
test.AssertNilError(t, err)
|
test.AssertNilError(t, err)
|
||||||
@ -51,7 +53,7 @@ func TestMakeEnvelopeFailsWithEmptyDomain(t *testing.T) {
|
|||||||
var (
|
var (
|
||||||
payload = []byte("happy hacking")
|
payload = []byte("happy hacking")
|
||||||
payloadType = []byte("/libp2p/testdata")
|
payloadType = []byte("/libp2p/testdata")
|
||||||
priv, _, err = test.RandTestKeyPair(Ed25519, 256)
|
priv, _, err = test.RandTestKeyPair(crypto.Ed25519, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -67,7 +69,7 @@ func TestEnvelopeValidateFailsForDifferentDomain(t *testing.T) {
|
|||||||
payload = []byte("happy hacking")
|
payload = []byte("happy hacking")
|
||||||
domain = "libp2p-testing"
|
domain = "libp2p-testing"
|
||||||
payloadType = []byte("/libp2p/testdata")
|
payloadType = []byte("/libp2p/testdata")
|
||||||
priv, _, err = test.RandTestKeyPair(Ed25519, 256)
|
priv, _, err = test.RandTestKeyPair(crypto.Ed25519, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
test.AssertNilError(t, err)
|
test.AssertNilError(t, err)
|
||||||
@ -87,7 +89,7 @@ func TestEnvelopeValidateFailsIfTypeHintIsAltered(t *testing.T) {
|
|||||||
payload = []byte("happy hacking")
|
payload = []byte("happy hacking")
|
||||||
domain = "libp2p-testing"
|
domain = "libp2p-testing"
|
||||||
payloadType = []byte("/libp2p/testdata")
|
payloadType = []byte("/libp2p/testdata")
|
||||||
priv, _, err = test.RandTestKeyPair(Ed25519, 256)
|
priv, _, err = test.RandTestKeyPair(crypto.Ed25519, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
test.AssertNilError(t, err)
|
test.AssertNilError(t, err)
|
||||||
@ -109,7 +111,7 @@ func TestEnvelopeValidateFailsIfContentsAreAltered(t *testing.T) {
|
|||||||
payload = []byte("happy hacking")
|
payload = []byte("happy hacking")
|
||||||
domain = "libp2p-testing"
|
domain = "libp2p-testing"
|
||||||
payloadType = []byte("/libp2p/testdata")
|
payloadType = []byte("/libp2p/testdata")
|
||||||
priv, _, err = test.RandTestKeyPair(Ed25519, 256)
|
priv, _, err = test.RandTestKeyPair(crypto.Ed25519, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
test.AssertNilError(t, err)
|
test.AssertNilError(t, err)
|
||||||
|
11
record/pb/Makefile
Normal file
11
record/pb/Makefile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
PB = $(wildcard *.proto)
|
||||||
|
GO = $(PB:.proto=.pb.go)
|
||||||
|
|
||||||
|
all: $(GO)
|
||||||
|
|
||||||
|
%.pb.go: %.proto
|
||||||
|
protoc --proto_path=$(PWD):$(PWD)/../.. --gogofaster_out=. $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.pb.go
|
||||||
|
rm -f *.go
|
@ -1,14 +1,14 @@
|
|||||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: envelope.proto
|
// source: envelope.proto
|
||||||
|
|
||||||
package crypto_pb
|
package record_pb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
proto "github.com/gogo/protobuf/proto"
|
proto "github.com/gogo/protobuf/proto"
|
||||||
|
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
|
||||||
io "io"
|
io "io"
|
||||||
math "math"
|
math "math"
|
||||||
math_bits "math/bits"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
@ -20,10 +20,10 @@ var _ = math.Inf
|
|||||||
// is compatible with the proto package it is being compiled against.
|
// is compatible with the proto package it is being compiled against.
|
||||||
// A compilation error at this line likely means your copy of the
|
// A compilation error at this line likely means your copy of the
|
||||||
// proto package needs to be updated.
|
// proto package needs to be updated.
|
||||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
type SignedEnvelope struct {
|
type SignedEnvelope struct {
|
||||||
PublicKey *PublicKey `protobuf:"bytes,1,opt,name=publicKey,proto3" json:"publicKey,omitempty"`
|
PublicKey *pb.PublicKey `protobuf:"bytes,1,opt,name=publicKey,proto3" json:"publicKey,omitempty"`
|
||||||
PayloadType []byte `protobuf:"bytes,2,opt,name=payloadType,proto3" json:"payloadType,omitempty"`
|
PayloadType []byte `protobuf:"bytes,2,opt,name=payloadType,proto3" json:"payloadType,omitempty"`
|
||||||
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
|
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
|
||||||
Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
|
Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||||
@ -43,7 +43,7 @@ func (m *SignedEnvelope) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro
|
|||||||
return xxx_messageInfo_SignedEnvelope.Marshal(b, m, deterministic)
|
return xxx_messageInfo_SignedEnvelope.Marshal(b, m, deterministic)
|
||||||
} else {
|
} else {
|
||||||
b = b[:cap(b)]
|
b = b[:cap(b)]
|
||||||
n, err := m.MarshalToSizedBuffer(b)
|
n, err := m.MarshalTo(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ func (m *SignedEnvelope) XXX_DiscardUnknown() {
|
|||||||
|
|
||||||
var xxx_messageInfo_SignedEnvelope proto.InternalMessageInfo
|
var xxx_messageInfo_SignedEnvelope proto.InternalMessageInfo
|
||||||
|
|
||||||
func (m *SignedEnvelope) GetPublicKey() *PublicKey {
|
func (m *SignedEnvelope) GetPublicKey() *pb.PublicKey {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
return m.PublicKey
|
return m.PublicKey
|
||||||
}
|
}
|
||||||
@ -91,31 +91,32 @@ func (m *SignedEnvelope) GetSignature() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*SignedEnvelope)(nil), "crypto.pb.SignedEnvelope")
|
proto.RegisterType((*SignedEnvelope)(nil), "record.pb.SignedEnvelope")
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { proto.RegisterFile("envelope.proto", fileDescriptor_ee266e8c558e9dc5) }
|
func init() { proto.RegisterFile("envelope.proto", fileDescriptor_ee266e8c558e9dc5) }
|
||||||
|
|
||||||
var fileDescriptor_ee266e8c558e9dc5 = []byte{
|
var fileDescriptor_ee266e8c558e9dc5 = []byte{
|
||||||
// 189 bytes of a gzipped FileDescriptorProto
|
// 200 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0xcd, 0x2b, 0x4b,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0xcd, 0x2b, 0x4b,
|
||||||
0xcd, 0xc9, 0x2f, 0x48, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4c, 0x2e, 0xaa, 0x2c,
|
0xcd, 0xc9, 0x2f, 0x48, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x2c, 0x4a, 0x4d, 0xce,
|
||||||
0x28, 0xc9, 0xd7, 0x2b, 0x48, 0x92, 0xe2, 0x81, 0x31, 0x41, 0x12, 0x4a, 0xf3, 0x18, 0xb9, 0xf8,
|
0x2f, 0x4a, 0xd1, 0x2b, 0x48, 0x92, 0x12, 0x4b, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0x2f, 0x48,
|
||||||
0x82, 0x33, 0xd3, 0xf3, 0x52, 0x53, 0x5c, 0xa1, 0x3a, 0x84, 0x8c, 0xb8, 0x38, 0x0b, 0x4a, 0x93,
|
0xd2, 0x87, 0xb0, 0x20, 0x4a, 0x94, 0xe6, 0x31, 0x72, 0xf1, 0x05, 0x67, 0xa6, 0xe7, 0xa5, 0xa6,
|
||||||
0x72, 0x32, 0x93, 0xbd, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, 0xf4, 0xe0,
|
0xb8, 0x42, 0xf5, 0x0a, 0x19, 0x71, 0x71, 0x16, 0x94, 0x26, 0xe5, 0x64, 0x26, 0x7b, 0xa7, 0x56,
|
||||||
0xfa, 0xf5, 0x02, 0x60, 0x72, 0x41, 0x08, 0x65, 0x42, 0x0a, 0x5c, 0xdc, 0x05, 0x89, 0x95, 0x39,
|
0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x89, 0xe8, 0xc1, 0x34, 0x25, 0xe9, 0x05, 0xc0, 0xe4,
|
||||||
0xf9, 0x89, 0x29, 0x21, 0x95, 0x05, 0xa9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0xc8, 0x42,
|
0x82, 0x10, 0xca, 0x84, 0x14, 0xb8, 0xb8, 0x0b, 0x12, 0x2b, 0x73, 0xf2, 0x13, 0x53, 0x42, 0x2a,
|
||||||
0x42, 0x12, 0x5c, 0xec, 0x50, 0xae, 0x04, 0x33, 0x58, 0x16, 0xc6, 0x15, 0x92, 0xe1, 0xe2, 0x2c,
|
0x0b, 0x52, 0x25, 0x98, 0x14, 0x18, 0x35, 0x78, 0x82, 0x90, 0x85, 0x84, 0x24, 0xb8, 0xd8, 0xa1,
|
||||||
0xce, 0x4c, 0xcf, 0x4b, 0x2c, 0x29, 0x2d, 0x4a, 0x95, 0x60, 0x01, 0xcb, 0x21, 0x04, 0x9c, 0x24,
|
0x5c, 0x09, 0x66, 0xb0, 0x2c, 0x8c, 0x2b, 0x24, 0xc3, 0xc5, 0x59, 0x9c, 0x99, 0x9e, 0x97, 0x58,
|
||||||
0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5,
|
0x52, 0x5a, 0x94, 0x2a, 0xc1, 0x02, 0x96, 0x43, 0x08, 0x38, 0x49, 0x9c, 0x78, 0x24, 0xc7, 0x78,
|
||||||
0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x89, 0x0d, 0xec, 0x03, 0x63, 0x40,
|
0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7,
|
||||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0xd3, 0xde, 0xe5, 0xec, 0x00, 0x00, 0x00,
|
0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x12, 0x1b, 0xd8, 0x07, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||||
|
0xfb, 0xd0, 0x77, 0x21, 0xf6, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SignedEnvelope) Marshal() (dAtA []byte, err error) {
|
func (m *SignedEnvelope) Marshal() (dAtA []byte, err error) {
|
||||||
size := m.Size()
|
size := m.Size()
|
||||||
dAtA = make([]byte, size)
|
dAtA = make([]byte, size)
|
||||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
n, err := m.MarshalTo(dAtA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -123,61 +124,49 @@ func (m *SignedEnvelope) Marshal() (dAtA []byte, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *SignedEnvelope) MarshalTo(dAtA []byte) (int, error) {
|
func (m *SignedEnvelope) MarshalTo(dAtA []byte) (int, error) {
|
||||||
size := m.Size()
|
var i int
|
||||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SignedEnvelope) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|
||||||
i := len(dAtA)
|
|
||||||
_ = i
|
_ = i
|
||||||
var l int
|
var l int
|
||||||
_ = l
|
_ = l
|
||||||
if len(m.Signature) > 0 {
|
|
||||||
i -= len(m.Signature)
|
|
||||||
copy(dAtA[i:], m.Signature)
|
|
||||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Signature)))
|
|
||||||
i--
|
|
||||||
dAtA[i] = 0x22
|
|
||||||
}
|
|
||||||
if len(m.Payload) > 0 {
|
|
||||||
i -= len(m.Payload)
|
|
||||||
copy(dAtA[i:], m.Payload)
|
|
||||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Payload)))
|
|
||||||
i--
|
|
||||||
dAtA[i] = 0x1a
|
|
||||||
}
|
|
||||||
if len(m.PayloadType) > 0 {
|
|
||||||
i -= len(m.PayloadType)
|
|
||||||
copy(dAtA[i:], m.PayloadType)
|
|
||||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.PayloadType)))
|
|
||||||
i--
|
|
||||||
dAtA[i] = 0x12
|
|
||||||
}
|
|
||||||
if m.PublicKey != nil {
|
if m.PublicKey != nil {
|
||||||
{
|
dAtA[i] = 0xa
|
||||||
size, err := m.PublicKey.MarshalToSizedBuffer(dAtA[:i])
|
i++
|
||||||
|
i = encodeVarintEnvelope(dAtA, i, uint64(m.PublicKey.Size()))
|
||||||
|
n1, err := m.PublicKey.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i -= size
|
i += n1
|
||||||
i = encodeVarintEnvelope(dAtA, i, uint64(size))
|
|
||||||
}
|
}
|
||||||
i--
|
if len(m.PayloadType) > 0 {
|
||||||
dAtA[i] = 0xa
|
dAtA[i] = 0x12
|
||||||
|
i++
|
||||||
|
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.PayloadType)))
|
||||||
|
i += copy(dAtA[i:], m.PayloadType)
|
||||||
}
|
}
|
||||||
return len(dAtA) - i, nil
|
if len(m.Payload) > 0 {
|
||||||
|
dAtA[i] = 0x1a
|
||||||
|
i++
|
||||||
|
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Payload)))
|
||||||
|
i += copy(dAtA[i:], m.Payload)
|
||||||
|
}
|
||||||
|
if len(m.Signature) > 0 {
|
||||||
|
dAtA[i] = 0x22
|
||||||
|
i++
|
||||||
|
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Signature)))
|
||||||
|
i += copy(dAtA[i:], m.Signature)
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeVarintEnvelope(dAtA []byte, offset int, v uint64) int {
|
func encodeVarintEnvelope(dAtA []byte, offset int, v uint64) int {
|
||||||
offset -= sovEnvelope(v)
|
|
||||||
base := offset
|
|
||||||
for v >= 1<<7 {
|
for v >= 1<<7 {
|
||||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||||
v >>= 7
|
v >>= 7
|
||||||
offset++
|
offset++
|
||||||
}
|
}
|
||||||
dAtA[offset] = uint8(v)
|
dAtA[offset] = uint8(v)
|
||||||
return base
|
return offset + 1
|
||||||
}
|
}
|
||||||
func (m *SignedEnvelope) Size() (n int) {
|
func (m *SignedEnvelope) Size() (n int) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
@ -205,7 +194,14 @@ func (m *SignedEnvelope) Size() (n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sovEnvelope(x uint64) (n int) {
|
func sovEnvelope(x uint64) (n int) {
|
||||||
return (math_bits.Len64(x|1) + 6) / 7
|
for {
|
||||||
|
n++
|
||||||
|
x >>= 7
|
||||||
|
if x == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
func sozEnvelope(x uint64) (n int) {
|
func sozEnvelope(x uint64) (n int) {
|
||||||
return sovEnvelope(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
return sovEnvelope(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||||
@ -269,7 +265,7 @@ func (m *SignedEnvelope) Unmarshal(dAtA []byte) error {
|
|||||||
return io.ErrUnexpectedEOF
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
if m.PublicKey == nil {
|
if m.PublicKey == nil {
|
||||||
m.PublicKey = &PublicKey{}
|
m.PublicKey = &pb.PublicKey{}
|
||||||
}
|
}
|
||||||
if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -404,7 +400,6 @@ func (m *SignedEnvelope) Unmarshal(dAtA []byte) error {
|
|||||||
func skipEnvelope(dAtA []byte) (n int, err error) {
|
func skipEnvelope(dAtA []byte) (n int, err error) {
|
||||||
l := len(dAtA)
|
l := len(dAtA)
|
||||||
iNdEx := 0
|
iNdEx := 0
|
||||||
depth := 0
|
|
||||||
for iNdEx < l {
|
for iNdEx < l {
|
||||||
var wire uint64
|
var wire uint64
|
||||||
for shift := uint(0); ; shift += 7 {
|
for shift := uint(0); ; shift += 7 {
|
||||||
@ -436,8 +431,10 @@ func skipEnvelope(dAtA []byte) (n int, err error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return iNdEx, nil
|
||||||
case 1:
|
case 1:
|
||||||
iNdEx += 8
|
iNdEx += 8
|
||||||
|
return iNdEx, nil
|
||||||
case 2:
|
case 2:
|
||||||
var length int
|
var length int
|
||||||
for shift := uint(0); ; shift += 7 {
|
for shift := uint(0); ; shift += 7 {
|
||||||
@ -458,30 +455,55 @@ func skipEnvelope(dAtA []byte) (n int, err error) {
|
|||||||
return 0, ErrInvalidLengthEnvelope
|
return 0, ErrInvalidLengthEnvelope
|
||||||
}
|
}
|
||||||
iNdEx += length
|
iNdEx += length
|
||||||
case 3:
|
|
||||||
depth++
|
|
||||||
case 4:
|
|
||||||
if depth == 0 {
|
|
||||||
return 0, ErrUnexpectedEndOfGroupEnvelope
|
|
||||||
}
|
|
||||||
depth--
|
|
||||||
case 5:
|
|
||||||
iNdEx += 4
|
|
||||||
default:
|
|
||||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
|
||||||
}
|
|
||||||
if iNdEx < 0 {
|
if iNdEx < 0 {
|
||||||
return 0, ErrInvalidLengthEnvelope
|
return 0, ErrInvalidLengthEnvelope
|
||||||
}
|
}
|
||||||
if depth == 0 {
|
|
||||||
return iNdEx, nil
|
return iNdEx, nil
|
||||||
|
case 3:
|
||||||
|
for {
|
||||||
|
var innerWire uint64
|
||||||
|
var start int = iNdEx
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowEnvelope
|
||||||
}
|
}
|
||||||
}
|
if iNdEx >= l {
|
||||||
return 0, io.ErrUnexpectedEOF
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
innerWire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
innerWireType := int(innerWire & 0x7)
|
||||||
|
if innerWireType == 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
next, err := skipEnvelope(dAtA[start:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
iNdEx = start + next
|
||||||
|
if iNdEx < 0 {
|
||||||
|
return 0, ErrInvalidLengthEnvelope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 4:
|
||||||
|
return iNdEx, nil
|
||||||
|
case 5:
|
||||||
|
iNdEx += 4
|
||||||
|
return iNdEx, nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidLengthEnvelope = fmt.Errorf("proto: negative length found during unmarshaling")
|
ErrInvalidLengthEnvelope = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||||
ErrIntOverflowEnvelope = fmt.Errorf("proto: integer overflow")
|
ErrIntOverflowEnvelope = fmt.Errorf("proto: integer overflow")
|
||||||
ErrUnexpectedEndOfGroupEnvelope = fmt.Errorf("proto: unexpected end of group")
|
|
||||||
)
|
)
|
@ -1,11 +1,11 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
package crypto.pb;
|
package record.pb;
|
||||||
|
|
||||||
import "crypto.proto";
|
import "crypto/pb/crypto.proto";
|
||||||
|
|
||||||
message SignedEnvelope {
|
message SignedEnvelope {
|
||||||
PublicKey publicKey = 1;
|
crypto.pb.PublicKey publicKey = 1;
|
||||||
bytes payloadType = 2;
|
bytes payloadType = 2;
|
||||||
bytes payload = 3;
|
bytes payload = 3;
|
||||||
bytes signature = 4;
|
bytes signature = 4;
|
@ -2,12 +2,14 @@ package routing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/libp2p/go-libp2p-core/crypto"
|
"github.com/libp2p/go-libp2p-core/crypto"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
"github.com/libp2p/go-libp2p-core/record"
|
||||||
pb "github.com/libp2p/go-libp2p-core/routing/pb"
|
pb "github.com/libp2p/go-libp2p-core/routing/pb"
|
||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The domain string used for routing state records contained in a SignedEnvelope.
|
// The domain string used for routing state records contained in a SignedEnvelope.
|
||||||
@ -29,7 +31,7 @@ type SignedRoutingState struct {
|
|||||||
|
|
||||||
// Envelope contains the signature and serialized RoutingStateRecord protobuf.
|
// Envelope contains the signature and serialized RoutingStateRecord protobuf.
|
||||||
// Although it uses a bit
|
// Although it uses a bit
|
||||||
Envelope *crypto.SignedEnvelope
|
Envelope *record.SignedEnvelope
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeSignedRoutingState returns a SignedRoutingState record containing the given multiaddrs,
|
// MakeSignedRoutingState returns a SignedRoutingState record containing the given multiaddrs,
|
||||||
@ -54,7 +56,7 @@ func MakeSignedRoutingState(privKey crypto.PrivKey, addrs []ma.Multiaddr) (*Sign
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
envelope, err := crypto.MakeEnvelope(privKey, StateEnvelopeDomain, StateEnvelopePayloadType, payload)
|
envelope, err := record.MakeEnvelope(privKey, StateEnvelopeDomain, StateEnvelopePayloadType, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -71,7 +73,7 @@ func MakeSignedRoutingState(privKey crypto.PrivKey, addrs []ma.Multiaddr) (*Sign
|
|||||||
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
||||||
// if deserialization of the envelope or its inner payload fails.
|
// if deserialization of the envelope or its inner payload fails.
|
||||||
func UnmarshalSignedRoutingState(envelopeBytes []byte) (*SignedRoutingState, error) {
|
func UnmarshalSignedRoutingState(envelopeBytes []byte) (*SignedRoutingState, error) {
|
||||||
envelope, err := crypto.OpenEnvelope(envelopeBytes, StateEnvelopeDomain)
|
envelope, err := record.ConsumeEnvelope(envelopeBytes, StateEnvelopeDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ func UnmarshalSignedRoutingState(envelopeBytes []byte) (*SignedRoutingState, err
|
|||||||
// a RoutingStateRecord protobuf and returns a SignedRoutingState record.
|
// a RoutingStateRecord protobuf and returns a SignedRoutingState record.
|
||||||
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
||||||
// or if deserialization of the envelope payload fails.
|
// or if deserialization of the envelope payload fails.
|
||||||
func SignedRoutingStateFromEnvelope(envelope *crypto.SignedEnvelope) (*SignedRoutingState, error) {
|
func SignedRoutingStateFromEnvelope(envelope *record.SignedEnvelope) (*SignedRoutingState, error) {
|
||||||
var msg pb.RoutingStateRecord
|
var msg pb.RoutingStateRecord
|
||||||
err := proto.Unmarshal(envelope.Payload, &msg)
|
err := proto.Unmarshal(envelope.Payload, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user