This commit is contained in:
number571 2024-01-29 05:10:10 +07:00
parent f69f6cf6f1
commit dfd2a5d303
8 changed files with 2187 additions and 2170 deletions

View File

@ -22,10 +22,9 @@
### Applications
1. HLFR: Hidden Lake Forum
2. HLFL: Hidden Lake Filer
3. HLN: Hidden Lake Network
4. HLP: Hidden Lake Publisher
5. HLSH: Hidden Lake Shell
2. HLN: Hidden Lake Network
3. HLP: Hidden Lake Publisher
4. HLSH: Hidden Lake Shell
### Articles -> Book

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%"><title>coverage: 56%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="35" height="20" fill="crimson"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">56%</text><text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">56%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 55%"><title>coverage: 55%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="35" height="20" fill="crimson"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">55%</text><text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">55%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@ import (
"net/http"
"os"
"strconv"
"time"
"github.com/number571/go-peer/cmd/hidden_lake/applications/filer/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/applications/filer/internal/utils"
@ -15,6 +14,8 @@ import (
hlf_settings "github.com/number571/go-peer/cmd/hidden_lake/applications/filer/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/applications/filer/web"
http_logger "github.com/number571/go-peer/internal/logger/http"
"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/logger"
)
@ -60,7 +61,7 @@ func StoragePage(pLogger logger.ILogger, pCfg config.IConfig, pPathTo string) ht
}
fileHash := pR.FormValue("file_hash")
if fileHash == "" {
if fileHash == "" || len(encoding.HexDecode(fileHash)) != hashing.CSHA256Size {
ErrorPage(pLogger, pCfg, "file_hash_error", "incorrect file hash")(pW, pR)
return
}
@ -77,24 +78,38 @@ func StoragePage(pLogger logger.ILogger, pCfg config.IConfig, pPathTo string) ht
return
}
baseFileName := getUniqFileName(pPathTo, fileName)
tempFileName := baseFileName + ".tmp"
baseFileName := fmt.Sprintf(
"%s/%s/%s_%s",
pPathTo,
hlf_settings.CPathLoadedSTG,
fileHash[:16],
fileName,
)
file, err := os.Create(tempFileName)
if err != nil {
ErrorPage(pLogger, pCfg, "create_file_error", "failed to create file")(pW, pR)
tmpFileName := baseFileName + ".tmp"
if _, err := os.Stat(baseFileName); !os.IsNotExist(err) {
ErrorPage(pLogger, pCfg, "file_already_exist", "file already loaded")(pW, pR)
return
}
defer func() {
file.Close()
os.Remove(tempFileName)
}()
gotSize := 0
startChunk := uint64(0)
tmpStat, err := os.Stat(tmpFileName)
if !os.IsNotExist(err) {
startChunk = utils.GetChunksCount(uint64(tmpStat.Size()), uint64(chunkSize))
}
tmpFile, err := os.OpenFile(tmpFileName, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
ErrorPage(pLogger, pCfg, "open_temp_file_error", "failed to open temp file")(pW, pR)
return
}
defer tmpFile.Close()
gotSize := (startChunk * chunkSize)
retryNum := 3
chunksCount := utils.GetChunksCount(uint64(fileSize), chunkSize)
for i := uint64(0); i < chunksCount; i++ {
for i := uint64(startChunk); i < chunksCount; i++ {
for j := 1; j <= retryNum; j++ {
chunk, err := hlfClient.LoadFileChunk(aliasName, fileName, i)
if err != nil {
@ -104,7 +119,7 @@ func StoragePage(pLogger logger.ILogger, pCfg config.IConfig, pPathTo string) ht
}
continue
}
n, err := file.Write(chunk)
n, err := tmpFile.Write(chunk)
if err != nil {
ErrorPage(pLogger, pCfg, "write_to_file", "failed write to file")(pW, pR)
return
@ -113,23 +128,25 @@ func StoragePage(pLogger logger.ILogger, pCfg config.IConfig, pPathTo string) ht
ErrorPage(pLogger, pCfg, "invalid_chunk_size", "got invalid chunk size")(pW, pR)
return
}
gotSize += n
gotSize += uint64(n)
break
}
}
if gotSize != fileSize {
defer os.Remove(tmpFileName)
if gotSize != uint64(fileSize) {
ErrorPage(pLogger, pCfg, "size_file", "invalid size file")(pW, pR)
return
}
if getFileHash(tempFileName) != fileHash {
if getFileHash(tmpFileName) != fileHash {
ErrorPage(pLogger, pCfg, "hash_file", "invalid hash file")(pW, pR)
return
}
// baseFile <- tempFile
if err := copyFile(baseFileName, tempFileName); err != nil {
if err := copyFile(baseFileName, tmpFileName); err != nil {
ErrorPage(pLogger, pCfg, "copy_file", "failed copy file")(pW, pR)
return
}
@ -168,20 +185,6 @@ func StoragePage(pLogger logger.ILogger, pCfg config.IConfig, pPathTo string) ht
}
}
func getUniqFileName(pPathTo, pFileName string) string {
origName := fmt.Sprintf("%s/%s/%s", pPathTo, hlf_settings.CPathLoadedSTG, pFileName)
if _, err := os.Stat(origName); os.IsNotExist(err) {
return origName
}
return fmt.Sprintf(
"%s/%s/%s_%s",
pPathTo,
hlf_settings.CPathLoadedSTG,
time.Now().Format("20060102150405"),
pFileName,
)
}
func copyFile(dst, src string) error {
sourceFileStat, err := os.Stat(src)
if err != nil {

View File

@ -1,12 +1,14 @@
package client
import (
"errors"
"fmt"
"net/http"
hlf_settings "github.com/number571/go-peer/cmd/hidden_lake/applications/filer/pkg/settings"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
hls_request "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/request"
"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/pkg/encoding"
)
@ -36,6 +38,11 @@ func (p *sRequester) GetListFiles(pAliasName string, pRequest hls_request.IReque
if err := encoding.DeserializeJSON(resp.GetBody(), &list); err != nil {
return nil, err // TODO: create errors
}
for _, info := range list {
if len(encoding.HexDecode(info.FHash)) != hashing.CSHA256Size {
return nil, errors.New("got invalid hash value")
}
}
return list, nil
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -2,6 +2,7 @@ GC=go build
.PHONY: default build run clean
default: clean build run
build:
cp 66eecc602041c455_image.jpg.tmp hlf.stg/loaded
cp hls_copy.yml hls.yml
run:
./prog_hls1 &

File diff suppressed because it is too large Load Diff