Comments (4)
from go-libp2p-core.
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.
It looks like we need to implement BinaryUnmarshal.
from go-libp2p-core.
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)
- Host event bus does not emit EvtPeerConnectednessChanged HOT 5
- Error in using libp2pquic.NewTransport with libp2p.Transport HOT 2
- Record envelope protobuf does not match spec HOT 2
- Add a `ClearDeadline` API HOT 4
- v0.7.0 breaks backward compatibility for multiple packages HOT 3
- add WithStat option for host.NewStream HOT 3
- Closing streams does not transmit all data HOT 1
- flaky TestResetBandwidthCounter test HOT 1
- How to know the conn has been closed
- What happened to the method in **helps**? HOT 1
- Reliable Notifiee events HOT 1
- looks unsafe HOT 2
- routing.go HOT 1
- How to convert PrivKey to crypto/ecdsa.PrivateKey? HOT 1
- Requesting release 0.16 with "update btcec dependency" change HOT 4
- btcec update leads to `go mod tidy` failure HOT 9
- extend `peer.Set` with the Remove method HOT 4
- Unable to know data on the connected node HOT 1
- use a mock clock in bandwidth counter tests HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-libp2p-core.