Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions p2p/kademlia/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"math"
"os"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -168,15 +169,18 @@ func (s *DHT) NodesLen() int {
func (s *DHT) getExternalIP() (string, error) {
s.mtx.Lock()
defer s.mtx.Unlock()
// if listen IP is localhost - then return itself
if s.ht.self.IP == "127.0.0.1" || s.ht.self.IP == "localhost" || s.ht.self.IP == "0.0.0.0" {
return s.ht.self.IP, nil
}

// Return cached value if already determined
if s.externalIP != "" {
return s.externalIP, nil
}

// Check environment variable to control IP behavior
if useExternal := os.Getenv("P2P_USE_EXTERNAL_IP"); useExternal == "false" || useExternal == "0" {
s.externalIP = s.ht.self.IP
return s.externalIP, nil
}

externalIP, err := utils.GetExternalIPAddress()
if err != nil {
return "", fmt.Errorf("get external ip addr: %s", err)
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/p2p/p2p_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
func TestP2PBasicIntegration(t *testing.T) {
log.Println("Starting P2P test...")

os.Setenv("P2P_USE_EXTERNAL_IP", "false")
defer os.Unsetenv("P2P_USE_EXTERNAL_IP")

snkeyring.InitSDKConfig()
conn.RegisterALTSRecordProtocols()
defer conn.UnregisterALTSRecordProtocols()
Expand Down
2 changes: 2 additions & 0 deletions tests/system/e2e_cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestCascadeE2E(t *testing.T) {
// ---------------------------------------
os.Setenv("SYSTEM_TEST", "true")
defer os.Unsetenv("SYSTEM_TEST")
os.Setenv("P2P_USE_EXTERNAL_IP", "false")
defer os.Unsetenv("P2P_USE_EXTERNAL_IP")
// Test account credentials - these values are consistent across test runs
const testMnemonic = "odor kiss switch swarm spell make planet bundle skate ozone path planet exclude butter atom ahead angle royal shuffle door prevent merry alter robust"
const expectedAddress = "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4"
Expand Down