Skip to content
Open
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
8 changes: 8 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ type Backend interface {
type ConfigKey struct{}

type UsersKey struct{}

// LimitEnforcer interface for traffic limit enforcement
type LimitEnforcer interface {
Start(ctx context.Context, refreshInterval interface{})
Stop()
ResetUserTraffic(userID int)
Comment on lines +29 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check the actual file structure and locate backend.go
find . -name "backend.go" -type f | head -20

Repository: PasarGuard/node

Length of output: 79


🏁 Script executed:

# Search for LimitEnforcer interface definition
rg -n "type LimitEnforcer interface" -A 10

Repository: PasarGuard/node

Length of output: 337


🏁 Script executed:

# Find all implementers of LimitEnforcer
rg -n "func.*Start.*context\.Context" --type go | head -30

Repository: PasarGuard/node

Length of output: 1247


🏁 Script executed:

# Find call sites where Start is called
rg -n "\.Start\(" --type go -B 2 -A 2 | head -50

Repository: PasarGuard/node

Length of output: 2343


🏁 Script executed:

# Check the specific call site in controller.go to see what type refreshInterval is
rg -n "refreshInterval" --type go -B 3 -A 3

Repository: PasarGuard/node

Length of output: 1954


🏁 Script executed:

# Get more context around the LimitEnforcer implementation
cat -n controller/limit_enforcer.go | sed -n '90,100p'

Repository: PasarGuard/node

Length of output: 465


🏁 Script executed:

# Check what type refreshInterval is in the controller
cat -n controller/controller.go | sed -n '95,110p'

Repository: PasarGuard/node

Length of output: 764


🏁 Script executed:

# Check if there are other implementations of LimitEnforcer interface
rg -n "func.*LimitEnforcer.*Start" --type go

Repository: PasarGuard/node

Length of output: 175


🏁 Script executed:

# Check the imports in backend/backend.go to see what's currently imported
cat -n backend/backend.go | head -30

Repository: PasarGuard/node

Length of output: 1126


🏁 Script executed:

# Verify the complete LimitEnforcer interface definition
cat -n backend/backend.go | sed -n '29,40p'

Repository: PasarGuard/node

Length of output: 311


Update the LimitEnforcer interface signature to use time.Duration instead of interface{}.

The interface declaration mismatches the implementation and call site. The actual implementation in controller/limit_enforcer.go:95 already correctly uses time.Duration, and the caller in controller/controller.go:104 already passes time.Duration. Update the interface definition in backend/backend.go to match.

♻️ Required changes
import (
	"context"
+	"time"

	"github.com/pasarguard/node/common"
)

 // LimitEnforcer interface for traffic limit enforcement
 type LimitEnforcer interface {
-	Start(ctx context.Context, refreshInterval interface{})
+	Start(ctx context.Context, refreshInterval time.Duration)
 	Stop()
 	ResetUserTraffic(userID int)
 	ResetAllTraffic()
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// LimitEnforcer interface for traffic limit enforcement
type LimitEnforcer interface {
Start(ctx context.Context, refreshInterval interface{})
Stop()
ResetUserTraffic(userID int)
import (
"context"
"time"
"github.com/pasarguard/node/common"
)
// LimitEnforcer interface for traffic limit enforcement
type LimitEnforcer interface {
Start(ctx context.Context, refreshInterval time.Duration)
Stop()
ResetUserTraffic(userID int)
ResetAllTraffic()
}
🤖 Prompt for AI Agents
In `@backend/backend.go` around lines 29 - 33, The LimitEnforcer interface
currently declares Start(ctx context.Context, refreshInterval interface{}),
which mismatches implementations and callers; change the Start method signature
on the LimitEnforcer interface to use time.Duration (i.e., Start(ctx
context.Context, refreshInterval time.Duration)) and import the time package if
not already imported so the interface matches controller/limit_enforcer.go and
controller/controller.go.

ResetAllTraffic()
}
49 changes: 43 additions & 6 deletions common/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions common/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ message Backend {
repeated User users = 3;
uint64 keep_alive = 4;
repeated string exclude_inbounds = 5;

// Limit enforcer configuration (sent from panel)
int32 node_id = 6;
string panel_api_url = 7;
int32 limit_check_interval = 8; // seconds, default 30
int32 limit_refresh_interval = 9; // seconds, default 60
}

// log
Expand Down
30 changes: 15 additions & 15 deletions common/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading