Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
215c389ac2
|
|||
|
e50d860c0b
|
|||
|
ce573a50b3
|
|||
|
4b6d0ab30c
|
@@ -689,3 +689,5 @@ Migrate custom validation logic to policy scripts:
|
||||
```
|
||||
|
||||
The policy system provides a flexible, maintainable way to implement complex relay behavior while maintaining performance and security.
|
||||
|
||||
|
||||
|
||||
@@ -615,3 +615,5 @@ When adding new features that require multi-relay testing:
|
||||
- [cmd/relay-tester/README.md](../../cmd/relay-tester/README.md) - Protocol testing
|
||||
|
||||
This guide provides the foundation for testing complex Nostr protocol features that require multiple relay coordination. The testing infrastructure is designed to be extensible and support various testing scenarios while maintaining reliability and performance.
|
||||
|
||||
|
||||
|
||||
6
go.mod
6
go.mod
@@ -22,16 +22,12 @@ require (
|
||||
honnef.co/go/tools v0.6.1
|
||||
lol.mleku.dev v1.0.5
|
||||
lukechampine.com/frand v1.5.1
|
||||
p256k1.mleku.dev v1.0.1
|
||||
p256k1.mleku.dev v1.0.3
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.6 // indirect
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/felixge/fgprof v0.9.5 // indirect
|
||||
|
||||
12
go.sum
12
go.sum
@@ -2,10 +2,6 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg
|
||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
|
||||
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.6 h1:IzlsEr9olcSRKB/n7c4351F3xHKxS2lma+1UFGCYd4E=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.6/go.mod h1:m22FrOAiuxl/tht9wIqAoGHcbnCCaPWyauO8y2LGGtQ=
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
|
||||
@@ -20,10 +16,6 @@ github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
|
||||
github.com/dgraph-io/badger/v4 v4.8.0 h1:JYph1ChBijCw8SLeybvPINizbDKWZ5n/GYbz2yhN/bs=
|
||||
github.com/dgraph-io/badger/v4 v4.8.0/go.mod h1:U6on6e8k/RTbUWxqKR0MvugJuVmkxSNc79ap4917h4w=
|
||||
github.com/dgraph-io/ristretto/v2 v2.3.0 h1:qTQ38m7oIyd4GAed/QkUZyPFNMnvVWyazGXRwvOt5zk=
|
||||
@@ -152,5 +144,5 @@ lol.mleku.dev v1.0.5 h1:irwfwz+Scv74G/2OXmv05YFKOzUNOVZ735EAkYgjgM8=
|
||||
lol.mleku.dev v1.0.5/go.mod h1:JlsqP0CZDLKRyd85XGcy79+ydSRqmFkrPzYFMYxQ+zs=
|
||||
lukechampine.com/frand v1.5.1 h1:fg0eRtdmGFIxhP5zQJzM1lFDbD6CUfu/f+7WgAZd5/w=
|
||||
lukechampine.com/frand v1.5.1/go.mod h1:4VstaWc2plN4Mjr10chUD46RAVGWhpkZ5Nja8+Azp0Q=
|
||||
p256k1.mleku.dev v1.0.1 h1:4ZQ+2xNfKpL6+e9urKP6f/QdHKKUNIEsqvFwogpluZw=
|
||||
p256k1.mleku.dev v1.0.1/go.mod h1:gY2ybEebhiSgSDlJ8ERgAe833dn2EDqs7aBsvwpgu0s=
|
||||
p256k1.mleku.dev v1.0.3 h1:2SBEH9XhNAotO1Ik8ejODjChTqc06Z/6ncQhrYkAdRA=
|
||||
p256k1.mleku.dev v1.0.3/go.mod h1:cWkZlx6Tu7CTmIxonFbdjhdNfkY3VbjjY5TFEILiTnY=
|
||||
|
||||
@@ -1 +1 @@
|
||||
v0.24.3
|
||||
v0.24.5
|
||||
@@ -6,7 +6,7 @@
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
GO_VERSION="1.23.1"
|
||||
GO_VERSION="1.25.3"
|
||||
GOROOT="$HOME/go"
|
||||
GOPATH="$HOME"
|
||||
GOBIN="$HOME/.local/bin"
|
||||
@@ -160,7 +160,7 @@ build_application() {
|
||||
|
||||
# Build the binary in the current directory
|
||||
log_info "Building binary in current directory..."
|
||||
CGO_ENABLED=1 go build -o "$BINARY_NAME"
|
||||
CGO_ENABLED=0 go build -o "$BINARY_NAME"
|
||||
|
||||
if [[ -f "./$BINARY_NAME" ]]; then
|
||||
log_success "ORLY relay built successfully"
|
||||
@@ -222,16 +222,6 @@ StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=$SERVICE_NAME
|
||||
|
||||
# Security settings
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=$working_dir $HOME/.local/share/ORLY $HOME/.cache/ORLY
|
||||
PrivateTmp=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectControlGroups=true
|
||||
|
||||
# Network settings
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
|
||||
|
||||
@@ -2,115 +2,112 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"next.orly.dev/app/config"
|
||||
"next.orly.dev/pkg/run"
|
||||
)
|
||||
|
||||
func TestDumbClientWorkaround(t *testing.T) {
|
||||
var relay *run.Relay
|
||||
var err error
|
||||
// func TestDumbClientWorkaround(t *testing.T) {
|
||||
// var relay *run.Relay
|
||||
// var err error
|
||||
|
||||
// Start local relay for testing
|
||||
if relay, _, err = startWorkaroundTestRelay(); err != nil {
|
||||
t.Fatalf("Failed to start test relay: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if stopErr := relay.Stop(); stopErr != nil {
|
||||
t.Logf("Error stopping relay: %v", stopErr)
|
||||
}
|
||||
}()
|
||||
// // Start local relay for testing
|
||||
// if relay, _, err = startWorkaroundTestRelay(); err != nil {
|
||||
// t.Fatalf("Failed to start test relay: %v", err)
|
||||
// }
|
||||
// defer func() {
|
||||
// if stopErr := relay.Stop(); stopErr != nil {
|
||||
// t.Logf("Error stopping relay: %v", stopErr)
|
||||
// }
|
||||
// }()
|
||||
|
||||
relayURL := "ws://127.0.0.1:3338"
|
||||
// relayURL := "ws://127.0.0.1:3338"
|
||||
|
||||
// Wait for relay to be ready
|
||||
if err = waitForRelay(relayURL, 10*time.Second); err != nil {
|
||||
t.Fatalf("Relay not ready after timeout: %v", err)
|
||||
}
|
||||
// // Wait for relay to be ready
|
||||
// if err = waitForRelay(relayURL, 10*time.Second); err != nil {
|
||||
// t.Fatalf("Relay not ready after timeout: %v", err)
|
||||
// }
|
||||
|
||||
t.Logf("Relay is ready at %s", relayURL)
|
||||
// t.Logf("Relay is ready at %s", relayURL)
|
||||
|
||||
// Test connection with a "dumb" client that doesn't handle ping/pong properly
|
||||
dialer := websocket.Dialer{
|
||||
HandshakeTimeout: 10 * time.Second,
|
||||
}
|
||||
// // Test connection with a "dumb" client that doesn't handle ping/pong properly
|
||||
// dialer := websocket.Dialer{
|
||||
// HandshakeTimeout: 10 * time.Second,
|
||||
// }
|
||||
|
||||
conn, _, err := dialer.Dial(relayURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
// conn, _, err := dialer.Dial(relayURL, nil)
|
||||
// if err != nil {
|
||||
// t.Fatalf("Failed to connect: %v", err)
|
||||
// }
|
||||
// defer conn.Close()
|
||||
|
||||
t.Logf("Connection established")
|
||||
// t.Logf("Connection established")
|
||||
|
||||
// Simulate a dumb client that sets a short read deadline and doesn't handle ping/pong
|
||||
conn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||
// // Simulate a dumb client that sets a short read deadline and doesn't handle ping/pong
|
||||
// conn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||
|
||||
startTime := time.Now()
|
||||
messageCount := 0
|
||||
// startTime := time.Now()
|
||||
// messageCount := 0
|
||||
|
||||
// The connection should stay alive despite the short client-side deadline
|
||||
// because our workaround sets a 24-hour server-side deadline
|
||||
connectionFailed := false
|
||||
for time.Since(startTime) < 2*time.Minute && !connectionFailed {
|
||||
// Extend client deadline every 10 seconds (simulating dumb client behavior)
|
||||
if time.Since(startTime).Seconds() > 10 && int(time.Since(startTime).Seconds())%10 == 0 {
|
||||
conn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||
t.Logf("Dumb client extended its own deadline")
|
||||
}
|
||||
// // The connection should stay alive despite the short client-side deadline
|
||||
// // because our workaround sets a 24-hour server-side deadline
|
||||
// connectionFailed := false
|
||||
// for time.Since(startTime) < 2*time.Minute && !connectionFailed {
|
||||
// // Extend client deadline every 10 seconds (simulating dumb client behavior)
|
||||
// if time.Since(startTime).Seconds() > 10 && int(time.Since(startTime).Seconds())%10 == 0 {
|
||||
// conn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||
// t.Logf("Dumb client extended its own deadline")
|
||||
// }
|
||||
|
||||
// Try to read with a short timeout to avoid blocking
|
||||
conn.SetReadDeadline(time.Now().Add(1 * time.Second))
|
||||
// // Try to read with a short timeout to avoid blocking
|
||||
// conn.SetReadDeadline(time.Now().Add(1 * time.Second))
|
||||
|
||||
// Use a function to catch panics from ReadMessage on failed connections
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if panicMsg, ok := r.(string); ok && panicMsg == "repeated read on failed websocket connection" {
|
||||
t.Logf("Connection failed, stopping read loop")
|
||||
connectionFailed = true
|
||||
return
|
||||
}
|
||||
// Re-panic if it's a different panic
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
// // Use a function to catch panics from ReadMessage on failed connections
|
||||
// func() {
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// if panicMsg, ok := r.(string); ok && panicMsg == "repeated read on failed websocket connection" {
|
||||
// t.Logf("Connection failed, stopping read loop")
|
||||
// connectionFailed = true
|
||||
// return
|
||||
// }
|
||||
// // Re-panic if it's a different panic
|
||||
// panic(r)
|
||||
// }
|
||||
// }()
|
||||
|
||||
msgType, data, err := conn.ReadMessage()
|
||||
conn.SetReadDeadline(time.Now().Add(30 * time.Second)) // Reset
|
||||
// msgType, data, err := conn.ReadMessage()
|
||||
// conn.SetReadDeadline(time.Now().Add(30 * time.Second)) // Reset
|
||||
|
||||
if err != nil {
|
||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||
// Timeout is expected - just continue
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
return
|
||||
}
|
||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
|
||||
t.Logf("Connection closed normally: %v", err)
|
||||
connectionFailed = true
|
||||
return
|
||||
}
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
connectionFailed = true
|
||||
return
|
||||
}
|
||||
// if err != nil {
|
||||
// if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||
// // Timeout is expected - just continue
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
// return
|
||||
// }
|
||||
// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
|
||||
// t.Logf("Connection closed normally: %v", err)
|
||||
// connectionFailed = true
|
||||
// return
|
||||
// }
|
||||
// t.Errorf("Unexpected error: %v", err)
|
||||
// connectionFailed = true
|
||||
// return
|
||||
// }
|
||||
|
||||
messageCount++
|
||||
t.Logf("Received message %d: type=%d, len=%d", messageCount, msgType, len(data))
|
||||
}()
|
||||
}
|
||||
// messageCount++
|
||||
// t.Logf("Received message %d: type=%d, len=%d", messageCount, msgType, len(data))
|
||||
// }()
|
||||
// }
|
||||
|
||||
elapsed := time.Since(startTime)
|
||||
if elapsed < 90*time.Second {
|
||||
t.Errorf("Connection died too early after %v (expected at least 90s)", elapsed)
|
||||
} else {
|
||||
t.Logf("Workaround successful: connection lasted %v with %d messages", elapsed, messageCount)
|
||||
}
|
||||
}
|
||||
// elapsed := time.Since(startTime)
|
||||
// if elapsed < 90*time.Second {
|
||||
// t.Errorf("Connection died too early after %v (expected at least 90s)", elapsed)
|
||||
// } else {
|
||||
// t.Logf("Workaround successful: connection lasted %v with %d messages", elapsed, messageCount)
|
||||
// }
|
||||
// }
|
||||
|
||||
// startWorkaroundTestRelay starts a relay for workaround testing
|
||||
func startWorkaroundTestRelay() (relay *run.Relay, port int, err error) {
|
||||
|
||||
Reference in New Issue
Block a user