Add mailservers to transport object

This commit is contained in:
Dmitry 2019-06-19 08:49:39 +03:00 committed by Dmitry Shulyak
parent 59b95d5420
commit f881f1d81f
2 changed files with 29 additions and 6 deletions

View File

@ -10,8 +10,8 @@ import (
"github.com/pkg/errors"
"github.com/ethereum/go-ethereum/p2p"
gethnode "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/status-im/status-go/services/shhext"
whisper "github.com/status-im/whisper/whisperv6"
@ -19,6 +19,11 @@ import (
"github.com/status-im/status-console-client/protocol/subscription"
)
var (
// ErrNoMailservers returned if there is no configured mailservers that can be used.
ErrNoMailservers = errors.New("no configured mailservers")
)
type WhisperServiceKeysManager struct {
shh *whisper.Whisper
@ -89,6 +94,7 @@ func NewWhisperServiceTransport(
return &WhisperServiceTransport{
node: node,
shh: shh,
mailservers: mailservers,
shhextAPI: shhext.NewPublicAPI(shhextService),
keysManager: &WhisperServiceKeysManager{
shh: shh,
@ -184,6 +190,9 @@ func (a *WhisperServiceTransport) selectAndAddMailServer() (string, error) {
if a.selectedMailServerEnode != "" {
return a.selectedMailServerEnode, nil
}
if len(a.mailservers) == 0 {
return "", ErrNoMailservers
}
enode := randomItem(a.mailservers)
errCh := waitForPeerAsync(

View File

@ -0,0 +1,14 @@
package transport
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSelectAndAddNoMailservers(t *testing.T) {
svc := &WhisperServiceTransport{}
rst, err := svc.selectAndAddMailServer()
require.Empty(t, rst)
require.EqualError(t, ErrNoMailservers, err.Error())
}