Integrate invitation process in router
This commit is contained in:
@ -10,10 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type RedisRouter struct {
|
||||
Name string
|
||||
ServerIdentity *Identity
|
||||
Client *redis.Client
|
||||
Context context.Context
|
||||
Name string
|
||||
ServerIdentity *Identity
|
||||
Client *redis.Client
|
||||
InvitationTimeout int
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
func NewRedisRouter(server *Identity, url string, password string, db int) *RedisRouter {
|
||||
@ -31,7 +32,8 @@ func NewRedisRouter(server *Identity, url string, password string, db int) *Redi
|
||||
|
||||
func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
|
||||
var from_server meowlib.FromServerMessage
|
||||
if len(msg.Messages) > 0 { // user message
|
||||
// user message
|
||||
if len(msg.Messages) > 0 {
|
||||
for _, usrmsg := range msg.Messages {
|
||||
// serialize the message to store it as byte array into redis
|
||||
out, err := proto.Marshal(usrmsg)
|
||||
@ -42,6 +44,7 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
||||
}
|
||||
from_server.UuidAck = msg.Uuid
|
||||
}
|
||||
// check for messages
|
||||
if len(msg.PullRequest) > 0 {
|
||||
for _, rq := range msg.PullRequest {
|
||||
msgcnt, err := r.Client.ZCount(rq.LookupKey, "-inf", "+inf").Result()
|
||||
@ -69,7 +72,7 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// manage Matriochka
|
||||
if msg.MatriochkaMessage != nil {
|
||||
out, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
@ -81,9 +84,39 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
||||
}
|
||||
from_server.UuidAck = msg.Uuid
|
||||
}
|
||||
|
||||
// Server list exchange
|
||||
if len(msg.KnownServers) > 0 {
|
||||
|
||||
}
|
||||
// Through server invitation process
|
||||
if msg.Invitation != nil {
|
||||
switch msg.Invitation.Step {
|
||||
case 1: // create invitation
|
||||
url, expiry := r.CreateInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.Urllen))
|
||||
from_server.Invitation.Url = url
|
||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
||||
case 2: // get invitation
|
||||
invitation, err := r.GetInvitation(msg.Invitation.Url, msg.Invitation.Password)
|
||||
if err != nil {
|
||||
if err.Error() == "auth failed" {
|
||||
from_server.Invitation.Payload = []byte("authentication failure")
|
||||
} else {
|
||||
from_server.Invitation.Payload = []byte("invitation expired")
|
||||
}
|
||||
} else {
|
||||
from_server.Invitation.Payload = invitation
|
||||
}
|
||||
case 3: // answer invitation
|
||||
expiry := r.AnswerInvitation(msg.Invitation.Url, int(msg.Invitation.Timeout), msg.Invitation.Payload, r.InvitationTimeout)
|
||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
||||
case 4: // get answer
|
||||
answer, err := r.GetInvitationAnswer(msg.Invitation.Url)
|
||||
if err != nil {
|
||||
from_server.Invitation.Payload = []byte("invitation expired")
|
||||
} else {
|
||||
from_server.Invitation.Payload = answer
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
|
Reference in New Issue
Block a user