diff --git a/waku/v2/protocol/pb/waku_message.pb.go b/waku/v2/protocol/pb/waku_message.pb.go index a6a357e6..d18a9437 100644 --- a/waku/v2/protocol/pb/waku_message.pb.go +++ b/waku/v2/protocol/pb/waku_message.pb.go @@ -115,6 +115,7 @@ type WakuMessage struct { Version uint32 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"` Timestamp int64 `protobuf:"zigzag64,10,opt,name=timestamp,proto3" json:"timestamp,omitempty"` RateLimitProof *RateLimitProof `protobuf:"bytes,21,opt,name=rate_limit_proof,json=rateLimitProof,proto3" json:"rate_limit_proof,omitempty"` + Ephemeral bool `protobuf:"varint,31,opt,name=ephemeral,proto3" json:"ephemeral,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -188,6 +189,13 @@ func (m *WakuMessage) GetRateLimitProof() *RateLimitProof { return nil } +func (m *WakuMessage) GetEphemeral() bool { + if m != nil { + return m.Ephemeral + } + return false +} + func init() { proto.RegisterType((*RateLimitProof)(nil), "pb.RateLimitProof") proto.RegisterType((*WakuMessage)(nil), "pb.WakuMessage") @@ -196,26 +204,27 @@ func init() { func init() { proto.RegisterFile("waku_message.proto", fileDescriptor_6f0a20862b3bf714) } var fileDescriptor_6f0a20862b3bf714 = []byte{ - // 299 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0xbf, 0x4e, 0xf3, 0x30, - 0x14, 0xc5, 0x3f, 0xf7, 0xa3, 0xad, 0x7a, 0x5b, 0xaa, 0xca, 0x02, 0xe1, 0x01, 0x85, 0xaa, 0x53, - 0xa7, 0x0e, 0xb0, 0x32, 0x31, 0x83, 0x84, 0x2c, 0x24, 0x60, 0x8a, 0x9c, 0x70, 0x4b, 0xad, 0xfc, - 0xb9, 0x96, 0xe3, 0x00, 0x7d, 0x13, 0x5e, 0x82, 0x87,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xe7, 0x30, 0xb3, 0xca, 0x61, 0x98, 0xd6, 0xab, 0x85, 0xcd, 0x5a, 0x87, 0x73, 0xb6, 0x1c, 0x9f, - 0xf2, 0x95, 0x89, 0x56, 0xdd, 0x41, 0xe5, 0xd4, 0x76, 0xf8, 0x62, 0xf6, 0x51, 0x05, 0xec, 0xb3, - 0x0a, 0xd8, 0x57, 0x15, 0xb0, 0xd7, 0xef, 0xe0, 0x5f, 0x34, 0xf0, 0x07, 0x39, 0xfb, 0x09, 0x00, - 0x00, 0xff, 0xff, 0x4a, 0x19, 0x2a, 0x86, 0xa6, 0x01, 0x00, 0x00, + // 313 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0x41, 0x4e, 0x02, 0x31, + 0x18, 0x85, 0x2d, 0x0a, 0xc8, 0x0f, 0x12, 0xd2, 0x68, 0xec, 0x82, 0x0c, 0x13, 0x56, 0xb3, 0x62, + 0xa1, 0x5b, 0x57, 0xae, 0x35, 0x31, 0x8d, 0x89, 0xba, 0x9a, 0x14, 0xfc, 0x91, 0x86, 0xe9, 0xfc, + 0x4d, 0xa7, 0xa8, 0xdc, 0xc4, 0x4b, 0x78, 0x0f, 0x97, 0xde, 0x40, 0x83, 0x17, 0x31, 0xd3, 0x91, + 0x8c, 0xec, 0xfa, 0xbe, 0x97, 0x97, 0xbc, 0xbe, 0x1f, 0xf8, 0x8b, 0x5a, 0xae, 0x52, 0x83, 0x45, + 0xa1, 0x9e, 0x70, 0x62, 0x1d, 0x79, 0xe2, 0x0d, 0x3b, 0x1d, 0xbf, 0x33, 0xe8, 0x4b, 0xe5, 0xf1, + 0x4a, 0x1b, 0xed, 0x6f, 0x1c, 0xd1, 0x9c, 0x1f, 0x43, 0xd3, 0x96, 0x0f, 0xc1, 0x62, 0x96, 0xf4, + 0x64, 0x25, 0xf8, 0x08, 0xba, 0x06, 0xdd, 0x32, 0xc3, 0xd4,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x00, 0xff, + 0xff, 0xe6, 0x01, 0x38, 0xc8, 0xc4, 0x01, 0x00, 0x00, } func (m *RateLimitProof) Marshal() (dAtA []byte, err error) { @@ -311,6 +320,18 @@ func (m *WakuMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } + if m.Ephemeral { + i-- + if m.Ephemeral { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xf8 + } if m.RateLimitProof != nil { { size, err := m.RateLimitProof.MarshalToSizedBuffer(dAtA[:i]) @@ -423,6 +444,9 @@ func (m *WakuMessage) Size() (n int) { l = m.RateLimitProof.Size() n += 2 + l + sovWakuMessage(uint64(l)) } + if m.Ephemeral { + n += 3 + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -861,6 +885,26 @@ func (m *WakuMessage) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 31: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Ephemeral", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Ephemeral = bool(v != 0) default: iNdEx = preIndex skippy, err := skipWakuMessage(dAtA[iNdEx:]) diff --git a/waku/v2/protocol/pb/waku_message.proto b/waku/v2/protocol/pb/waku_message.proto index 4cb13b76..becf7482 100644 --- a/waku/v2/protocol/pb/waku_message.proto +++ b/waku/v2/protocol/pb/waku_message.proto @@ -17,4 +17,5 @@ message WakuMessage { uint32 version = 3; sint64 timestamp = 10; RateLimitProof rate_limit_proof = 21; + bool ephemeral = 31; } \ No newline at end of file diff --git a/waku/v2/protocol/store/waku_store.go b/waku/v2/protocol/store/waku_store.go index 1d82fe14..d843a487 100644 --- a/waku/v2/protocol/store/waku_store.go +++ b/waku/v2/protocol/store/waku_store.go @@ -214,6 +214,10 @@ func (store *WakuStore) storeMessage(env *protocol.Envelope) error { return ErrFutureMessage } + if env.Message().Ephemeral { + return nil + } + err := store.msgProvider.Put(env) if err != nil { store.log.Error("storing message", zap.Error(err)) diff --git a/waku/v2/protocol/store/waku_store_persistence_test.go b/waku/v2/protocol/store/waku_store_persistence_test.go index e84bc4e4..7563b5b2 100644 --- a/waku/v2/protocol/store/waku_store_persistence_test.go +++ b/waku/v2/protocol/store/waku_store_persistence_test.go @@ -22,8 +22,18 @@ func TestStorePersistence(t *testing.T) { Version: 0, Timestamp: utils.GetUnixEpoch(), } + err := s1.storeMessage(protocol.NewEnvelope(msg, utils.GetUnixEpoch(), defaultPubSubTopic)) + require.NoError(t, err) - _ = s1.storeMessage(protocol.NewEnvelope(msg, utils.GetUnixEpoch(), defaultPubSubTopic)) + msg2 := &pb.WakuMessage{ + Payload: []byte{4, 5, 6}, + ContentTopic: defaultContentTopic, + Version: 0, + Timestamp: utils.GetUnixEpoch(), + Ephemeral: true, // Should not insert this message + } + err = s1.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), defaultPubSubTopic)) + require.NoError(t, err) allMsgs, err := db.GetAll() require.NoError(t, err)