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 4d3b5fd commit 82e8940
Show file tree
Hide file tree
Showing 56 changed files with 10,967 additions and 8,568 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Update `cmd/hidden_lake/helpers/traffic`: rename "storage_enabled" -> "database_enabled"
- Update `cmd/hidden_lake/helpers/traffic`: "messages_capacity" can be = 0
- Update `pkg/storage/cache`: cache/lru/lru.go -> cache/lru.go
- Update `internal/api`: Request success if "200 >= code < 300" (old version only code=200)

<!-- ... -->

Expand Down
1 change: 0 additions & 1 deletion cmd/hidden_lake/_configs/hlt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
settings:
message_size_bytes: 8192
key_size_bits: 4096
messages_capacity: 2048
logging:
- info
- warn
Expand Down
9,434 changes: 5,918 additions & 3,516 deletions cmd/hidden_lake/_test/result/coverage.out

Large diffs are not rendered by default.

634 changes: 311 additions & 323 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/loader/internal/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"

hll_settings "github.com/number571/go-peer/cmd/hidden_lake/helpers/loader/pkg/settings"
hlt_settings "github.com/number571/go-peer/cmd/hidden_lake/helpers/traffic/pkg/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
logger "github.com/number571/go-peer/internal/logger/std"
)
Expand All @@ -16,7 +15,7 @@ func InitConfig(cfgPath string, initCfg *SConfig) (IConfig, error) {
if initCfg == nil {
initCfg = &SConfig{
FSettings: &SConfigSettings{
FMessagesCapacity: hlt_settings.CDefaultMessagesCapacity,
FMessagesCapacity: hll_settings.CDefaultMessagesCapacity,
FWorkSizeBits: hls_settings.CDefaultWorkSizeBits,
FNetworkKey: hls_settings.CDefaultNetworkKey,
},
Expand Down
4 changes: 4 additions & 0 deletions cmd/hidden_lake/helpers/loader/pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const (
CPathYML = "hll.yml"
)

const (
CDefaultMessagesCapacity = (2 << 10) // count
)

const (
CDefaultHTTPAddress = "127.0.0.1:9561"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/hidden_lake/helpers/traffic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Default config `hlt.yml`
settings:
message_size_bytes: 8192
key_size_bits: 4096
messages_capacity: 2048
logging:
- info
- warn
Expand Down
5 changes: 5 additions & 0 deletions cmd/hidden_lake/helpers/traffic/internal/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cache

import "testing"

func TestNothing(_ *testing.T) {}
10 changes: 8 additions & 2 deletions cmd/hidden_lake/helpers/traffic/internal/handler/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func HandleMessageAPI(
query := pR.URL.Query()

hash := encoding.HexDecode(query.Get("hash"))
if hash == nil {
if len(hash) == 0 {
pHTTPLogger.PushWarn(logBuilder.WithMessage(http_logger.CLogDecodeBody))
_ = api.Response(pW, http.StatusNotFound, "failed: decode message")
_ = api.Response(pW, http.StatusTeapot, "failed: decode hash")
return
}

Expand Down Expand Up @@ -81,6 +81,12 @@ func HandleMessageAPI(
return
}

if !pNode.GetCacheSetter().Set(netMsg.GetHash(), []byte{}) {
pHTTPLogger.PushInfo(logBuilder.WithMessage("hash_already_exist"))
_ = api.Response(pW, http.StatusAccepted, "accepted: hash already exist")
return // hash of message already in queue
}

if err := tcpHandler(pCtx, pNode, nil, netMsg); err != nil {
// internal logger
_ = api.Response(pW, http.StatusBadRequest, "failed: handle message")
Expand Down
6 changes: 3 additions & 3 deletions cmd/hidden_lake/helpers/traffic/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ func (p *sMessageStorage) Push(pMsg net_message.IMessage) error {
return utils.MergeErrors(ErrLoadMessage, err)
}
hash := pMsg.GetHash()
if ok := p.fLRUCache.Set(hash, pMsg.ToBytes()); !ok {
return ErrMessageIsExist
}
_, err := p.fDatabase.Get(hash)
if err == nil {
return ErrHashAlreadyExist
Expand All @@ -74,6 +71,9 @@ func (p *sMessageStorage) Push(pMsg net_message.IMessage) error {
if err := p.fDatabase.Set(hash, []byte{}); err != nil {
return utils.MergeErrors(ErrSetHashIntoDB, err)
}
if ok := p.fLRUCache.Set(hash, pMsg.ToBytes()); !ok {
return ErrMessageIsExist
}
return nil
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/hidden_lake/helpers/traffic/pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const (
CPathDB = "hlt.db"
)

const (
CDefaultHashesWindow = (2 << 10)
CDefaultMessagesCapacity = (2 << 10)
)

const (
CHandleIndexPath = "/api/index"
CHandleStoragePointerPath = "/api/storage/pointer"
Expand All @@ -24,7 +19,8 @@ const (
)

const (
CDefaultDatabaseEnabled = false
CDefaultMessagesCapacity = 0
CDefaultDatabaseEnabled = false
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
fetch_timeout_ms: 60000
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 60000
queue_period_ms: 30_000
messages_capacity: 2048
address:
tcp: :8581
http: :8582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
fetch_timeout_ms: 60000
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 60000
queue_period_ms: 30_000
messages_capacity: 2048
address:
tcp: :7581
http: :7582
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :8581
http: :8582
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :7581
http: :7582
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/filesharer/routing/middle_hlt_1/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/filesharer/routing/middle_hlt_2/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/filesharer/routing/middle_hlt_3/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :8581
http: :8582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :7581
http: :7582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 60000
queue_period_ms: 20_000
rand_queue_period_ms: 10_000
rand_message_size_bytes: 1024
queue_period_ms: 5000
logging:
- info
- warn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 1024
address:
tcp: :8581
http: :8582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 60000
queue_period_ms: 20_000
rand_queue_period_ms: 10_000
rand_message_size_bytes: 1024
queue_period_ms: 5000
logging:
- info
- warn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 1024
address:
tcp: :7581
http: :7582
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/messenger/group/middle_hlt/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
logging:
- info
- warn
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/messenger/routing/middle_hlt_1/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/messenger/routing/middle_hlt_2/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
1 change: 0 additions & 1 deletion examples/anonymity/messenger/routing/middle_hlt_3/hlt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 8192
key_size_bits: 4096
work_size_bits: 22
messages_capacity: 2048
rand_message_size_bytes: 4096
network_key: oMj49BD8he1n8bfq
logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
fetch_timeout_ms: 60000
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :8581
http: :8582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
fetch_timeout_ms: 60000
work_size_bits: 22
fetch_timeout_ms: 300_000
queue_period_ms: 30_000
logging:
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ settings:
message_size_bytes: 4096
key_size_bits: 2048
work_size_bits: 22
messages_capacity: 2048
address:
tcp: :7581
http: :7582
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
settings:
message_size_bytes: 4096
work_size_bits: 22
key_size_bits: 2048
work_size_bits: 22
fetch_timeout_ms: 60000
queue_period_ms: 20_000
rand_queue_period_ms: 10_000
rand_message_size_bytes: 1024
queue_period_ms: 5000
logging:
- info
- warn
Expand Down
Loading

0 comments on commit 82e8940

Please sign in to comment.