Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 3, 2024
1 parent 5bb0e89 commit a1443ec
Show file tree
Hide file tree
Showing 78 changed files with 26,297 additions and 27,956 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 `pkg/network/conn`: add context to NewConn function, rename NewConn -> Connect
- Update `pkg/network/anonymity`: delete f2f_disabled=true option (insecure)
- Update `pkg/network/anonymity/queue`: delete queue_period=0 option (insecure)
- Update `pkg/network|pkg/network/anonymity/queue`: delete IVSettings

### BUG FIXES

Expand Down
29,072 changes: 13,952 additions & 15,120 deletions cmd/hidden_lake/_test/result/coverage.out

Large diffs are not rendered by default.

640 changes: 326 additions & 314 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.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ func SettingsPage(
}

switch pR.FormValue("method") {
case http.MethodPatch:
networkKey := strings.TrimSpace(pR.FormValue("network_key"))
if err := pHlsClient.SetNetworkKey(pCtx, networkKey); err != nil {
ErrorPage(pLogger, cfg, "set_network_key", "update network key")(pW, pR)
return
}
case http.MethodPut:
strLang := strings.TrimSpace(pR.FormValue("language"))
ilang, err := language.ToILanguage(strLang)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ <h5 class="card-header text-white bg-secondary p-2">
<!-- HTML does not support another methods (PUT, DELETE, etc...) -->
<input hidden name="method" value="PATCH">
<div class="row">
<div class="col-md-8 w-75">
<div class="col-md-12 w-100">
{{if (eq .FLanguage 0)}}
<input type="text" name="network_key" placeholder="Network key" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{else if (eq .FLanguage 1)}}
<input type="text" name="network_key" placeholder="Ключ сети" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{else if (eq .FLanguage 2)}}
<input type="text" name="network_key" placeholder="Reto-ŝlosilo" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{end}}
</div>
<div class="col-md-4 w-25">
<!-- <div class="col-md-4 w-25">
<input type="submit" name="submit" value="◀" class="btn btn-info w-100">
</div>
</div> -->
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ func SettingsPage(
}

