@@ -49,12 +49,14 @@ type Statistics struct {
4949}
5050
5151const (
52- maxMsgSizeIdx = iota // Maximal message length allowed by the whisper node
53- overflowIdx // Indicator of message queue overflow
54- minPowIdx // Minimal PoW required by the whisper node
55- minPowToleranceIdx // Minimal PoW tolerated by the whisper node for a limited time
56- bloomFilterIdx // Bloom filter for topics of interest for this node
57- bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time
52+ maxMsgSizeIdx = iota // Maximal message length allowed by the whisper node
53+ overflowIdx // Indicator of message queue overflow
54+ minPowIdx // Minimal PoW required by the whisper node
55+ minPowToleranceIdx // Minimal PoW tolerated by the whisper node for a limited time
56+ bloomFilterIdx // Bloom filter for topics of interest for this node
57+ bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time
58+ lightClientModeIdx // Light client mode. (does not forward any messages)
59+ restrictConnectionBetweenLightClientsIdx // Restrict connection between two light clients
5860)
5961
6062// Whisper represents a dark communication interface through the Ethereum
@@ -82,8 +84,6 @@ type Whisper struct {
8284
8385 syncAllowance int // maximum time in seconds allowed to process the whisper-related messages
8486
85- lightClient bool // indicates is this node is pure light client (does not forward any messages)
86-
8787 statsMu sync.Mutex // guard stats
8888 stats Statistics // Statistics of whisper node
8989
@@ -113,6 +113,7 @@ func New(cfg *Config) *Whisper {
113113 whisper .settings .Store (minPowIdx , cfg .MinimumAcceptedPOW )
114114 whisper .settings .Store (maxMsgSizeIdx , cfg .MaxMessageSize )
115115 whisper .settings .Store (overflowIdx , false )
116+ whisper .settings .Store (restrictConnectionBetweenLightClientsIdx , cfg .RestrictConnectionBetweenLightClients )
116117
117118 // p2p whisper sub protocol handler
118119 whisper .protocol = p2p.Protocol {
@@ -276,6 +277,31 @@ func (whisper *Whisper) SetMinimumPowTest(val float64) {
276277 whisper .settings .Store (minPowToleranceIdx , val )
277278}
278279
280+ //SetLightClientMode makes node light client (does not forward any messages)
281+ func (whisper * Whisper ) SetLightClientMode (v bool ) {
282+ whisper .settings .Store (lightClientModeIdx , v )
283+ }
284+
285+ //LightClientMode indicates is this node is light client (does not forward any messages)
286+ func (whisper * Whisper ) LightClientMode () bool {
287+ val , exist := whisper .settings .Load (lightClientModeIdx )
288+ if ! exist || val == nil {
289+ return false
290+ }
291+ v , ok := val .(bool )
292+ return v && ok
293+ }
294+
295+ //LightClientModeConnectionRestricted indicates that connection to light client in light client mode not allowed
296+ func (whisper * Whisper ) LightClientModeConnectionRestricted () bool {
297+ val , exist := whisper .settings .Load (restrictConnectionBetweenLightClientsIdx )
298+ if ! exist || val == nil {
299+ return false
300+ }
301+ v , ok := val .(bool )
302+ return v && ok
303+ }
304+
279305func (whisper * Whisper ) notifyPeersAboutPowRequirementChange (pow float64 ) {
280306 arr := whisper .getPeers ()
281307 for _ , p := range arr {
@@ -672,7 +698,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
672698
673699 trouble := false
674700 for _ , env := range envelopes {
675- cached , err := whisper .add (env , whisper .lightClient )
701+ cached , err := whisper .add (env , whisper .LightClientMode () )
676702 if err != nil {
677703 trouble = true
678704 log .Error ("bad envelope received, peer will be disconnected" , "peer" , p .peer .ID (), "err" , err )
0 commit comments