From e22bda5bc7c6a52726a0b91ab981b73c884c3315 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 6 Jan 2022 14:35:05 -0500 Subject: [PATCH] un/block now respect other permissions. removed uneeded serialize --- model/conversation.go | 6 ------ peer/cwtch_peer.go | 38 +++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/model/conversation.go b/model/conversation.go index 9ed837b..df7e151 100644 --- a/model/conversation.go +++ b/model/conversation.go @@ -13,12 +13,6 @@ type AccessControl struct { Append bool // Allows a handle to append new messages to the conversation } -// Serialize transforms the AccessControl into json. -func (ac *AccessControl) Serialize() []byte { - data, _ := json.Marshal(ac) - return data -} - // DefaultP2PAccessControl - because in the year 2021, go does not support constant structs... func DefaultP2PAccessControl() AccessControl { return AccessControl{Read: true, Append: true, Blocked: false} diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 3a06846..2450df4 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -503,16 +503,6 @@ func (cp *cwtchPeer) AcceptConversation(id int) error { // BlockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true` // This will cause Cwtch to never try to connect to and refuse connections from the peer func (cp *cwtchPeer) BlockConversation(id int) error { - return cp.setACL(id, &model.AccessControl{Blocked: true, Read: false, Append: false}) -} - -// UnblockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true` -// Further actions depend on the Accepted field -func (cp *cwtchPeer) UnblockConversation(id int) error { - return cp.setACL(id, &model.AccessControl{Blocked: false, Read: false, Append: false}) -} - -func (cp *cwtchPeer) setACL(id int, acl *model.AccessControl) error { cp.mutex.Lock() defer cp.mutex.Unlock() ci, err := cp.storage.GetConversation(id) @@ -521,7 +511,33 @@ func (cp *cwtchPeer) setACL(id int, acl *model.AccessControl) error { } // p2p conversations have a single ACL referencing the remote peer. Set this to blocked... - ci.ACL[ci.Handle] = *acl + if ac, exists := ci.ACL[ci.Handle]; exists { + ac.Blocked = true + ci.ACL[ci.Handle] = ac + } + + // Send an event in any case to block the protocol engine... + // TODO at some point in the future engine needs to understand ACLs not just legacy auth status + cp.sendUpdateAuth(id, ci.Handle, ci.Accepted, ci.ACL[ci.Handle].Blocked) + + return cp.storage.SetConversationACL(id, ci.ACL) +} + +// UnblockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true` +// Further actions depend on the Accepted field +func (cp *cwtchPeer) UnblockConversation(id int) error { + cp.mutex.Lock() + defer cp.mutex.Unlock() + ci, err := cp.storage.GetConversation(id) + if err != nil { + return err + } + + // p2p conversations have a single ACL referencing the remote peer. Set ACL's blocked to false... + if ac, exists := ci.ACL[ci.Handle]; exists { + ac.Blocked = false + ci.ACL[ci.Handle] = ac + } // Send an event in any case to block the protocol engine... // TODO at some point in the future engine needs to understand ACLs not just legacy auth status