Giter Club home page Giter Club logo

Comments (4)

aarshkshah1992 avatar aarshkshah1992 commented on July 2, 2024

cc @Stebalien @marten-seemann

from go-libp2p-core.

marten-seemann avatar marten-seemann commented on July 2, 2024

This seems to be a problem with encoding/gob, not in our stack. If I just use encoding/json everything works fine:

// Message stores a type of message and a body.
// The message is the data that gets passed between nodes when they communicate.
type Message struct {
	ID         string        `json:"id"`
	Body       []byte        `json:"body"`        // the actual payload.
	OriginNode peer.AddrInfo `json:"origin_node"` // the node that sent the message
}

// NewMessage builds up a new message.
func NewMessage(b []byte, o peer.AddrInfo) Message {
	return Message{
		ID:         "identifier",
		Body:       b,
		OriginNode: o,
	}
}

// Marshal takes a node message and marshals it into an array of bytes.
func (m Message) Marshal() ([]byte, error) {
	return json.Marshal(m)
}

// UnmarshalMessage takes a slice of bytes and a returns a message struct.
func UnmarshalMessage(input []byte) (Message, error) {
	msg := Message{}
	return msg, json.Unmarshal(input, &msg)
}

I'm not really familiar with encoding/gob to be honest, but here's the relevant part of the stack trace:

panic(0x131e400, 0xc00009de60)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/runtime/panic.go:969 +0x1b9
encoding/gob.catchError(0xc00012c0f0)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/error.go:38 +0x85
panic(0x131e400, 0xc00009de60)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/runtime/panic.go:969 +0x1b9
encoding/gob.(*Decoder).decodeGobDecoder(0xc00012c080, 0xc0000cdcc0, 0xc0000b1760, 0x1342be0, 0xc000099fb0, 0x194)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:736 +0x1fd
encoding/gob.(*Decoder).gobDecodeOpFor.func1(0xc0001481c0, 0xc0000b1760, 0x1342be0, 0xc000099fb0, 0x194)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:960 +0x7a
encoding/gob.(*Decoder).decodeArrayHelper(0xc00012c080, 0xc0000b1760, 0x1303b60, 0xc0000e4268, 0x197, 0xc0000b1960, 0x1, 0x14df3e0, 0xc000099fa0, 0x0)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:530 +0x179
encoding/gob.(*Decoder).decodeSlice(0xc00012c080, 0xc0000b1760, 0x1303b60, 0xc0000e4268, 0x197, 0xc0000b1960, 0x14df3e0, 0xc000099fa0, 0x0)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:630 +0x23c
encoding/gob.(*Decoder).decOpFor.func3(0xc0000ce8f8, 0xc0000b1760, 0x1303b60, 0xc0000e4268, 0x197)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:848 +0x78
encoding/gob.(*Decoder).decodeStruct(0xc00012c080, 0xc0000b1920, 0x133a2e0, 0xc0000e4258, 0x199)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:471 +0xe6
encoding/gob.(*Decoder).decOpFor.func4(0xc0000bc800, 0xc0000b1740, 0x133a2e0, 0xc0000e4258, 0x199)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:860 +0x54
encoding/gob.(*Decoder).decodeStruct(0xc00012c080, 0xc0000b1900, 0x133fda0, 0xc0000e4230, 0x199)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:471 +0xe6
encoding/gob.(*Decoder).decodeValue(0xc00012c080, 0x41, 0x1316d40, 0xc0000e4230, 0x16)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decode.go:1205 +0x2c5
encoding/gob.(*Decoder).DecodeValue(0xc00012c080, 0x1316d40, 0xc0000e4230, 0x16, 0x0, 0x0)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decoder.go:213 +0x146
encoding/gob.(*Decoder).Decode(0xc00012c080, 0x1316d40, 0xc0000e4230, 0xc000099c40, 0x1)
	/usr/local/Cellar/go/1.15.7_1/libexec/src/encoding/gob/decoder.go:188 +0x173
github.com/libp2p/go-libp2p-core/cmd.UnmarshalMessage(0xc00013e000, 0xd2, 0x17c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)

from go-libp2p-core.

Stebalien avatar Stebalien commented on July 2, 2024

It looks like we need to implement BinaryUnmarshal.

from go-libp2p-core.

Stebalien avatar Stebalien commented on July 2, 2024

But I'm not sure how to actually do this unless we want to define a custom "binary" format for address info objects.

from go-libp2p-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.