Archived
2
0

custom ipfetch #63.

This commit is contained in:
Miroslav Šedivý
2021-06-26 13:44:41 +02:00
parent 3a79615a2b
commit 7aa7e0eacb
2 changed files with 13 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"n.eko.moe/neko/internal/utils"
@ -31,6 +32,11 @@ func (WebRTC) Init(cmd *cobra.Command) error {
return err
}
cmd.PersistentFlags().String("ipfetch", "http://checkip.amazonaws.com", "automatically fetch IP address from given URL when nat1to1 is not present")
if err := viper.BindPFlag("ipfetch", cmd.PersistentFlags().Lookup("ipfetch")); err != nil {
return err
}
cmd.PersistentFlags().Bool("icelite", false, "configures whether or not the ice agent should be a lite agent")
if err := viper.BindPFlag("icelite", cmd.PersistentFlags().Lookup("icelite")); err != nil {
return err
@ -68,10 +74,12 @@ func (s *WebRTC) Set() {
}
if len(s.NAT1To1IPs) == 0 {
ip, err := utils.GetIP()
if err == nil {
s.NAT1To1IPs = append(s.NAT1To1IPs, ip)
ipfetch := viper.GetString("ipfetch")
ip, err := utils.GetIP(ipfetch)
if err != nil {
log.Panic().Err(err).Str("ipfetch", ipfetch).Msg("failed to fetch ip address")
}
s.NAT1To1IPs = append(s.NAT1To1IPs, ip)
}
min := uint16(59000)