mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-04-29 08:10:34 +00:00
refactor(internal/peer): reduce default logging
This commit is contained in:
parent
cc2de7bc9b
commit
6c12375e17
@ -5,9 +5,9 @@ import (
|
|||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"koti.casa/numenor-labs/dsfx/internal/lib/crypto/identity"
|
"koti.casa/numenor-labs/dsfx/internal/lib/crypto/identity"
|
||||||
@ -85,7 +85,7 @@ func New(disk disk.Disk, system system.System) *Peer {
|
|||||||
func (p *Peer) Run(ctx context.Context) error {
|
func (p *Peer) Run(ctx context.Context) error {
|
||||||
opts := &slog.HandlerOptions{
|
opts := &slog.HandlerOptions{
|
||||||
AddSource: false,
|
AddSource: false,
|
||||||
Level: slog.LevelDebug,
|
Level: slog.LevelInfo,
|
||||||
}
|
}
|
||||||
logger := slog.New(slog.NewTextHandler(p.system.Stdout(), opts))
|
logger := slog.New(slog.NewTextHandler(p.system.Stdout(), opts))
|
||||||
|
|
||||||
@ -169,9 +169,6 @@ func (p *Peer) loadAdmins() ([]string, error) {
|
|||||||
func (p *Peer) hasAdminsFile() (bool, error) {
|
func (p *Peer) hasAdminsFile() (bool, error) {
|
||||||
f, err := p.config.Open("admins")
|
f, err := p.config.Open("admins")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@ -237,11 +234,8 @@ func (p *Peer) loadIdentity() (ed25519.PrivateKey, error) {
|
|||||||
|
|
||||||
// hasKeyFile checks if the key file exists in the disk storage.
|
// hasKeyFile checks if the key file exists in the disk storage.
|
||||||
func (p *Peer) hasKeyFile() (bool, error) {
|
func (p *Peer) hasKeyFile() (bool, error) {
|
||||||
f, err := p.config.Open("key")
|
f, err := p.config.Open("ed25519.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@ -251,7 +245,7 @@ func (p *Peer) hasKeyFile() (bool, error) {
|
|||||||
|
|
||||||
// createKeyFile creates a new key file with a generated private key.
|
// createKeyFile creates a new key file with a generated private key.
|
||||||
func (p *Peer) createKeyFile() error {
|
func (p *Peer) createKeyFile() error {
|
||||||
f, err := p.config.Create("key")
|
f, err := p.config.Create("ed25519.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -272,19 +266,23 @@ func (p *Peer) createKeyFile() error {
|
|||||||
|
|
||||||
// readKeyFile reads the private key from the key file and returns it as an ed25519.PrivateKey.
|
// readKeyFile reads the private key from the key file and returns it as an ed25519.PrivateKey.
|
||||||
func (p *Peer) readKeyFile() (ed25519.PrivateKey, error) {
|
func (p *Peer) readKeyFile() (ed25519.PrivateKey, error) {
|
||||||
f, err := p.config.Open("key")
|
f, err := p.config.Open("ed25519.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
keyRaw := make([]byte, ed25519.PrivateKeySize)
|
keyRawBase64, err := io.ReadAll(f)
|
||||||
n, err := f.Read(keyRaw)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if n != ed25519.PrivateKeySize {
|
|
||||||
return nil, fmt.Errorf("key file is not the correct size: %d", n)
|
keyRaw, err := base64.StdEncoding.DecodeString(string(keyRawBase64))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(keyRaw) != ed25519.PrivateKeySize {
|
||||||
|
return nil, fmt.Errorf("key file is not the correct size: %d", len(keyRaw))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ed25519.PrivateKey(keyRaw), nil
|
return ed25519.PrivateKey(keyRaw), nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user