Add NIP-11 relay synchronization and group management features
- Introduced a new `sync` package for managing NIP-11 relay information and relay group configurations. - Implemented a cache for NIP-11 documents, allowing retrieval of relay public keys and authoritative configurations. - Enhanced the sync manager to update peer lists based on authoritative configurations from relay group events. - Updated event handling to incorporate policy checks during event imports, ensuring compliance with relay rules. - Refactored various components to utilize the new `sha256-simd` package for improved performance. - Added comprehensive tests to validate the new synchronization and group management functionalities. - Bumped version to v0.24.1 to reflect these changes.
This commit is contained in:
@@ -23,6 +23,7 @@ type Managed struct {
|
||||
managedACL *database.ManagedACL
|
||||
owners [][]byte
|
||||
admins [][]byte
|
||||
peerAdmins [][]byte // peer relay identity pubkeys with admin access
|
||||
mx sync.RWMutex
|
||||
}
|
||||
|
||||
@@ -73,6 +74,15 @@ func (m *Managed) Configure(cfg ...any) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// UpdatePeerAdmins updates the list of peer relay identity pubkeys that have admin access
|
||||
func (m *Managed) UpdatePeerAdmins(peerPubkeys [][]byte) {
|
||||
m.mx.Lock()
|
||||
defer m.mx.Unlock()
|
||||
m.peerAdmins = make([][]byte, len(peerPubkeys))
|
||||
copy(m.peerAdmins, peerPubkeys)
|
||||
log.I.F("updated peer admin list with %d pubkeys", len(peerPubkeys))
|
||||
}
|
||||
|
||||
func (m *Managed) GetAccessLevel(pub []byte, address string) (level string) {
|
||||
m.mx.RLock()
|
||||
defer m.mx.RUnlock()
|
||||
@@ -96,6 +106,13 @@ func (m *Managed) GetAccessLevel(pub []byte, address string) (level string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check peer relay identity pubkeys (they get admin access)
|
||||
for _, v := range m.peerAdmins {
|
||||
if utils.FastEqual(v, pub) {
|
||||
return "admin"
|
||||
}
|
||||
}
|
||||
|
||||
// Check if pubkey is banned
|
||||
pubkeyHex := hex.EncodeToString(pub)
|
||||
if banned, err := m.managedACL.IsPubkeyBanned(pubkeyHex); err == nil && banned {
|
||||
|
||||
Reference in New Issue
Block a user