Use the flag RPCMaxClients instead of the const RPCMaxInboundConnections

This commit is contained in:
msutton 2022-06-15 14:45:21 +03:00
parent 346efb90c5
commit feb35165da
4 changed files with 10 additions and 12 deletions

View File

@ -38,8 +38,9 @@ const (
defaultBanDuration = time.Hour * 24 defaultBanDuration = time.Hour * 24
defaultBanThreshold = 100 defaultBanThreshold = 100
//DefaultConnectTimeout is the default connection timeout when dialing //DefaultConnectTimeout is the default connection timeout when dialing
DefaultConnectTimeout = time.Second * 30 DefaultConnectTimeout = time.Second * 30
defaultMaxRPCClients = 10 //DefaultMaxRPCClients is the default max number of RPC clients
DefaultMaxRPCClients = 128
defaultMaxRPCWebsockets = 25 defaultMaxRPCWebsockets = 25
defaultMaxRPCConcurrentReqs = 20 defaultMaxRPCConcurrentReqs = 20
defaultBlockMaxMass = 10_000_000 defaultBlockMaxMass = 10_000_000
@ -178,7 +179,7 @@ func defaultFlags() *Flags {
MaxInboundPeers: defaultMaxInboundPeers, MaxInboundPeers: defaultMaxInboundPeers,
BanDuration: defaultBanDuration, BanDuration: defaultBanDuration,
BanThreshold: defaultBanThreshold, BanThreshold: defaultBanThreshold,
RPCMaxClients: defaultMaxRPCClients, RPCMaxClients: DefaultMaxRPCClients,
RPCMaxWebsockets: defaultMaxRPCWebsockets, RPCMaxWebsockets: defaultMaxRPCWebsockets,
RPCMaxConcurrentReqs: defaultMaxRPCConcurrentReqs, RPCMaxConcurrentReqs: defaultMaxRPCConcurrentReqs,
AppDir: defaultDataDir, AppDir: defaultDataDir,

View File

@ -46,7 +46,7 @@ func NewNetAdapter(cfg *config.Config) (*NetAdapter, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
rpcServer, err := grpcserver.NewRPCServer(cfg.RPCListeners) rpcServer, err := grpcserver.NewRPCServer(cfg.RPCListeners, cfg.RPCMaxClients)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -14,12 +14,9 @@ type rpcServer struct {
// RPCMaxMessageSize is the max message size for the RPC server to send and receive // RPCMaxMessageSize is the max message size for the RPC server to send and receive
const RPCMaxMessageSize = 1024 * 1024 * 1024 // 1 GB const RPCMaxMessageSize = 1024 * 1024 * 1024 // 1 GB
// RPCMaxInboundConnections is the max amount of inbound connections for the RPC server
const RPCMaxInboundConnections = 128
// NewRPCServer creates a new RPCServer // NewRPCServer creates a new RPCServer
func NewRPCServer(listeningAddresses []string) (server.Server, error) { func NewRPCServer(listeningAddresses []string, rpcMaxInboundConnections int) (server.Server, error) {
gRPCServer := newGRPCServer(listeningAddresses, RPCMaxMessageSize, RPCMaxInboundConnections, "RPC") gRPCServer := newGRPCServer(listeningAddresses, RPCMaxMessageSize, rpcMaxInboundConnections, "RPC")
rpcServer := &rpcServer{gRPCServer: *gRPCServer} rpcServer := &rpcServer{gRPCServer: *gRPCServer}
protowire.RegisterRPCServer(gRPCServer.server, rpcServer) protowire.RegisterRPCServer(gRPCServer.server, rpcServer)
return rpcServer, nil return rpcServer, nil

View File

@ -1,7 +1,7 @@
package integration package integration
import ( import (
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver" "github.com/kaspanet/kaspad/infrastructure/config"
"testing" "testing"
"time" "time"
@ -45,7 +45,7 @@ func TestRPCMaxInboundConnections(t *testing.T) {
rpcClients := []*testRPCClient{} rpcClients := []*testRPCClient{}
doneChan := make(chan error) doneChan := make(chan error)
go func() { go func() {
for i := 0; i < grpcserver.RPCMaxInboundConnections; i++ { for i := 0; i < config.DefaultMaxRPCClients; i++ {
rpcClient, err := newTestRPCClient(harness.rpcAddress) rpcClient, err := newTestRPCClient(harness.rpcAddress)
if err != nil { if err != nil {
doneChan <- err doneChan <- err
@ -60,7 +60,7 @@ func TestRPCMaxInboundConnections(t *testing.T) {
t.Fatalf("newTestRPCClient: %s", err) t.Fatalf("newTestRPCClient: %s", err)
} }
case <-time.After(time.Second * 5): case <-time.After(time.Second * 5):
t.Fatalf("Timeout for connecting %d RPC connections elapsed", grpcserver.RPCMaxInboundConnections) t.Fatalf("Timeout for connecting %d RPC connections elapsed", config.DefaultMaxRPCClients)
} }
// Try to connect another client. We expect this to fail // Try to connect another client. We expect this to fail