Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 7, 2024
1 parent 20c7f2a commit e5f2ce7
Show file tree
Hide file tree
Showing 11 changed files with 6,991 additions and 6,436 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Update `cmd/hidden_lake/helpers/traffic`: database now only store hashes, messages stores in memory
- Update `cmd/hidden_lake/helpers/traffic`: rename "storage_enabled" -> "database_enabled"
- Update `cmd/hidden_lake/helpers/traffic`: "messages_capacity" can be = 0

<!-- ... -->

Expand Down
8,376 changes: 4,447 additions & 3,929 deletions cmd/hidden_lake/_test/result/coverage.out

Large diffs are not rendered by default.

616 changes: 314 additions & 302 deletions cmd/hidden_lake/_test/result/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions cmd/hidden_lake/helpers/traffic/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type SConfigSettings struct {
FMessageSizeBytes uint64 `json:"message_size_bytes" yaml:"message_size_bytes"`
FKeySizeBits uint64 `json:"key_size_bits" yaml:"key_size_bits"`
FWorkSizeBits uint64 `json:"work_size_bits,omitempty" yaml:"work_size_bits,omitempty"`
FMessagesCapacity uint64 `json:"messages_capacity" yaml:"messages_capacity"`
FMessagesCapacity uint64 `json:"messages_capacity,omitempty" yaml:"messages_capacity,omitempty"`
FRandMessageSizeBytes uint64 `json:"rand_message_size_bytes,omitempty" yaml:"rand_message_size_bytes,omitempty"`
FNetworkKey string `json:"network_key,omitempty" yaml:"network_key,omitempty"`
FDatabaseEnabled bool `json:"database_enabled,omitempty" yaml:"database_enabled,omitempty"`
Expand Down Expand Up @@ -112,7 +112,6 @@ func (p *SConfigSettings) GetDatabaseEnabled() bool {
func (p *SConfig) isValid() bool {
return true &&
p.FSettings.FMessageSizeBytes != 0 &&
p.FSettings.FMessagesCapacity != 0 &&
p.FSettings.FKeySizeBits != 0
}

Expand Down
35 changes: 21 additions & 14 deletions cmd/hidden_lake/helpers/traffic/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (
)

const (
tcConfigFile = "config_test.txt"
tcLogging = true
tcStorage = true
tcNetwork = "test_network"
tcAddress1 = "test_address1"
tcAddress2 = "test_address2"
tcAddress3 = "test_address3"
tcConnection1 = "test_connection1"
tcConnection2 = "test_connection2"
tcConsumer1 = "test_consumer1"
tcConsumer2 = "test_consumer2"
tcMessageSize = (1 << 20)
tcWorkSize = 22
tcCapMessages = 1000
tcConfigFile = "config_test.txt"
tcLogging = true
tcStorage = true
tcNetwork = "test_network"
tcAddress1 = "test_address1"
tcAddress2 = "test_address2"
tcAddress3 = "test_address3"
tcConnection1 = "test_connection1"
tcConnection2 = "test_connection2"
tcConsumer1 = "test_consumer1"
tcConsumer2 = "test_consumer2"
tcMessageSize = (1 << 20)
tcWorkSize = 22
tcCapMessages = 1000
tcDatabaseEnabled = true
)

func TestError(t *testing.T) {
Expand All @@ -43,6 +44,7 @@ func testConfigDefaultInit(configPath string) {
FMessagesCapacity: tcCapMessages,
FNetworkKey: tcNetwork,
FKeySizeBits: testutils.TcKeySize,
FDatabaseEnabled: true,
},
FLogging: []string{"info", "erro"},
FAddress: &SAddress{
Expand Down Expand Up @@ -88,6 +90,11 @@ func TestConfig(t *testing.T) {
return
}

if cfg.GetSettings().GetDatabaseEnabled() != tcDatabaseEnabled {
t.Error("settings database enabled is invalid")
return
}

if cfg.GetLogging().HasInfo() != tcLogging {
t.Error("logging.info is invalid")
return
Expand Down
10 changes: 5 additions & 5 deletions cmd/hidden_lake/helpers/traffic/pkg/app/init_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

func (p *sApp) initStorage(pDatabase database.IKVDatabase) {
cfgSettings := p.fConfig.GetSettings()
p.fStorage = storage.NewMessageStorage(
cfgSettings,
pDatabase,
lru.NewLRUCache(cfgSettings.GetMessagesCapacity()),
)
lruCache := newVoidLRUCache()
if mcap := cfgSettings.GetMessagesCapacity(); mcap != 0 {
lruCache = lru.NewLRUCache(mcap)
}
p.fStorage = storage.NewMessageStorage(cfgSettings, pDatabase, lruCache)
}
18 changes: 18 additions & 0 deletions cmd/hidden_lake/helpers/traffic/pkg/app/void_lru.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package app

import (
"github.com/number571/go-peer/pkg/storage/cache/lru"
)

var (
_ lru.ILRUCache = &sVoidLRUCache{}
)

type sVoidLRUCache struct{}

func newVoidLRUCache() lru.ILRUCache { return &sVoidLRUCache{} }

func (p *sVoidLRUCache) GetIndex() uint64 { return 0 }
func (p *sVoidLRUCache) GetKey(_ uint64) ([]byte, bool) { return nil, false }
func (p *sVoidLRUCache) Get(_ []byte) ([]byte, bool) { return nil, false }
func (p *sVoidLRUCache) Set(_, _ []byte) bool { return true }
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/result/badge_coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e5f2ce7

Please sign in to comment.