diff options
| author | Jeff Carr <[email protected]> | 2025-10-17 01:29:58 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-17 01:29:58 -0500 |
| commit | ad65f65ff65d5068ff79daffca330183239aead2 (patch) | |
| tree | b15cac35ae5143bf307de24795f09648c197db20 | |
| parent | 3fc1bb304ec83948f7f721814b1234b2c20d0ec8 (diff) | |
improving new user flow still. add IPv6 test
| -rw-r--r-- | doNewUser.go | 28 | ||||
| -rw-r--r-- | doNormal.go | 1 | ||||
| -rw-r--r-- | doRebuild.go | 7 | ||||
| -rw-r--r-- | ipv6test.go | 33 | ||||
| -rw-r--r-- | ipv6test.go.new | 55 | ||||
| -rw-r--r-- | resources/IPv4 | 9 |
6 files changed, 118 insertions, 15 deletions
diff --git a/doNewUser.go b/doNewUser.go index 55a9b7c..6cb359b 100644 --- a/doNewUser.go +++ b/doNewUser.go @@ -6,8 +6,6 @@ package main // An app to submit patches for the 30 GO GUI repos import ( - "fmt" - "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" @@ -18,16 +16,16 @@ func doNewUser() (string, error) { var s string var err error + if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { + // not new user + return s, err + } if me.forge.Config.Mode == forgepb.ForgeMode_UNKNOWN { dumpDebug() log.Info("---- ----") log.Info("---- Welcome to forge!!! ----") log.Info("---- ----") // this should never happen - log.Info("You are a new user and we never introduced ourselves") - if fhelp.QuestionUser("forge will scan ~/go/src for git repos") { - log.Info("continue") - } if err := me.forge.SetMode(forgepb.ForgeMode_NEWUSER); err != nil { log.Info("early forge new user handling failed", err) return "forge is still new and under development", err @@ -36,7 +34,14 @@ func doNewUser() (string, error) { // log.Info("MODE NOT UNKNOWN") } + if me.forge.Config.ReposPB == "" { + log.Info("broken config. load default config here") + me.forge.Config, err = forgepb.MakeDefaultConfig() + } + if shell.Exists(me.forge.Config.ReposPB) { + log.Info("looks like you might not be a new user") + log.Info("a repos file already exists at", me.forge.Config.ReposPB) // not a new user return s, err } @@ -45,15 +50,6 @@ func doNewUser() (string, error) { pfile, _ := resources.ReadFile("resources/NEWUSER") log.Info("") log.Info(string(pfile)) - s = fmt.Sprintf("Initialize forge?") - if fhelp.QuestionUser(s) { - } else { - me.sh.GoodExit("no? porque?") - } - if fhelp.QuestionUser("forge will not look for git repos in ~/go/src") { - } else { - me.sh.GoodExit("no? porque?") - } me.forge.ScanRepoDir() // looks for new dirs, checks existing repos for changes if me.forge.Config.Mode == forgepb.ForgeMode_NEWUSER { @@ -74,6 +70,8 @@ func doNewUser() (string, error) { err := me.forge.ConfigSave() if err != nil { log.Info("ConfigSave() failed", err) + } else { + log.Info("ConfigSave() worked filename =", me.forge.Config.Filename) } } me.sh.GoodExit("try running: 'forge rebuild forge' to test out that forge is working on your machine") diff --git a/doNormal.go b/doNormal.go index a8e53f8..f7af92a 100644 --- a/doNormal.go +++ b/doNormal.go @@ -71,6 +71,7 @@ func doNormalAttempt() (string, error) { if err != nil { return "not everything is 'normal' yet", err } + me.forge.SetMode(forgepb.ForgeMode_MASTER) log.Info("normal mode on") return "normal mode on", nil } diff --git a/doRebuild.go b/doRebuild.go index 717f35d..b61706f 100644 --- a/doRebuild.go +++ b/doRebuild.go @@ -21,6 +21,13 @@ func doRebuild() (string, error) { var s string var err error + s, err = IPv6test() + if err != nil { + log.Info(s) + log.Info("THIS FEATURE IS NOT SUPPORTED ON IPv4") + return "Forge requires IPv6 for many things. IPv4 support will be deprecated", err + } + if argv.Rebuild.Forge != nil { s, err = doRebuildForge() } diff --git a/ipv6test.go b/ipv6test.go new file mode 100644 index 0000000..c18faf9 --- /dev/null +++ b/ipv6test.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "net" + "time" +) + +// The host we will try to connect to. +// ipv6.google.com is a good choice as it's highly available and resolves only to AAAA records (IPv6). +const ipv6TestHost = "ipv6.google.com" +const testPort = "443" // HTTPS port, almost always open. + +func IPv6test() (string, error) { + // We use net.DialTimeout to attempt a TCP connection. + // By specifying "tcp6" as the network, we force the dialer to use IPv6 only. + // If the system can't resolve the AAAA record or can't route to the IPv6 address, + // this will fail. + timeout := 2 * time.Second + conn, err := net.DialTimeout("tcp6", net.JoinHostPort(ipv6TestHost, testPort), timeout) + + // Check the result. + if err != nil { + // The connection failed. This indicates that IPv6 is not working correctly. + return fmt.Sprintf("IPv6 connectivity test failed: %v"), err + } + + // If we get here, the connection was successful. + // It's good practice to close the connection we opened. + conn.Close() + + return fmt.Sprintf("IPv6 connectivity test successful."), nil +} diff --git a/ipv6test.go.new b/ipv6test.go.new new file mode 100644 index 0000000..c9d814e --- /dev/null +++ b/ipv6test.go.new @@ -0,0 +1,55 @@ +package main + +import ( + "context" + "fmt" + "net" + "os" + "time" +) + +const ( + ipv6TestHost = "ipv6.google.com" + testPort = "443" // HTTPS port +) + +func main() { + // --- Step 1: Fast DNS Lookup --- + // We'll use a separate, short timeout just for the DNS resolution. + // If DNS is broken, we'll know in a second or two. + dnsTimeout := 2 * time.Second + ctx, cancel := context.WithTimeout(context.Background(), dnsTimeout) + defer cancel() + + // net.DefaultResolver.LookupIPAddr forces the resolver to look up the host. + // We specify "ip6" to ensure we only get AAAA records. + addrs, err := net.DefaultResolver.LookupIPAddr(ctx, "ip6", ipv6TestHost) + if err != nil { + fmt.Printf("IPv6 DNS resolution failed: %v\n", err) + fmt.Println("This likely means your network cannot resolve IPv6 addresses.") + os.Exit(1) + } + + if len(addrs) == 0 { + fmt.Printf("No IPv6 addresses found for %s\n", ipv6TestHost) + os.Exit(1) + } + + // If we get here, DNS is working. Let's use the first address we found. + targetIP := addrs[0].IP.String() + fmt.Printf("Successfully resolved %s to IPv6 address: %s\n", ipv6TestHost, targetIP) + + // --- Step 2: Connection Attempt --- + // Now we try to connect to the IP we found. This tests routing and firewalls. + connectionTimeout := 3 * time.Second + conn, err := net.DialTimeout("tcp6", net.JoinHostPort(targetIP, testPort), connectionTimeout) + if err != nil { + fmt.Printf("IPv6 connection to %s failed: %v\n", targetIP, err) + fmt.Println("This likely means your network has an IPv6 routing or firewall issue.") + os.Exit(1) + } + defer conn.Close() + + fmt.Println("IPv6 connectivity test successful.") + os.Exit(0) +} diff --git a/resources/IPv4 b/resources/IPv4 new file mode 100644 index 0000000..903f4c2 --- /dev/null +++ b/resources/IPv4 @@ -0,0 +1,9 @@ +####################################################### +# # +# This feature in forge requires IPv6 # +# # +####################################################### + +IPv6 support is required for many features in forge. +forge will deprecate support for IPv4 at some point. +You can work around this: TODO: instructions here |
