From 62b9a38323c8d237a2eeb46d0cf2f24596f63f1e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 28 Oct 2019 15:32:22 -0700 Subject: [PATCH] chore(dep): update deps * update go-libp2p-core and fix tests for new minimum key size. This slows down the test but terribly. * switch to go-multiaddr-fmt * update the datastore * update gogo/protobuf --- p2p/host/peerstore/addr/sorting.go | 2 +- p2p/host/peerstore/pb/pstore.pb.go | 170 ++++++++++----------- p2p/host/peerstore/test/keybook_suite.go | 57 ++++--- p2p/host/peerstore/test/peerstore_suite.go | 20 ++- 4 files changed, 128 insertions(+), 121 deletions(-) diff --git a/p2p/host/peerstore/addr/sorting.go b/p2p/host/peerstore/addr/sorting.go index f8a89150a2..5c7c6c3a3d 100644 --- a/p2p/host/peerstore/addr/sorting.go +++ b/p2p/host/peerstore/addr/sorting.go @@ -4,8 +4,8 @@ import ( "bytes" ma "github.com/multiformats/go-multiaddr" + mafmt "github.com/multiformats/go-multiaddr-fmt" manet "github.com/multiformats/go-multiaddr-net" - mafmt "github.com/whyrusleeping/mafmt" ) func isFDCostlyTransport(a ma.Multiaddr) bool { diff --git a/p2p/host/peerstore/pb/pstore.pb.go b/p2p/host/peerstore/pb/pstore.pb.go index c80958cce5..c3dbaeb344 100644 --- a/p2p/host/peerstore/pb/pstore.pb.go +++ b/p2p/host/peerstore/pb/pstore.pb.go @@ -9,6 +9,7 @@ import ( proto "github.com/gogo/protobuf/proto" io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -20,7 +21,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // AddrBookRecord represents a record for a peer in the address book. type AddrBookRecord struct { @@ -44,7 +45,7 @@ func (m *AddrBookRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return xxx_messageInfo_AddrBookRecord.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -93,7 +94,7 @@ func (m *AddrBookRecord_AddrEntry) XXX_Marshal(b []byte, deterministic bool) ([] return xxx_messageInfo_AddrBookRecord_AddrEntry.Marshal(b, m, deterministic) } else { b = b[:cap(b)] - n, err := m.MarshalTo(b) + n, err := m.MarshalToSizedBuffer(b) if err != nil { return nil, err } @@ -156,7 +157,7 @@ var fileDescriptor_f96873690e08a98f = []byte{ func (m *AddrBookRecord) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -164,39 +165,48 @@ func (m *AddrBookRecord) Marshal() (dAtA []byte, err error) { } func (m *AddrBookRecord) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddrBookRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Id != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintPstore(dAtA, i, uint64(m.Id.Size())) - n1, err := m.Id.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } if len(m.Addrs) > 0 { - for _, msg := range m.Addrs { + for iNdEx := len(m.Addrs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Addrs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPstore(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0x12 - i++ - i = encodeVarintPstore(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { + } + } + if m.Id != nil { + { + size := m.Id.Size() + i -= size + if _, err := m.Id.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i += n + i = encodeVarintPstore(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *AddrBookRecord_AddrEntry) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -204,46 +214,55 @@ func (m *AddrBookRecord_AddrEntry) Marshal() (dAtA []byte, err error) { } func (m *AddrBookRecord_AddrEntry) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddrBookRecord_AddrEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Addr != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintPstore(dAtA, i, uint64(m.Addr.Size())) - n2, err := m.Addr.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 + if m.Ttl != 0 { + i = encodeVarintPstore(dAtA, i, uint64(m.Ttl)) + i-- + dAtA[i] = 0x18 } if m.Expiry != 0 { - dAtA[i] = 0x10 - i++ i = encodeVarintPstore(dAtA, i, uint64(m.Expiry)) + i-- + dAtA[i] = 0x10 } - if m.Ttl != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintPstore(dAtA, i, uint64(m.Ttl)) + if m.Addr != nil { + { + size := m.Addr.Size() + i -= size + if _, err := m.Addr.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPstore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func encodeVarintPstore(dAtA []byte, offset int, v uint64) int { + offset -= sovPstore(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func NewPopulatedAddrBookRecord(r randyPstore, easy bool) *AddrBookRecord { this := &AddrBookRecord{} this.Id = NewPopulatedProtoPeerID(r) - if r.Intn(10) != 0 { + if r.Intn(5) != 0 { v1 := r.Intn(5) this.Addrs = make([]*AddrBookRecord_AddrEntry, v1) for i := 0; i < v1; i++ { @@ -382,14 +401,7 @@ func (m *AddrBookRecord_AddrEntry) Size() (n int) { } func sovPstore(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozPstore(x uint64) (n int) { return sovPstore(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -645,6 +657,7 @@ func (m *AddrBookRecord_AddrEntry) Unmarshal(dAtA []byte) error { func skipPstore(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -676,10 +689,8 @@ func skipPstore(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -700,55 +711,30 @@ func skipPstore(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthPstore } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthPstore - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPstore - } - if iNdEx >= l { - 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 := skipPstore(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthPstore - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPstore + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthPstore + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthPstore = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPstore = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthPstore = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPstore = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPstore = fmt.Errorf("proto: unexpected end of group") ) diff --git a/p2p/host/peerstore/test/keybook_suite.go b/p2p/host/peerstore/test/keybook_suite.go index c8dbc268bb..ec6d9362cb 100644 --- a/p2p/host/peerstore/test/keybook_suite.go +++ b/p2p/host/peerstore/test/keybook_suite.go @@ -41,9 +41,9 @@ func testKeybookPrivKey(kb pstore.KeyBook) func(t *testing.T) { t.Error("expected peers to be empty on init") } - priv, _, err := pt.RandTestKeyPair(ic.RSA, 512) + priv, _, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - t.Error(err) + t.Fatal(err) } id, err := peer.IDFromPrivateKey(priv) @@ -76,14 +76,14 @@ func testKeyBookPubKey(kb pstore.KeyBook) func(t *testing.T) { t.Error("expected peers to be empty on init") } - _, pub, err := pt.RandTestKeyPair(ic.RSA, 512) + _, pub, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - t.Error(err) + t.Fatal(err) } id, err := peer.IDFromPublicKey(pub) if err != nil { - t.Error(err) + t.Fatal(err) } if res := kb.PubKey(id); res != nil { @@ -114,13 +114,22 @@ func testKeyBookPeers(kb pstore.KeyBook) func(t *testing.T) { var peers peer.IDSlice for i := 0; i < 10; i++ { // Add a public key. - _, pub, _ := pt.RandTestKeyPair(ic.RSA, 512) - p1, _ := peer.IDFromPublicKey(pub) + _, pub, err := pt.RandTestKeyPair(ic.RSA, 2048) + if err != nil { + t.Fatal(err) + } + p1, err := peer.IDFromPublicKey(pub) + if err != nil { + t.Fatal(err) + } kb.AddPubKey(p1, pub) // Add a private key. - priv, _, _ := pt.RandTestKeyPair(ic.RSA, 512) - p2, _ := peer.IDFromPrivateKey(priv) + priv, _, err := pt.RandTestKeyPair(ic.RSA, 2048) + p2, err := peer.IDFromPrivateKey(priv) + if err != nil { + t.Fatal(err) + } kb.AddPrivKey(p2, priv) peers = append(peers, []peer.ID{p1, p2}...) @@ -192,14 +201,14 @@ func BenchmarkKeyBook(b *testing.B, factory KeyBookFactory) { func benchmarkPubKey(kb pstore.KeyBook) func(*testing.B) { return func(b *testing.B) { - _, pub, err := pt.RandTestKeyPair(ic.RSA, 512) + _, pub, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - b.Error(err) + b.Fatal(err) } id, err := peer.IDFromPublicKey(pub) if err != nil { - b.Error(err) + b.Fatal(err) } err = kb.AddPubKey(id, pub) @@ -216,14 +225,14 @@ func benchmarkPubKey(kb pstore.KeyBook) func(*testing.B) { func benchmarkAddPubKey(kb pstore.KeyBook) func(*testing.B) { return func(b *testing.B) { - _, pub, err := pt.RandTestKeyPair(ic.RSA, 512) + _, pub, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - b.Error(err) + b.Fatal(err) } id, err := peer.IDFromPublicKey(pub) if err != nil { - b.Error(err) + b.Fatal(err) } b.ResetTimer() @@ -235,14 +244,14 @@ func benchmarkAddPubKey(kb pstore.KeyBook) func(*testing.B) { func benchmarkPrivKey(kb pstore.KeyBook) func(*testing.B) { return func(b *testing.B) { - priv, _, err := pt.RandTestKeyPair(ic.RSA, 512) + priv, _, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - b.Error(err) + b.Fatal(err) } id, err := peer.IDFromPrivateKey(priv) if err != nil { - b.Error(err) + b.Fatal(err) } err = kb.AddPrivKey(id, priv) @@ -259,14 +268,14 @@ func benchmarkPrivKey(kb pstore.KeyBook) func(*testing.B) { func benchmarkAddPrivKey(kb pstore.KeyBook) func(*testing.B) { return func(b *testing.B) { - priv, _, err := pt.RandTestKeyPair(ic.RSA, 512) + priv, _, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - b.Error(err) + b.Fatal(err) } id, err := peer.IDFromPrivateKey(priv) if err != nil { - b.Error(err) + b.Fatal(err) } b.ResetTimer() @@ -279,14 +288,14 @@ func benchmarkAddPrivKey(kb pstore.KeyBook) func(*testing.B) { func benchmarkPeersWithKeys(kb pstore.KeyBook) func(*testing.B) { return func(b *testing.B) { for i := 0; i < 10; i++ { - priv, pub, err := pt.RandTestKeyPair(ic.RSA, 512) + priv, pub, err := pt.RandTestKeyPair(ic.RSA, 2048) if err != nil { - b.Error(err) + b.Fatal(err) } id, err := peer.IDFromPublicKey(pub) if err != nil { - b.Error(err) + b.Fatal(err) } err = kb.AddPubKey(id, pub) diff --git a/p2p/host/peerstore/test/peerstore_suite.go b/p2p/host/peerstore/test/peerstore_suite.go index fb4a813769..a0ae326c9a 100644 --- a/p2p/host/peerstore/test/peerstore_suite.go +++ b/p2p/host/peerstore/test/peerstore_suite.go @@ -287,8 +287,14 @@ func testBasicPeerstore(ps pstore.Peerstore) func(t *testing.T) { addrs := getAddrs(t, 10) for _, a := range addrs { - priv, _, _ := crypto.GenerateKeyPair(crypto.RSA, 512) - p, _ := peer.IDFromPrivateKey(priv) + priv, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048) + if err != nil { + t.Fatal(err) + } + p, err := peer.IDFromPrivateKey(priv) + if err != nil { + t.Fatal(err) + } pids = append(pids, p) ps.AddAddr(p, a, pstore.PermanentAddrTTL) } @@ -309,8 +315,14 @@ func testMetadata(ps pstore.Peerstore) func(t *testing.T) { return func(t *testing.T) { pids := make([]peer.ID, 10) for i := range pids { - priv, _, _ := crypto.GenerateKeyPair(crypto.RSA, 512) - p, _ := peer.IDFromPrivateKey(priv) + priv, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048) + if err != nil { + t.Fatal(err) + } + p, err := peer.IDFromPrivateKey(priv) + if err != nil { + t.Fatal(err) + } pids[i] = p } for _, p := range pids {