changed some logs and added bool for server pull

This commit is contained in:
0xdcarns 2021-10-14 12:15:25 -04:00
parent 3b58aa5cec
commit 7f6a288e21
3 changed files with 11 additions and 11 deletions

View file

@ -142,7 +142,7 @@ func ServerCheckin(mac string, network string) error {
return err
}
newNode, err = ServerPull(mac, network)
newNode, err = ServerPull(mac, network, false)
if isDeleteError(err) {
return ServerLeave(mac, network)
} else if err != nil {
@ -158,7 +158,7 @@ func ServerCheckin(mac string, network string) error {
}
// ServerPull - pulls current config/peers for server
func ServerPull(mac string, network string) (*models.Node, error) {
func ServerPull(mac string, network string, onErr bool) (*models.Node, error) {
var serverNode models.Node
var err error
@ -174,7 +174,7 @@ func ServerPull(mac string, network string) (*models.Node, error) {
}
serverNode.OS = runtime.GOOS
if serverNode.PullChanges == "yes" {
if serverNode.PullChanges == "yes" || onErr {
// check for interface change
var isIfacePresent bool
var oldIfaceName string
@ -197,7 +197,7 @@ func ServerPull(mac string, network string) (*models.Node, error) {
} else {
if err = setWGConfig(serverNode, network, true); err != nil {
if errors.Is(err, os.ErrNotExist) {
return ServerPull(serverNode.MacAddress, serverNode.Network)
return ServerPull(serverNode.MacAddress, serverNode.Network, true)
} else {
return &serverNode, err
}

View file

@ -161,7 +161,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
}
if _, err := ncutils.RunCmd(ipExec+" link set down dev "+ifacename, false); err != nil {
ncutils.Log("attempted to remove interface before editing")
Log("attempted to remove interface before editing", 2)
return err
}
@ -171,7 +171,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
}
// set MTU of node interface
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
ncutils.Log("failed to create interface with mtu " + ifacename)
Log("failed to create interface with mtu "+ifacename, 2)
return err
}
@ -224,18 +224,18 @@ func setServerPeers(iface string, keepalive int32, peers []wgtypes.PeerConfig) e
client, err := wgctrl.New()
if err != nil {
ncutils.PrintLog("failed to start wgctrl", 0)
Log("failed to start wgctrl", 0)
return err
}
device, err := client.Device(iface)
if err != nil {
ncutils.PrintLog("failed to parse interface", 0)
Log("failed to parse interface", 0)
return err
}
devicePeers := device.Peers
if len(devicePeers) > 1 && len(peers) == 0 {
ncutils.PrintLog("no peers pulled", 1)
Log("no peers pulled", 1)
return err
}
@ -272,7 +272,7 @@ func setServerPeers(iface string, keepalive int32, peers []wgtypes.PeerConfig) e
" allowed-ips "+allowedips, true)
}
if err != nil {
log.Println("error setting peer", peer.PublicKey.String())
Log("error setting peer "+peer.PublicKey.String(), 1)
}
}

View file

@ -107,7 +107,7 @@ func HandleContainedClient() error {
err = logic.ServerCheckin(servercfg.GetNodeID(), serverNet.NetID)
if err != nil {
logic.Log("error occurred during server checkin, running a pull: "+err.Error(), 1)
_, err = logic.ServerPull(servercfg.GetNodeID(), serverNet.NetID)
_, err = logic.ServerPull(servercfg.GetNodeID(), serverNet.NetID, true)
if err != nil {
logic.Log("error when pulling after checkin: "+err.Error(), 1)
}