Merge pull request 'Correctly Handle Messages from Unknown Peers' (#332) from first_contact into master
the build was successful
Details
the build was successful
Details
Reviewed-on: #332 discussion was had about permissions, tracking unknowns, and querying vals of unknowns and changes were made to protect getVal requests, and since the meaning of isApproved is changing to rename isAllowed. this is to smooth the introduction process of new peers, following a twitter DM style. Protection is still afforded for anyone with BlockUnknownPeers enabled. Previously described schemes in the 2020 Feb doc on getVal and new peer experience around this that still haven’t been implemented are further shelved for now
This commit is contained in:
commit
c79b083bbc
|
@ -573,6 +573,9 @@ func (cp *cwtchPeer) Shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *cwtchPeer) StoreMessage(onion string, messageTxt string, sent time.Time) {
|
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.mutex.Lock()
|
||||||
cp.Profile.AddMessageToContactTimeline(onion, messageTxt, sent)
|
cp.Profile.AddMessageToContactTimeline(onion, messageTxt, sent)
|
||||||
cp.mutex.Unlock()
|
cp.mutex.Unlock()
|
||||||
|
@ -620,6 +623,8 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
|
|
||||||
log.Debugf("NewGetValMessageFromPeer for %v%v from %v\n", scope, path, onion)
|
log.Debugf("NewGetValMessageFromPeer for %v%v from %v\n", scope, path, onion)
|
||||||
|
|
||||||
|
remotePeer := cp.GetContact(onion)
|
||||||
|
if remotePeer != nil && remotePeer.Authorization == model.AuthApproved {
|
||||||
if scope == attr.PublicScope {
|
if scope == attr.PublicScope {
|
||||||
val, exists := cp.GetAttribute(attr.GetPublicScope(path))
|
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 := event.NewEvent(event.SendRetValMessageToPeer, map[event.Field]string{event.RemotePeer: onion, event.Exists: strconv.FormatBool(exists)})
|
||||||
|
@ -633,6 +638,7 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
|
|
||||||
cp.eventBus.Publish(resp)
|
cp.eventBus.Publish(resp)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***** Non default but requestable handlable events *****/
|
/***** Non default but requestable handlable events *****/
|
||||||
|
|
||||||
|
|
|
@ -195,18 +195,22 @@ func (e *engine) isBlocked(onion string) bool {
|
||||||
return authorization.(model.Authorization) == model.AuthBlocked
|
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)
|
authorization, known := e.authorizations.Load(onion)
|
||||||
if !known {
|
if !known {
|
||||||
|
log.Errorf("attempted to lookup authorization of onion not in map...that should never happen")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if e.blockUnknownContacts {
|
||||||
return authorization.(model.Authorization) == model.AuthApproved
|
return authorization.(model.Authorization) == model.AuthApproved
|
||||||
|
}
|
||||||
|
return authorization.(model.Authorization) != model.AuthBlocked
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *engine) createPeerTemplate() *PeerApp {
|
func (e *engine) createPeerTemplate() *PeerApp {
|
||||||
peerAppTemplate := new(PeerApp)
|
peerAppTemplate := new(PeerApp)
|
||||||
peerAppTemplate.IsBlocked = e.isBlocked
|
peerAppTemplate.IsBlocked = e.isBlocked
|
||||||
peerAppTemplate.IsApproved = e.isApproved
|
peerAppTemplate.IsAllowed = e.isAllowed
|
||||||
peerAppTemplate.MessageHandler = e.handlePeerMessage
|
peerAppTemplate.MessageHandler = e.handlePeerMessage
|
||||||
peerAppTemplate.OnAcknowledgement = e.ignoreOnShutdown2(e.peerAck)
|
peerAppTemplate.OnAcknowledgement = e.ignoreOnShutdown2(e.peerAck)
|
||||||
peerAppTemplate.OnAuth = e.ignoreOnShutdown(e.peerAuthed)
|
peerAppTemplate.OnAuth = e.ignoreOnShutdown(e.peerAuthed)
|
||||||
|
|
|
@ -18,7 +18,7 @@ type PeerApp struct {
|
||||||
MessageHandler func(string, string, string, []byte)
|
MessageHandler func(string, string, string, []byte)
|
||||||
RetValHandler func(string, []byte, []byte)
|
RetValHandler func(string, []byte, []byte)
|
||||||
IsBlocked func(string) bool
|
IsBlocked func(string) bool
|
||||||
IsApproved func(string) bool
|
IsAllowed func(string) bool
|
||||||
OnAcknowledgement func(string, string)
|
OnAcknowledgement func(string, string)
|
||||||
OnAuth func(string)
|
OnAuth func(string)
|
||||||
OnClose func(string)
|
OnClose func(string)
|
||||||
|
@ -48,7 +48,7 @@ func (pa *PeerApp) NewInstance() tapir.Application {
|
||||||
newApp := new(PeerApp)
|
newApp := new(PeerApp)
|
||||||
newApp.MessageHandler = pa.MessageHandler
|
newApp.MessageHandler = pa.MessageHandler
|
||||||
newApp.IsBlocked = pa.IsBlocked
|
newApp.IsBlocked = pa.IsBlocked
|
||||||
newApp.IsApproved = pa.IsApproved
|
newApp.IsAllowed = pa.IsAllowed
|
||||||
newApp.OnAcknowledgement = pa.OnAcknowledgement
|
newApp.OnAcknowledgement = pa.OnAcknowledgement
|
||||||
newApp.OnAuth = pa.OnAuth
|
newApp.OnAuth = pa.OnAuth
|
||||||
newApp.OnClose = pa.OnClose
|
newApp.OnClose = pa.OnClose
|
||||||
|
@ -101,7 +101,7 @@ func (pa *PeerApp) listen() {
|
||||||
pa.getValRequests.Delete(peerMessage.ID)
|
pa.getValRequests.Delete(peerMessage.ID)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if pa.IsApproved(pa.connection.Hostname()) {
|
if pa.IsAllowed(pa.connection.Hostname()) {
|
||||||
pa.MessageHandler(pa.connection.Hostname(), peerMessage.ID, peerMessage.Context, peerMessage.Data)
|
pa.MessageHandler(pa.connection.Hostname(), peerMessage.ID, peerMessage.Context, peerMessage.Data)
|
||||||
|
|
||||||
// Acknowledge the message
|
// Acknowledge the message
|
||||||
|
|
Loading…
Reference in New Issue