From 25ef943eea51a3d97b1f75e4590f1c7bf3f4b0d8 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 9 Jan 2017 09:52:07 -0800 Subject: [PATCH] change from field to bytes to avoid json marshalling corruption --- floodsub.go | 3 +-- pb/rpc.pb.go | 10 +++++----- pb/rpc.proto | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/floodsub.go b/floodsub.go index 0d7dec5..adefd5f 100644 --- a/floodsub.go +++ b/floodsub.go @@ -8,7 +8,6 @@ import ( pb "github.com/libp2p/go-floodsub/pb" - proto "github.com/gogo/protobuf/proto" logging "github.com/ipfs/go-log" host "github.com/libp2p/go-libp2p-host" inet "github.com/libp2p/go-libp2p-net" @@ -401,7 +400,7 @@ func (p *PubSub) Publish(topic string, data []byte) error { &pb.Message{ Data: data, TopicIDs: []string{topic}, - From: proto.String(string(p.host.ID())), + From: []byte(p.host.ID()), Seqno: seqno, }, } diff --git a/pb/rpc.pb.go b/pb/rpc.pb.go index 2418c4c..a5933c0 100644 --- a/pb/rpc.pb.go +++ b/pb/rpc.pb.go @@ -145,7 +145,7 @@ func (m *RPC_SubOpts) GetTopicid() string { } type Message struct { - From *string `protobuf:"bytes,1,opt,name=from" json:"from,omitempty"` + From []byte `protobuf:"bytes,1,opt,name=from" json:"from,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` Seqno []byte `protobuf:"bytes,3,opt,name=seqno" json:"seqno,omitempty"` TopicIDs []string `protobuf:"bytes,4,rep,name=topicIDs" json:"topicIDs,omitempty"` @@ -156,11 +156,11 @@ func (m *Message) Reset() { *m = Message{} } func (m *Message) String() string { return proto.CompactTextString(m) } func (*Message) ProtoMessage() {} -func (m *Message) GetFrom() string { - if m != nil && m.From != nil { - return *m.From +func (m *Message) GetFrom() []byte { + if m != nil { + return m.From } - return "" + return nil } func (m *Message) GetData() []byte { diff --git a/pb/rpc.proto b/pb/rpc.proto index 22f4ca1..f43d3c1 100644 --- a/pb/rpc.proto +++ b/pb/rpc.proto @@ -11,7 +11,7 @@ message RPC { } message Message { - optional string from = 1; + optional bytes from = 1; optional bytes data = 2; optional bytes seqno = 3; repeated string topicIDs = 4;