diff --git a/client/helpers/invitationAnswerHelper.go b/client/helpers/invitationAnswerHelper.go index fac6ec5..932a739 100644 --- a/client/helpers/invitationAnswerHelper.go +++ b/client/helpers/invitationAnswerHelper.go @@ -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 diff --git a/doc/docgen.sh b/doc/docgen.sh index fa6fedf..db31c37 100755 --- a/doc/docgen.sh +++ b/doc/docgen.sh @@ -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 + diff --git a/doc/sq_srvinv02.puml b/doc/sq_srvinv02.puml index 7e2ac17..f60a8f7 100644 --- a/doc/sq_srvinv02.puml +++ b/doc/sq_srvinv02.puml @@ -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 \ No newline at end of file diff --git a/server/invitation.go b/server/invitation.go index 774e44d..6aa0e7b 100644 --- a/server/invitation.go +++ b/server/invitation.go @@ -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 diff --git a/server/router.go b/server/router.go index ad290f5..7326fbf 100644 --- a/server/router.go +++ b/server/router.go @@ -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 - } - */ } } /*