mirror of
https://github.com/status-im/whisper.git
synced 2025-01-20 07:39:00 +00:00
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:
parent
4fae75da94
commit
f55e777bd6
@ -513,6 +513,17 @@ func (whisper *Whisper) SendP2PDirect(peer *Peer, envelopes ...*Envelope) error
|
|||||||
return p2p.Send(peer.ws, p2pMessageCode, envelopes)
|
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
|
// 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.
|
// it into the known identities for message decryption. Returns ID of the new key pair.
|
||||||
func (whisper *Whisper) NewKeyPair() (string, error) {
|
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)
|
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)
|
whisper.mailServer.Archive(envelope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user