This commit is contained in:
Number571 2023-01-14 05:01:05 -05:00
parent 4eb0138229
commit 433ec3f519
225 changed files with 1738 additions and 2230 deletions

View File

@ -4,11 +4,9 @@ N=1
default: clean test
clean:
make -C ./cmd/hls clean
make -C ./cmd/hlm clean
make -C ./cmd/hms clean
make -C ./cmd/hmc clean
make -C ./cmd/ubc clean
make -C ./cmd/hidden_lake/service clean
make -C ./cmd/hidden_lake/messenger clean
make -C ./cmd/hidden_lake/traffic clean
make -C ./examples/_cmd/anon_messenger clean
make -C ./examples/_cmd/echo_service clean

View File

@ -19,9 +19,9 @@ The `go-peer` library contains a large number of functions necessary to ensure t
## TODO
1. Write or close commented tests as 'TODO'
2. Update HMS's, HMC's package structure
3. Try merge HLS with HMS and HLC with HMC
4. Create UBC application
2. Create UBC application
3. Databases to ISettings
4. Write tests for HLT
## Dependencies
@ -36,11 +36,11 @@ The `go-peer` library contains a large number of functions necessary to ensure t
1. [Hidden Lake Service](#1-hidden-lake-service)
2. [Hidden Lake Messenger](#2-hidden-lake-messenger)
3. [Another applications](#3-another-applications)
3. [Hidden Lake Traffic](#3-hidden-lake-traffic)
## 1. Hidden Lake Service
> [github.com/number571/go-peer/tree/master/cmd/hls](https://github.com/number571/go-peer/tree/master/cmd/hls "HLS")
> [github.com/number571/go-peer/tree/master/cmd/hidden_lake/service](https://github.com/number571/go-peer/tree/master/cmd/hidden_lake/service "HLS")
<img src="examples/images/hls_logo.png" alt="hls_logo.png"/>
@ -159,7 +159,7 @@ Decode response
## 2. Hidden Lake Messenger
> [github.com/number571/go-peer/tree/master/cmd/hlm](https://github.com/number571/go-peer/tree/master/cmd/hlm "HLM");
> [github.com/number571/go-peer/tree/master/cmd/hidden_lake/messenger](https://github.com/number571/go-peer/tree/master/cmd/hidden_lake/messenger "HLM");
<img src="examples/images/hlm_logo.png" alt="hlm_logo.png"/>
@ -204,15 +204,11 @@ Next, you need to login by going to the Sign in page. Enter your `login=user` an
To see the success of sending and receiving messages, you need to do all the same operations, but with `localhost:7070` as `node2_hlm`. This node will be Alice.
> More example images about HLM pages in the [github.com/number571/go-peer/cmd/hlm/examples/images](https://github.com/number571/go-peer/tree/master/cmd/hlm/examples/images "Path to HLM images")
> More example images about HLM pages in the [github.com/number571/go-peer/cmd/hidden_lake/messenger/examples/images](https://github.com/number571/go-peer/tree/master/cmd/hlm/examples/images "Path to HLM images")
## 3. Another applications
## 3. Hidden Lake Traffic
* Hidden Message Service: [github.com/number571/go-peer/tree/master/cmd/hms](https://github.com/number571/go-peer/tree/master/cmd/hms "HMS");
* Hidden Message Client: [github.com/number571/go-peer/tree/master/cmd/hmc](https://github.com/number571/go-peer/tree/master/cmd/hmc "HMC");
* Asymmetric Keys Generator: [github.com/number571/go-peer/tree/master/cmd/akg](https://github.com/number571/go-peer/tree/master/cmd/akg "AKG");
* Cryptographic Data Storage: [github.com/number571/go-peer/tree/master/cmd/cds](https://github.com/number571/go-peer/tree/master/cmd/cds "CDS");
* In developing... Union Block Chain: [github.com/number571/go-peer/tree/master/cmd/ubc](https://github.com/number571/go-peer/tree/master/cmd/ubc "UBC");
TODO
### Deprecated applications

View File

@ -3,8 +3,8 @@ GC=go build
.PHONY: default build run test clean
default: build run
build:
make build -C ../hls
cp ../hls/hls prog_hls
make build -C ../service
cp ../service/hls prog_hls
$(GC) -o hlm ./cmd/hlm
run:
./prog_hls &

View File

@ -45,7 +45,7 @@ Next, you need to login by going to the Sign in page. Enter your `login=user` an
To see the success of sending and receiving messages, you need to do all the same operations, but with `localhost:7070` as `node2_hlm`. This node will be Alice.
> More example images about HLM pages in the [github.com/number571/go-peer/cmd/hlm/examples/images](https://github.com/number571/go-peer/tree/master/cmd/hlm/examples/images "Path to HLM images")
> More example images about HLM pages in the [github.com/number571/go-peer/cmd/hidden_lake/messenger/examples/images](https://github.com/number571/go-peer/tree/master/cmd/hlm/examples/images "Path to HLM images")
## Cryptographic algorithms and functions

View File

@ -3,13 +3,13 @@ package main
import (
"fmt"
"github.com/number571/go-peer/cmd/hlm/internal/app"
"github.com/number571/go-peer/cmd/hlm/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/config"
"github.com/number571/go-peer/pkg/filesystem"
"github.com/number571/go-peer/pkg/types"
hlm_settings "github.com/number571/go-peer/cmd/hlm/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
hlm_settings "github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
)
func initApp() (types.IApp, error) {

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -6,13 +6,13 @@ import (
"os"
"time"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/internal/config"
"github.com/number571/go-peer/cmd/hlm/internal/database"
"github.com/number571/go-peer/cmd/hlm/internal/handler"
hlm_settings "github.com/number571/go-peer/cmd/hlm/internal/settings"
"github.com/number571/go-peer/cmd/hlm/web"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/database"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/handler"
hlm_settings "github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/pkg/closer"
"github.com/number571/go-peer/pkg/storage"
"github.com/number571/go-peer/pkg/types"

View File

@ -1,7 +1,7 @@
package state
import (
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
)

View File

@ -4,14 +4,14 @@ import (
"fmt"
"sync"
"github.com/number571/go-peer/cmd/hlm/internal/database"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/database"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/crypto/entropy"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/storage"
hlm_settings "github.com/number571/go-peer/cmd/hlm/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
hlm_settings "github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
)
type sState struct {

View File

@ -1,8 +1,8 @@
package state
import (
"github.com/number571/go-peer/cmd/hlm/internal/database"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/database"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/storage"
)

View File

@ -4,8 +4,8 @@ import (
"html/template"
"net/http"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
)
func AboutPage(s state.IState) http.HandlerFunc {

View File

@ -7,12 +7,12 @@ import (
"net/http"
"strings"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/internal/database"
hlm_settings "github.com/number571/go-peer/cmd/hlm/internal/settings"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hls/pkg/request"
hls_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/database"
hlm_settings "github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
"github.com/number571/go-peer/cmd/hidden_lake/service/pkg/request"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
)
const (

View File

@ -1,7 +1,7 @@
package handler
import (
"github.com/number571/go-peer/cmd/hlm/internal/chat_queue"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/chat_queue"
"golang.org/x/net/websocket"
)

View File

@ -3,7 +3,7 @@ package handler
import (
"net/http"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
)
func FaviconPage(s state.IState) http.HandlerFunc {

View File

@ -7,8 +7,8 @@ import (
"sort"
"strings"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
)

View File

@ -6,13 +6,13 @@ import (
"net/http"
"strings"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/internal/chat_queue"
"github.com/number571/go-peer/cmd/hlm/internal/database"
"github.com/number571/go-peer/cmd/hlm/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/chat_queue"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/database"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
hls_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
)
func HandleIncomigHTTP(s state.IState) http.HandlerFunc {

View File

@ -3,7 +3,7 @@ package handler
import (
"net/http"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
)
func IndexPage(s state.IState) http.HandlerFunc {

View File

@ -4,8 +4,8 @@ import (
"html/template"
"net/http"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
)
func NotFoundPage(s state.IState) http.HandlerFunc {

View File

@ -7,7 +7,7 @@ import (
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
)
func QRPublicKeyPage(s state.IState) http.HandlerFunc {

View File

@ -7,8 +7,8 @@ import (
"strconv"
"strings"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
)
type sSettings struct {

View File

@ -9,8 +9,8 @@ import (
"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hlm/web"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
)
func SignInPage(s state.IState) http.HandlerFunc {

View File

@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
)
func SignOutPage(s state.IState) http.HandlerFunc {

View File

@ -7,12 +7,12 @@ import (
"net/http"
"strings"
"github.com/number571/go-peer/cmd/hlm/internal/app/state"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/internal/app/state"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/cmd/hlm/web"
hls_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/messenger/web"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
)
func SignUpPage(s state.IState) http.HandlerFunc {

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,5 +1,7 @@
hls
hls.stg
hls.cfg
hls.db
pub.key
priv.key
*.db_push1

View File

@ -4,12 +4,12 @@ import (
"flag"
"fmt"
"github.com/number571/go-peer/cmd/hls/internal/app"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/app"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/filesystem"
"github.com/number571/go-peer/pkg/types"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
)
func initApp() (types.IApp, error) {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
"github.com/number571/go-peer/pkg/filesystem"
)
@ -11,6 +11,7 @@ func initConfig() (config.IConfig, error) {
return config.LoadConfig(hls_settings.CPathCFG)
}
initCfg := &config.SConfig{
FLogging: []string{config.CLogInfo, config.CLogWarn, config.CLogErro},
FAddress: &config.SAddress{
FTCP: "localhost:9571",
FHTTP: "localhost:9572",

View File

@ -3,8 +3,11 @@ package main
import (
"os"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
hlt_client "github.com/number571/go-peer/cmd/hidden_lake/traffic/pkg/client"
"github.com/number571/go-peer/pkg/client/message"
"github.com/number571/go-peer/pkg/client/queue"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/friends"
@ -20,6 +23,40 @@ func initNode(cfg config.IConfig, privKey asymmetric.IPrivKey) anonymity.INode {
anonymity.NewSettings(&anonymity.SSettings{
FRetryEnqueue: hls_settings.CRetryEnqueue,
FTimeWait: hls_settings.CWaitTime,
FTraffic: anonymity.NewTraffic(
func() <-chan message.IMessage {
ch := make(chan message.IMessage, 300)
go func() {
defer close(ch)
for _, addr := range cfg.Traffic().Download() {
client := initTrafficClient(addr)
hashes, err := client.Hashes()
if err != nil {
// TODO: log
continue
}
for _, hash := range hashes {
msg, err := client.Load(hash)
if err != nil {
continue
}
ch <- msg
}
}
}()
return ch
},
func(msg message.IMessage) error {
for _, addr := range cfg.Traffic().Upload() {
client := initTrafficClient(addr)
if err := client.Push(msg); err != nil {
// TODO: log
continue
}
}
return nil
},
),
}),
// Insecure to use logging in real anonymity projects!
// Logging should only be used in overview or testing;
@ -36,7 +73,7 @@ func initNode(cfg config.IConfig, privKey asymmetric.IPrivKey) anonymity.INode {
FMaxConnects: hls_settings.CNetworkMaxConns,
FConnSettings: conn.NewSettings(&conn.SSettings{
FNetworkKey: cfg.Network(),
FMessageSize: hls_settings.CMessageSize,
FMessageSize: pkg_settings.CMessageSize,
FTimeWait: hls_settings.CNetworkWaitTime,
}),
}),
@ -59,13 +96,23 @@ func initNode(cfg config.IConfig, privKey asymmetric.IPrivKey) anonymity.INode {
)
}
func loggerSettings(enabled bool) logger.ISettings {
if !enabled {
return logger.NewSettings(&logger.SSettings{})
}
return logger.NewSettings(&logger.SSettings{
FInfo: os.Stdout,
FWarn: os.Stderr,
FErro: os.Stderr,
})
func initTrafficClient(addr string) hlt_client.IClient {
return hlt_client.NewClient(
hlt_client.NewBuilder(),
hlt_client.NewRequester(addr),
)
}
func loggerSettings(logging config.ILogging) logger.ISettings {
sett := &logger.SSettings{}
if logging.Info() {
sett.FInfo = os.Stdout
}
if logging.Warn() {
sett.FInfo = os.Stderr
}
if logging.Erro() {
sett.FInfo = os.Stderr
}
return logger.NewSettings(sett)
}

View File

@ -6,14 +6,14 @@ import (
"net/http"
"time"
"github.com/number571/go-peer/cmd/hls/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
"github.com/number571/go-peer/pkg/closer"
"github.com/number571/go-peer/pkg/network/anonymity"
"github.com/number571/go-peer/pkg/network/conn_keeper"
"github.com/number571/go-peer/pkg/types"
"github.com/number571/go-peer/cmd/hls/internal/handler"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/handler"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
)
const (
@ -48,8 +48,7 @@ func (app *sApp) Run() error {
res := make(chan error)
go func() {
httpAddress := app.fWrapper.Config().Address().HTTP()
if httpAddress == "" {
if app.fWrapper.Config().Address().HTTP() == "" {
return
}

View File

@ -5,11 +5,11 @@ import (
"os"
"testing"
"github.com/number571/go-peer/cmd/hls/internal/config"
"github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
testutils "github.com/number571/go-peer/test/_data"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
anon_testutils "github.com/number571/go-peer/test/_data/anonymity"
)

View File

@ -1,7 +1,7 @@
package app
import (
"github.com/number571/go-peer/cmd/hls/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
"github.com/number571/go-peer/pkg/network/anonymity"
"github.com/number571/go-peer/pkg/network/conn_keeper"
)

View File

@ -3,9 +3,9 @@ package app
import (
"net/http"
"github.com/number571/go-peer/cmd/hls/internal/config"
"github.com/number571/go-peer/cmd/hls/internal/handler"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/handler"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/network/anonymity"
)

View File

@ -4,32 +4,49 @@ import (
"fmt"
"sync"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/filesystem"
)
const (
CLogInfo = "info"
CLogWarn = "warn"
CLogErro = "erro"
)
var (
_ IConfig = &SConfig{}
_ iAddress = &SAddress{}
_ IAddress = &SAddress{}
_ ITraffic = &STraffic{}
_ ILogging = &sLogging{}
)
type SConfig struct {
FLogging bool `json:"logging,omitempty"`
FNetwork string `json:"network,omitempty"`
FAddress *SAddress `json:"address,omitempty"`
FServices map[string]string `json:"services,omitempty"`
FAddress *SAddress `json:"address,omitempty"`
FTraffic *STraffic `json:"traffic,omitempty"`
FLogging []string `json:"logging,omitempty"`
FConnections []string `json:"connections,omitempty"`
FServices map[string]string `json:"services,omitempty"`
FFriends map[string]string `json:"friends,omitempty"`
fFilepath string
fMutex sync.Mutex
fLogging *sLogging
fFriends map[string]asymmetric.IPubKey
}
type sLogging []bool
type STraffic struct {
FDownload []string `json:"download,omitempty"`
FUpload []string `json:"upload,omitempty"`
}
type SAddress struct {
FTCP string `json:"tcp,omitempty"`
FHTTP string `json:"http,omitempty"`
@ -46,11 +63,9 @@ func NewConfig(filepath string, cfg *SConfig) (IConfig, error) {
return nil, err
}
cfg.fFilepath = filepath
if err := cfg.loadPubKeys(); err != nil {
if err := cfg.initConfig(filepath); err != nil {
return nil, err
}
return cfg, nil
}
@ -71,14 +86,48 @@ func LoadConfig(filepath string) (IConfig, error) {
return nil, err
}
cfg.fFilepath = filepath
if err := cfg.loadPubKeys(); err != nil {
if err := cfg.initConfig(filepath); err != nil {
return nil, err
}
return cfg, nil
}
func (cfg *SConfig) initConfig(filepath string) error {
cfg.fFilepath = filepath
if err := cfg.loadPubKeys(); err != nil {
return err
}
if err := cfg.loadLogging(); err != nil {
return err
}
return nil
}
func (cfg *SConfig) loadLogging() error {
// [info, warn, erro]
logging := sLogging(make([]bool, 3))
mapping := map[string]int{
"info": 0,
"warn": 1,
"erro": 2,
}
for _, v := range cfg.FLogging {
logType, ok := mapping[v]
if !ok {
return fmt.Errorf("undefined log type '%s'", v)
}
logging[logType] = true
}
cfg.fLogging = &logging
return nil
}
func (cfg *SConfig) loadPubKeys() error {
cfg.fFriends = make(map[string]asymmetric.IPubKey)
@ -100,10 +149,6 @@ func (cfg *SConfig) loadPubKeys() error {
return nil
}
func (cfg *SConfig) Logging() bool {
return cfg.FLogging
}
func (cfg *SConfig) Network() string {
return cfg.FNetwork
}
@ -119,10 +164,18 @@ func (cfg *SConfig) Friends() map[string]asymmetric.IPubKey {
return result
}
func (cfg *SConfig) Address() iAddress {
func (cfg *SConfig) Logging() ILogging {
return cfg.fLogging
}
func (cfg *SConfig) Address() IAddress {
return cfg.FAddress
}
func (cfg *SConfig) Traffic() ITraffic {
return cfg.FTraffic
}
func (cfg *SConfig) Connections() []string {
return cfg.FConnections
}
@ -135,6 +188,32 @@ func (cfg *SConfig) Service(name string) (string, bool) {
return addr, ok
}
func (traffic *STraffic) Download() []string {
if traffic == nil {
return nil
}
return traffic.FDownload
}
func (traffic *STraffic) Upload() []string {
if traffic == nil {
return nil
}
return traffic.FUpload
}
func (logging *sLogging) Info() bool {
return (*logging)[0]
}
func (logging *sLogging) Warn() bool {
return (*logging)[1]
}
func (logging *sLogging) Erro() bool {
return (*logging)[2]
}
func (address *SAddress) TCP() string {
if address == nil {
return ""

View File

@ -16,6 +16,8 @@ const (
const (
tcLogging = true
tcNetwork = "test_network_key"
tcDownloader = "test_downloader"
tcUploader = "test_uploader"
tcAddressTCP = "test_address_tcp"
tcAddressHTTP = "test_address_http"
tcPubKeyAlias1 = "test_alias1"
@ -41,12 +43,22 @@ var (
const (
tcConfigTemplate = `{
"logging": %t,
"logging": ["info", "erro"],
"network": "%s",
"address": {
"tcp": "%s",
"http": "%s"
},
"traffic": {
"download": [
"%s",
"%s"
],
"upload": [
"%s",
"%s"
]
},
"connections": [
"%s",
"%s"
@ -65,12 +77,15 @@ const (
func testNewConfigString() string {
return fmt.Sprintf(
tcConfigTemplate,
tcLogging,
tcNetwork,
tcAddressTCP,
tcAddressHTTP,
tgConnects[0],
tgConnects[1],
tgConnects[0],
tgConnects[1],
tgConnects[0],
tgConnects[1],
tcPubKeyAlias1,
tgPubKeys[tcPubKeyAlias1],
tcPubKeyAlias2,
@ -93,27 +108,69 @@ func TestConfig(t *testing.T) {
cfg, err := LoadConfig(tcConfigFile)
if err != nil {
t.Error(err)
return
}
if cfg.Logging() != tcLogging {
t.Error("logging is invalid")
if cfg.Logging().Info() != tcLogging {
t.Error("logging.info is invalid")
return
}
if cfg.Logging().Erro() != tcLogging {
t.Error("logging.erro is invalid")
return
}
if cfg.Logging().Warn() == tcLogging {
t.Error("logging.warn is invalid")
return
}
if cfg.Network() != tcNetwork {
t.Error("network is invalid")
return
}
if cfg.Address().TCP() != tcAddressTCP {
t.Error("address_tcp is invalid")
return
}
if cfg.Address().HTTP() != tcAddressHTTP {
t.Error("address_http is invalid")
return
}
if len(cfg.Traffic().Download()) != 2 {
t.Error("len traffic download != 2")
return
}
for i, v := range cfg.Traffic().Download() {
if v != tgConnects[i] {
t.Errorf("traffic download '%d' is invalid", i)
return
}
}
if len(cfg.Traffic().Upload()) != 2 {
t.Error("len traffic upload != 2")
return
}
for i, v := range cfg.Traffic().Upload() {
if v != tgConnects[i] {
t.Errorf("traffic upload '%d' is invalid", i)
return
}
}
if len(cfg.Connections()) != 2 {
t.Error("len connections != 2")
return
}
for i, v := range cfg.Connections() {
if v != tgConnects[i] {
t.Errorf("connection '%d' is invalid", i)
return
}
}
@ -121,9 +178,11 @@ func TestConfig(t *testing.T) {
v1, ok := cfg.Service(k)
if !ok {
t.Errorf("service undefined '%s'", k)
return
}
if v != v1 {
t.Errorf("service address is invalid '%s'", v1)
return
}
}
@ -132,6 +191,7 @@ func TestConfig(t *testing.T) {
pubKey := asymmetric.LoadRSAPubKey(pubStr)
if pubKey.Address().String() != v1.Address().String() {
t.Errorf("public key is invalid '%s'", v1)
return
}
}
}
@ -143,6 +203,7 @@ func TestWrapper(t *testing.T) {
cfg, err := LoadConfig(tcConfigFile)
if err != nil {
t.Error(err)
return
}
if len(cfg.Friends()) == 0 {
@ -161,6 +222,7 @@ func TestWrapper(t *testing.T) {
cfg, err = LoadConfig(tcConfigFile)
if err != nil {
t.Error(err)
return
}
if len(cfg.Friends()) != 0 {

View File

@ -4,7 +4,7 @@ import (
"fmt"
"sync"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/filesystem"

View File

@ -15,15 +15,27 @@ type IEditor interface {
}
type IConfig interface {
Logging() bool
Network() string
Address() iAddress
Logging() ILogging
Address() IAddress
Traffic() ITraffic
Connections() []string
Friends() map[string]asymmetric.IPubKey
Service(string) (string, bool)
}
type iAddress interface {
type ITraffic interface {
Download() []string
Upload() []string
}
type ILogging interface {
Info() bool
Warn() bool
Erro() bool
}
type IAddress interface {
TCP() string
HTTP() string
}

View File

@ -5,8 +5,8 @@ import (
"net/http"
"strings"
"github.com/number571/go-peer/cmd/hls/internal/config"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/network/anonymity"
)

View File

@ -4,8 +4,8 @@ import (
"fmt"
"testing"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
testutils "github.com/number571/go-peer/test/_data"
)

View File

@ -6,8 +6,8 @@ import (
"net/http"
"strings"
"github.com/number571/go-peer/cmd/hls/internal/config"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/network/anonymity"
)

View File

@ -4,8 +4,8 @@ import (
"fmt"
"testing"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
testutils "github.com/number571/go-peer/test/_data"
)

View File

@ -5,9 +5,9 @@ import (
"os"
"time"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/closer"
"github.com/number571/go-peer/pkg/filesystem"
"github.com/number571/go-peer/pkg/network/anonymity"

View File

@ -3,8 +3,8 @@ package handler
import (
"net/http"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
)
func HandleIndexAPI() http.HandlerFunc {

View File

@ -6,7 +6,7 @@ import (
"sort"
"strings"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/network/anonymity"
)

View File

@ -6,9 +6,9 @@ import (
"testing"
"time"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/pkg/closer"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/network/anonymity"

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
"net/http"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/network/anonymity"

View File

@ -7,10 +7,10 @@ import (
"testing"
"time"
"github.com/number571/go-peer/cmd/hls/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hls/pkg/request"
"github.com/number571/go-peer/cmd/hidden_lake/service/internal/config"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
hls_client "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/pkg/request"
"github.com/number571/go-peer/pkg/closer"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/network/anonymity"

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
"net/http"
hls_settings "github.com/number571/go-peer/cmd/hls/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hls/pkg/settings"
hls_settings "github.com/number571/go-peer/cmd/hidden_lake/service/internal/settings"
pkg_settings "github.com/number571/go-peer/cmd/hidden_lake/service/pkg/settings"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
"github.com/number571/go-peer/pkg/network/anonymity"
)

View File

@ -4,7 +4,7 @@ import (
"fmt"
"testing"
"github.com/number571/go-peer/cmd/hls/pkg/client"
"github.com/number571/go-peer/cmd/hidden_lake/service/pkg/client"
"github.com/number571/go-peer/pkg/crypto/asymmetric"
testutils "github.com/number571/go-peer/test/_data"
)

Some files were not shown because too many files have changed in this diff Show More