mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
whisper: test function introduced
This commit is contained in:
parent
04353a80f3
commit
f78a54c6d9
4 changed files with 31 additions and 21 deletions
|
|
@ -118,7 +118,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32)
|
||||||
|
|
||||||
// SetMinPow sets the minimum PoW for a message before it is accepted.
|
// SetMinPow sets the minimum PoW for a message before it is accepted.
|
||||||
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
|
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
|
||||||
return true, api.w.SetMinimumPoW(pow, false)
|
return true, api.w.SetMinimumPoW(pow)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkTrustedPeer marks a peer trusted. , which will allow it to send historic (expired) messages.
|
// MarkTrustedPeer marks a peer trusted. , which will allow it to send historic (expired) messages.
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ func initialize(t *testing.T) {
|
||||||
for i := 0; i < NumNodes; i++ {
|
for i := 0; i < NumNodes; i++ {
|
||||||
var node TestNode
|
var node TestNode
|
||||||
node.shh = New(&DefaultConfig)
|
node.shh = New(&DefaultConfig)
|
||||||
node.shh.SetMinimumPoW(0.00000001, true)
|
node.shh.SetMinimumPowTest(0.00000001)
|
||||||
node.shh.Start(nil)
|
node.shh.Start(nil)
|
||||||
topics := make([]TopicType, 0)
|
topics := make([]TopicType, 0)
|
||||||
topics = append(topics, sharedTopic)
|
topics = append(topics, sharedTopic)
|
||||||
|
|
@ -342,7 +342,7 @@ func powReqExchange(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pow float64 = 7777777.0
|
const pow float64 = 7777777.0
|
||||||
nodes[0].shh.SetMinimumPoW(pow, true)
|
nodes[0].shh.SetMinimumPoW(pow)
|
||||||
|
|
||||||
// wait until all the messages are delivered
|
// wait until all the messages are delivered
|
||||||
time.Sleep(64 * time.Millisecond)
|
time.Sleep(64 * time.Millisecond)
|
||||||
|
|
|
||||||
|
|
@ -181,30 +181,40 @@ func (w *Whisper) SetMaxMessageSize(size uint32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMinimumPoW sets the minimal PoW required by this node
|
// SetMinimumPoW sets the minimal PoW required by this node
|
||||||
func (w *Whisper) SetMinimumPoW(val float64, testMode bool) error {
|
func (w *Whisper) SetMinimumPoW(val float64) error {
|
||||||
if val <= 0.0 {
|
if val < 0.0 {
|
||||||
return fmt.Errorf("invalid PoW: %f", val)
|
return fmt.Errorf("invalid PoW: %f", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.notifyPeersAboutPowRequirementChange(val)
|
w.notifyPeersAboutPowRequirementChange(val)
|
||||||
|
|
||||||
if testMode {
|
go func() {
|
||||||
|
// allow some time before all the peers have processed the notification
|
||||||
|
time.Sleep(time.Duration(w.reactionAllowance) * time.Second)
|
||||||
w.settings.Store(minPowIdx, val)
|
w.settings.Store(minPowIdx, val)
|
||||||
} else {
|
}()
|
||||||
go func() {
|
|
||||||
// allow some time before all the peers have processed the notification
|
|
||||||
time.Sleep(time.Duration(w.reactionAllowance) * time.Second)
|
|
||||||
w.settings.Store(minPowIdx, val)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMinimumPoW sets the minimal PoW in test environment
|
||||||
|
func (w *Whisper) SetMinimumPowTest(val float64) {
|
||||||
|
w.notifyPeersAboutPowRequirementChange(val)
|
||||||
|
w.settings.Store(minPowIdx, val)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Whisper) notifyPeersAboutPowRequirementChange(pow float64) {
|
func (w *Whisper) notifyPeersAboutPowRequirementChange(pow float64) {
|
||||||
|
arr := make([]*Peer, len(w.peers))
|
||||||
|
i := 0
|
||||||
|
|
||||||
w.peerMu.Lock()
|
w.peerMu.Lock()
|
||||||
defer w.peerMu.Unlock()
|
|
||||||
for p := range w.peers {
|
for p := range w.peers {
|
||||||
|
arr[i] = p
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
w.peerMu.Unlock()
|
||||||
|
|
||||||
|
for _, p := range arr {
|
||||||
err := p.notifyAboutPowRequirementChange(pow)
|
err := p.notifyAboutPowRequirementChange(pow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// allow one retry
|
// allow one retry
|
||||||
|
|
|
||||||
|
|
@ -472,8 +472,8 @@ func TestExpiry(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
w.SetMinimumPoW(0.0000001, true)
|
w.SetMinimumPowTest(0.0000001)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
defer w.SetMinimumPowTest(DefaultMinimumPoW)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
||||||
|
|
@ -529,7 +529,7 @@ func TestCustomization(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
defer w.SetMinimumPowTest(DefaultMinimumPoW)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -563,7 +563,7 @@ func TestCustomization(t *testing.T) {
|
||||||
t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed)
|
t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.SetMinimumPoW(smallPoW/2, true)
|
w.SetMinimumPowTest(smallPoW / 2)
|
||||||
err = w.Send(env)
|
err = w.Send(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
|
t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
|
||||||
|
|
@ -625,7 +625,7 @@ func TestSymmetricSendCycle(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
defer w.SetMinimumPowTest(DefaultMinimumPoW)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -714,7 +714,7 @@ func TestSymmetricSendWithoutAKey(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
defer w.SetMinimumPowTest(DefaultMinimumPoW)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -782,7 +782,7 @@ func TestSymmetricSendKeyMismatch(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
defer w.SetMinimumPowTest(DefaultMinimumPoW)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue