From f62a6add56188bede75b06c219b9e0e4f79af6e3 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 6 May 2019 14:33:58 +0200 Subject: [PATCH] Use rawsyncresponse --- whisperv6/doc.go | 9 +++++++++ whisperv6/whisper.go | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/whisperv6/doc.go b/whisperv6/doc.go index 75b7157..97733ed 100644 --- a/whisperv6/doc.go +++ b/whisperv6/doc.go @@ -142,6 +142,15 @@ type SyncResponse struct { Error string } +// RawSyncResponse is a struct representing a response sent to the peer +// asking for syncing archived envelopes. +type RawSyncResponse struct { + Envelopes []rlp.RawValue + Cursor []byte + Final bool // if true it means all envelopes were processed + Error string +} + // MessagesResponse sent as a response after processing batch of envelopes. type MessagesResponse struct { // Hash is a hash of all envelopes sent in the single batch. diff --git a/whisperv6/whisper.go b/whisperv6/whisper.go index 747611c..5edc3c8 100644 --- a/whisperv6/whisper.go +++ b/whisperv6/whisper.go @@ -493,6 +493,11 @@ func (whisper *Whisper) SendSyncResponse(p *Peer, data SyncResponse) error { return p2p.Send(p.ws, p2pSyncResponseCode, data) } +// SendRawSyncResponse sends a response to a Mail Server with a slice of envelopes. +func (whisper *Whisper) SendRawSyncResponse(p *Peer, data RawSyncResponse) error { + return p2p.Send(p.ws, p2pSyncResponseCode, data) +} + // SendP2PMessage sends a peer-to-peer message to a specific peer. func (whisper *Whisper) SendP2PMessage(peerID []byte, envelopes ...*Envelope) error { p, err := whisper.getPeer(peerID) @@ -1073,12 +1078,7 @@ 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 _, rawEnvelope := range resp.Envelopes { - var envelope *Envelope - if err := rlp.DecodeBytes(rawEnvelope, &envelope); err != nil { - return errors.New("invalid envelopes") - } - + for _, envelope := range resp.Envelopes { whisper.mailServer.Archive(envelope) }