diff --git a/pinner/pinmgr.go b/pinner/pinmgr.go index 2848d9b8..b193b0fb 100644 --- a/pinner/pinmgr.go +++ b/pinner/pinmgr.go @@ -361,8 +361,8 @@ type AddrInfoString struct { Addrs []string } type PinningOperationSerialize struct { - po PinningOperation - peers []AddrInfoString + Po PinningOperation + Peers []AddrInfoString } func encode_msgpack(po *PinningOperation) ([]byte, error) { @@ -377,8 +377,10 @@ func encode_msgpack(po *PinningOperation) ([]byte, error) { newpeer := AddrInfoString{ID: peers[i].ID, Addrs: newaddrs} serialPeers = append(serialPeers, newpeer) } - savedObject := PinningOperationSerialize{po: *po, peers: serialPeers} - return msgpack.Marshal(&savedObject) + savedObject := PinningOperationSerialize{Po: *po, Peers: serialPeers} + bytes, err := msgpack.Marshal(&savedObject) + po.Peers = peers + return bytes, err } func decode_msgpack(po_bytes []byte) (*PinningOperation, error) { var next *PinningOperationSerialize @@ -386,9 +388,9 @@ func decode_msgpack(po_bytes []byte) (*PinningOperation, error) { if err != nil { log.Fatal(err) } - po := next.po + po := next.Po newPeers := []*peer.AddrInfo{} - peers := next.peers + peers := next.Peers for i := 0; i < len(peers); i++ { newaddrs := []ma.Multiaddr{} for j := 0; j < len(peers[i].Addrs); j++ { diff --git a/pinner/pinmgr_test.go b/pinner/pinmgr_test.go index 92e29696..e0149cca 100644 --- a/pinner/pinmgr_test.go +++ b/pinner/pinmgr_test.go @@ -114,15 +114,19 @@ func TestEncodeDecode(t *testing.T) { fmt.Println(err) } peer := []*peer.AddrInfo{{ID: peer.ID("12D3KooWCsxFFH242NZ4bjRMJEVc61La6Ha4yGVNXeEEwpf8KWCX"), Addrs: []ma.Multiaddr{addr}}} - po := &PinningOperation{Peers: peer} + po := &PinningOperation{Peers: peer, Name: "pinning operation name"} bytes, err := encode_msgpack(po) if err != nil { fmt.Println(err) } - po, err = decode_msgpack(bytes) + newpo, err := decode_msgpack(bytes) if err != nil { fmt.Println(err) } + assert.Equal(t, newpo.Name, po.Name, "name doesnt match") + assert.Equal(t, newpo.Peers[0].Addrs[0].String(), po.Peers[0].Addrs[0].String(), "addr doesnt match") + assert.Equal(t, newpo.Peers[0].ID, po.Peers[0].ID, "ID doesnt match") + }) } func newPinData(name string, userid int, contid int) PinningOperation {