Wrap the metadata with a mutex to guarantee thread safety across core/router/sessions

This commit is contained in:
Neil Alexander 2018-12-12 22:40:49 +00:00
parent 97464feba9
commit 042a3400fe
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 40 additions and 14 deletions

View file

@ -58,7 +58,9 @@ func (r *router) init(core *Core) {
r.addr = *address_addrForNodeID(&r.core.dht.nodeID)
r.subnet = *address_subnetForNodeID(&r.core.dht.nodeID)
in := make(chan []byte, 32) // TODO something better than this...
r.core.sessions.myMetadataMutex.RLock()
p := r.core.peers.newPeer(&r.core.boxPub, &r.core.sigPub, &boxSharedKey{}, "(self)", r.core.sessions.myMetadata)
r.core.sessions.myMetadataMutex.RUnlock()
p.out = func(packet []byte) {
// This is to make very sure it never blocks
select {