Cleanup + proto update + Peers functions
This commit is contained in:
parent
4b20844e51
commit
01aec23f76
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,3 +6,6 @@ doc/protocol.pdf
|
||||
doc/protocol.synctex.gz
|
||||
out/doc/general_deployment/general_deployment.png
|
||||
out/doc/server_deployment/server_deployment.png
|
||||
*.json
|
||||
test
|
||||
id.enc
|
||||
|
@ -17,6 +17,8 @@ type Identity struct {
|
||||
Peers PeerList `json:"peers,omitempty"`
|
||||
KnownServers InternalServerList `json:"known_servers,omitempty"`
|
||||
MessageServers InternalServerList `json:"message_servers,omitempty"`
|
||||
DefaultDbPassword string `json:"default_db_password,omitempty"`
|
||||
DbPasswordStore bool `json:"db_password_store,omitempty"`
|
||||
}
|
||||
|
||||
func CreateIdentity(nickname string) *Identity {
|
||||
|
@ -24,6 +24,8 @@ type Peer struct {
|
||||
MessageNotification string `json:"message_notification,omitempty"`
|
||||
OnionMode bool `json:"onion_mode,omitempty"`
|
||||
LastMessage time.Time `json:"last_message,omitempty"`
|
||||
MessageDb string `json:"message_db,omitempty"` // sql url for messages storage
|
||||
DbPassword string `json:"db_password,omitempty"`
|
||||
}
|
||||
|
||||
type PeerList []Peer
|
||||
@ -52,14 +54,14 @@ func (pl *PeerList) GetFromName(name string) *Peer {
|
||||
}
|
||||
|
||||
// AsymEncryptMessage prepares a message to send to a specific peer contact
|
||||
func (p *Peer) AsymEncryptMessage(Message []byte) (LookupPublicKey string, EncryptedMessage []byte, Signature []byte, Servers []*meowlib.Server, err error) {
|
||||
func (p *Peer) AsymEncryptMessage(Message []byte) (EncryptedMessage []byte, Signature []byte, Servers []*meowlib.Server, err error) {
|
||||
EncryptedMessage, Signature, err = meowlib.EncryptAndSign(p.Contact.EncryptionPublicKey, p.Me.Private, Message)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return "", nil, nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return p.LookupKp.Public, EncryptedMessage, Signature, p.Contact.PullServers, err
|
||||
return EncryptedMessage, Signature, p.Contact.PullServers, err
|
||||
}
|
||||
|
||||
// AsymDecryptMessage reads a message from a specific peer contact
|
||||
@ -71,3 +73,34 @@ func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMe
|
||||
}
|
||||
return DecryptedMessage, err
|
||||
}
|
||||
|
||||
// Pack will package the previously encrypted message for sending it to the peer in protobuff format
|
||||
func (p *Peer) Pack(message []byte, signature []byte) meowlib.PackedUserMessage {
|
||||
var msg meowlib.PackedUserMessage
|
||||
msg.Destination = p.Contact.LookupPublicKey
|
||||
msg.From = p.Me.Public
|
||||
msg.Payload = message
|
||||
msg.Signature = signature
|
||||
return msg
|
||||
}
|
||||
|
||||
func (p *Peer) GetConversationRequest() meowlib.ToServerMessage_ConversationRequest {
|
||||
var cr meowlib.ToServerMessage_ConversationRequest
|
||||
return cr
|
||||
}
|
||||
|
||||
func (p *Peer) StoreMessage(msg []byte) {
|
||||
|
||||
}
|
||||
|
||||
func (p *Peer) LoadMessage(uid string) {
|
||||
|
||||
}
|
||||
|
||||
func (p *Peer) LoadLastMessages(qty int) {
|
||||
|
||||
}
|
||||
|
||||
func (p *Peer) GetLastMessageUid(msg []byte) {
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"forge.redroom.link/yves/meowlib"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type InternalServer struct {
|
||||
@ -53,3 +54,29 @@ func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte)
|
||||
}
|
||||
return DecryptedMessage, err
|
||||
}
|
||||
|
||||
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||
func (ints *InternalServer) CreateMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
|
||||
var msg meowlib.ToServerMessage
|
||||
msg.Type = "1"
|
||||
msg.From = ints.Me.Public
|
||||
msg.Messages = append(msg.Messages, usermsg)
|
||||
out, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||
func (ints *InternalServer) CreateMessageRequestMessage(lookupKeys []string) ([]byte, error) {
|
||||
var msg meowlib.ToServerMessage
|
||||
msg.Type = "1"
|
||||
msg.From = ints.Me.Public
|
||||
|
||||
out, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
@ -69,11 +69,11 @@ func TestEndToEnd(t *testing.T) {
|
||||
|
||||
// create message to simulated friend
|
||||
sentmessage := "Hello friend!"
|
||||
lookupK, EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
|
||||
EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
fmt.Println(lookupK)
|
||||
|
||||
fmt.Println(len(Servers))
|
||||
// simulated friend decoding the message
|
||||
//ReadMessage
|
||||
@ -85,11 +85,11 @@ func TestEndToEnd(t *testing.T) {
|
||||
if err2 != nil {
|
||||
fmt.Println(err2.Error())
|
||||
}
|
||||
|
||||
fmt.Println(decMess)
|
||||
// simulates a new server to send a message to
|
||||
var intS1 client.InternalServer
|
||||
intS1.ServerData.Name = "IntS1"
|
||||
intS1.ServerData.Description = "Internal Serveur 1"
|
||||
intS1.ServerData.Name = "My friend's Server 1"
|
||||
intS1.ServerData.Description = "My friend's Server 1"
|
||||
intS1.Me = meowlib.NewKeyPair()
|
||||
intS1.ServerData.Url = "http://myfriend.org/meow/"
|
||||
KP := meowlib.NewKeyPair()
|
||||
|
828
messages.pb.go
828
messages.pb.go
File diff suppressed because it is too large
Load Diff
@ -2,93 +2,86 @@ syntax = "proto3";
|
||||
package meowlib;
|
||||
option go_package = "forge.redroom.link/yves/meowlib";
|
||||
|
||||
// structure for sending a message intended for server use in protobuf format
|
||||
// structure definnig a message as received by a server in protobuf format
|
||||
message PackedServerMessage {
|
||||
string From = 1;
|
||||
bytes Payload = 2;
|
||||
bytes Signature = 3;
|
||||
string from = 1; // The client public key for that server to get an answer
|
||||
bytes payload = 2; // The ToServerMessage encrypted with the server public key
|
||||
bytes signature = 3; // The message signature with the client public key
|
||||
}
|
||||
|
||||
// structure for sending a message to be forwarded to another user in protobuf format
|
||||
message PackedUserMessage {
|
||||
string From = 1;
|
||||
string Destination=2;
|
||||
bytes Payload=3;
|
||||
bytes Signature=4;
|
||||
}
|
||||
|
||||
// structure defining a message encrypted, then sent in a "packedmessage" payload
|
||||
// structure defining a message for a server, that will be encrypted, then sent in a "packedmessage" payload
|
||||
message ToServerMessage {
|
||||
string Type = 1; // Type
|
||||
string ServerPubKey = 2 ; // My pub key for the server to send me an encrypter answer
|
||||
bytes Payload = 3 ; // optional payload for server
|
||||
string type = 1; // Type
|
||||
string from = 2 ; // My pub key for the server to send me an encrypter answer
|
||||
bytes payload = 3 ; // optional payload for server
|
||||
|
||||
message ConversationRequest { // Structure for requestion incoming messages
|
||||
// structure for requesting incoming messages
|
||||
message ConversationRequest {
|
||||
string lookupKey = 1; // lookup key for a conversation
|
||||
string LastServerUuidOK = 2; // Last Server message UUID received (send me all after that one)
|
||||
bool PublishOnline = 3; // ?? Publish my online status for that contact ?
|
||||
string lastServerUuidOK = 2; // Last Server message UUID received (send me all after that one)
|
||||
bool publishOnline = 3; // ?? Publish my online status for that contact ?
|
||||
string lookupSignature = 4; // prove that I own the private key by signing that block
|
||||
}
|
||||
|
||||
repeated ConversationRequest PullRequest = 7;
|
||||
repeated ConversationRequest pullRequest = 4;
|
||||
|
||||
repeated PackedUserMessage messages = 5;
|
||||
|
||||
repeated Server knownServers = 6;
|
||||
|
||||
message PostedMessage{
|
||||
string lookupKey= 1;
|
||||
repeated PackedUserMessage Messages = 2;
|
||||
}
|
||||
repeated PostedMessage Messages = 9;
|
||||
string NextServerKey = 10;
|
||||
string Url = 11;
|
||||
}
|
||||
|
||||
// structure defining a from serve receiver message decrypted from a "packedmessage" payload
|
||||
// structure defining a from server receiver message decrypted from a "packedmessage" payload
|
||||
message FromServerMessage {
|
||||
string Type = 1; // Type
|
||||
string ServerPubKey = 2 ; // My pub key for the server to send me an encrypter answer
|
||||
bytes Payload = 3 ; //
|
||||
uint64 ServerReceived = 4 ;
|
||||
string ServerUuid = 5 ;
|
||||
string type = 1; // Type
|
||||
string serverPubKey = 2 ; // My pub key for the server to send me an encrypter answer
|
||||
bytes payload = 3 ; //
|
||||
uint64 serverReceived = 4 ;
|
||||
string serverUuid = 5 ;
|
||||
|
||||
message ConversationResponse {
|
||||
repeated string MessageUuids = 1;
|
||||
repeated string messageUuids = 1;
|
||||
}
|
||||
|
||||
map<string,ConversationResponse> PullResponse = 8;
|
||||
map<string,ConversationResponse> pullResponse = 6;
|
||||
|
||||
message PostedMessage{
|
||||
string lookupKey= 1;
|
||||
repeated PackedUserMessage Messages = 2;
|
||||
repeated PackedUserMessage messages = 2;
|
||||
}
|
||||
repeated PostedMessage Messages = 9;
|
||||
string NextServerKey = 10;
|
||||
string Url = 11;
|
||||
repeated PostedMessage chat = 7;
|
||||
|
||||
}
|
||||
|
||||
// structure describing required server attributes
|
||||
message Server {
|
||||
string Name = 1;
|
||||
string Description=2;
|
||||
string PublicKey = 3;
|
||||
string Url = 4;
|
||||
int32 ConfidenceLevel = 5;
|
||||
string name = 1;
|
||||
string description=2;
|
||||
string publicKey = 3;
|
||||
string url = 4;
|
||||
int32 confidenceLevel = 5;
|
||||
}
|
||||
|
||||
// structure describing a user contact card ie the minimum set of attributes for exchanging identities
|
||||
message ContactCard {
|
||||
string name=1;
|
||||
string contactPublicKey =2;
|
||||
string encryptionPublicKey= 3;
|
||||
string lookupPublicKey =4;
|
||||
repeated Server PullServers =5;
|
||||
repeated Server pullServers =5;
|
||||
int32 version = 6;
|
||||
}
|
||||
|
||||
|
||||
message MinimalContact {
|
||||
string name=1;
|
||||
string publicKey=2;
|
||||
repeated Server TrustedServers = 3;
|
||||
// structure for sending a message to be forwarded to another user in protobuf format
|
||||
message PackedUserMessage {
|
||||
string from = 1; // the client identity public key as known by the destination peer
|
||||
string destination=2; // the peer's current conversation lookup public key
|
||||
bytes payload=3; // the message UserMessage encrypted with the destination peer's public key
|
||||
bytes signature=4; // the payload signature with the client identity private key
|
||||
}
|
||||
|
||||
// structure defining information that might be exchanged between two peers.
|
||||
message UserMessage {
|
||||
|
||||
string Destination = 1;
|
||||
string From = 2;
|
||||
string Type = 3;
|
||||
@ -99,21 +92,18 @@ message UserMessage {
|
||||
uint64 Sent = 3 ;
|
||||
uint64 Received = 4;
|
||||
uint64 Processed = 5;
|
||||
string NextCkey = 6; // contact key
|
||||
bool NextCkeyAck = 7; // false when proposing a new id, true for accepting it
|
||||
string NextEkey = 8; // encryption key
|
||||
bool NextKeyEkeyAck = 9; // false when proposing a new key, true for accpeting it
|
||||
string NextLkey = 10; // lookup key
|
||||
bool NextLkeyAck = 11; // false when proposing a new id, true for accepting it
|
||||
ContactCard myNextIdentity = 6;
|
||||
int32 peerNextIdentityAck = 7; // version of the new peed accepted id
|
||||
}
|
||||
ConversationStatus Status = 5;
|
||||
|
||||
ContactCard contact = 6;
|
||||
|
||||
MinimalContact contact = 6;
|
||||
Server knownServers = 7;
|
||||
|
||||
message Group{
|
||||
string name=1;
|
||||
repeated MinimalContact members = 2;
|
||||
repeated ContactCard members = 2;
|
||||
}
|
||||
Group group = 7;
|
||||
Group group = 8;
|
||||
}
|
Loading…
Reference in New Issue
Block a user