various minor cleanups and improvements to error handling

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-05-04 12:48:28 +02:00
parent 9814c5c382
commit 1fc478b902
11 changed files with 19 additions and 17 deletions

View File

@@ -62,6 +62,7 @@ func daemon(cmd *cobra.Command, args []string) {
}
if logger.Core().Enabled(zap.DebugLevel) {
logger.Debug("Loaded configuration:")
cfg.Dump(&zapio.Writer{Log: logger})
}

View File

@@ -69,7 +69,7 @@ func docsManpage(cmd *cobra.Command, args []string) error {
d, err := time.Parse(time.RFC3339, date)
if err != nil {
return fmt.Errorf("failed to parse build date")
d = time.Now()
}
header := &doc.GenManHeader{

View File

@@ -34,10 +34,6 @@ func CmpNet(a, b *net.IPNet) int {
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.
// It will return an error if the system's secure random
// number generator fails to function correctly, in which

View File

@@ -64,7 +64,7 @@ func (i *BaseInterface) Close() error {
for _, p := range i.peers {
if err := p.Close(); err != nil {
return err
return fmt.Errorf("failed to close peer: %w", err)
}
}

View File

@@ -32,6 +32,6 @@ func TestWireguardLink(t *testing.T) {
}
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)
}
}

View File

@@ -55,7 +55,7 @@ func waitForSocket(path string) error {
func Connect(path string) (*Client, error) {
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)

View File

@@ -23,7 +23,7 @@ import (
"riasc.eu/wice/pkg/socket"
)
// Agent is a host running WICE
// Agent is a host running ɯice
type Agent struct {
*g.Host
@@ -120,7 +120,7 @@ func (a *Agent) Start(directArgs ...interface{}) error {
log.Fatal(err)
}
cmd, err := buildWICE(a.Network())
cmd, err := buildBinary(a.Network())
if err != nil {
return fmt.Errorf("failed to build wice: %w", err)
}

View File

@@ -2,18 +2,23 @@ package e2e
import (
"fmt"
"sync"
g "github.com/stv0g/gont/pkg"
)
var (
// Singleton for compiled wice executable
wiceBinary string
binary string
binaryMutex sync.Mutex
)
func buildWICE(n *g.Network) (string, error) {
if wiceBinary != "" {
return wiceBinary, nil
func buildBinary(n *g.Network) (string, error) {
binaryMutex.Lock()
defer binaryMutex.Unlock()
if binary != "" {
return binary, nil
}
wiceBinary := "/tmp/wice"

View File

@@ -9,7 +9,7 @@ import (
)
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")
if err != nil {
return nil, err

View File

@@ -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)))
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()

View File

@@ -51,7 +51,7 @@ func (s *GrpcSignalingNode) Start(_ ...interface{}) error {
"--listen", fmt.Sprintf(":%d", s.port),
}
cmd, err := buildWICE(s.Network())
cmd, err := buildBinary(s.Network())
if err != nil {
return fmt.Errorf("failed to build wice: %w", err)
}