mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-28 02:31:32 +08:00
various minor cleanups and improvements to error handling
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -62,6 +62,7 @@ func daemon(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if logger.Core().Enabled(zap.DebugLevel) {
|
if logger.Core().Enabled(zap.DebugLevel) {
|
||||||
|
logger.Debug("Loaded configuration:")
|
||||||
cfg.Dump(&zapio.Writer{Log: logger})
|
cfg.Dump(&zapio.Writer{Log: logger})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func docsManpage(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
d, err := time.Parse(time.RFC3339, date)
|
d, err := time.Parse(time.RFC3339, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse build date")
|
d = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
header := &doc.GenManHeader{
|
header := &doc.GenManHeader{
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ func CmpNet(a, b *net.IPNet) int {
|
|||||||
return bytes.Compare(a.IP, b.IP)
|
return bytes.Compare(a.IP, b.IP)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func lessNets(nets []net.IPNet) Less {
|
|
||||||
// return func(i, j int) bool { return cmpNet(&nets[i], &nets[j]) < 0 }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// GenerateRandomBytes returns securely generated random bytes.
|
// GenerateRandomBytes returns securely generated random bytes.
|
||||||
// It will return an error if the system's secure random
|
// It will return an error if the system's secure random
|
||||||
// number generator fails to function correctly, in which
|
// number generator fails to function correctly, in which
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (i *BaseInterface) Close() error {
|
|||||||
|
|
||||||
for _, p := range i.peers {
|
for _, p := range i.peers {
|
||||||
if err := p.Close(); err != nil {
|
if err := p.Close(); err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to close peer: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ func TestWireguardLink(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := netlink.LinkDel(l); err != nil {
|
if err := netlink.LinkDel(l); err != nil {
|
||||||
t.Errorf("failed to delete Wireguard device: %w", err)
|
t.Errorf("failed to delete Wireguard device: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func waitForSocket(path string) error {
|
|||||||
|
|
||||||
func Connect(path string) (*Client, error) {
|
func Connect(path string) (*Client, error) {
|
||||||
if err := waitForSocket(path); err != nil {
|
if err := waitForSocket(path); err != nil {
|
||||||
return nil, fmt.Errorf("failed to wait for socket: %w", err)
|
return nil, fmt.Errorf("failed to wait for socket: %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tgt := fmt.Sprintf("unix://%s", path)
|
tgt := fmt.Sprintf("unix://%s", path)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
"riasc.eu/wice/pkg/socket"
|
"riasc.eu/wice/pkg/socket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Agent is a host running WICE
|
// Agent is a host running ɯice
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
*g.Host
|
*g.Host
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ func (a *Agent) Start(directArgs ...interface{}) error {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := buildWICE(a.Network())
|
cmd, err := buildBinary(a.Network())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to build wice: %w", err)
|
return fmt.Errorf("failed to build wice: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,23 @@ package e2e
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
g "github.com/stv0g/gont/pkg"
|
g "github.com/stv0g/gont/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Singleton for compiled wice executable
|
// Singleton for compiled wice executable
|
||||||
wiceBinary string
|
binary string
|
||||||
|
binaryMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildWICE(n *g.Network) (string, error) {
|
func buildBinary(n *g.Network) (string, error) {
|
||||||
if wiceBinary != "" {
|
binaryMutex.Lock()
|
||||||
return wiceBinary, nil
|
defer binaryMutex.Unlock()
|
||||||
|
|
||||||
|
if binary != "" {
|
||||||
|
return binary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
wiceBinary := "/tmp/wice"
|
wiceBinary := "/tmp/wice"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Filtered(p *NetworkParams) (*Network, error) {
|
func Filtered(p *NetworkParams) (*Network, error) {
|
||||||
// We are dropped packets between the WICE nodes to force ICE using the relay
|
// We are dropped packets between the ɯice nodes to force ICE using the relay
|
||||||
_, hostNetV4, err := net.ParseCIDR("10.0.1.0/24")
|
_, hostNetV4, err := net.ParseCIDR("10.0.1.0/24")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func RunTest(t *testing.T, factory net.NetworkFactory, p *net.NetworkParams, arg
|
|||||||
|
|
||||||
logger.Info("Starting agent nodes", zap.Int("count", len(n.Agents)))
|
logger.Info("Starting agent nodes", zap.Int("count", len(n.Agents)))
|
||||||
if err := n.Agents.Start(args...); err != nil {
|
if err := n.Agents.Start(args...); err != nil {
|
||||||
t.Fatalf("Failed to start WICE: %s", err)
|
t.Fatalf("Failed to start ɯice: %s", err)
|
||||||
}
|
}
|
||||||
defer n.Agents.Stop()
|
defer n.Agents.Stop()
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (s *GrpcSignalingNode) Start(_ ...interface{}) error {
|
|||||||
"--listen", fmt.Sprintf(":%d", s.port),
|
"--listen", fmt.Sprintf(":%d", s.port),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := buildWICE(s.Network())
|
cmd, err := buildBinary(s.Network())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to build wice: %w", err)
|
return fmt.Errorf("failed to build wice: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user