Compare commits

..

No commits in common. "5aec7b3ad4f3b8fafe57e33908212f19a32ba5d6" and "05df08efcb0daac4f262123e978e06fb3d9e48fc" have entirely different histories.

3 changed files with 129 additions and 150 deletions

View File

@ -2,7 +2,7 @@ package helpers
import "forge.redroom.link/yves/meowlib/client" import "forge.redroom.link/yves/meowlib/client"
func PrepareUserMessage(message string, srvuid string, peer_idx int, replyToUid string, filelist []string) ([]byte, string, error) { func PrepareUserMessage(message string, srvuid string, peer_idx int, filelist []string) ([]byte, string, error) {
peer := client.GetConfig().GetIdentity().Peers[peer_idx] peer := client.GetConfig().GetIdentity().Peers[peer_idx]
srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid) srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid)
@ -20,7 +20,6 @@ func PrepareUserMessage(message string, srvuid string, peer_idx int, replyToUid
return nil, "PrepareServerMessage : AddFile", err return nil, "PrepareServerMessage : AddFile", err
} }
} }
usermessage.Status.AnswerToUuid = replyToUid
// Prepare cyphered + packed user message // Prepare cyphered + packed user message
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage) packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
if err != nil { if err != nil {

View File

@ -159,7 +159,7 @@ message UserMessage {
string from = 2; // My public key for that contact string from = 2; // My public key for that contact
string type = 3; string type = 3;
bytes data = 4; bytes data = 4;
ConversationStatus status = 5; ConversationStatus Status = 5;
ContactCard contact = 6; ContactCard contact = 6;
ServerCard knownServers = 7; ServerCard knownServers = 7;
Group group = 8; Group group = 8;

View File

@ -37,7 +37,7 @@ func NewRedisRouter(server *Identity, redisUrl string, password string, db int,
} }
func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) { func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
var from_server *meowlib.FromServerMessage var from_server meowlib.FromServerMessage
// update messages counter // update messages counter
err := r.Client.Incr("statistics:messages:total").Err() err := r.Client.Incr("statistics:messages:total").Err()
if err != nil { if err != nil {
@ -45,59 +45,10 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
} }
// user message => store // user message => store
if len(msg.Messages) > 0 { if len(msg.Messages) > 0 {
from_server, err = r.storeMessage(msg)
if err != nil {
return nil, err
}
}
// check for messages
if len(msg.PullRequest) > 0 {
from_server, err = r.checkForMessage(msg)
if err != nil {
return nil, err
}
}
// manage Matriochka
if msg.MatriochkaMessage != nil {
from_server, err = r.handleMatriochka(msg)
if err != nil {
return nil, err
}
}
// Server list exchange
if len(msg.KnownServers) > 0 {
}
// Through server invitation process
if msg.Invitation != nil {
from_server, err = r.handleInvitation(msg)
if err != nil {
return nil, err
}
}
/*
case "s": // servers list
breakmsgs
case "m": // matriochka
break
case "b": // broadcast
break
case "a": // admin
break
}
*/
return from_server, nil
}
func (r *RedisRouter) storeMessage(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
var from_server meowlib.FromServerMessage
// update messages counter // update messages counter
err := r.Client.Incr("statistics:messages:usermessages").Err() err := r.Client.Incr("statistics:messages:usermessages").Err()
if err != nil { if err != nil {
return nil, err panic(err)
} }
for _, usrmsg := range msg.Messages { for _, usrmsg := range msg.Messages {
// serialize the message to store it as byte array into redis // serialize the message to store it as byte array into redis
@ -108,16 +59,14 @@ func (r *RedisRouter) storeMessage(msg *meowlib.ToServerMessage) (*meowlib.FromS
r.Client.ZAdd(usrmsg.Destination, redis.Z{Score: float64(time.Now().Unix()), Member: out}) r.Client.ZAdd(usrmsg.Destination, redis.Z{Score: float64(time.Now().Unix()), Member: out})
} }
from_server.UuidAck = msg.Uuid from_server.UuidAck = msg.Uuid
return &from_server, nil }
} // check for messages
if len(msg.PullRequest) > 0 {
func (r *RedisRouter) checkForMessage(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
var from_server meowlib.FromServerMessage
//dataFound := false //dataFound := false
// update messages counter // update messages counter
err := r.Client.Incr("statistics:messages:messagelookups").Err() err := r.Client.Incr("statistics:messages:messagelookups").Err()
if err != nil { if err != nil {
return nil, err panic(err)
} }
for _, rq := range msg.PullRequest { for _, rq := range msg.PullRequest {
// get messages from redis // get messages from redis
@ -162,15 +111,34 @@ func (r *RedisRouter) checkForMessage(msg *meowlib.ToServerMessage) (*meowlib.Fr
} }
} }
return &from_server, nil }
} // manage Matriochka
if msg.MatriochkaMessage != nil {
// update messages counter
err := r.Client.Incr("statistics:messages:matriochka").Err()
if err != nil {
panic(err)
}
out, err := proto.Marshal(msg)
if err != nil {
return nil, err
}
r.Client.ZAdd("mtk", redis.Z{Score: float64(time.Now().Unix()), Member: out})
if msg.MatriochkaMessage.LookupKey != "" {
//r.Client.ZAdd("trk:" + msg.MatriochkaMessage.Next.Uuid,{})
}
from_server.UuidAck = msg.Uuid
}
// Server list exchange
if len(msg.KnownServers) > 0 {
func (r *RedisRouter) handleInvitation(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) { }
var from_server meowlib.FromServerMessage // Through server invitation process
if msg.Invitation != nil {
// update messages counter // update messages counter
err := r.Client.Incr("statistics:messages:invitation").Err() err := r.Client.Incr("statistics:messages:invitation").Err()
if err != nil { if err != nil {
return nil, err panic(err)
} }
switch msg.Invitation.Step { switch msg.Invitation.Step {
// create invitation => provide shortcode and expiry // create invitation => provide shortcode and expiry
@ -208,25 +176,37 @@ func (r *RedisRouter) handleInvitation(msg *meowlib.ToServerMessage) (*meowlib.F
expiry := r.StoreAnswerToInvitation(usermsg.Destination, int(msg.Invitation.Timeout), data, r.InvitationTimeout) expiry := r.StoreAnswerToInvitation(usermsg.Destination, int(msg.Invitation.Timeout), data, r.InvitationTimeout)
from_server.Invitation = &meowlib.Invitation{} from_server.Invitation = &meowlib.Invitation{}
from_server.Invitation.Expiry = expiry.UTC().Unix() from_server.Invitation.Expiry = expiry.UTC().Unix()
}
return &from_server, nil
}
func (r *RedisRouter) handleMatriochka(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) { // DONE IN NORMAL MESSAGE FLOW
var from_server meowlib.FromServerMessage // get accepted invitation => send accepted invitation to initiator
// update messages counter /* case 4:
err := r.Client.Incr("statistics:messages:matriochka").Err() from_server.Invitation = &meowlib.Invitation{}
var answer meowlib.Invitation
storedAanswer, err := r.GetAnswerToInvitation(msg.Invitation.Uuid)
if err != nil { if err != nil {
return nil, err from_server.Invitation.Payload = []byte("invitation answer not found")
} } else {
out, err := proto.Marshal(msg) err := proto.Unmarshal(storedAanswer, &answer)
if err != nil { if err != nil {
return nil, err from_server.Invitation.Payload = []byte("invitation answer corrupted")
} }
r.Client.ZAdd("mtk", redis.Z{Score: float64(time.Now().Unix()), Member: out}) from_server.Invitation = &answer
if msg.MatriochkaMessage.LookupKey != "" {
//r.Client.ZAdd("trk:" + msg.MatriochkaMessage.Next.Uuid,{})
} }
from_server.UuidAck = msg.Uuid */
}
}
/*
case "s": // servers list
breakmsgs
case "m": // matriochka
break
case "b": // broadcast
break
case "a": // admin
break
}
*/
return &from_server, nil return &from_server, nil
} }