mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
## Description Whew, some stuff is still not re-implemented, but it's working! Rabbit's gonna explode with the amount of changes I reckon 😅 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a peer-to-peer relay system using libp2p with enhanced stream forwarding, room state synchronization, and mDNS peer discovery. - Added decentralized room and participant management, metrics publishing, and safe, size-limited, concurrent message streaming with robust framing and callback dispatching. - Implemented asynchronous, callback-driven message handling over custom libp2p streams replacing WebSocket signaling. - **Improvements** - Migrated signaling and stream protocols from WebSocket to libp2p, improving reliability and scalability. - Simplified configuration and environment variables, removing deprecated flags and adding persistent data support. - Enhanced logging, error handling, and connection management for better observability and robustness. - Refined RTP header extension registration and NAT IP handling for improved WebRTC performance. - **Bug Fixes** - Improved ICE candidate buffering and SDP negotiation in WebRTC connections. - Fixed NAT IP and UDP port range configuration issues. - **Refactor** - Modularized codebase, reorganized relay and server logic, and removed deprecated WebSocket-based components. - Streamlined message structures, removed obsolete enums and message types, and simplified SafeMap concurrency. - Replaced WebSocket signaling with libp2p stream protocols in server and relay components. - **Chores** - Updated and cleaned dependencies across Go, Rust, and JavaScript packages. - Added `.gitignore` for persistent data directory in relay package. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Philipp Neumann <3daquawolf@gmail.com>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package common
|
|
|
|
import (
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/oklog/ulid/v2"
|
|
)
|
|
|
|
func NewULID() (ulid.ULID, error) {
|
|
return ulid.New(ulid.Timestamp(time.Now()), ulid.Monotonic(rand.Reader, 0))
|
|
}
|
|
|
|
// GenerateED25519Key generates a new ED25519 key
|
|
func GenerateED25519Key() (ed25519.PrivateKey, error) {
|
|
_, priv, err := ed25519.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to generate ED25519 key pair: %w", err)
|
|
}
|
|
return priv, nil
|
|
}
|
|
|
|
// SaveED25519Key saves an ED25519 private key to a path as a binary file
|
|
func SaveED25519Key(privateKey ed25519.PrivateKey, filePath string) error {
|
|
if privateKey == nil {
|
|
return errors.New("private key cannot be nil")
|
|
}
|
|
if len(privateKey) != ed25519.PrivateKeySize {
|
|
return errors.New("private key must be exactly 64 bytes for ED25519")
|
|
}
|
|
if err := os.WriteFile(filePath, privateKey, 0600); err != nil {
|
|
return fmt.Errorf("failed to save ED25519 key to %s: %w", filePath, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// LoadED25519Key loads an ED25519 private key binary file from a path
|
|
func LoadED25519Key(filePath string) (ed25519.PrivateKey, error) {
|
|
data, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read ED25519 key from %s: %w", filePath, err)
|
|
}
|
|
if len(data) != ed25519.PrivateKeySize {
|
|
return nil, fmt.Errorf("ED25519 key must be exactly %d bytes, got %d", ed25519.PrivateKeySize, len(data))
|
|
}
|
|
return data, nil
|
|
}
|