-
Notifications
You must be signed in to change notification settings - Fork 20.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
whisperv5: integrate whisper and implement API #14540
Conversation
65aa33d
to
7f00d42
Compare
9371b12
to
86dfaa8
Compare
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5276ad1
to
9625710
Compare
w.statsMu.Lock() | ||
defer w.statsMu.Unlock() | ||
|
||
return w.stats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The locking here seems unnecessary, you"re returning the w.stats
object, so if the caller does modifications on it, these locks won"t prevent that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w.stats
is returned by value which makes a copy.
Last commit removed commented out code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs minor code changes.
whisper/whisperv5/client.go
Outdated
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package whisperv5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client should be in its own package, "whisper/shhclient" to remove the rpc dependency from whisper core.
whisper/whisperv5/config.go
Outdated
} | ||
|
||
Flags = []cli.Flag{WhisperEnabledFlag, MaxMessageSizeFlag, MinPOWFlag} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don"t like adding CLI flags to library packages. We have some in internal/debug, but it should usually be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can put them into "whisper/shhapi" for now.
@@ -62,7 +62,7 @@ func (e *Envelope) rlpWithoutNonce() []byte { | |||
|
|||
// NewEnvelope wraps a Whisper message with expiration and destination data | |||
// included into an envelope for network forwarding. | |||
func NewEnvelope(ttl uint32, topic TopicType, aesNonce []byte, msg *SentMessage) *Envelope { | |||
func NewEnvelope(ttl uint32, topic TopicType, aesNonce []byte, msg *sentMessage) *Envelope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sentMessage private means that no code outside package whisperv5 can call NewEnvelope. Not sure if that"s good or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still create a sent message with whisperv5.NewSentMessage
.
whisper/whisperv5/config.go
Outdated
"gopkg.in/urfave/cli.v1" | ||
) | ||
|
||
//go:generate gencodec -type Config -formats toml -out gen_config.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to use gencodec because none of its features (required fields, field type override, etc.) are used. Please remove the generated file and this line.
whisper/whisperv5/api_test.go
Outdated
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete the file if these tests are no longer meaningful.
whisper/whisperv5/whisper.go
Outdated
|
||
mailServer MailServer // MailServer interface | ||
} | ||
|
||
// New creates a Whisper client ready to communicate through the Ethereum P2P network. | ||
func New() *Whisper { | ||
func New(cfg *Config) *Whisper { | ||
whisper := &Whisper{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
if cfg == nil {
cfg = DefaultConfig
}
whisper/whisperv5/whisper.go
Outdated
} | ||
m2[idx] = val | ||
s.vault.Store(m2) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don"t get this type. Please explain. It smells like overengineering.
If you really need a fast concurrent map, use golang.org/x/sync/syncmap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the api it is possible to change several settings at runtime. This requires locks to prevent simultaneous updates and reads. I have replace the custom map with the syncmap as suggested.
whisper/whisperv5/topic.go
Outdated
} | ||
*t = BytesToTopic(b) | ||
*t = BytesToTopic(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use hexutil.UnmarshalFixedText here.
whisper/whisperv5/api.go
Outdated
InvalidPublicKeyErr = errors.New("invalid public key") | ||
InvalidSigningPubKey = errors.New("invalid signing public key") | ||
TooLowPoWErr = errors.New("message rejected, PoW too low") | ||
NoTopicsErr = errors.New("missing topic(s)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error variables should be named ErrXXX
.
General feedback about the API: There are lots of key management methods. These can be hard to use correctly. IMHO we should use the normal keystore for asymmetric keys and push responsibility to generate and manage symmetric keys to the user of the API. |
Moving from the current key management to a "normal" keystore should be something that is done in a different PR. This one is already getting huge. @gluk256 ping. |
Please, let us keep focus on the current task. This PR has one very specific purpose: make the v5 working again. Refactoring could be done only after we will be able to build the project and call all the functions. |
@fjl If you want, we can discuss the key management later, and refactor if necessity arise. But as long as whisper remains broken, we should concentrate on fixing it ASAP. |
Some small fixes necessary after testing:
|
Renamed
The only possible return value of
I expect that you use an invalid field name but an example script would help. Here is an example with symmetric keys that uses filters. |
The last 2 errors were a problem on my side. From what i tested it looks like working. 👍 |
Once this is merged, we can add it to the geth console internally: web3/web3.js#902 |
Those files can be used: Please include them and test the API and basic functions inside the console. |
cmd/geth/usage.go
Outdated
@@ -188,17 +188,18 @@ var AppHelpFlagGroups = []flagGroup{ | |||
}, debug.Flags...), | |||
}, | |||
{ | |||
Name: "Whisper (EXPERIMENTAL)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make "Whisper" all uppercase. That"s how everything else is.
This PR holds several things:
geth --shh.maxmessagesize <...>
would enable whisper.implements the whisper v5 API.
adds the
whisper/whisperv5/client
package. This client works in a similar way as theethclient
package and can be used to build whisper go DApp"s.