From defafcf9961c28d31f43fde24c1a4fce78cce1e5 Mon Sep 17 00:00:00 2001 From: ycc Date: Tue, 20 Feb 2024 20:25:07 +0100 Subject: [PATCH] Refactor invitation handling in router.go --- doc/sq_srvinv01.puml | 12 ++++++++++++ doc/sq_srvinv02.puml | 11 +++++++++++ doc/sq_srvinv03.puml | 12 ++++++++++++ doc/sq_srvinv04.puml | 10 ++++++++++ server/router.go | 27 ++++++++++++++++----------- 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 doc/sq_srvinv01.puml create mode 100644 doc/sq_srvinv02.puml create mode 100644 doc/sq_srvinv03.puml create mode 100644 doc/sq_srvinv04.puml diff --git a/doc/sq_srvinv01.puml b/doc/sq_srvinv01.puml new file mode 100644 index 0000000..67c2e14 --- /dev/null +++ b/doc/sq_srvinv01.puml @@ -0,0 +1,12 @@ +@startuml Server Invitation Step 01 +User -> Bastet : fill invitation +User -> Bastet : select servers +Bastet -> NativeLib : get server cards for selected uids +NativeLib -> Bastet : server cards +Bastet -> NativeLib : invitationCreateMessage +NativeLib -> Bastet : invitationMessage +Bastet -> Server : send invitation +Server -> Redis : Store invitation +Server -> Bastet : invitation URL +Bastet -> User : invitation URL +@enduml \ No newline at end of file diff --git a/doc/sq_srvinv02.puml b/doc/sq_srvinv02.puml new file mode 100644 index 0000000..7e2ac17 --- /dev/null +++ b/doc/sq_srvinv02.puml @@ -0,0 +1,11 @@ +@startuml Server Invitation Step 02 +User -> Bastet : paste URL +Bastet -> NativeLib : build invitationGetMessage +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 -> User : invitation data +@enduml \ No newline at end of file diff --git a/doc/sq_srvinv03.puml b/doc/sq_srvinv03.puml new file mode 100644 index 0000000..90b0594 --- /dev/null +++ b/doc/sq_srvinv03.puml @@ -0,0 +1,12 @@ + +@startuml Server Invitation Step 03 +User -> Bastet : select servers +User -> Bastet : accept invitation +Bastet -> NativeLib : accept invitation +Bastet -> NativeLib : build accept message +NativeLib -> Bastet : invitationGetMessage +Bastet -> Server : send accept message +Server -> Redis : store accept message +Server -> Bastet : accept message ok +Bastet -> User : msg sent +@enduml \ No newline at end of file diff --git a/doc/sq_srvinv04.puml b/doc/sq_srvinv04.puml new file mode 100644 index 0000000..2a85d36 --- /dev/null +++ b/doc/sq_srvinv04.puml @@ -0,0 +1,10 @@ + +@startuml Server Invitation Step 03 +Bastet -> NativeLib : periodic message check +Bastet -> NativeLib : build accept message +NativeLib -> Bastet : invitationGetMessage +Bastet -> Server : send accept message +Server -> Redis : store accept message +Server -> Bastet : accept message ok +Bastet -> User : msg sent +@enduml \ No newline at end of file diff --git a/server/router.go b/server/router.go index 28c4e6e..ad290f5 100644 --- a/server/router.go +++ b/server/router.go @@ -141,17 +141,22 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe from_server.Invitation.Payload = invitation // protobuf invitation } - /* should not happen - case 3: // answer invitation - 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 - } + 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) + 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 + } */ } }