Server invitation step 3/4
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-03-26 20:22:56 +01:00
parent 6bf6fadaaa
commit 788512c391
5 changed files with 37 additions and 39 deletions

View File

@ -115,30 +115,22 @@ func InvitationAnswerMessage(invitationId string, invitationServerUid string) ([
return nil, "InvitationAnswerMessage: LoadServer", err
}
// jsonsrv, err := json.Marshal(peer)
// if err != nil {
// return gobin2c(berrorToJson(err, "InvitationAnswerMessage: Marshal"))
// }
//fmt.Println(string(jsonsrv))
// Prepare cyphered + packed user message
// this will be the invitation's payload
packedMsg, err := peer.ProcessOutboundUserMessage(answermsg)
if err != nil {
return nil, "InvitationAnswerMessage: ProcessOutboundUserMessage", err
}
// jsonsrv, err = json.Marshal(invitationServer)
// if err != nil {
// return gobin2c(berrorToJson(err, "InvitationAnswerMessage: Marshal"))
// }
//fmt.Println(string(jsonsrv))
// Creating Server message for transporting the user message
toServerMessage := invitationServer.BuildToServerMessageFromUserMessage(packedMsg)
toServerMessage.Invitation = &meowlib.Invitation{Step: 3}
toServerMessage.Invitation.From = peer.MyIdentity.Public
pld, err := proto.Marshal(packedMsg)
// move the payload to invitation
toServerMessage.Messages = nil
invitationPayload, err := proto.Marshal(packedMsg)
if err != nil {
return nil, "InvitationAnswerMessage: proto.Marshal", err
}
toServerMessage.Invitation.Payload = pld
toServerMessage.Invitation.Payload = invitationPayload
toServerMessage.Invitation = &meowlib.Invitation{Step: 3}
toServerMessage.Invitation.From = peer.MyIdentity.Public
bytemsg, err := invitationServer.ProcessOutboundMessage(toServerMessage)
if err != nil {
return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err

View File

@ -5,8 +5,13 @@ go-plantuml generate -o generated/client.puml -d ../client
sed -i 's/\.\.\/client/client/g' generated/client.puml
go-plantuml generate -o generated/server.puml -d ../server
sed -i 's/\.\.\/server/server/g' generated/server.puml
cp *.puml generated/
cd generated
plantuml .
plantuml -latex .
mv *.tex tex/
mv *.png png/
rm *.log *.aux *.fdb_latexmk *.fls *.gz *.puml

View File

@ -5,7 +5,7 @@ NativeLib -> Bastet : invitationGetMessage
Bastet -> Server : send invitationGetMessage
Redis -> Server : retrieve invitation
Server -> Bastet : invitation message
Bastet -> NativeLib : please invitation message
NativeLib -> Bastet : invitation message
Bastet -> NativeLib : decode invitation message
NativeLib -> Bastet : invitation data
Bastet -> User : invitation data
@enduml

View File

@ -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

View File

@ -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
//! store answer !!
from_server.Invitation.Payload = msg.Invitation.Payload
/*
expiry := r.AnswerInvitation(msg.Invitation.Id, int(msg.Invitation.Timeout), msg.Invitation.Payload, r.InvitationTimeout)
// 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()
case 4: // get answer
answer, err := r.GetInvitationAnswer(msg.Invitation.Id)
// 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 expired")
from_server.Invitation.Payload = []byte("invitation answer not found")
} else {
from_server.Invitation.Payload = answer
}
*/
}
}
/*