This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
func (r *RedisRouter) CreateInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
|
||||
func (r *RedisRouter) StoreInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
|
||||
id := r.createShortId(urlLen)
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
@ -38,7 +38,7 @@ func (r *RedisRouter) GetInvitation(id string, password string) ([]byte, error)
|
||||
return []byte(mwiv), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) AnswerInvitation(id string, timeout int, invitation []byte, serverTimeout int) time.Time {
|
||||
func (r *RedisRouter) StoreAnswerToInvitation(id string, timeout int, invitation []byte, serverTimeout int) time.Time {
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
}
|
||||
@ -46,7 +46,7 @@ func (r *RedisRouter) AnswerInvitation(id string, timeout int, invitation []byte
|
||||
return time.Now().Add(time.Duration(timeout * 1000000)).UTC()
|
||||
}
|
||||
|
||||
func (r *RedisRouter) GetInvitationAnswer(id string) ([]byte, error) {
|
||||
func (r *RedisRouter) GetAnswerToInvitation(id string) ([]byte, error) {
|
||||
mwan, err := r.Client.Get("mwiv:" + id).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -122,12 +122,14 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
||||
panic(err)
|
||||
}
|
||||
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.ShortcodeLen))
|
||||
// create invitation => provide shortcode and expiry
|
||||
case 1:
|
||||
url, expiry := r.StoreInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
||||
from_server.Invitation = &meowlib.Invitation{}
|
||||
from_server.Invitation.Shortcode = url
|
||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
||||
case 2: // get invitation
|
||||
// get invitation => retrieve invitation from redis and send
|
||||
case 2:
|
||||
from_server.Invitation = &meowlib.Invitation{}
|
||||
invitation, err := r.GetInvitation(msg.Invitation.Shortcode, msg.Invitation.Password)
|
||||
|
||||
@ -141,23 +143,22 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
||||
from_server.Invitation.Payload = invitation // protobuf invitation
|
||||
}
|
||||
|
||||
case 3: // answer invitation
|
||||
// just propagate the source publickey
|
||||
from_server.Invitation.From = msg.Invitation.From
|
||||
// accept invitation => store accepted invitation for initiator
|
||||
case 3:
|
||||
expiry := r.StoreAnswerToInvitation(msg.Invitation.Uuid, int(msg.Invitation.Timeout), msg.Invitation.Payload, r.InvitationTimeout)
|
||||
from_server.Invitation = &meowlib.Invitation{}
|
||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
||||
|
||||
// get accepted invitation => send accepted invitation to initiator
|
||||
case 4:
|
||||
from_server.Invitation = &meowlib.Invitation{}
|
||||
answer, err := r.GetAnswerToInvitation(msg.Invitation.Uuid)
|
||||
if err != nil {
|
||||
from_server.Invitation.Payload = []byte("invitation answer not found")
|
||||
} else {
|
||||
from_server.Invitation.Payload = answer
|
||||
}
|
||||
|
||||
//! store answer !!
|
||||
from_server.Invitation.Payload = msg.Invitation.Payload
|
||||
/*
|
||||
expiry := r.AnswerInvitation(msg.Invitation.Id, 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.Id)
|
||||
if err != nil {
|
||||
from_server.Invitation.Payload = []byte("invitation expired")
|
||||
} else {
|
||||
from_server.Invitation.Payload = answer
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
Reference in New Issue
Block a user