parent
a339d7ed33
commit
6173d3ee06
25
node/node.go
25
node/node.go
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
@ -194,22 +195,27 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
|
|||
logger.Info("SHH protocol is disabled")
|
||||
return nil
|
||||
}
|
||||
if config.WhisperConfig.EnableNTPSync {
|
||||
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) {
|
||||
return timesource.Default(), nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||
var timeSource *timesource.NTPTimeSource
|
||||
if err := ctx.Service(&timeSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
whisperServiceConfig := &whisper.Config{
|
||||
MaxMessageSize: whisper.DefaultMaxMessageSize,
|
||||
MinimumAcceptedPOW: 0.001,
|
||||
TimeSource: timeSource.Now,
|
||||
TimeSource: time.Now,
|
||||
}
|
||||
|
||||
if config.WhisperConfig.EnableNTPSync {
|
||||
if whisperServiceConfig.TimeSource, err = whisperTimeSource(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
whisperService := whisper.New(whisperServiceConfig)
|
||||
|
||||
// enable metrics
|
||||
|
@ -296,3 +302,12 @@ func parseNodesV5(enodes []string) []*discv5.Node {
|
|||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// whisperTimeSource get timeSource to be used by whisper
|
||||
func whisperTimeSource(ctx *node.ServiceContext) (func() time.Time, error) {
|
||||
var timeSource *timesource.NTPTimeSource
|
||||
if err := ctx.Service(&timeSource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return timeSource.Now, nil
|
||||
}
|
||||
|
|
|
@ -116,6 +116,9 @@ type WhisperConfig struct {
|
|||
|
||||
// FirebaseConfig extra configuration for Firebase Cloud Messaging
|
||||
FirebaseConfig *FirebaseConfig `json:"FirebaseConfig,"`
|
||||
|
||||
// EnableNTPSync enables NTP synchronizations
|
||||
EnableNTPSync bool
|
||||
}
|
||||
|
||||
// ReadPasswordFile reads and returns content of the password file
|
||||
|
@ -353,6 +356,7 @@ func NewNodeConfig(dataDir string, clstrCfgFile string, networkID uint64) (*Node
|
|||
FirebaseConfig: &FirebaseConfig{
|
||||
NotificationTriggerURL: FirebaseNotificationTriggerURL,
|
||||
},
|
||||
EnableNTPSync: true,
|
||||
},
|
||||
SwarmConfig: &SwarmConfig{},
|
||||
RegisterTopics: []discv5.Topic{},
|
||||
|
|
|
@ -255,6 +255,8 @@ func MakeTestNodeConfig(networkID int) (*params.NodeConfig, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodeConfig.WhisperConfig.EnableNTPSync = false
|
||||
|
||||
return nodeConfig, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue