Skip to content

Commit

Permalink
Merge branch 'develop' into patch-181
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Dec 5, 2023
2 parents bbf801f + 090a158 commit 706571c
Show file tree
Hide file tree
Showing 59 changed files with 2,400 additions and 3,235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest", "macOS-latest"]
go: ["1.17.x", "1.18.x", "1.19.x", "1.20.x"]
go: ["1.19.x", "1.20.x"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ site

# Test binary, built with `go test -c`
*.test
testdata

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand All @@ -27,6 +28,6 @@ testdb
data/

# docker genesis documents
testnet/conf/node*/config/genesis.json
testnet/local/conf/node*/config/genesis.json

plugin/ops/__pycache__
plugin/ops/__pycache__
4 changes: 4 additions & 0 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ default: lint test

.PHONY: lint
lint:
# cd ../tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint
# $(GOPATH)/bin/golangci-lint run -e gosec ./... --timeout=2m
# cd ../ test && go install honnef.co/go/tools/cmd/[email protected]
# $(GOPATH)/bin/staticcheck ./...
go vet ./...
go fmt ./...
go mod tidy
Expand Down
17 changes: 17 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ docker run --rm \
-w /client \
golang:buster \
/bin/bash -c "GORACE=history_size=7 go test -race"
## or to run fuzzing use below command
# go test -fuzz ./...
```

The above can be de-constructed as follows:
Expand All @@ -24,3 +26,18 @@ The above can be de-constructed as follows:
- `-w /client`: Working directory for the docker image
- `golang:buster`: The docker image to be used
- `/bin/bash -c "GORACE=history_size=7 go test -race"`: The command to run inside the container


### Fuzzing test

To run fuzzing test
```
go test -fuzz=<Test Name here>
```

example: `go test -fuzz=FuzzQueuePushSerial`

- Tests
- FuzzQueue
- FuzzQueuePushSerial
- FuzzQueuePushParalell
2 changes: 1 addition & 1 deletion client/client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ChainID = "test-chain-QvpdAC"
PrimaryAddress = "tcp://127.0.0.1:26657"
WitnessesAddresses = ["tcp://127.0.0.1:26657"]
DatabaseName = "test_meson_server_pkiclient_db"
DatabaseName = "test_meson_server_pkiclient"
DatabaseDir = "/tmp/meson_server/server_data"
RPCAddress = "tcp://127.0.0.1:26657"

Expand Down
6 changes: 3 additions & 3 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ func (tcCfg *Katzenmint) validate() error {
return err
}
if tcCfg.PrimaryAddress == "" {
return errors.New("Primary address is missing")
return errors.New("primary address is missing")
}
if tcCfg.DatabaseName == "" || tcCfg.DatabaseDir == "" {
return errors.New("Database name or directory is missing")
return errors.New("database name or directory is missing")
}
if tcCfg.RPCAddress == "" {
return errors.New("RPC address is missing")
return errors.New("rpc address is missing")
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion client/minclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type ClientConfig struct {
// an error will be treated as a signal to tear down the connection.
OnACKFn func(*[constants.SURBIDLength]byte, []byte) error

// OnDocumentFn is the callback function taht will be called when a
// OnDocumentFn is the callback function that will be called when a
// new directory document is retreived for the current epoch.
OnDocumentFn func(*cpki.Document)

Expand Down
4 changes: 2 additions & 2 deletions client/minclient/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (p *pki) currentDocument() *cpki.Document {
p.log.Debugf("Couldn't find epoch: %+v", err)
return nil
}
for i := 0; i < katzenmint.LifeCycle; i++ {
if d, _ := p.docs.Load(now - uint64(i)); d != nil {
for i := uint64(0); i < katzenmint.LifeCycle; i++ {
if d, _ := p.docs.Load(now - i); d != nil {
return d.(*cpki.Document)
}
}
Expand Down
8 changes: 3 additions & 5 deletions client/pkiclient/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ import (
)

var (
errNotSupported = errors.New("pkiclient: operation not supported")
errHalted = errors.New("pkiclient: client was halted")
errHalted = errors.New("pkiclient: client was halted")

fetchBacklog = 8
lruMaxSize = 8
epochRetrieveInterval = 3 * time.Second
fetchBacklog = 8
lruMaxSize = 8
)

type cacheEntry struct {
Expand Down
4 changes: 1 addition & 3 deletions client/pkiclient/katzenmint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"math"

dbm "github.com/cometbft/cometbft-db"
costypes "github.com/cosmos/cosmos-sdk/store/types"
kpki "github.com/hashcloak/Meson/katzenmint"
"github.com/hashcloak/Meson/katzenmint/s11n"
Expand All @@ -22,7 +23,6 @@ import (
rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/http"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
dbm "github.com/tendermint/tm-db"
"gopkg.in/op/go-logging.v1"
)

Expand Down Expand Up @@ -87,8 +87,6 @@ func (p *PKIClient) query(ctx context.Context, epoch uint64, command kpki.Comman

// GetEpoch returns the epoch information of PKI.
func (p *PKIClient) GetEpoch(ctx context.Context) (epoch uint64, ellapsedHeight uint64, err error) {
p.log.Debugf("Query epoch")

resp, err := p.query(ctx, 0, kpki.GetEpoch)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion client/pkiclient/katzenmint_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/stretchr/testify/require"

dbm "github.com/cosmos/cosmos-db"
dbm "github.com/cometbft/cometbft-db"
log "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/light"
"github.com/tendermint/tendermint/light/provider/http"
Expand Down
4 changes: 2 additions & 2 deletions client/pkiclient/katzenmint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

// ics23 "github.com/confio/ics23/go"
"github.com/cosmos/iavl"

ics23 "github.com/confio/ics23/go"
dbm "github.com/cosmos/cosmos-db"
costypes "github.com/cosmos/cosmos-sdk/store/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
Expand All @@ -33,6 +31,8 @@ import (
rpcmock "github.com/tendermint/tendermint/rpc/client/mocks"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"

dbm "github.com/cometbft/cometbft-db"
)

var (
Expand Down
67 changes: 66 additions & 1 deletion client/queue_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package client

import (
"testing"
"sync"

"github.com/katzenpost/client/constants"
"github.com/stretchr/testify/assert"
"testing"
)

type foo struct {
Expand Down Expand Up @@ -39,3 +41,66 @@ func TestQueue(t *testing.T) {
_, err = q.Pop()
assert.Error(err)
}

func FuzzQueue(f *testing.F) {
f.Fuzz(func(t *testing.T, _, s string) {
q := new(Queue)
t.Log("Pushing", s)
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
item, err := q.Pop()
if err != nil {
t.Errorf("Pop %v %v %v", s, item, err)
}
})
}

func FuzzQueuePushSerial(f *testing.F) {
f.Fuzz(func(t *testing.T, i int, s string) {
q := new(Queue)
if i > constants.MaxEgressQueueSize {
return
}
for j := 0; j < i; j++ {
t.Log("Pushing", s)
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
}
})
}

func FuzzQueuePushParalell(f *testing.F) {
f.Add(1, "abcde")
f.Add(1, "")
f.Add(1, string([]byte{0x00}))
f.Fuzz(func(t *testing.T, i int, s string) {
q := new(Queue)
if i > constants.MaxEgressQueueSize {
return
}
if i < 0 {
return
}
t.Logf("Pushing '%v' for %v times", s, i)
var wg sync.WaitGroup
for j := 0; j < i; j++ {
t.Log("Pushing", s)
wg.Add(1)
go func(wg *sync.WaitGroup, s string, q *Queue, t *testing.T) {
defer wg.Done()
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
}(&wg, s, q, t)
}
wg.Wait()
if q.len != i {
t.Errorf("Expected len: %v, actual %v", i, q.len)
}
})
}
4 changes: 4 additions & 0 deletions genconfig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ default: lint test
# Exclude S1034: assigning the result of this type assertion to a variable (switch cfg := cfg.(type)) could eliminate type assertions in switch cases
.PHONY: lint
lint:
# cd ../tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint
# $(GOPATH)/bin/golangci-lint run -e gosec ./... --timeout=2m
# cd ../ test && go install honnef.co/go/tools/cmd/[email protected]
# $(GOPATH)/bin/staticcheck ./...
go vet ./...
go fmt ./...
go mod tidy
Expand Down
23 changes: 11 additions & 12 deletions genconfig/cmd/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type katzenpost struct {
currency int
mainnet bool

authIdentity *eddsa.PrivateKey
authPubIdentity string

nodeConfigs []*sConfig.Config
Expand Down Expand Up @@ -627,9 +626,9 @@ func configName(cfg interface{}) string {
}

func identifier(cfg interface{}) string {
switch cfg.(type) {
switch cfg := cfg.(type) {
case *sConfig.Config:
return cfg.(*sConfig.Config).Server.Identifier
return cfg.Server.Identifier
default:
log.Fatalf("identifier() passed unexpected type")
return ""
Expand All @@ -654,12 +653,12 @@ func saveCfg(outputDir string, cfg interface{}) error {
}

// links between mix and providers
func (s *katzenpost) spk(a *sConfig.Config) *eddsa.PublicKey {
priv := filepath.Join(s.outputDir, a.Server.Identifier, "identity.private.pem")
public := filepath.Join(s.outputDir, a.Server.Identifier, "identity.public.pem")
idKey, err := eddsa.Load(priv, public, rand.Reader)
if err != nil {
panic(err)
}
return idKey.PublicKey()
}
// func (s *katzenpost) spk(a *sConfig.Config) *eddsa.PublicKey {
// priv := filepath.Join(s.outputDir, a.Server.Identifier, "identity.private.pem")
// public := filepath.Join(s.outputDir, a.Server.Identifier, "identity.public.pem")
// idKey, err := eddsa.Load(priv, public, rand.Reader)
// if err != nil {
// panic(err)
// }
// return idKey.PublicKey()
// }
Loading

0 comments on commit 706571c

Please sign in to comment.