Browse Source

un/block now respect other permissions. removed uneeded serialize

fixAcceptBlock
Dan Ballard 1 week ago
parent
commit
e22bda5bc7
  1. 6
      model/conversation.go
  2. 30
      peer/cwtch_peer.go

6
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}

30
peer/cwtch_peer.go

@ -503,16 +503,29 @@ 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})
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 this to blocked...
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 {
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)
@ -520,8 +533,11 @@ func (cp *cwtchPeer) setACL(id int, acl *model.AccessControl) error {
return err
}
// p2p conversations have a single ACL referencing the remote peer. Set this to blocked...
ci.ACL[ci.Handle] = *acl
// 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

Loading…
Cancel
Save