-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
number571
committed
Sep 14, 2024
1 parent
41d4eeb
commit 1519e63
Showing
53 changed files
with
33,044 additions
and
6,804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
settings: {} | ||
logging: | ||
- info | ||
- warn | ||
- erro | ||
address: | ||
http: 127.0.0.1:9521 | ||
services: | ||
hidden-lake-messenger: 127.0.0.1:9592 | ||
hidden-lake-filesharer: 127.0.0.1:9542 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM --platform=linux/amd64 ubuntu:20.04 | ||
|
||
RUN apt-get update && apt-get install -y wget gcc | ||
RUN wget https://go.dev/dl/go1.16.linux-amd64.tar.gz && \ | ||
tar -C /opt -xzf go1.16.linux-amd64.tar.gz | ||
|
||
WORKDIR /go-peer | ||
ENV PATH="${PATH}:/opt/go/bin" | ||
COPY ./ ./ | ||
RUN go build -o hll ./cmd/hidden_lake/helpers/distributor/cmd/hld | ||
|
||
ENV SERVICE_PATH="/mounted" | ||
CMD ./hld -path="${SERVICE_PATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
N=1 | ||
GC=go build | ||
ROOPATH=../../../.. | ||
BINPATH=$(ROOPATH)/bin | ||
|
||
.PHONY: default build run test clean | ||
|
||
default: build run | ||
default-config: | ||
cp $(ROOPATH)/cmd/hidden_lake/_configs/hld.yml . | ||
build: default-config | ||
$(GC) -o $(BINPATH)/hld ./cmd/hld | ||
|
||
for arch in amd64 arm64; \ | ||
do \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=$${arch} go build -o $(BINPATH)/hld_$${arch}_linux ./cmd/hld; \ | ||
CGO_ENABLED=0 GOOS=windows GOARCH=$${arch} go build -o $(BINPATH)/hld_$${arch}_windows.exe ./cmd/hld; \ | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=$${arch} go build -o $(BINPATH)/hld_$${arch}_darwin ./cmd/hld; \ | ||
done; | ||
run: | ||
./$(BINPATH)/hld | ||
test: | ||
for i in {1..$(N)}; do go clean -testcache; echo $$i; go test ./...; done | ||
clean: | ||
rm -f $(BINPATH)/hld $(BINPATH)/hld_* | ||
rm -rf hld.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# HLD | ||
|
||
> Hidden Lake Distributor |
24 changes: 24 additions & 0 deletions
24
cmd/hidden_lake/helpers/distributor/_daemon/install_hld.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# root mode | ||
echo " | ||
[Unit] | ||
Description=HiddenLakeDistributor | ||
[Service] | ||
ExecStart=/root/hld_amd64_linux -path=/root | ||
Restart=always | ||
RestartSec=10 | ||
[Install] | ||
WantedBy=multi-user.target | ||
" > /etc/systemd/system/hidden_lake_distributor.service | ||
|
||
cd /root && \ | ||
rm -f hld_amd64_linux && \ | ||
wget https://github.com/number571/go-peer/releases/latest/download/hld_amd64_linux && \ | ||
chmod +x hld_amd64_linux | ||
|
||
systemctl daemon-reload | ||
systemctl enable hidden_lake_distributor.service | ||
systemctl restart hidden_lake_distributor.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
journalctl -eu hidden_lake_distributor.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# root mode | ||
systemctl restart hidden_lake_distributor.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
watch -c SYSTEMD_COLORS=1 systemctl status -o cat hidden_lake_distributor.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# root mode | ||
systemctl stop hidden_lake_distributor.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestNothing(_ *testing.T) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
gopeer "github.com/number571/go-peer" | ||
"github.com/number571/go-peer/cmd/hidden_lake/helpers/distributor/pkg/app" | ||
"github.com/number571/go-peer/internal/flag" | ||
) | ||
|
||
func main() { | ||
args := os.Args[1:] | ||
|
||
if flag.GetBoolFlagValue(args, "version") { | ||
fmt.Println(gopeer.CVersion) | ||
return | ||
} | ||
|
||
app, err := app.InitApp(args, ".") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
shutdown := make(chan os.Signal, 1) | ||
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
closed := make(chan struct{}) | ||
defer func() { | ||
cancel() | ||
<-closed | ||
}() | ||
|
||
go func() { | ||
defer func() { closed <- struct{}{} }() | ||
if err := app.Run(ctx); err != nil && !errors.Is(err, context.Canceled) { | ||
log.Fatal(err) | ||
} | ||
}() | ||
|
||
<-shutdown | ||
} |
128 changes: 128 additions & 0 deletions
128
cmd/hidden_lake/helpers/distributor/internal/config/config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
logger "github.com/number571/go-peer/internal/logger/std" | ||
"github.com/number571/go-peer/pkg/encoding" | ||
"github.com/number571/go-peer/pkg/utils" | ||
) | ||
|
||
var ( | ||
_ IConfig = &SConfig{} | ||
_ IAddress = &SAddress{} | ||
) | ||
|
||
type SConfigSettings struct { | ||
} | ||
|
||
type SConfig struct { | ||
fLogging logger.ILogging | ||
|
||
FSettings *SConfigSettings `yaml:"settings"` | ||
FLogging []string `yaml:"logging,omitempty"` | ||
FAddress *SAddress `yaml:"address"` | ||
FServices map[string]string `yaml:"services,omitempty"` | ||
} | ||
|
||
type SAddress struct { | ||
FHTTP string `yaml:"http"` | ||
FPPROF string `yaml:"pprof,omitempty"` | ||
} | ||
|
||
func BuildConfig(pFilepath string, pCfg *SConfig) (IConfig, error) { | ||
if _, err := os.Stat(pFilepath); !os.IsNotExist(err) { | ||
return nil, utils.MergeErrors(ErrConfigAlreadyExist, err) | ||
} | ||
|
||
if err := pCfg.initConfig(); err != nil { | ||
return nil, utils.MergeErrors(ErrInitConfig, err) | ||
} | ||
|
||
if err := os.WriteFile(pFilepath, encoding.SerializeYAML(pCfg), 0o600); err != nil { | ||
return nil, utils.MergeErrors(ErrWriteConfig, err) | ||
} | ||
|
||
return pCfg, nil | ||
} | ||
|
||
func LoadConfig(pFilepath string) (IConfig, error) { | ||
if _, err := os.Stat(pFilepath); os.IsNotExist(err) { | ||
return nil, utils.MergeErrors(ErrConfigNotExist, err) | ||
} | ||
|
||
bytes, err := os.ReadFile(pFilepath) | ||
if err != nil { | ||
return nil, utils.MergeErrors(ErrReadConfig, err) | ||
} | ||
|
||
cfg := new(SConfig) | ||
if err := encoding.DeserializeYAML(bytes, cfg); err != nil { | ||
return nil, utils.MergeErrors(ErrDeserializeConfig, err) | ||
} | ||
|
||
if err := cfg.initConfig(); err != nil { | ||
return nil, utils.MergeErrors(ErrInitConfig, err) | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func (p *SConfig) isValid() bool { | ||
return true && | ||
p.FAddress.FHTTP != "" | ||
} | ||
|
||
func (p *SConfig) initConfig() error { | ||
if p.FSettings == nil { | ||
p.FSettings = new(SConfigSettings) | ||
} | ||
|
||
if p.FAddress == nil { | ||
p.FAddress = new(SAddress) | ||
} | ||
|
||
if !p.isValid() { | ||
return ErrInvalidConfig | ||
} | ||
|
||
if err := p.loadLogging(); err != nil { | ||
return utils.MergeErrors(ErrLoadLogging, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *SConfig) loadLogging() error { | ||
result, err := logger.LoadLogging(p.FLogging) | ||
if err != nil { | ||
return utils.MergeErrors(ErrInvalidLogging, err) | ||
} | ||
p.fLogging = result | ||
return nil | ||
} | ||
|
||
func (p *SConfig) GetSettings() IConfigSettings { | ||
return p.FSettings | ||
} | ||
|
||
func (p *SConfig) GetAddress() IAddress { | ||
return p.FAddress | ||
} | ||
|
||
func (p *SAddress) GetHTTP() string { | ||
return p.FHTTP | ||
} | ||
|
||
func (p *SAddress) GetPPROF() string { | ||
return p.FPPROF | ||
} | ||
|
||
func (p *SConfig) GetService(name string) (string, bool) { | ||
service, ok := p.FServices[name] | ||
return service, ok | ||
} | ||
|
||
func (p *SConfig) GetLogging() logger.ILogging { | ||
return p.fLogging | ||
} |
85 changes: 85 additions & 0 deletions
85
cmd/hidden_lake/helpers/distributor/internal/config/config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
const ( | ||
tcConfigFile = "config_test.txt" | ||
tcLogging = true | ||
tcAddress1 = "test_address1" | ||
tcAddress2 = "test_address2" | ||
tcService1 = "test_service1" | ||
tcServiceAddress1 = "test_service_address1" | ||
tcWorkSize = 22 | ||
tcCapMessages = 1000 | ||
) | ||
|
||
func TestError(t *testing.T) { | ||
t.Parallel() | ||
|
||
str := "value" | ||
err := &SConfigError{str} | ||
if err.Error() != errPrefix+str { | ||
t.Error("incorrect err.Error()") | ||
return | ||
} | ||
} | ||
|
||
func testConfigDefaultInit(configPath string) { | ||
_, _ = BuildConfig(configPath, &SConfig{ | ||
FSettings: &SConfigSettings{}, | ||
FLogging: []string{"info", "erro"}, | ||
FAddress: &SAddress{ | ||
FHTTP: tcAddress1, | ||
FPPROF: tcAddress2, | ||
}, | ||
FServices: map[string]string{ | ||
tcService1: tcServiceAddress1, | ||
}, | ||
}) | ||
} | ||
|
||
func TestConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
testConfigDefaultInit(tcConfigFile) | ||
defer os.Remove(tcConfigFile) | ||
|
||
cfg, err := LoadConfig(tcConfigFile) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
if cfg.GetLogging().HasInfo() != tcLogging { | ||
t.Error("logging.info is invalid") | ||
return | ||
} | ||
|
||
if cfg.GetLogging().HasErro() != tcLogging { | ||
t.Error("logging.erro is invalid") | ||
return | ||
} | ||
|
||
if cfg.GetLogging().HasWarn() == tcLogging { | ||
t.Error("logging.warn is invalid") | ||
return | ||
} | ||
|
||
if cfg.GetAddress().GetHTTP() != tcAddress1 { | ||
t.Error("address http is invalid") | ||
return | ||
} | ||
|
||
if cfg.GetAddress().GetPPROF() != tcAddress2 { | ||
t.Error("address pprof is invalid") | ||
return | ||
} | ||
|
||
if v, ok := cfg.GetService(tcService1); !ok || v != tcServiceAddress1 { | ||
t.Error("service address is invalid") | ||
return | ||
} | ||
} |
Oops, something went wrong.