Add NIP-11 relay synchronization and group management features
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- 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:
2025-11-03 18:17:15 +00:00
parent e161d0e4be
commit e56bf76257
83 changed files with 3712 additions and 7417 deletions

View File

@@ -238,6 +238,98 @@ This package works with:
- **event package**: For event structures
- **EventStore**: Can be integrated with any event storage system
## Testing
The directory-client package includes comprehensive tests to ensure reliability and correctness:
### Running Tests
```bash
# Run directory-client tests
go test ./pkg/protocol/directory-client
# Run all tests including directory-client
go test ./...
# Run with verbose output
go test -v ./pkg/protocol/directory-client
# Run with race detection
go test -race ./pkg/protocol/directory-client
# Run with coverage
go test -cover ./pkg/protocol/directory-client
```
### Integration Testing
The directory-client is tested as part of the project's integration test suite:
```bash
# Run the full test suite
./scripts/test.sh
# Run specific package tests
go test ./pkg/protocol/...
```
### Test Coverage
The test suite covers:
- **Identity Resolution**: Delegate key mapping, identity resolution, caching
- **Trust Calculation**: Trust score computation, act aggregation, expiration handling
- **Replication Filtering**: Trust threshold filtering, relay selection
- **Event Collection**: Event parsing, filtering by type, collection utilities
- **Trust Graph**: Graph construction, relationship analysis
- **Thread Safety**: Concurrent access patterns, race condition prevention
- **Error Handling**: Invalid events, malformed data, edge cases
### Example Test Usage
```bash
# Test identity resolution functionality
go test -v ./pkg/protocol/directory-client -run TestIdentityResolver
# Test trust calculation
go test -v ./pkg/protocol/directory-client -run TestTrustCalculator
# Test thread safety
go test -race -v ./pkg/protocol/directory-client
```
## Development
### Building and Usage
```bash
# Build the directory-client package
go build ./pkg/protocol/directory-client
# Run example usage
go run -tags=example ./pkg/protocol/directory-client
```
### Code Quality
The directory-client follows Go best practices:
- Comprehensive error handling with custom error types
- Thread-safe concurrent access
- Memory-efficient data structures
- Extensive documentation and examples
- Full test coverage with race detection
### Adding New Features
When adding new functionality:
1. Add unit tests for new components
2. Update existing tests if behavior changes
3. Ensure thread safety for concurrent access
4. Add documentation and examples
5. Update the API reference section
## Related Documentation
- [NIP-XX Specification](../../docs/NIP-XX-distributed-directory-consensus.md)