diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index b7bd742..614f6e5 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -573,6 +573,9 @@ func (cp *cwtchPeer) Shutdown() { } func (cp *cwtchPeer) StoreMessage(onion string, messageTxt string, sent time.Time) { + if cp.GetContact(onion) == nil { + cp.AddContact(onion, onion, model.AuthUnknown) + } cp.mutex.Lock() cp.Profile.AddMessageToContactTimeline(onion, messageTxt, sent) cp.mutex.Unlock() @@ -620,18 +623,21 @@ func (cp *cwtchPeer) eventHandler() { log.Debugf("NewGetValMessageFromPeer for %v%v from %v\n", scope, path, onion) - if scope == attr.PublicScope { - val, exists := cp.GetAttribute(attr.GetPublicScope(path)) - resp := event.NewEvent(event.SendRetValMessageToPeer, map[event.Field]string{event.RemotePeer: onion, event.Exists: strconv.FormatBool(exists)}) - resp.EventID = ev.EventID - if exists { - resp.Data[event.Data] = val - } else { - resp.Data[event.Data] = "" - } - log.Debugf("Responding with SendRetValMessageToPeer exists:%v data: %v\n", exists, val) + remotePeer := cp.GetContact(onion) + if remotePeer != nil && remotePeer.Authorization == model.AuthApproved { + if scope == attr.PublicScope { + val, exists := cp.GetAttribute(attr.GetPublicScope(path)) + resp := event.NewEvent(event.SendRetValMessageToPeer, map[event.Field]string{event.RemotePeer: onion, event.Exists: strconv.FormatBool(exists)}) + resp.EventID = ev.EventID + if exists { + resp.Data[event.Data] = val + } else { + resp.Data[event.Data] = "" + } + log.Debugf("Responding with SendRetValMessageToPeer exists:%v data: %v\n", exists, val) - cp.eventBus.Publish(resp) + cp.eventBus.Publish(resp) + } } /***** Non default but requestable handlable events *****/ diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index 11d84b6..29be800 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -195,18 +195,22 @@ func (e *engine) isBlocked(onion string) bool { return authorization.(model.Authorization) == model.AuthBlocked } -func (e *engine) isApproved(onion string) bool { +func (e *engine) isAllowed(onion string) bool { authorization, known := e.authorizations.Load(onion) if !known { + log.Errorf("attempted to lookup authorization of onion not in map...that should never happen") return false } - return authorization.(model.Authorization) == model.AuthApproved + if e.blockUnknownContacts { + return authorization.(model.Authorization) == model.AuthApproved + } + return authorization.(model.Authorization) != model.AuthBlocked } func (e *engine) createPeerTemplate() *PeerApp { peerAppTemplate := new(PeerApp) peerAppTemplate.IsBlocked = e.isBlocked - peerAppTemplate.IsApproved = e.isApproved + peerAppTemplate.IsAllowed = e.isAllowed peerAppTemplate.MessageHandler = e.handlePeerMessage peerAppTemplate.OnAcknowledgement = e.ignoreOnShutdown2(e.peerAck) peerAppTemplate.OnAuth = e.ignoreOnShutdown(e.peerAuthed) diff --git a/protocol/connections/peerapp.go b/protocol/connections/peerapp.go index 45b601c..24650b1 100644 --- a/protocol/connections/peerapp.go +++ b/protocol/connections/peerapp.go @@ -18,7 +18,7 @@ type PeerApp struct { MessageHandler func(string, string, string, []byte) RetValHandler func(string, []byte, []byte) IsBlocked func(string) bool - IsApproved func(string) bool + IsAllowed func(string) bool OnAcknowledgement func(string, string) OnAuth func(string) OnClose func(string) @@ -48,7 +48,7 @@ func (pa *PeerApp) NewInstance() tapir.Application { newApp := new(PeerApp) newApp.MessageHandler = pa.MessageHandler newApp.IsBlocked = pa.IsBlocked - newApp.IsApproved = pa.IsApproved + newApp.IsAllowed = pa.IsAllowed newApp.OnAcknowledgement = pa.OnAcknowledgement newApp.OnAuth = pa.OnAuth newApp.OnClose = pa.OnClose @@ -101,7 +101,7 @@ func (pa *PeerApp) listen() { pa.getValRequests.Delete(peerMessage.ID) } default: - if pa.IsApproved(pa.connection.Hostname()) { + if pa.IsAllowed(pa.connection.Hostname()) { pa.MessageHandler(pa.connection.Hostname(), peerMessage.ID, peerMessage.Context, peerMessage.Data) // Acknowledge the message