Add SendRawP2PDirect

Adds a function to send RawValue envelopes. This is needed as a
performance optimization, as currently most of the processing time is
spent decoding envelopes and coding them back when sending them.
This will allow us to skip this unnecessary step.
This commit is contained in:
Andrea Maria Piana 2019-05-06 12:32:09 +02:00
parent 4fae75da94
commit f55e777bd6
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424

View File

@ -513,6 +513,17 @@ func (whisper *Whisper) SendP2PDirect(peer *Peer, envelopes ...*Envelope) error
return p2p.Send(peer.ws, p2pMessageCode, envelopes)
}
// SendRawP2PDirect sends a peer-to-peer message to a specific peer.
// If only a single envelope is given, data is sent as a single object
// rather than a slice. This is important to keep this method backward compatible
// as it used to send only single envelopes.
func (whisper *Whisper) SendRawP2PDirect(peer *Peer, envelopes ...rlp.RawValue) error {
if len(envelopes) == 1 {
return p2p.Send(peer.ws, p2pMessageCode, envelopes[0])
}
return p2p.Send(peer.ws, p2pMessageCode, envelopes)
}
// NewKeyPair generates a new cryptographic identity for the client, and injects
// it into the known identities for message decryption. Returns ID of the new key pair.
func (whisper *Whisper) NewKeyPair() (string, error) {
@ -1062,7 +1073,12 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Info("received sync response", "count", len(resp.Envelopes), "final", resp.Final, "err", resp.Error, "cursor", resp.Cursor)
for _, envelope := range resp.Envelopes {
for _, rawEnvelope := range resp.Envelopes {
var envelope *Envelope
if err := rlp.DecodeBytes(rawEnvelope, &envelope); err != nil {
return errors.New("invalid envelopes")
}
whisper.mailServer.Archive(envelope)
}