Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Jan 16, 2025
1 parent 039a1d9 commit 8a0ac76
Show file tree
Hide file tree
Showing 29 changed files with 342 additions and 360 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

*??? ??, ????*

### CHANGES

- `cmd/hls`: move threads param from args -> hls.yml config (pow_parallel, default=0->1)
- `build/settings.yml`: move consumers_cap -> hls.yml config (qb_consumers, default=0->1)

<!-- ... -->

## v1.8.3
Expand Down
8 changes: 3 additions & 5 deletions build/build_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ type SSettings struct {
FService uint32 `yaml:"service"`
} `yaml:"proto_mask"`
FQueueProblem struct {
FMainPoolCap uint64 `yaml:"main_pool_cap"`
FRandPoolCap uint64 `yaml:"rand_pool_cap"`
FConsumersCap uint64 `yaml:"consumers_cap"`
FMainPoolCap uint64 `yaml:"main_pool_cap"`
FRandPoolCap uint64 `yaml:"rand_pool_cap"`
} `yaml:"queue_problem"`
FNetworkManager struct {
FConnectsLimiter uint64 `yaml:"connects_limiter"`
Expand All @@ -51,8 +50,7 @@ func (p SSettings) validate() error {
switch {
case
p.FQueueProblem.FMainPoolCap == 0,
p.FQueueProblem.FRandPoolCap == 0,
p.FQueueProblem.FConsumersCap == 0:
p.FQueueProblem.FRandPoolCap == 0:
return errors.New("queue_problem is invalid")
case
p.FNetworkManager.FConnectsLimiter == 0,
Expand Down
5 changes: 0 additions & 5 deletions build/build_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestHiddenLakeSettings(t *testing.T) {

settings.FQueueProblem.FMainPoolCap = 64
settings.FQueueProblem.FRandPoolCap = 64
settings.FQueueProblem.FConsumersCap = 1
if err := settings.validate(); err == nil {
t.Error("success validate with invalid network manager")
return
Expand Down Expand Up @@ -55,10 +54,6 @@ func TestHiddenLakeSettings(t *testing.T) {
t.Error(`GSettings.QueueCapacity.FRandPoolCap != 32`)
return
}
if GSettings.FQueueProblem.FConsumersCap != 1 {
t.Error(`GSettings.QueueCapacity.FConsumersCap != 1`)
return
}
if GSettings.FNetworkManager.FCacheHashesCap != 2048 {
t.Error(`GSettings.NetworkManager.CacheHashesCap != 2048`)
return
Expand Down
1 change: 0 additions & 1 deletion build/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ proto_mask:
queue_problem:
main_pool_cap: 256
rand_pool_cap: 32
consumers_cap: 1
network_manager:
connects_limiter: 256
cache_hashes_cap: 2048
Expand Down
2 changes: 1 addition & 1 deletion cmd/hla/hla_tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
).Build()
)
Expand Down
3 changes: 1 addition & 2 deletions cmd/hlc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ RUN go build -o hlc ./cmd/hlc

ENV SERVICE_NETWORK=""
ENV SERVICE_PATH="."
ENV SERVICE_THREADS="1"
CMD ./hlc --path "${SERVICE_PATH}" --network "${SERVICE_NETWORK}" --threads "${SERVICE_THREADS}"
CMD ./hlc --path "${SERVICE_PATH}" --network "${SERVICE_NETWORK}"
3 changes: 1 addition & 2 deletions cmd/hlc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ Creates [`./hlc.yml`](./hlc.yml) file.
## Running options

```bash
$ hlc --path /root --network xxx --threads 1
$ hlc --path /root --network xxx
# path = path to config, database, key files
# network = use network configuration from networks.yml
# threads = num of parallel functions for PoW algorithm
```
2 changes: 1 addition & 1 deletion cmd/hlc/daemon/install_hlc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ echo "
Description=HiddenLakeComposite
[Service]
ExecStart=/root/hlc_amd64_linux --path /root --threads 1
ExecStart=/root/hlc_amd64_linux --path /root
Restart=always
RestartSec=10
Expand Down
5 changes: 1 addition & 4 deletions cmd/hlc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
flag.NewFlagBuilder("-t", "--threads").
WithDescription("set num of parallel functions to calculate PoW").
WithDefinedValue("1"),
).Build()
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/hls/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN go build -o hls ./cmd/hls
ENV SERVICE_NETWORK=""
ENV SERVICE_PATH="."
ENV SERVICE_THREADS="1"
CMD ./hls --path "${SERVICE_PATH}" --network "${SERVICE_NETWORK}" --threads "${SERVICE_THREADS}"
CMD ./hls --path "${SERVICE_PATH}" --network "${SERVICE_NETWORK}"
7 changes: 3 additions & 4 deletions cmd/hls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ The file `hls.db` stores hashes of sent/received messages.
## Running options

```bash
$ hls --path /root --network xxx --threads 1
# path = path to config, database, key files
# network = use network configuration from networks.yml
# threads = num of parallel functions for PoW algorithm
$ hls --path /root --network xxx
# path = path to config, database, key files
# network = use network configuration from networks.yml
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion cmd/hls/daemon/install_hls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ echo "
Description=HiddenLakeService
[Service]
ExecStart=/root/hls_amd64_linux --path /root --threads 1
ExecStart=/root/hls_amd64_linux --path /root
Restart=always
RestartSec=10
Expand Down
5 changes: 1 addition & 4 deletions cmd/hls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
flag.NewFlagBuilder("-t", "--threads").
WithDescription("set num of parallel functions to calculate PoW").
WithDefinedValue("1"),
).Build()
)

Expand Down
2 changes: 1 addition & 1 deletion internal/adapters/tcp/pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
).Build()
)
Expand Down
10 changes: 1 addition & 9 deletions internal/composite/pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
flag.NewFlagBuilder("-t", "--threads").
WithDescription("set num of parallel functions to calculate PoW").
WithDefinedValue("1"),
).Build()
)

Expand Down Expand Up @@ -137,11 +134,6 @@ func TestInitApp(t *testing.T) {
return
}

if _, err := InitApp([]string{"--path", tcTestdataPath, "--threads", "abc"}, tgFlags); err == nil {
t.Error("success init app with threads=abc")
return
}

if _, err := InitApp([]string{"--path", "./not_exist/path/to/hlc"}, tgFlags); err == nil {
t.Error("success init app with undefined dir key")
return
Expand Down
7 changes: 2 additions & 5 deletions internal/service/pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ var (
)

type sApp struct {
fState state.IState
fPathTo string
fParallel uint64
fState state.IState
fPathTo string

fCfgW config.IWrapper
fNode network.IHiddenLakeNode
Expand All @@ -49,7 +48,6 @@ func NewApp(
pCfg config.IConfig,
pPrivKey asymmetric.IPrivKey,
pPathTo string,
pParallel uint64,
) types.IRunner {
logging := pCfg.GetLogging()

Expand All @@ -62,7 +60,6 @@ func NewApp(
return &sApp{
fState: state.NewBoolState(),
fPathTo: pPathTo,
fParallel: pParallel,
fCfgW: config.NewWrapper(pCfg),
fPrivKey: pPrivKey,
fAnonLogger: anonLogger,
Expand Down
12 changes: 2 additions & 10 deletions internal/service/pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ var (
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
flag.NewFlagBuilder("-t", "--threads").
WithDescription("set num of parallel functions to calculate PoW").
WithDefinedValue("1"),
).Build()
)

Expand Down Expand Up @@ -70,11 +67,6 @@ func TestInitApp(t *testing.T) {
return
}

if _, err := InitApp([]string{"--path", tcTestdataPath, "--threads", "abc"}, tgFlags); err == nil {
t.Error("success init app with threads=abc")
return
}

if _, err := InitApp([]string{"--path", "./not_exist/path/to/hls"}, tgFlags); err == nil {
t.Error("success init app with undefined dir key")
return
Expand Down Expand Up @@ -110,7 +102,7 @@ func TestApp(t *testing.T) {
}

privKey := asymmetric.NewPrivKey()
app := NewApp(cfg, privKey, ".", 1)
app := NewApp(cfg, privKey, ".")

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
10 changes: 10 additions & 0 deletions internal/service/pkg/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type SConfigSettings struct {
FFetchTimeoutMS uint64 `json:"fetch_timeout_ms" yaml:"fetch_timeout_ms"`
FQueuePeriodMS uint64 `json:"queue_period_ms" yaml:"queue_period_ms"`
FWorkSizeBits uint64 `json:"work_size_bits,omitempty" yaml:"work_size_bits,omitempty"`
FQBConsumers uint64 `json:"qb_consumers,omitempty" yaml:"qb_consumers,omitempty"`
FPowParallel uint64 `json:"pow_parallel,omitempty" yaml:"pow_parallel,omitempty"`
FNetworkKey string `json:"network_key,omitempty" yaml:"network_key,omitempty"`
}

Expand Down Expand Up @@ -108,6 +110,14 @@ func (p *SConfigSettings) GetNetworkKey() string {
return p.FNetworkKey
}

func (p *SConfigSettings) GetQBConsumers() uint64 {
return p.FQBConsumers
}

func (p *SConfigSettings) GetPowParallel() uint64 {
return p.FPowParallel
}

func (p *SConfig) GetSettings() IConfigSettings {
return p.FSettings
}
Expand Down
3 changes: 3 additions & 0 deletions internal/service/pkg/app/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type IConfigSettings interface {
GetMessageSizeBytes() uint64
GetFetchTimeout() time.Duration
GetQueuePeriod() time.Duration

GetPowParallel() uint64
GetQBConsumers() uint64
}

type IConfig interface {
Expand Down
1 change: 1 addition & 0 deletions internal/service/pkg/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
ErrInitConfig = &SAppError{"init config"}
ErrSetParallelNull = &SAppError{"set parallel = 0"}
ErrGetParallel = &SAppError{"get parallel"}
ErrGetConsumers = &SAppError{"get consumers"}
ErrCreateAnonNode = &SAppError{"create anon node"}
ErrOpenKVDatabase = &SAppError{"open kv database"}
ErrReadKVDatabase = &SAppError{"read kv database"}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/pkg/app/init_anon_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func (p *sApp) initAnonNode() error {
FFetchTimeout: cfgSettings.GetFetchTimeout(),
FSubSettings: &network.SSubSettings{
FServiceName: hls_settings.GServiceName.Short(),
FParallel: p.fParallel,
FLogger: p.fAnonLogger,
FParallel: cfgSettings.GetPowParallel(),
FQBConsumers: cfgSettings.GetQBConsumers(),
},
}),
p.fPrivKey,
Expand Down
9 changes: 1 addition & 8 deletions internal/service/pkg/app/init_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"errors"
"path/filepath"
"strconv"
"strings"

"github.com/number571/go-peer/pkg/types"
Expand All @@ -16,12 +15,6 @@ import (

// initApp work with the raw data = read files, read args
func InitApp(pArgs []string, pFlags flag.IFlags) (types.IRunner, error) {
strParallel := pFlags.Get("-t").GetStringValue(pArgs)
setParallel, err := strconv.ParseUint(strParallel, 10, 64)
if err != nil {
return nil, errors.Join(ErrGetParallel, err)
}

inputPath := strings.TrimSuffix(pFlags.Get("-p").GetStringValue(pArgs), "/")

cfgPath := filepath.Join(inputPath, pkg_settings.CPathYML)
Expand All @@ -36,5 +29,5 @@ func InitApp(pArgs []string, pFlags flag.IFlags) (types.IRunner, error) {
return nil, errors.Join(ErrGetPrivateKey, err)
}

return NewApp(cfg, privKey, inputPath, setParallel), nil
return NewApp(cfg, privKey, inputPath), nil
}
2 changes: 2 additions & 0 deletions internal/service/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func GetConfigSettings(pCfg config.IConfig, pClient client.IClient) SConfigSetti
FNetworkKey: sett.GetNetworkKey(),
FMessageSizeBytes: sett.GetMessageSizeBytes(),
FWorkSizeBits: sett.GetWorkSizeBits(),
FQBConsumers: sett.GetQBConsumers(),
FPowParallel: sett.GetPowParallel(),
FFetchTimeoutMS: uint64(sett.GetFetchTimeout() / time.Millisecond),
FQueuePeriodMS: uint64(sett.GetQueuePeriod() / time.Millisecond),
},
Expand Down
8 changes: 2 additions & 6 deletions internal/utils/help/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func ExamplePrintln() {
WithDescription("set path to config, database files").
WithDefinedValue("."),
flag.NewFlagBuilder("-n", "--network").
WithDescription("set network key for connections").
WithDescription("set network key of connections from build").
WithDefinedValue(""),
flag.NewFlagBuilder("-t", "--threads").
WithDescription("set num of parallel functions to calculate PoW").
WithDefinedValue("1"),
).Build(),
)
// Output:
Expand All @@ -32,6 +29,5 @@ func ExamplePrintln() {
// [ -v, --version ] = print information about service
// [ -h, --help ] = print version of service
// [ -p, --path ] = set path to config, database files
// [ -n, --network ] = set network key for connections
// [ -t, --threads ] = set num of parallel functions to calculate PoW
// [ -n, --network ] = set network key of connections from build
}
4 changes: 2 additions & 2 deletions pkg/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func NewHiddenLakeNode(
FSettings: adaptersSettings,
FParallel: pSettings.GetParallel(),
}),
FQueuePeriod: pSettings.GetQueuePeriod(),
FNetworkMask: build.GSettings.FProtoMask.FNetwork,
FConsumersCap: build.GSettings.FQueueProblem.FConsumersCap,
FQueuePeriod: pSettings.GetQueuePeriod(),
FConsumersCap: pSettings.GetQBConsumers(),
FQueuePoolCap: [2]uint64{
build.GSettings.FQueueProblem.FMainPoolCap,
build.GSettings.FQueueProblem.FRandPoolCap,
Expand Down
Loading

0 comments on commit 8a0ac76

Please sign in to comment.