Skip to content
Snippets Groups Projects
Commit af82b7b7 authored by David Stainton's avatar David Stainton
Browse files

Merge remote-tracking branch 'origin/project/channels' into project/channels

parents 9949370c 5b12901b
No related branches found
No related tags found
6 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!371[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast,!354Channels impl,!340Project/channels,!339Project/channels
#!/bin/bash
#///////////////////////////////////////////////////////////////////////////////
#/ Copyright © 2020 xx network SEZC //
#/ //
#/ Use of this source code is governed by a license that can be found in the //
#/ LICENSE file //
#///////////////////////////////////////////////////////////////////////////////
protoc --go_out=paths=source_relative:. channels/messages.proto
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package channels
import (
"github.com/golang/protobuf/proto"
"sync"
)
// UserMessageInternal is the internal structure of a UserMessage protobuf.
type UserMessageInternal struct {
mux sync.RWMutex
userMessage *UserMessage
channelMessage *ChannelMessage
}
func NewUserMessageInternal(ursMsg *UserMessage) *UserMessageInternal {
return &UserMessageInternal{
mux: sync.RWMutex{},
userMessage: ursMsg,
channelMessage: nil,
}
}
// GetUserMessage retrieves the UserMessage within
// UserMessageInternal.
func (umi *UserMessageInternal) GetUserMessage() *UserMessage {
umi.mux.RLock()
umi.mux.RUnlock()
return umi.userMessage
}
// GetChannelMessage retrieves the ChannelMessage within
// UserMessageInternal. This is a lazy getter which will
// deserialize the ChannelMessage within the UserMessage.Message field.
// This deserialized ChannelMessage will then be placed into
// UserMessageInternal's channelMessage field and return. On subsequent calls it will return
// the message stored in UserMessageInternal.
func (umi *UserMessageInternal) GetChannelMessage() (*ChannelMessage, error) {
umi.mux.Lock()
defer umi.mux.Unlock()
if umi.channelMessage == nil {
chanMessage := &ChannelMessage{}
err := proto.Unmarshal(umi.userMessage.Message, chanMessage)
if err != nil {
return nil, err
}
umi.channelMessage = chanMessage
}
return umi.channelMessage, nil
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: channels/messages.proto
package channels
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// ChannelMessage is transmitted by the channel. Effectively it is
// a command for the channel sent by a user with admin access of the channel.
type ChannelMessage struct {
// Lease is the length that this channel message will take effect.
Lease int64 `protobuf:"varint,1,opt,name=Lease,proto3" json:"Lease,omitempty"`
// The round this message was sent on
RoundID uint64 `protobuf:"varint,2,opt,name=RoundID,proto3" json:"RoundID,omitempty"`
// The type the below payload is. This may be some form of channel command,
// such as BAN<username1>.
PayloadType uint32 `protobuf:"varint,3,opt,name=PayloadType,proto3" json:"PayloadType,omitempty"`
// Payload is the actual message payload. It will be processed differently based
// on the PayloadType
Payload []byte `protobuf:"bytes,4,opt,name=Payload,proto3" json:"Payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ChannelMessage) Reset() { *m = ChannelMessage{} }
func (m *ChannelMessage) String() string { return proto.CompactTextString(m) }
func (*ChannelMessage) ProtoMessage() {}
func (*ChannelMessage) Descriptor() ([]byte, []int) {
return fileDescriptor_91ac4de6d1711204, []int{0}
}
func (m *ChannelMessage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ChannelMessage.Unmarshal(m, b)
}
func (m *ChannelMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ChannelMessage.Marshal(b, m, deterministic)
}
func (m *ChannelMessage) XXX_Merge(src proto.Message) {
xxx_messageInfo_ChannelMessage.Merge(m, src)
}
func (m *ChannelMessage) XXX_Size() int {
return xxx_messageInfo_ChannelMessage.Size(m)
}
func (m *ChannelMessage) XXX_DiscardUnknown() {
xxx_messageInfo_ChannelMessage.DiscardUnknown(m)
}
var xxx_messageInfo_ChannelMessage proto.InternalMessageInfo
func (m *ChannelMessage) GetLease() int64 {
if m != nil {
return m.Lease
}
return 0
}
func (m *ChannelMessage) GetRoundID() uint64 {
if m != nil {
return m.RoundID
}
return 0
}
func (m *ChannelMessage) GetPayloadType() uint32 {
if m != nil {
return m.PayloadType
}
return 0
}
func (m *ChannelMessage) GetPayload() []byte {
if m != nil {
return m.Payload
}
return nil
}
// UserMessage is a message sent by a user who is a member within the channel.
type UserMessage struct {
// Message contains the contents of the message. This is typically what
// the end-user has submitted to the channel.
Message []byte `protobuf:"bytes,1,opt,name=Message,proto3" json:"Message,omitempty"`
// ValidationSignature is the signature validating this user owns
// their username and may send messages to the channel under this username.
// This signature is provided by UD and may be validated by all members of
// the channel.
// ValidationSignature = Sig(UD_ECCPrivKey,Username|ECCPublicKey|UsernameLease)
ValidationSignature []byte `protobuf:"bytes,2,opt,name=ValidationSignature,proto3" json:"ValidationSignature,omitempty"`
// Signature is the signature proving this message has been
// sent by the owner of this user's public key.
// Signature = Sig(User_ECCPublicKey,Message)
Signature []byte `protobuf:"bytes,3,opt,name=Signature,proto3" json:"Signature,omitempty"`
// Username is the username the user has registered with the channel and
// with UD.
Username string `protobuf:"bytes,4,opt,name=Username,proto3" json:"Username,omitempty"`
// ECCPublicKey is the user's EC Public key. This is provided by the network.
ECCPublicKey []byte `protobuf:"bytes,5,opt,name=ECCPublicKey,proto3" json:"ECCPublicKey,omitempty"`
// UsernameLease is the lease that has been provided to the username.
// This value is provide by UD.
UsernameLease int64 `protobuf:"varint,6,opt,name=UsernameLease,proto3" json:"UsernameLease,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UserMessage) Reset() { *m = UserMessage{} }
func (m *UserMessage) String() string { return proto.CompactTextString(m) }
func (*UserMessage) ProtoMessage() {}
func (*UserMessage) Descriptor() ([]byte, []int) {
return fileDescriptor_91ac4de6d1711204, []int{1}
}
func (m *UserMessage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UserMessage.Unmarshal(m, b)
}
func (m *UserMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UserMessage.Marshal(b, m, deterministic)
}
func (m *UserMessage) XXX_Merge(src proto.Message) {
xxx_messageInfo_UserMessage.Merge(m, src)
}
func (m *UserMessage) XXX_Size() int {
return xxx_messageInfo_UserMessage.Size(m)
}
func (m *UserMessage) XXX_DiscardUnknown() {
xxx_messageInfo_UserMessage.DiscardUnknown(m)
}
var xxx_messageInfo_UserMessage proto.InternalMessageInfo
func (m *UserMessage) GetMessage() []byte {
if m != nil {
return m.Message
}
return nil
}
func (m *UserMessage) GetValidationSignature() []byte {
if m != nil {
return m.ValidationSignature
}
return nil
}
func (m *UserMessage) GetSignature() []byte {
if m != nil {
return m.Signature
}
return nil
}
func (m *UserMessage) GetUsername() string {
if m != nil {
return m.Username
}
return ""
}
func (m *UserMessage) GetECCPublicKey() []byte {
if m != nil {
return m.ECCPublicKey
}
return nil
}
func (m *UserMessage) GetUsernameLease() int64 {
if m != nil {
return m.UsernameLease
}
return 0
}
func init() {
proto.RegisterType((*ChannelMessage)(nil), "parse.ChannelMessage")
proto.RegisterType((*UserMessage)(nil), "parse.UserMessage")
}
func init() {
proto.RegisterFile("channels/messages.proto", fileDescriptor_91ac4de6d1711204)
}
var fileDescriptor_91ac4de6d1711204 = []byte{
// 261 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x4f, 0x4b, 0xc3, 0x40,
0x10, 0xc5, 0x59, 0xd3, 0xf4, 0xcf, 0x34, 0xf5, 0x30, 0x0a, 0x2e, 0xe2, 0x21, 0x04, 0x0f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bb, 0x28, 0x8b, 0xe5, 0x13, 0x77, 0x32, 0x74,
0xc7, 0x7b, 0x1a, 0x5e, 0xc2, 0xcc, 0xfb, 0xfb, 0xb6, 0x86, 0xae, 0xad, 0x7d, 0xf1, 0x0e, 0x3e,
0xc7, 0xbe, 0xff, 0xc5, 0xd0, 0xf5, 0x7e, 0xfb, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xb2, 0xc9,
0xf7, 0x92, 0x01, 0x00, 0x00,
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
syntax = "proto3";
package parse;
option go_package = "channels";
// ChannelMessage is transmitted by the channel. Effectively it is
// a command for the channel sent by a user with admin access of the channel.
message ChannelMessage{
// Lease is the length that this channel message will take effect.
int64 Lease = 1;
// The round this message was sent on
uint64 RoundID = 2;
// The type the below payload is. This may be some form of channel command,
// such as BAN<username1>.
uint32 PayloadType = 3;
// Payload is the actual message payload. It will be processed differently based
// on the PayloadType
bytes Payload = 4;
}
// UserMessage is a message sent by a user who is a member within the channel.
message UserMessage {
// Message contains the contents of the message. This is typically what
// the end-user has submitted to the channel. This is a serialization of the
// ChannelMessage.
bytes Message = 1;
// ValidationSignature is the signature validating this user owns
// their username and may send messages to the channel under this username.
// This signature is provided by UD and may be validated by all members of
// the channel.
// ValidationSignature = Sig(UD_ECCPrivKey,Username|ECCPublicKey|UsernameLease)
bytes ValidationSignature = 2;
// Signature is the signature proving this message has been
// sent by the owner of this user's public key.
// Signature = Sig(User_ECCPublicKey,Message)
bytes Signature = 3;
// Username is the username the user has registered with the channel and
// with UD.
string Username = 4;
// ECCPublicKey is the user's EC Public key. This is provided by the network.
bytes ECCPublicKey = 5;
// UsernameLease is the lease that has been provided to the username.
// This value is provide by UD.
int64 UsernameLease = 6;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
package channels
import (
"bytes"
"github.com/golang/protobuf/proto"
"testing"
)
func TestUserMessageInternal_GetChannelMessage(t *testing.T) {
channelMsg := &ChannelMessage{
Payload: []byte("ban_badUSer"),
}
serialized, err := proto.Marshal(channelMsg)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
usrMsg := &UserMessage{
Message: serialized,
ValidationSignature: []byte("sig"),
Signature: []byte("sig"),
Username: "hunter",
}
internal := NewUserMessageInternal(usrMsg)
received, err := internal.GetChannelMessage()
if err != nil {
t.Fatalf("GetChannelMessage error: %v", err)
}
if !bytes.Equal(received.Payload, channelMsg.Payload) {
t.Fatalf("GetChannelMessage did not return expected data."+
"\nExpected: %v"+
"\nReceived: %v", channelMsg, received)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment