Skip to content

Commit

Permalink
set static ports by default for server, with dynamic prots option
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Sep 26, 2022
1 parent 173abf7 commit 57f21a7
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 360 deletions.
8 changes: 8 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (c *client) Start(ctx context.Context, execPath string, opts ...OpOption) (
req.CustomNodeConfigs = ret.customNodeConfigs
}
req.ReassignPortsIfUsed = &ret.reassignPortsIfUsed
req.DynamicPorts = &ret.dynamicPorts

c.log.Info("start")
return c.controlc.Start(ctx, req)
Expand Down Expand Up @@ -340,6 +341,7 @@ type Op struct {
chainConfigs map[string]string
upgradeConfigs map[string]string
reassignPortsIfUsed bool
dynamicPorts bool
}

type OpOption func(*Op)
Expand Down Expand Up @@ -426,6 +428,12 @@ func WithReassignPortsIfUsed(reassignPortsIfUsed bool) OpOption {
}
}

func WithDynamicPorts(dynamicPorts bool) OpOption {
return func(op *Op) {
op.dynamicPorts = dynamicPorts
}
}

func isClientCanceled(ctxErr error, err error) bool {
if ctxErr != nil {
return true
Expand Down
10 changes: 9 additions & 1 deletion cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var (
chainConfigs string
upgradeConfigs string
reassignPortsIfUsed bool
dynamicPorts bool
)

func newStartCommand() *cobra.Command {
Expand Down Expand Up @@ -175,7 +176,13 @@ func newStartCommand() *cobra.Command {
&reassignPortsIfUsed,
"reassign-ports-if-used",
false,
"true to reassign given ports if already taken",
"true to reassign default/given ports if already taken",
)
cmd.PersistentFlags().BoolVar(
&dynamicPorts,
"dynamic-ports",
false,
"true to assign dynamic ports",
)
if err := cmd.MarkPersistentFlagRequired("avalanchego-path"); err != nil {
panic(err)
Expand All @@ -196,6 +203,7 @@ func startFunc(cmd *cobra.Command, args []string) error {
client.WithWhitelistedSubnets(whitelistedSubnets),
client.WithRootDataDir(rootDataDir),
client.WithReassignPortsIfUsed(reassignPortsIfUsed),
client.WithDynamicPorts(dynamicPorts),
}

if globalNodeConfig != "" {
Expand Down
Loading

0 comments on commit 57f21a7

Please sign in to comment.