switch pR.FormValue("method") {
case http.MethodPatch:
networkKey := strings.TrimSpace(pR.FormValue("network_key"))
if err := pHlsClient.SetNetworkKey(pCtx, networkKey); err != nil {
ErrorPage(pLogger, cfg, "set_network_key", "update network key")(pW, pR)
return
}
case http.MethodPut:
strLang := strings.TrimSpace(pR.FormValue("language"))
ilang, err := language.ToILanguage(strLang)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ <h5 class="card-header text-white bg-secondary p-2">
<!-- HTML does not support another methods (PUT, DELETE, etc...) -->
<input hidden name="method" value="PATCH">
<div class="row">
<div class="col-md-8 w-75">
<div class="col-md-12 w-100">
{{if (eq .FLanguage 0)}}
<input type="text" name="network_key" placeholder="Network key" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{else if (eq .FLanguage 1)}}
<input type="text" name="network_key" placeholder="Ключ сети" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{else if (eq .FLanguage 2)}}
<input type="text" name="network_key" placeholder="Reto-ŝlosilo" value="{{.FNetworkKey}}"
<input disabled type="text" name="network_key" placeholder="(void)" value="{{.FNetworkKey}}"
class="text-center form-control bg-dark text-white w-100">
{{end}}
</div>
<div class="col-md-4 w-25">
<!-- <div class="col-md-4 w-25">
<input type="submit" name="submit" value="◀" class="btn btn-info w-100">
</div>
</div> -->
</div>
</form>
</div>
Expand Down
8 changes: 5 additions & 3 deletions cmd/hidden_lake/helpers/encryptor/internal/handler/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ func HandleMessageEncryptAPI(

cfgSett := pConfig.GetSettings()
netMsg := net_message.NewMessage(
net_message.NewSettings(&net_message.SSettings{
FWorkSizeBits: cfgSett.GetWorkSizeBits(),
FNetworkKey: cfgSett.GetNetworkKey(),
net_message.NewConstructSettings(&net_message.SConstructSettings{
FSettings: net_message.NewSettings(&net_message.SSettings{
FWorkSizeBits: cfgSett.GetWorkSizeBits(),
FNetworkKey: cfgSett.GetNetworkKey(),
}),
FParallel: pParallel,
FRandMessageSizeBytes: cfgSett.GetRandMessageSizeBytes(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ func TestErrorsAPI(t *testing.T) {
}

pld := payload.NewPayload32(testutils.TcHead, []byte(testutils.TcBody))
sett := message.NewSettings(&message.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
sett := message.NewConstructSettings(&message.SConstructSettings{
FSettings: message.NewSettings(&message.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
}),
})
if _, _, err := client.DecryptMessage(context.Background(), message.NewMessage(sett, pld)); err == nil {
t.Error("success decrypt message with unknown host")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ func TestHandleTransferAPI(t *testing.T) {

// INIT SERVICES

netMsgSettings := net_message.NewSettings(&net_message.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
FNetworkKey: testutils.TCNetworkKey,
netMsgSettings := net_message.NewConstructSettings(&net_message.SConstructSettings{
FSettings: net_message.NewSettings(&net_message.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
FNetworkKey: testutils.TCNetworkKey,
}),
})

cancel1, hltClient1, err := testCreateHLT(netMsgSettings, tcNameHLT1, tgProducer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,11 @@ func newNetworkMessageWithData(cl client.IClient, networkKey, data string) (net_
return nil, err
}
netMsg := net_message.NewMessage(
net_message.NewSettings(&net_message.SSettings{
FNetworkKey: networkKey,
FWorkSizeBits: testutils.TCWorkSize,
net_message.NewConstructSettings(&net_message.SConstructSettings{
FSettings: net_message.NewSettings(&net_message.SSettings{
FNetworkKey: networkKey,
FWorkSizeBits: testutils.TCWorkSize,
}),
}),
payload.NewPayload32(0, msg),
)
Expand Down
34 changes: 7 additions & 27 deletions cmd/hidden_lake/helpers/traffic/internal/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func TestError(t *testing.T) {
}

func testNetworkMessageSettings() net_message.IConstructSettings {
return net_message.NewSettings(&net_message.SSettings{
FNetworkKey: testutils.TCNetworkKey,
FWorkSizeBits: testutils.TCWorkSize,
return net_message.NewConstructSettings(&net_message.SConstructSettings{
FSettings: net_message.NewSettings(&net_message.SSettings{
FNetworkKey: testutils.TCNetworkKey,
FWorkSizeBits: testutils.TCWorkSize,
}),
})
}

Expand Down Expand Up @@ -126,26 +128,7 @@ func testRunService(db database.IDatabase, addr string, addrNode string) (*http.
},
}

node := network.NewNode(
network.NewSettings(&network.SSettings{
FMaxConnects: testutils.TCMaxConnects,
FReadTimeout: time.Minute,
FWriteTimeout: time.Minute,
FConnSettings: conn.NewSettings(&conn.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
FLimitMessageSizeBytes: testutils.TCMessageSize,
FWaitReadTimeout: time.Hour,
FDialTimeout: time.Minute,
FReadTimeout: time.Minute,
FWriteTimeout: time.Minute,
}),
}),
conn.NewVSettings(&conn.SVSettings{
FNetworkKey: testutils.TCNetworkKey,
}),
lru.NewLRUCache(testutils.TCCapacity),
)

node := testNewNetworkNode("")
logger := logger.NewLogger(
logger.NewSettings(&logger.SSettings{}),
func(_ logger.ILogArg) string { return "" },
Expand Down Expand Up @@ -187,17 +170,14 @@ func testNewNetworkNode(addr string) network.INode {
FReadTimeout: time.Minute,
FWriteTimeout: time.Minute,
FConnSettings: conn.NewSettings(&conn.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
FMessageSettings: testNetworkMessageSettings(),
FLimitMessageSizeBytes: testutils.TCMessageSize,
FWaitReadTimeout: time.Hour,
FDialTimeout: time.Minute,
FReadTimeout: time.Minute,
FWriteTimeout: time.Minute,
}),
}),
conn.NewVSettings(&conn.SVSettings{
FNetworkKey: testutils.TCNetworkKey,
}),
lru.NewLRUCache(testutils.TCCapacity),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestErrorsAPI(t *testing.T) {
)

pld := payload.NewPayload32(testutils.TcHead, []byte(testutils.TcBody))
sett := message.NewSettings(&message.SSettings{
FWorkSizeBits: testutils.TCWorkSize,
sett := message.NewConstructSettings(&message.SConstructSettings{
FSettings: testNetworkMessageSettings(),
})
if err := client.PutMessage(context.Background(), message.NewMessage(sett, pld)); err == nil {
t.Error("success put message with unknown host")
Expand Down
5 changes: 1 addition & 4 deletions cmd/hidden_lake/helpers/traffic/internal/handler/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ func HandleMessageAPI(pCtx context.Context, pCfg config.IConfig, pDatabase datab
}

netMsg, err := net_message.LoadMessage(
net_message.NewSettings(&net_message.SSettings{
FNetworkKey: pNode.GetVSettings().GetNetworkKey(),
FWorkSizeBits: pNode.GetSettings().GetConnSettings().GetWorkSizeBits(),
}),
pNode.GetSettings().GetConnSettings(),
string(msgStringAsBytes),
)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions cmd/hidden_lake/helpers/traffic/pkg/app/init_network_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ func (p *sApp) initNetworkNode(pDatabase database.IDatabase) {
FReadTimeout: hls_settings.CNetworkReadTimeout,
FWriteTimeout: hls_settings.CNetworkWriteTimeout,
FConnSettings: conn.NewSettings(&conn.SSettings{
FMessageSettings: cfgSettings,
FLimitMessageSizeBytes: cfgSettings.GetMessageSizeBytes() + cfgSettings.GetRandMessageSizeBytes(),
FWorkSizeBits: cfgSettings.GetWorkSizeBits(),
FWaitReadTimeout: hls_settings.CConnWaitReadTimeout,
FDialTimeout: hls_settings.CConnDialTimeout,
FReadTimeout: hls_settings.CNetworkReadTimeout,
FWriteTimeout: hls_settings.CNetworkWriteTimeout,
}),
}),
conn.NewVSettings(&conn.SVSettings{
FNetworkKey: cfgSettings.GetNetworkKey(),
}),
lru.NewLRUCache(hls_settings.CNetworkQueueCapacity),
).HandleFunc(
hls_settings.CNetworkMask,
Expand Down
19 changes: 1 addition & 18 deletions cmd/hidden_lake/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ and put result to "hex_data" HLS API
```
1. GET/POST/DELETE /api/config/connects
2. GET/POST/DELETE /api/config/friends
3. GET/POST /api/config/settings
3. GET /api/config/settings
4. GET/DELETE /api/network/online
5. POST/PUT /api/network/request
6. GET /api/network/pubkey
Expand Down Expand Up @@ -419,23 +419,6 @@ Content-Length: 120
{"message_size_bytes":8192,"queue_period_ms":5000,"key_size_bits":4096,"work_size_bits":22}
```

#### 3.2. POST Request

```bash
curl -i -X POST -H 'Accept: application/json' http://localhost:9572/api/config/settings --data "used_network_key"'
```
#### 3.2. POST Response
```
HTTP/1.1 200 OK
Date: Sun, 06 Aug 2023 23:22:49 GMT
Content-Length: 24
Content-Type: text/plain; charset=utf-8
success: set network key
```
### 4. /api/network/online

#### 4.1. GET Request
Expand Down
45 changes: 6 additions & 39 deletions cmd/hidden_lake/service/internal/handler/config_settings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"io"
"net/http"

"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
Expand All @@ -11,8 +10,6 @@ import (
http_logger "github.com/number571/go-peer/internal/logger/http"
"github.com/number571/go-peer/pkg/logger"
"github.com/number571/go-peer/pkg/network/anonymity"
"github.com/number571/go-peer/pkg/network/anonymity/queue"
"github.com/number571/go-peer/pkg/network/conn"
)

func HandleConfigSettingsAPI(
Expand All @@ -23,46 +20,16 @@ func HandleConfigSettingsAPI(
return func(pW http.ResponseWriter, pR *http.Request) {
logBuilder := http_logger.NewLogBuilder(pkg_settings.CServiceName, pR)

if pR.Method != http.MethodGet && pR.Method != http.MethodPost {
if pR.Method != http.MethodGet {
pLogger.PushWarn(logBuilder.WithMessage(http_logger.CLogMethod))
_ = api.Response(pW, http.StatusMethodNotAllowed, "failed: incorrect method")
return
}

switch pR.Method {
case http.MethodGet:
pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = api.Response(pW, http.StatusOK, pkg_config.GetConfigSettings(
pWrapper.GetConfig(),
pNode.GetMessageQueue().GetClient(),
))
return

case http.MethodPost:
networkKeyBytes, err := io.ReadAll(pR.Body)
if err != nil {
pLogger.PushWarn(logBuilder.WithMessage(http_logger.CLogDecodeBody))
_ = api.Response(pW, http.StatusConflict, "failed: read network key bytes")
return
}

networkKey := string(networkKeyBytes)
if err := pWrapper.GetEditor().UpdateNetworkKey(networkKey); err != nil {
pLogger.PushWarn(logBuilder.WithMessage("update_key"))
_ = api.Response(pW, http.StatusInternalServerError, "failed: update network key")
return
}

pNode.GetNetworkNode().SetVSettings(
conn.NewVSettings(&conn.SVSettings{FNetworkKey: networkKey}),
)
pNode.GetMessageQueue().SetVSettings(
queue.NewVSettings(&queue.SVSettings{FNetworkKey: networkKey}),
)

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = api.Response(pW, http.StatusOK, "success: set network key")
return
}
pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = api.Response(pW, http.StatusOK, pkg_config.GetConfigSettings(
pWrapper.GetConfig(),
pNode.GetMessageQueue().GetClient(),
))
}
}
Loading

0 comments on commit a1443ec

Please sign in to comment.