fix: lint

This commit is contained in:
Richard Ramos 2022-10-20 09:19:23 -04:00 committed by RichΛrd
parent 97973e3226
commit e393b68ab7
4 changed files with 14 additions and 7 deletions

View File

@ -61,7 +61,7 @@ vendor:
lint-install:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
bash -s -- -b $(shell ${GOBIN} env GOPATH)/bin v1.46.2
bash -s -- -b $(shell ${GOBIN} env GOPATH)/bin v1.50.0
lint:
@echo "lint"

View File

@ -23,6 +23,7 @@ type PrivateService struct {
log *zap.Logger
messages map[string][]*pb.WakuMessage
cacheCapacity int
messagesMutex sync.RWMutex
runner *runnerService
@ -57,11 +58,12 @@ type AsymmetricMessagesArgs struct {
PrivateKey string `json:"privateKey"`
}
func NewPrivateService(node *node.WakuNode, log *zap.Logger) *PrivateService {
func NewPrivateService(node *node.WakuNode, cacheCapacity int, log *zap.Logger) *PrivateService {
p := &PrivateService{
node: node,
messages: make(map[string][]*pb.WakuMessage),
log: log.Named("private"),
node: node,
cacheCapacity: cacheCapacity,
messages: make(map[string][]*pb.WakuMessage),
log: log.Named("private"),
}
p.runner = newRunnerService(node.Broadcaster(), p.addEnvelope)
@ -75,6 +77,11 @@ func (p *PrivateService) addEnvelope(envelope *protocol.Envelope) {
p.messages[envelope.PubsubTopic()] = make([]*pb.WakuMessage, 0)
}
// Keep a specific max number of messages per topic
if len(p.messages[envelope.PubsubTopic()]) >= p.cacheCapacity {
p.messages[envelope.PubsubTopic()] = p.messages[envelope.PubsubTopic()][1:]
}
p.messages[envelope.PubsubTopic()] = append(p.messages[envelope.PubsubTopic()], envelope.Message())
}

View File

@ -18,7 +18,7 @@ func makePrivateService(t *testing.T) *PrivateService {
err = n.Start()
require.NoError(t, err)
return NewPrivateService(n, utils.Logger())
return NewPrivateService(n, 30, utils.Logger())
}
func TestGetV1SymmetricKey(t *testing.T) {

View File

@ -72,7 +72,7 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, enableAdmin bool,
}
if enablePrivate {
privateService := NewPrivateService(node, log)
privateService := NewPrivateService(node, cacheCapacity, log)
err = s.RegisterService(privateService, "Private")
if err != nil {
wrpc.log.Error("registering private service", zap.Error(err))