@@ -179,7 +179,7 @@ var (
179179 LightPeersFlag = cli.IntFlag {
180180 Name : "lightpeers" ,
181181 Usage : "Maximum number of LES client peers" ,
182- Value : 20 ,
182+ Value : eth . DefaultConfig . LightPeers ,
183183 }
184184 LightKDFFlag = cli.BoolFlag {
185185 Name : "lightkdf" ,
@@ -791,20 +791,40 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
791791 setBootstrapNodes (ctx , cfg )
792792 setBootstrapNodesV5 (ctx , cfg )
793793
794+ lightClient := ctx .GlobalBool (LightModeFlag .Name ) || ctx .GlobalString (SyncModeFlag .Name ) == "light"
795+ lightServer := ctx .GlobalInt (LightServFlag .Name ) != 0
796+ lightPeers := ctx .GlobalInt (LightPeersFlag .Name )
797+
794798 if ctx .GlobalIsSet (MaxPeersFlag .Name ) {
795799 cfg .MaxPeers = ctx .GlobalInt (MaxPeersFlag .Name )
800+ } else {
801+ if lightServer {
802+ cfg .MaxPeers += lightPeers
803+ }
804+ if lightClient && ctx .GlobalIsSet (LightPeersFlag .Name ) && cfg .MaxPeers < lightPeers {
805+ cfg .MaxPeers = lightPeers
806+ }
796807 }
808+ if ! (lightClient || lightServer ) {
809+ lightPeers = 0
810+ }
811+ ethPeers := cfg .MaxPeers - lightPeers
812+ if lightClient {
813+ ethPeers = 0
814+ }
815+ log .Info ("Maximum peer count" , "ETH" , ethPeers , "LES" , lightPeers , "total" , cfg .MaxPeers )
816+
797817 if ctx .GlobalIsSet (MaxPendingPeersFlag .Name ) {
798818 cfg .MaxPendingPeers = ctx .GlobalInt (MaxPendingPeersFlag .Name )
799819 }
800- if ctx .GlobalIsSet (NoDiscoverFlag .Name ) || ctx . GlobalBool ( LightModeFlag . Name ) {
820+ if ctx .GlobalIsSet (NoDiscoverFlag .Name ) || lightClient {
801821 cfg .NoDiscovery = true
802822 }
803823
804824 // if we're running a light client or server, force enable the v5 peer discovery
805825 // unless it is explicitly disabled with --nodiscover note that explicitly specifying
806826 // --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
807- forceV5Discovery := (ctx . GlobalBool ( LightModeFlag . Name ) || ctx . GlobalInt ( LightServFlag . Name ) > 0 ) && ! ctx .GlobalBool (NoDiscoverFlag .Name )
827+ forceV5Discovery := (lightClient || lightServer ) && ! ctx .GlobalBool (NoDiscoverFlag .Name )
808828 if ctx .GlobalIsSet (DiscoveryV5Flag .Name ) {
809829 cfg .DiscoveryV5 = ctx .GlobalBool (DiscoveryV5Flag .Name )
810830 } else if forceV5Discovery {
0 commit comments