Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func FormSekaiJoinerConfigs(tc *TargetSeedKiraConfig) error {
}
pubIP, err := GetPublicIP()
if err != nil {
return err
// return err
log.Debug("unable to get public ip", zap.Error(err))
pubIP = "0.0.0.0"
}
configToml.P2P.ExternalAddress = fmt.Sprintf("tcp://%v:%v", pubIP, types.DEFAULT_P2P_PORT)
log.Info(fmt.Sprintf("%+v", configToml))
Expand Down Expand Up @@ -368,9 +370,17 @@ func GetPublicIP() (string, error) {

// fetchIP retrieves the public IP address from a single service
func fetchIP(url string) (string, error) {
resp, err := http.Get(url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", fmt.Errorf("error creating request: %w", err)
}

req.Header.Set("Accept", "text/plain")
req.Header.Set("User-Agent", "curl/7.68.0")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", err
return "", fmt.Errorf("error making request: %w", err)
}
defer resp.Body.Close()

Expand All @@ -380,8 +390,14 @@ func fetchIP(url string) (string, error) {

body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
return "", fmt.Errorf("error reading response: %w", err)
}

ip := strings.TrimSpace(string(body))

if !utils.ValidateIP(ip) {
return "", fmt.Errorf("invalid IP format received: %s", ip)
}

return string(body), nil
return ip, nil
}
Loading