Refactor *Raw methods in message_processor.go
We used *Raw method in message_processor as before we had non-Raw method during the transition from status-react to status-go. This naming is not meaningful anymore, so I have changed it.
This commit is contained in:
parent
8ba6625df0
commit
2d17c40631
|
@ -91,43 +91,41 @@ func (p *messageProcessor) Stop() {
|
|||
p.datasync.Stop() // idempotent op
|
||||
}
|
||||
|
||||
// SendPrivateRaw takes encoded data, encrypts it and sends through the wire.
|
||||
func (p *messageProcessor) SendPrivateRaw(
|
||||
// SendPrivate takes encoded data, encrypts it and sends through the wire.
|
||||
func (p *messageProcessor) SendPrivate(
|
||||
ctx context.Context,
|
||||
recipient *ecdsa.PublicKey,
|
||||
data []byte,
|
||||
messageType protobuf.ApplicationMetadataMessage_Type,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
p.logger.Debug(
|
||||
"sending a private message",
|
||||
zap.Binary("public-key", crypto.FromECDSAPub(recipient)),
|
||||
zap.String("site", "SendPrivateRaw"),
|
||||
zap.String("site", "SendPrivate"),
|
||||
)
|
||||
return p.sendPrivate(ctx, recipient, data, messageType)
|
||||
return p.sendPrivate(ctx, recipient, rawMessage)
|
||||
}
|
||||
|
||||
// SendGroupRaw takes encoded data, encrypts it and sends through the wire,
|
||||
// always return the messageID
|
||||
func (p *messageProcessor) SendGroupRaw(
|
||||
func (p *messageProcessor) SendGroup(
|
||||
ctx context.Context,
|
||||
recipients []*ecdsa.PublicKey,
|
||||
data []byte,
|
||||
messageType protobuf.ApplicationMetadataMessage_Type,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
p.logger.Debug(
|
||||
"sending a private group message",
|
||||
zap.String("site", "SendGroupRaw"),
|
||||
zap.String("site", "SendGroup"),
|
||||
)
|
||||
// Calculate messageID first
|
||||
wrappedMessage, err := p.wrapMessageV1(data, messageType)
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
||||
messageID := v1protocol.MessageID(&p.identity.PublicKey, wrappedMessage)
|
||||
|
||||
// Send to each recipients
|
||||
for _, recipient := range recipients {
|
||||
_, err = p.sendPrivate(ctx, recipient, data, messageType)
|
||||
_, err = p.sendPrivate(ctx, recipient, rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to send message")
|
||||
}
|
||||
|
@ -139,12 +137,11 @@ func (p *messageProcessor) SendGroupRaw(
|
|||
func (p *messageProcessor) sendPrivate(
|
||||
ctx context.Context,
|
||||
recipient *ecdsa.PublicKey,
|
||||
data []byte,
|
||||
messageType protobuf.ApplicationMetadataMessage_Type,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
p.logger.Debug("sending private message", zap.Binary("recipient", crypto.FromECDSAPub(recipient)))
|
||||
|
||||
wrappedMessage, err := p.wrapMessageV1(data, messageType)
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
@ -179,12 +176,11 @@ func (p *messageProcessor) sendPrivate(
|
|||
func (p *messageProcessor) SendPairInstallation(
|
||||
ctx context.Context,
|
||||
recipient *ecdsa.PublicKey,
|
||||
data []byte,
|
||||
messageType protobuf.ApplicationMetadataMessage_Type,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
p.logger.Debug("sending private message", zap.Binary("recipient", crypto.FromECDSAPub(recipient)))
|
||||
|
||||
wrappedMessage, err := p.wrapMessageV1(data, messageType)
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
@ -225,16 +221,15 @@ func (p *messageProcessor) EncodeMembershipUpdate(
|
|||
return encodedMessage, nil
|
||||
}
|
||||
|
||||
// SendPublicRaw takes encoded data, encrypts it and sends through the wire.
|
||||
func (p *messageProcessor) SendPublicRaw(
|
||||
// SendPublic takes encoded data, encrypts it and sends through the wire.
|
||||
func (p *messageProcessor) SendPublic(
|
||||
ctx context.Context,
|
||||
chatName string,
|
||||
data []byte,
|
||||
messageType protobuf.ApplicationMetadataMessage_Type,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
var newMessage *types.NewMessage
|
||||
|
||||
wrappedMessage, err := p.wrapMessageV1(data, messageType)
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
@ -242,7 +237,7 @@ func (p *messageProcessor) SendPublicRaw(
|
|||
newMessage = &types.NewMessage{
|
||||
TTL: whisperTTL,
|
||||
Payload: wrappedMessage,
|
||||
PowTarget: whisperPoW,
|
||||
PowTarget: calculatePoW(wrappedMessage),
|
||||
PowTime: whisperPoWTime,
|
||||
}
|
||||
|
||||
|
@ -345,8 +340,8 @@ func (p *messageProcessor) handleErrDeviceNotFound(ctx context.Context, publicKe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *messageProcessor) wrapMessageV1(encodedMessage []byte, messageType protobuf.ApplicationMetadataMessage_Type) ([]byte, error) {
|
||||
wrappedMessage, err := v1protocol.WrapMessageV1(encodedMessage, messageType, p.identity)
|
||||
func (p *messageProcessor) wrapMessageV1(rawMessage *RawMessage) ([]byte, error) {
|
||||
wrappedMessage, err := v1protocol.WrapMessageV1(rawMessage.Payload, rawMessage.MessageType, p.identity)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
|
|
@ -1279,11 +1279,11 @@ func (m *Messenger) hasPairedDevices() bool {
|
|||
}
|
||||
|
||||
// sendToPairedDevices will check if we have any paired devices and send to them if necessary
|
||||
func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error {
|
||||
func (m *Messenger) sendToPairedDevices(ctx context.Context, spec *RawMessage) error {
|
||||
hasPairedDevices := m.hasPairedDevices()
|
||||
// We send a message to any paired device
|
||||
if hasPairedDevices {
|
||||
_, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType)
|
||||
_, err := m.processor.SendPrivate(ctx, &m.identity.PublicKey, spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1295,7 +1295,7 @@ func (m *Messenger) dispatchPairInstallationMessage(ctx context.Context, spec *R
|
|||
var err error
|
||||
var id []byte
|
||||
|
||||
id, err = m.processor.SendPairInstallation(ctx, &m.identity.PublicKey, spec.Payload, spec.MessageType)
|
||||
id, err = m.processor.SendPairInstallation(ctx, &m.identity.PublicKey, spec)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1326,14 +1326,14 @@ func (m *Messenger) dispatchMessage(ctx context.Context, spec *RawMessage) ([]by
|
|||
return nil, err
|
||||
}
|
||||
if !isPubKeyEqual(publicKey, &m.identity.PublicKey) {
|
||||
id, err = m.processor.SendPrivateRaw(ctx, publicKey, spec.Payload, spec.MessageType)
|
||||
id, err = m.processor.SendPrivate(ctx, publicKey, spec)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = m.sendToPairedDevices(ctx, spec.Payload, spec.MessageType)
|
||||
err = m.sendToPairedDevices(ctx, spec)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1341,7 +1341,7 @@ func (m *Messenger) dispatchMessage(ctx context.Context, spec *RawMessage) ([]by
|
|||
|
||||
case ChatTypePublic:
|
||||
logger.Debug("sending public message", zap.String("chatName", chat.Name))
|
||||
id, err = m.processor.SendPublicRaw(ctx, chat.ID, spec.Payload, spec.MessageType)
|
||||
id, err = m.processor.SendPublic(ctx, chat.ID, spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1368,8 +1368,9 @@ func (m *Messenger) dispatchMessage(ctx context.Context, spec *RawMessage) ([]by
|
|||
spec.Recipients = spec.Recipients[:n]
|
||||
}
|
||||
|
||||
spec.MessageType = protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE
|
||||
// We always wrap in group information
|
||||
id, err = m.processor.SendGroupRaw(ctx, spec.Recipients, spec.Payload, protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE)
|
||||
id, err = m.processor.SendGroup(ctx, spec.Recipients, spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ func _1561059284_add_waku_keysDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1561059284_add_waku_keys.down.sql", size: 22, mode: os.FileMode(0644), modTime: time.Unix(1581443166, 0)}
|
||||
info := bindataFileInfo{name: "1561059284_add_waku_keys.down.sql", size: 22, mode: os.FileMode(0644), modTime: time.Unix(1579069853, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe5, 0x2a, 0x7e, 0x9, 0xa3, 0xdd, 0xc6, 0x3, 0xfa, 0xaa, 0x98, 0xa0, 0x26, 0x5e, 0x67, 0x43, 0xe6, 0x20, 0xfd, 0x10, 0xfd, 0x60, 0x89, 0x17, 0x13, 0x87, 0x1b, 0x44, 0x36, 0x79, 0xb6, 0x60}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func _1561059284_add_waku_keysUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1561059284_add_waku_keys.up.sql", size: 109, mode: os.FileMode(0644), modTime: time.Unix(1581443166, 0)}
|
||||
info := bindataFileInfo{name: "1561059284_add_waku_keys.up.sql", size: 109, mode: os.FileMode(0644), modTime: time.Unix(1579069853, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa9, 0x5c, 0x8, 0x32, 0xef, 0x12, 0x88, 0x21, 0xd, 0x7a, 0x42, 0x4d, 0xe7, 0x2d, 0x6c, 0x99, 0xb6, 0x1, 0xf1, 0xba, 0x2c, 0x40, 0x8d, 0xa9, 0x4b, 0xe6, 0xc4, 0x21, 0xec, 0x47, 0x6b, 0xf7}}
|
||||
return a, nil
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ func _1561059285_add_whisper_keysDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1561059285_add_whisper_keys.down.sql", size: 25, mode: os.FileMode(0644), modTime: time.Unix(1581443166, 0)}
|
||||
info := bindataFileInfo{name: "1561059285_add_whisper_keys.down.sql", size: 25, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb9, 0x31, 0x3f, 0xce, 0xfa, 0x44, 0x36, 0x1b, 0xb0, 0xec, 0x5d, 0xb, 0x90, 0xb, 0x21, 0x4f, 0xd5, 0xe5, 0x50, 0xed, 0xc7, 0x43, 0xdf, 0x83, 0xb4, 0x3a, 0xc1, 0x55, 0x2e, 0x53, 0x7c, 0x67}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func _1561059285_add_whisper_keysUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1561059285_add_whisper_keys.up.sql", size: 112, mode: os.FileMode(0644), modTime: time.Unix(1581443166, 0)}
|
||||
info := bindataFileInfo{name: "1561059285_add_whisper_keys.up.sql", size: 112, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x25, 0x41, 0xc, 0x92, 0xdd, 0x9e, 0xff, 0x5d, 0xd0, 0x93, 0xe4, 0x24, 0x50, 0x29, 0xcf, 0xc6, 0xf7, 0x49, 0x3c, 0x73, 0xd9, 0x8c, 0xfa, 0xf2, 0xcf, 0xf6, 0x6f, 0xbc, 0x31, 0xe6, 0xf7, 0xe2}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func docGo() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "doc.go", size: 373, mode: os.FileMode(0644), modTime: time.Unix(1581443166, 0)}
|
||||
info := bindataFileInfo{name: "doc.go", size: 373, mode: os.FileMode(0644), modTime: time.Unix(1574354941, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x23, 0x6a, 0xc1, 0xce, 0x94, 0xf6, 0xef, 0xf1, 0x97, 0x95, 0xb, 0x35, 0xaf, 0x5f, 0xe7, 0x5f, 0xac, 0x6e, 0xb8, 0xab, 0xba, 0xb5, 0x35, 0x97, 0x22, 0x36, 0x11, 0xce, 0x44, 0xfc, 0xfa, 0xac}}
|
||||
return a, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue