diff --git a/examples/chat/chat.go b/examples/chat/chat.go index fc4c55f656..f5d3c11404 100644 --- a/examples/chat/chat.go +++ b/examples/chat/chat.go @@ -144,10 +144,8 @@ func main() { } - // Wait until canceled - select { - case <-ctx.Done(): - } + // Wait forever + select {} } func makeHost(ctx context.Context, port int, randomness io.Reader) (host.Host, error) { diff --git a/examples/chat/chat_test.go b/examples/chat/chat_test.go index c5faa7f499..a63ddd74dd 100644 --- a/examples/chat/chat_test.go +++ b/examples/chat/chat_test.go @@ -65,8 +65,6 @@ func TestMain(t *testing.T) { rw.Flush() }() - select { - case <-ctx.Done(): - } + <-ctx.Done() }) } diff --git a/examples/echo/main.go b/examples/echo/main.go index c3e163c500..396cf2cc11 100644 --- a/examples/echo/main.go +++ b/examples/echo/main.go @@ -120,9 +120,7 @@ func runListener(ctx context.Context, ha host.Host, listenPort int, insecure boo } // Wait until canceled - select { - case <-ctx.Done(): - } + <-ctx.Done() } func runSender(ctx context.Context, ha host.Host, targetPeer string) { @@ -155,7 +153,7 @@ func runSender(ctx context.Context, ha host.Host, targetPeer string) { return } - peerid, err := peer.IDB58Decode(pid) + peerid, err := peer.Decode(pid) if err != nil { log.Println(err) return diff --git a/examples/go.mod b/examples/go.mod index c771d28eb9..a8e1aa2a26 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -14,12 +14,10 @@ require ( github.com/libp2p/go-libp2p-discovery v0.5.0 github.com/libp2p/go-libp2p-kad-dht v0.11.1 github.com/libp2p/go-libp2p-quic-transport v0.10.0 - github.com/libp2p/go-libp2p-routing v0.1.0 github.com/libp2p/go-libp2p-secio v0.2.2 github.com/libp2p/go-libp2p-swarm v0.5.0 github.com/libp2p/go-libp2p-tls v0.1.3 github.com/multiformats/go-multiaddr v0.3.1 - github.com/multiformats/go-multiaddr-net v0.2.0 ) // Ensure that examples always use the go-libp2p version in the same git checkout. diff --git a/examples/go.sum b/examples/go.sum index 9639e7842e..f0c260cff0 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -300,8 +300,6 @@ github.com/libp2p/go-libp2p-quic-transport v0.10.0/go.mod h1:RfJbZ8IqXIhxBRm5hqU github.com/libp2p/go-libp2p-record v0.1.2/go.mod h1:pal0eNcT5nqZaTV7UGhqeGqxFgGdsU/9W//C8dqjQDk= github.com/libp2p/go-libp2p-record v0.1.3 h1:R27hoScIhQf/A8XJZ8lYpnqh9LatJ5YbHs28kCIfql0= github.com/libp2p/go-libp2p-record v0.1.3/go.mod h1:yNUff/adKIfPnYQXgp6FQmNu3gLJ6EMg7+/vv2+9pY4= -github.com/libp2p/go-libp2p-routing v0.1.0 h1:hFnj3WR3E2tOcKaGpyzfP4gvFZ3t8JkQmbapN0Ct+oU= -github.com/libp2p/go-libp2p-routing v0.1.0/go.mod h1:zfLhI1RI8RLEzmEaaPwzonRvXeeSHddONWkcTcB54nE= github.com/libp2p/go-libp2p-routing-helpers v0.2.3/go.mod h1:795bh+9YeoFl99rMASoiVgHdi5bjack0N1+AFAdbvBw= github.com/libp2p/go-libp2p-secio v0.2.2 h1:rLLPvShPQAcY6eNurKNZq3eZjPWfU9kXF2eI9jIYdrg= github.com/libp2p/go-libp2p-secio v0.2.2/go.mod h1:wP3bS+m5AUnFA+OFO7Er03uO1mncHG0uVwGrwvjYlNY= diff --git a/examples/http-proxy/proxy.go b/examples/http-proxy/proxy.go index 8c25627cb0..d94a0a0954 100644 --- a/examples/http-proxy/proxy.go +++ b/examples/http-proxy/proxy.go @@ -18,7 +18,7 @@ import ( "github.com/libp2p/go-libp2p-core/peerstore" ma "github.com/multiformats/go-multiaddr" - manet "github.com/multiformats/go-multiaddr-net" + manet "github.com/multiformats/go-multiaddr/net" ) // Protocol defines the libp2p protocol that we will use for the libp2p proxy @@ -65,7 +65,7 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe fmt.Println("Proxy server is ready") fmt.Println("libp2p-peer addresses:") for _, a := range h.Addrs() { - fmt.Printf("%s/ipfs/%s\n", a, peer.IDB58Encode(h.ID())) + fmt.Printf("%s/ipfs/%s\n", a, peer.Encode(h.ID())) } return &ProxyService{ @@ -206,7 +206,7 @@ func addAddrToPeerstore(h host.Host, addr string) peer.ID { log.Fatalln(err) } - peerid, err := peer.IDB58Decode(pid) + peerid, err := peer.Decode(pid) if err != nil { log.Fatalln(err) } @@ -214,7 +214,7 @@ func addAddrToPeerstore(h host.Host, addr string) peer.ID { // Decapsulate the /ipfs/ part from the target // /ip4//ipfs/ becomes /ip4/ targetPeerAddr, _ := ma.NewMultiaddr( - fmt.Sprintf("/ipfs/%s", peer.IDB58Encode(peerid))) + fmt.Sprintf("/ipfs/%s", peer.Encode(peerid))) targetAddr := ipfsaddr.Decapsulate(targetPeerAddr) // We have a peer ID and a targetAddr so we add diff --git a/examples/ipfs-camp-2019/06-Pubsub/main.go b/examples/ipfs-camp-2019/06-Pubsub/main.go index 6be51b4658..7697fd2bf1 100644 --- a/examples/ipfs-camp-2019/06-Pubsub/main.go +++ b/examples/ipfs-camp-2019/06-Pubsub/main.go @@ -117,6 +117,9 @@ func main() { routingDiscovery := disc.NewRoutingDiscovery(dht) disc.Advertise(ctx, routingDiscovery, string(chatProtocol)) peers, err := disc.FindPeers(ctx, routingDiscovery, string(chatProtocol)) + if err != nil { + panic(err) + } for _, peer := range peers { notifee.HandlePeerFound(peer) } diff --git a/examples/ipfs-camp-2019/07-Messaging/chat.pb.go b/examples/ipfs-camp-2019/07-Messaging/chat.pb.go index 6b357d3d6c..059bb036c1 100644 --- a/examples/ipfs-camp-2019/07-Messaging/chat.pb.go +++ b/examples/ipfs-camp-2019/07-Messaging/chat.pb.go @@ -5,11 +5,8 @@ package main import ( fmt "fmt" - io "io" + proto "github.com/gogo/protobuf/proto" math "math" - - github_com_golang_protobuf_proto "github.com/golang/protobuf/proto" - proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -21,7 +18,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.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Request_Type int32 @@ -79,25 +76,16 @@ func (*Request) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_Request.Unmarshal(m, b) } func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Request.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_Request.Marshal(b, m, deterministic) } func (m *Request) XXX_Merge(src proto.Message) { xxx_messageInfo_Request.Merge(m, src) } func (m *Request) XXX_Size() int { - return m.Size() + return xxx_messageInfo_Request.Size(m) } func (m *Request) XXX_DiscardUnknown() { xxx_messageInfo_Request.DiscardUnknown(m) @@ -142,25 +130,16 @@ func (*SendMessage) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{1} } func (m *SendMessage) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_SendMessage.Unmarshal(m, b) } func (m *SendMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SendMessage.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_SendMessage.Marshal(b, m, deterministic) } func (m *SendMessage) XXX_Merge(src proto.Message) { xxx_messageInfo_SendMessage.Merge(m, src) } func (m *SendMessage) XXX_Size() int { - return m.Size() + return xxx_messageInfo_SendMessage.Size(m) } func (m *SendMessage) XXX_DiscardUnknown() { xxx_messageInfo_SendMessage.DiscardUnknown(m) @@ -203,25 +182,16 @@ func (*UpdatePeer) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{2} } func (m *UpdatePeer) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_UpdatePeer.Unmarshal(m, b) } func (m *UpdatePeer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UpdatePeer.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_UpdatePeer.Marshal(b, m, deterministic) } func (m *UpdatePeer) XXX_Merge(src proto.Message) { xxx_messageInfo_UpdatePeer.Merge(m, src) } func (m *UpdatePeer) XXX_Size() int { - return m.Size() + return xxx_messageInfo_UpdatePeer.Size(m) } func (m *UpdatePeer) XXX_DiscardUnknown() { xxx_messageInfo_UpdatePeer.DiscardUnknown(m) @@ -246,731 +216,21 @@ func init() { func init() { proto.RegisterFile("chat.proto", fileDescriptor_8c585a45e2093e54) } var fileDescriptor_8c585a45e2093e54 = []byte{ - // 276 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0xf3, 0x40, - 0x14, 0x85, 0x3b, 0x93, 0x40, 0xe1, 0x26, 0xf4, 0xcf, 0x7f, 0x57, 0xb3, 0x0a, 0x21, 0x0b, 0x89, - 0x20, 0x41, 0xea, 0x13, 0x54, 0x3a, 0x28, 0x48, 0x25, 0x4c, 0xda, 0x75, 0x19, 0x3a, 0x17, 0x0d, - 0x68, 0x1a, 0x93, 0xc9, 0xa2, 0x6f, 0xe2, 0xfb, 0xb8, 0x71, 0xe9, 0x23, 0x48, 0x7c, 0x11, 0x49, - 0xaa, 0x36, 0xbb, 0x99, 0x73, 0xbe, 0xc3, 0xb9, 0xf7, 0x02, 0xec, 0x1e, 0xb5, 0x4d, 0xab, 0x7a, - 0x6f, 0xf7, 0xe8, 0x3e, 0xeb, 0xa2, 0x8c, 0xdf, 0x18, 0x4c, 0x15, 0xbd, 0xb4, 0xd4, 0x58, 0x3c, - 0x03, 0xd7, 0x1e, 0x2a, 0x12, 0x2c, 0xe2, 0xc9, 0x6c, 0x8e, 0x69, 0x0f, 0xa4, 0x3f, 0x66, 0xba, - 0x3e, 0x54, 0xa4, 0x06, 0x1f, 0xaf, 0xc0, 0x6b, 0xa8, 0x34, 0x2b, 0x6a, 0x1a, 0xfd, 0x40, 0x82, - 0x47, 0x2c, 0xf1, 0xe6, 0xff, 0x8f, 0x78, 0x7e, 0x32, 0xd4, 0x98, 0xc2, 0x4b, 0x80, 0xb6, 0x32, - 0xda, 0x52, 0x46, 0x54, 0x0b, 0x67, 0xc8, 0x04, 0xc7, 0xcc, 0xe6, 0x4f, 0x57, 0x23, 0x26, 0x3e, - 0x07, 0xb7, 0x2f, 0xc5, 0x00, 0xfc, 0x5c, 0xde, 0x2f, 0xb7, 0x2b, 0x99, 0xe7, 0x8b, 0x1b, 0x19, - 0x4c, 0xf0, 0x1f, 0x78, 0x9b, 0x6c, 0xb9, 0x58, 0xcb, 0x6d, 0x26, 0xa5, 0x0a, 0x58, 0x7c, 0x07, - 0xde, 0xa8, 0x18, 0x11, 0x5c, 0xa3, 0xad, 0x1e, 0x16, 0xf1, 0xd5, 0xf0, 0x46, 0x01, 0xd3, 0x5d, - 0x4d, 0xda, 0x92, 0x11, 0x3c, 0xe2, 0x89, 0xa3, 0x7e, 0xbf, 0x38, 0x03, 0x5e, 0x18, 0xe1, 0x0c, - 0x2c, 0x2f, 0x4c, 0x7c, 0x01, 0x70, 0x9a, 0x08, 0x43, 0x80, 0xb6, 0xa1, 0xfa, 0x56, 0x97, 0xe6, - 0xa9, 0x3f, 0x0d, 0x4b, 0x7c, 0x35, 0x52, 0xae, 0x83, 0xf7, 0x2e, 0x64, 0x1f, 0x5d, 0xc8, 0x3e, - 0xbb, 0x90, 0xbd, 0x7e, 0x85, 0x93, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x34, 0xa3, 0x90, 0xc9, - 0x65, 0x01, 0x00, 0x00, -} - -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Type == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x8 - i++ - i = encodeVarintChat(dAtA, i, uint64(*m.Type)) - } - if m.SendMessage != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintChat(dAtA, i, uint64(m.SendMessage.Size())) - n1, err := m.SendMessage.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.UpdatePeer != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintChat(dAtA, i, uint64(m.UpdatePeer.Size())) - n2, err := m.UpdatePeer.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *SendMessage) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SendMessage) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Data == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0xa - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.Created == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x10 - i++ - i = encodeVarintChat(dAtA, i, uint64(*m.Created)) - } - if m.Id == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x1a - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.Id))) - i += copy(dAtA[i:], m.Id) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *UpdatePeer) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UpdatePeer) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.UserHandle != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.UserHandle))) - i += copy(dAtA[i:], m.UserHandle) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintChat(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != nil { - n += 1 + sovChat(uint64(*m.Type)) - } - if m.SendMessage != nil { - l = m.SendMessage.Size() - n += 1 + l + sovChat(uint64(l)) - } - if m.UpdatePeer != nil { - l = m.UpdatePeer.Size() - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *SendMessage) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovChat(uint64(l)) - } - if m.Created != nil { - n += 1 + sovChat(uint64(*m.Created)) - } - if m.Id != nil { - l = len(m.Id) - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *UpdatePeer) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.UserHandle != nil { - l = len(m.UserHandle) - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n + // 251 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x51, 0x4b, 0xc3, 0x30, + 0x14, 0x85, 0x4d, 0x5a, 0x18, 0xdc, 0x96, 0x59, 0xef, 0x53, 0x9e, 0xa4, 0xf4, 0x41, 0x2a, 0x48, + 0x91, 0xf9, 0x0b, 0x06, 0x0b, 0x0a, 0x32, 0x29, 0xe9, 0xf6, 0x3c, 0xc2, 0x72, 0xd1, 0x82, 0x76, + 0xb5, 0x49, 0x1f, 0xf6, 0xfb, 0xfc, 0x63, 0xd2, 0x4c, 0xb7, 0xbc, 0x25, 0xe7, 0x7c, 0x87, 0x73, + 0xef, 0x05, 0xd8, 0x7f, 0x68, 0x57, 0xf5, 0xc3, 0xc1, 0x1d, 0x30, 0xfe, 0xd2, 0x6d, 0x57, 0xfc, + 0x30, 0x98, 0x29, 0xfa, 0x1e, 0xc9, 0x3a, 0xbc, 0x83, 0xd8, 0x1d, 0x7b, 0x12, 0x2c, 0xe7, 0xe5, + 0x7c, 0x81, 0xd5, 0x04, 0x54, 0x7f, 0x66, 0xb5, 0x39, 0xf6, 0xa4, 0xbc, 0x8f, 0x4f, 0x90, 0x58, + 0xea, 0xcc, 0x9a, 0xac, 0xd5, 0xef, 0x24, 0x78, 0xce, 0xca, 0x64, 0x71, 0x73, 0xc2, 0x9b, 0x8b, + 0xa1, 0x42, 0x0a, 0x1f, 0x01, 0xc6, 0xde, 0x68, 0x47, 0x35, 0xd1, 0x20, 0x22, 0x9f, 0xc9, 0x4e, + 0x99, 0xed, 0x59, 0x57, 0x01, 0x53, 0xdc, 0x43, 0x3c, 0x95, 0x62, 0x06, 0x69, 0x23, 0xdf, 0x56, + 0xbb, 0xb5, 0x6c, 0x9a, 0xe5, 0xb3, 0xcc, 0xae, 0xf0, 0x1a, 0x92, 0x6d, 0xbd, 0x5a, 0x6e, 0xe4, + 0xae, 0x96, 0x52, 0x65, 0xac, 0x78, 0x85, 0x24, 0x28, 0x46, 0x84, 0xd8, 0x68, 0xa7, 0xfd, 0x22, + 0xa9, 0xf2, 0x6f, 0x14, 0x30, 0xdb, 0x0f, 0xa4, 0x1d, 0x19, 0xc1, 0x73, 0x5e, 0x46, 0xea, 0xff, + 0x8b, 0x73, 0xe0, 0xad, 0x11, 0x91, 0x67, 0x79, 0x6b, 0x8a, 0x07, 0x80, 0xcb, 0x44, 0x78, 0x0b, + 0x30, 0x5a, 0x1a, 0x5e, 0x74, 0x67, 0x3e, 0xa7, 0xd3, 0xb0, 0x32, 0x55, 0x81, 0xf2, 0x1b, 0x00, + 0x00, 0xff, 0xff, 0x5c, 0xd9, 0x58, 0xd2, 0x53, 0x01, 0x00, 0x00, } - -func sovChat(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozChat(x uint64) (n int) { - return sovChat(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - var hasFields [1]uint64 - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - var v Request_Type - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Request_Type(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Type = &v - hasFields[0] |= uint64(0x00000001) - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SendMessage", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SendMessage == nil { - m.SendMessage = &SendMessage{} - } - if err := m.SendMessage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdatePeer", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.UpdatePeer == nil { - m.UpdatePeer = &UpdatePeer{} - } - if err := m.UpdatePeer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - if hasFields[0]&uint64(0x00000001) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SendMessage) Unmarshal(dAtA []byte) error { - var hasFields [1]uint64 - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SendMessage: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SendMessage: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - hasFields[0] |= uint64(0x00000001) - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Created = &v - hasFields[0] |= uint64(0x00000002) - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Id = append(m.Id[:0], dAtA[iNdEx:postIndex]...) - if m.Id == nil { - m.Id = []byte{} - } - iNdEx = postIndex - hasFields[0] |= uint64(0x00000004) - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - if hasFields[0]&uint64(0x00000001) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - if hasFields[0]&uint64(0x00000002) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - if hasFields[0]&uint64(0x00000004) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UpdatePeer) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UpdatePeer: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UpdatePeer: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserHandle", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.UserHandle = append(m.UserHandle[:0], dAtA[iNdEx:postIndex]...) - if m.UserHandle == nil { - m.UserHandle = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipChat(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthChat - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthChat - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - 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 := skipChat(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthChat - } - } - 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 ( - ErrInvalidLengthChat = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowChat = fmt.Errorf("proto: integer overflow") -) diff --git a/examples/ipfs-camp-2019/07-Messaging/protocol.go b/examples/ipfs-camp-2019/07-Messaging/protocol.go index aac9fc3f29..327d77c2c3 100644 --- a/examples/ipfs-camp-2019/07-Messaging/protocol.go +++ b/examples/ipfs-camp-2019/07-Messaging/protocol.go @@ -8,6 +8,7 @@ import ( "os" "time" + "github.com/gogo/protobuf/proto" "github.com/libp2p/go-libp2p-core/host" pubsub "github.com/libp2p/go-libp2p-pubsub" ) @@ -33,7 +34,7 @@ func chatInputLoop(ctx context.Context, h host.Host, ps *pubsub.PubSub, donec ch Created: &now, }, } - msgBytes, err := req.Marshal() + msgBytes, err := proto.Marshal(req) if err != nil { continue } diff --git a/examples/ipfs-camp-2019/07-Messaging/pubsub.go b/examples/ipfs-camp-2019/07-Messaging/pubsub.go index 0756bb0021..e875cdf06f 100644 --- a/examples/ipfs-camp-2019/07-Messaging/pubsub.go +++ b/examples/ipfs-camp-2019/07-Messaging/pubsub.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/gogo/protobuf/proto" peer "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" ) @@ -28,7 +29,7 @@ func pubsubHandler(ctx context.Context, sub *pubsub.Subscription) { } req := &Request{} - err = req.Unmarshal(msg.Data) + err = proto.Unmarshal(msg.Data, req) if err != nil { fmt.Fprintln(os.Stderr, err) continue diff --git a/examples/ipfs-camp-2019/08-End/chat.pb.go b/examples/ipfs-camp-2019/08-End/chat.pb.go index 6b357d3d6c..059bb036c1 100644 --- a/examples/ipfs-camp-2019/08-End/chat.pb.go +++ b/examples/ipfs-camp-2019/08-End/chat.pb.go @@ -5,11 +5,8 @@ package main import ( fmt "fmt" - io "io" + proto "github.com/gogo/protobuf/proto" math "math" - - github_com_golang_protobuf_proto "github.com/golang/protobuf/proto" - proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -21,7 +18,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.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Request_Type int32 @@ -79,25 +76,16 @@ func (*Request) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_Request.Unmarshal(m, b) } func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Request.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_Request.Marshal(b, m, deterministic) } func (m *Request) XXX_Merge(src proto.Message) { xxx_messageInfo_Request.Merge(m, src) } func (m *Request) XXX_Size() int { - return m.Size() + return xxx_messageInfo_Request.Size(m) } func (m *Request) XXX_DiscardUnknown() { xxx_messageInfo_Request.DiscardUnknown(m) @@ -142,25 +130,16 @@ func (*SendMessage) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{1} } func (m *SendMessage) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_SendMessage.Unmarshal(m, b) } func (m *SendMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SendMessage.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_SendMessage.Marshal(b, m, deterministic) } func (m *SendMessage) XXX_Merge(src proto.Message) { xxx_messageInfo_SendMessage.Merge(m, src) } func (m *SendMessage) XXX_Size() int { - return m.Size() + return xxx_messageInfo_SendMessage.Size(m) } func (m *SendMessage) XXX_DiscardUnknown() { xxx_messageInfo_SendMessage.DiscardUnknown(m) @@ -203,25 +182,16 @@ func (*UpdatePeer) Descriptor() ([]byte, []int) { return fileDescriptor_8c585a45e2093e54, []int{2} } func (m *UpdatePeer) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_UpdatePeer.Unmarshal(m, b) } func (m *UpdatePeer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UpdatePeer.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_UpdatePeer.Marshal(b, m, deterministic) } func (m *UpdatePeer) XXX_Merge(src proto.Message) { xxx_messageInfo_UpdatePeer.Merge(m, src) } func (m *UpdatePeer) XXX_Size() int { - return m.Size() + return xxx_messageInfo_UpdatePeer.Size(m) } func (m *UpdatePeer) XXX_DiscardUnknown() { xxx_messageInfo_UpdatePeer.DiscardUnknown(m) @@ -246,731 +216,21 @@ func init() { func init() { proto.RegisterFile("chat.proto", fileDescriptor_8c585a45e2093e54) } var fileDescriptor_8c585a45e2093e54 = []byte{ - // 276 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0xf3, 0x40, - 0x14, 0x85, 0x3b, 0x93, 0x40, 0xe1, 0x26, 0xf4, 0xcf, 0x7f, 0x57, 0xb3, 0x0a, 0x21, 0x0b, 0x89, - 0x20, 0x41, 0xea, 0x13, 0x54, 0x3a, 0x28, 0x48, 0x25, 0x4c, 0xda, 0x75, 0x19, 0x3a, 0x17, 0x0d, - 0x68, 0x1a, 0x93, 0xc9, 0xa2, 0x6f, 0xe2, 0xfb, 0xb8, 0x71, 0xe9, 0x23, 0x48, 0x7c, 0x11, 0x49, - 0xaa, 0x36, 0xbb, 0x99, 0x73, 0xbe, 0xc3, 0xb9, 0xf7, 0x02, 0xec, 0x1e, 0xb5, 0x4d, 0xab, 0x7a, - 0x6f, 0xf7, 0xe8, 0x3e, 0xeb, 0xa2, 0x8c, 0xdf, 0x18, 0x4c, 0x15, 0xbd, 0xb4, 0xd4, 0x58, 0x3c, - 0x03, 0xd7, 0x1e, 0x2a, 0x12, 0x2c, 0xe2, 0xc9, 0x6c, 0x8e, 0x69, 0x0f, 0xa4, 0x3f, 0x66, 0xba, - 0x3e, 0x54, 0xa4, 0x06, 0x1f, 0xaf, 0xc0, 0x6b, 0xa8, 0x34, 0x2b, 0x6a, 0x1a, 0xfd, 0x40, 0x82, - 0x47, 0x2c, 0xf1, 0xe6, 0xff, 0x8f, 0x78, 0x7e, 0x32, 0xd4, 0x98, 0xc2, 0x4b, 0x80, 0xb6, 0x32, - 0xda, 0x52, 0x46, 0x54, 0x0b, 0x67, 0xc8, 0x04, 0xc7, 0xcc, 0xe6, 0x4f, 0x57, 0x23, 0x26, 0x3e, - 0x07, 0xb7, 0x2f, 0xc5, 0x00, 0xfc, 0x5c, 0xde, 0x2f, 0xb7, 0x2b, 0x99, 0xe7, 0x8b, 0x1b, 0x19, - 0x4c, 0xf0, 0x1f, 0x78, 0x9b, 0x6c, 0xb9, 0x58, 0xcb, 0x6d, 0x26, 0xa5, 0x0a, 0x58, 0x7c, 0x07, - 0xde, 0xa8, 0x18, 0x11, 0x5c, 0xa3, 0xad, 0x1e, 0x16, 0xf1, 0xd5, 0xf0, 0x46, 0x01, 0xd3, 0x5d, - 0x4d, 0xda, 0x92, 0x11, 0x3c, 0xe2, 0x89, 0xa3, 0x7e, 0xbf, 0x38, 0x03, 0x5e, 0x18, 0xe1, 0x0c, - 0x2c, 0x2f, 0x4c, 0x7c, 0x01, 0x70, 0x9a, 0x08, 0x43, 0x80, 0xb6, 0xa1, 0xfa, 0x56, 0x97, 0xe6, - 0xa9, 0x3f, 0x0d, 0x4b, 0x7c, 0x35, 0x52, 0xae, 0x83, 0xf7, 0x2e, 0x64, 0x1f, 0x5d, 0xc8, 0x3e, - 0xbb, 0x90, 0xbd, 0x7e, 0x85, 0x93, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x34, 0xa3, 0x90, 0xc9, - 0x65, 0x01, 0x00, 0x00, -} - -func (m *Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Request) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Type == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x8 - i++ - i = encodeVarintChat(dAtA, i, uint64(*m.Type)) - } - if m.SendMessage != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintChat(dAtA, i, uint64(m.SendMessage.Size())) - n1, err := m.SendMessage.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.UpdatePeer != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintChat(dAtA, i, uint64(m.UpdatePeer.Size())) - n2, err := m.UpdatePeer.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *SendMessage) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SendMessage) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Data == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0xa - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.Created == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x10 - i++ - i = encodeVarintChat(dAtA, i, uint64(*m.Created)) - } - if m.Id == nil { - return 0, new(github_com_golang_protobuf_proto.RequiredNotSetError) - } else { - dAtA[i] = 0x1a - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.Id))) - i += copy(dAtA[i:], m.Id) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *UpdatePeer) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UpdatePeer) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.UserHandle != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintChat(dAtA, i, uint64(len(m.UserHandle))) - i += copy(dAtA[i:], m.UserHandle) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintChat(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Request) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != nil { - n += 1 + sovChat(uint64(*m.Type)) - } - if m.SendMessage != nil { - l = m.SendMessage.Size() - n += 1 + l + sovChat(uint64(l)) - } - if m.UpdatePeer != nil { - l = m.UpdatePeer.Size() - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *SendMessage) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovChat(uint64(l)) - } - if m.Created != nil { - n += 1 + sovChat(uint64(*m.Created)) - } - if m.Id != nil { - l = len(m.Id) - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *UpdatePeer) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.UserHandle != nil { - l = len(m.UserHandle) - n += 1 + l + sovChat(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n + // 251 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x51, 0x4b, 0xc3, 0x30, + 0x14, 0x85, 0x4d, 0x5a, 0x18, 0xdc, 0x96, 0x59, 0xef, 0x53, 0x9e, 0xa4, 0xf4, 0x41, 0x2a, 0x48, + 0x91, 0xf9, 0x0b, 0x06, 0x0b, 0x0a, 0x32, 0x29, 0xe9, 0xf6, 0x3c, 0xc2, 0x72, 0xd1, 0x82, 0x76, + 0xb5, 0x49, 0x1f, 0xf6, 0xfb, 0xfc, 0x63, 0xd2, 0x4c, 0xb7, 0xbc, 0x25, 0xe7, 0x7c, 0x87, 0x73, + 0xef, 0x05, 0xd8, 0x7f, 0x68, 0x57, 0xf5, 0xc3, 0xc1, 0x1d, 0x30, 0xfe, 0xd2, 0x6d, 0x57, 0xfc, + 0x30, 0x98, 0x29, 0xfa, 0x1e, 0xc9, 0x3a, 0xbc, 0x83, 0xd8, 0x1d, 0x7b, 0x12, 0x2c, 0xe7, 0xe5, + 0x7c, 0x81, 0xd5, 0x04, 0x54, 0x7f, 0x66, 0xb5, 0x39, 0xf6, 0xa4, 0xbc, 0x8f, 0x4f, 0x90, 0x58, + 0xea, 0xcc, 0x9a, 0xac, 0xd5, 0xef, 0x24, 0x78, 0xce, 0xca, 0x64, 0x71, 0x73, 0xc2, 0x9b, 0x8b, + 0xa1, 0x42, 0x0a, 0x1f, 0x01, 0xc6, 0xde, 0x68, 0x47, 0x35, 0xd1, 0x20, 0x22, 0x9f, 0xc9, 0x4e, + 0x99, 0xed, 0x59, 0x57, 0x01, 0x53, 0xdc, 0x43, 0x3c, 0x95, 0x62, 0x06, 0x69, 0x23, 0xdf, 0x56, + 0xbb, 0xb5, 0x6c, 0x9a, 0xe5, 0xb3, 0xcc, 0xae, 0xf0, 0x1a, 0x92, 0x6d, 0xbd, 0x5a, 0x6e, 0xe4, + 0xae, 0x96, 0x52, 0x65, 0xac, 0x78, 0x85, 0x24, 0x28, 0x46, 0x84, 0xd8, 0x68, 0xa7, 0xfd, 0x22, + 0xa9, 0xf2, 0x6f, 0x14, 0x30, 0xdb, 0x0f, 0xa4, 0x1d, 0x19, 0xc1, 0x73, 0x5e, 0x46, 0xea, 0xff, + 0x8b, 0x73, 0xe0, 0xad, 0x11, 0x91, 0x67, 0x79, 0x6b, 0x8a, 0x07, 0x80, 0xcb, 0x44, 0x78, 0x0b, + 0x30, 0x5a, 0x1a, 0x5e, 0x74, 0x67, 0x3e, 0xa7, 0xd3, 0xb0, 0x32, 0x55, 0x81, 0xf2, 0x1b, 0x00, + 0x00, 0xff, 0xff, 0x5c, 0xd9, 0x58, 0xd2, 0x53, 0x01, 0x00, 0x00, } - -func sovChat(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozChat(x uint64) (n int) { - return sovChat(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Request) Unmarshal(dAtA []byte) error { - var hasFields [1]uint64 - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - var v Request_Type - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Request_Type(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Type = &v - hasFields[0] |= uint64(0x00000001) - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SendMessage", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SendMessage == nil { - m.SendMessage = &SendMessage{} - } - if err := m.SendMessage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdatePeer", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.UpdatePeer == nil { - m.UpdatePeer = &UpdatePeer{} - } - if err := m.UpdatePeer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - if hasFields[0]&uint64(0x00000001) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SendMessage) Unmarshal(dAtA []byte) error { - var hasFields [1]uint64 - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SendMessage: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SendMessage: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - hasFields[0] |= uint64(0x00000001) - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Created = &v - hasFields[0] |= uint64(0x00000002) - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Id = append(m.Id[:0], dAtA[iNdEx:postIndex]...) - if m.Id == nil { - m.Id = []byte{} - } - iNdEx = postIndex - hasFields[0] |= uint64(0x00000004) - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - if hasFields[0]&uint64(0x00000001) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - if hasFields[0]&uint64(0x00000002) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - if hasFields[0]&uint64(0x00000004) == 0 { - return new(github_com_golang_protobuf_proto.RequiredNotSetError) - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UpdatePeer) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UpdatePeer: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UpdatePeer: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UserHandle", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChat - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthChat - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthChat - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.UserHandle = append(m.UserHandle[:0], dAtA[iNdEx:postIndex]...) - if m.UserHandle == nil { - m.UserHandle = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipChat(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthChat - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipChat(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthChat - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthChat - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChat - } - 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 := skipChat(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthChat - } - } - 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 ( - ErrInvalidLengthChat = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowChat = fmt.Errorf("proto: integer overflow") -) diff --git a/examples/ipfs-camp-2019/08-End/protocol.go b/examples/ipfs-camp-2019/08-End/protocol.go index 8fc3dda3e7..3887607df5 100644 --- a/examples/ipfs-camp-2019/08-End/protocol.go +++ b/examples/ipfs-camp-2019/08-End/protocol.go @@ -10,6 +10,7 @@ import ( "strings" + "github.com/gogo/protobuf/proto" "github.com/libp2p/go-libp2p-core/host" peer "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" @@ -35,7 +36,7 @@ func sendMessage(ps *pubsub.PubSub, msg string) { Created: &now, }, } - msgBytes, err := req.Marshal() + msgBytes, err := proto.Marshal(req) if err != nil { return } @@ -55,7 +56,7 @@ func updatePeer(ps *pubsub.PubSub, id peer.ID, handle string) { UserHandle: []byte(handle), }, } - reqBytes, err := req.Marshal() + reqBytes, err := proto.Marshal(req) if err != nil { fmt.Fprintln(os.Stderr, err) return diff --git a/examples/ipfs-camp-2019/08-End/pubsub.go b/examples/ipfs-camp-2019/08-End/pubsub.go index 4e1dcbb517..7180d04a20 100644 --- a/examples/ipfs-camp-2019/08-End/pubsub.go +++ b/examples/ipfs-camp-2019/08-End/pubsub.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/gogo/protobuf/proto" peer "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" ) @@ -39,7 +40,7 @@ func pubsubHandler(ctx context.Context, sub *pubsub.Subscription) { } req := &Request{} - err = req.Unmarshal(msg.Data) + err = proto.Unmarshal(msg.Data, req) if err != nil { fmt.Fprintln(os.Stderr, err) continue diff --git a/examples/ipfs-camp-2019/go.mod b/examples/ipfs-camp-2019/go.mod index f2cd10386c..f555ea71ce 100644 --- a/examples/ipfs-camp-2019/go.mod +++ b/examples/ipfs-camp-2019/go.mod @@ -3,7 +3,7 @@ module github.com/libp2p/go-libp2p/examples/ipfs-camp-2019 go 1.12 require ( - github.com/golang/protobuf v1.4.3 + github.com/gogo/protobuf v1.3.2 github.com/libp2p/go-libp2p v0.13.0 github.com/libp2p/go-libp2p-core v0.8.5 github.com/libp2p/go-libp2p-discovery v0.5.0 diff --git a/examples/libp2p-host/host.go b/examples/libp2p-host/host.go index e262ebc77d..797c63e036 100644 --- a/examples/libp2p-host/host.go +++ b/examples/libp2p-host/host.go @@ -9,9 +9,9 @@ import ( connmgr "github.com/libp2p/go-libp2p-connmgr" "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/host" + routing "github.com/libp2p/go-libp2p-core/routing" dht "github.com/libp2p/go-libp2p-kad-dht" libp2pquic "github.com/libp2p/go-libp2p-quic-transport" - routing "github.com/libp2p/go-libp2p-routing" secio "github.com/libp2p/go-libp2p-secio" libp2ptls "github.com/libp2p/go-libp2p-tls" ) diff --git a/examples/multipro/node.go b/examples/multipro/node.go index 907ff8ab2d..16c3978b6f 100644 --- a/examples/multipro/node.go +++ b/examples/multipro/node.go @@ -54,7 +54,7 @@ func (n *Node) authenticateMessage(message proto.Message, data *p2p.MessageData) data.Sign = sign // restore peer id binary format from base58 encoded node id data - peerId, err := peer.IDB58Decode(data.NodeId) + peerId, err := peer.Decode(data.NodeId) if err != nil { log.Println(err, "Failed to decode node id from base58") return false @@ -128,7 +128,7 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData { } return &p2p.MessageData{ClientVersion: clientVersion, - NodeId: peer.IDB58Encode(n.ID()), + NodeId: peer.Encode(n.ID()), NodePubKey: nodePubKey, Timestamp: time.Now().Unix(), Id: messageId, diff --git a/examples/routed-echo/main.go b/examples/routed-echo/main.go index 23ddad3354..af1c1e2f83 100644 --- a/examples/routed-echo/main.go +++ b/examples/routed-echo/main.go @@ -154,7 +154,7 @@ func main() { } /**** This is where the listener code ends ****/ - peerid, err := peer.IDB58Decode(*target) + peerid, err := peer.Decode(*target) if err != nil { log.Fatalln(err) } diff --git a/examples/testutils/logharness.go b/examples/testutils/logharness.go index 8e7c6dc44f..2f075645eb 100644 --- a/examples/testutils/logharness.go +++ b/examples/testutils/logharness.go @@ -107,8 +107,6 @@ exploop: return } } - - return } // Expect adds an expectation that the log contains a line equal to s