Skip to content

Commit a6e83ad

Browse files
p2p fixes
1 parent febf37b commit a6e83ad

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

.vscode/launch.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4-
5-
6-
74
{
85
"name": "Launch Supernode",
96
"type": "go",
@@ -25,6 +22,15 @@
2522
"env": {
2623
"LOG_LEVEL": "debug" // This may vary depending on your logger
2724
}
25+
},
26+
{
27+
"name": "Run P2P Test",
28+
"type": "go",
29+
"request": "launch",
30+
"mode": "test",
31+
"program": "${workspaceFolder}/tests/integration/p2p",
32+
"args": ["-test.run=TestP2PBasicIntegration", "-test.v"],
33+
"showLog": true
2834
}
2935
]
3036
}

p2p/kademlia/bootstrap.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
const (
20-
bootstrapRetryInterval = 10
21-
badAddrExpiryHours = 12
20+
bootstrapRetryInterval = 10
21+
badAddrExpiryHours = 12
22+
defaultSuperNodeP2PPort = 4444
2223
)
2324

2425
func (s *DHT) skipBadBootstrapAddrs() {
@@ -46,24 +47,46 @@ func (s *DHT) parseNode(extP2P string, selfAddr string) (*Node, error) {
4647
return nil, errors.New("configure: skip bad p2p boostrap addr")
4748
}
4849

49-
addr := strings.Split(extP2P, ":")
50-
if len(addr) != 2 {
51-
return nil, errors.New("wrong number of field")
50+
// Extract IP and port from the address
51+
var ip string
52+
var port uint16
53+
54+
if idx := strings.LastIndex(extP2P, ":"); idx != -1 {
55+
ip = extP2P[:idx]
56+
portStr := extP2P[idx+1:]
57+
58+
// If we have a port in the address, parse it
59+
if portStr != "" {
60+
portNum, err := strconv.ParseUint(portStr, 10, 16)
61+
if err != nil {
62+
return nil, errors.New("invalid port number")
63+
}
64+
65+
// For system testing, use port+1 if SYSTEM_TEST=true
66+
if os.Getenv("SYSTEM_TEST") == "true" {
67+
port = uint16(portNum) + 1
68+
log.P2P().WithField("original_port", portNum).
69+
WithField("adjusted_port", port).
70+
Info("Using port+1 for system testing")
71+
} else {
72+
// For normal P2P operation, always use the default port
73+
port = defaultNetworkPort
74+
}
75+
}
76+
} else {
77+
// No port in the address
78+
ip = extP2P
79+
port = defaultNetworkPort
5280
}
53-
ip := addr[0]
5481

5582
if ip == "" {
5683
return nil, errors.New("empty ip")
5784
}
5885

59-
port, err := strconv.ParseUint(addr[1], 10, 16)
60-
if err != nil {
61-
return nil, errors.New("invalid port number")
62-
}
63-
86+
// Create the node with the correct IP and port
6487
return &Node{
6588
IP: ip,
66-
Port: uint16(port),
89+
Port: port,
6790
}, nil
6891
}
6992

@@ -154,9 +177,6 @@ func (s *DHT) ConfigureBootstrapNodes(ctx context.Context, bootstrapNodes string
154177

155178
// Convert the map to a slice
156179
for _, node := range mapNodes {
157-
if os.Getenv("INTEGRATION_TEST") != "true" {
158-
node.Port = node.Port + 1
159-
}
160180
hID, _ := utils.Blake3Hash(node.ID)
161181
node.HashedID = hID
162182
fmt.Println("node adding", node.String(), "hashed id", string(node.HashedID))

p2p/kademlia/hashtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323

2424
const (
2525
// Alpha - a small number representing the degree of parallelism in network calls
26-
Alpha = 3
26+
Alpha = 6
2727

2828
// B - the size in bits of the keys used to identify nodes and store and
2929
// retrieve data; in basic Kademlia this is 256, the length of a SHA3-256

tests/system/e2e_cascade_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ func TestCascadeE2E(t *testing.T) {
4646
// ---------------------------------------
4747
// Constants and Configuration Parameters
4848
// ---------------------------------------
49-
49+
os.Setenv("SYSTEM_TEST", "true")
50+
defer os.Unsetenv("SYSTEM_TEST")
5051
// Test account credentials - these values are consistent across test runs
5152
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"
5253
const expectedAddress = "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4"

0 commit comments

Comments
 (0)