This commit is contained in:
parent
6bf6fadaaa
commit
788512c391
@ -115,30 +115,22 @@ func InvitationAnswerMessage(invitationId string, invitationServerUid string) ([
|
|||||||
return nil, "InvitationAnswerMessage: LoadServer", err
|
return nil, "InvitationAnswerMessage: LoadServer", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// jsonsrv, err := json.Marshal(peer)
|
// this will be the invitation's payload
|
||||||
// if err != nil {
|
|
||||||
// return gobin2c(berrorToJson(err, "InvitationAnswerMessage: Marshal"))
|
|
||||||
// }
|
|
||||||
//fmt.Println(string(jsonsrv))
|
|
||||||
// Prepare cyphered + packed user message
|
|
||||||
packedMsg, err := peer.ProcessOutboundUserMessage(answermsg)
|
packedMsg, err := peer.ProcessOutboundUserMessage(answermsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "InvitationAnswerMessage: ProcessOutboundUserMessage", err
|
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
|
// Creating Server message for transporting the user message
|
||||||
toServerMessage := invitationServer.BuildToServerMessageFromUserMessage(packedMsg)
|
toServerMessage := invitationServer.BuildToServerMessageFromUserMessage(packedMsg)
|
||||||
toServerMessage.Invitation = &meowlib.Invitation{Step: 3}
|
// move the payload to invitation
|
||||||
toServerMessage.Invitation.From = peer.MyIdentity.Public
|
toServerMessage.Messages = nil
|
||||||
pld, err := proto.Marshal(packedMsg)
|
invitationPayload, err := proto.Marshal(packedMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "InvitationAnswerMessage: proto.Marshal", err
|
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)
|
bytemsg, err := invitationServer.ProcessOutboundMessage(toServerMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err
|
return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err
|
||||||
|
@ -5,8 +5,13 @@ go-plantuml generate -o generated/client.puml -d ../client
|
|||||||
sed -i 's/\.\.\/client/client/g' generated/client.puml
|
sed -i 's/\.\.\/client/client/g' generated/client.puml
|
||||||
go-plantuml generate -o generated/server.puml -d ../server
|
go-plantuml generate -o generated/server.puml -d ../server
|
||||||
sed -i 's/\.\.\/server/server/g' generated/server.puml
|
sed -i 's/\.\.\/server/server/g' generated/server.puml
|
||||||
|
cp *.puml generated/
|
||||||
cd generated
|
cd generated
|
||||||
plantuml .
|
plantuml .
|
||||||
plantuml -latex .
|
plantuml -latex .
|
||||||
|
mv *.tex tex/
|
||||||
|
mv *.png png/
|
||||||
|
rm *.log *.aux *.fdb_latexmk *.fls *.gz *.puml
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ NativeLib -> Bastet : invitationGetMessage
|
|||||||
Bastet -> Server : send invitationGetMessage
|
Bastet -> Server : send invitationGetMessage
|
||||||
Redis -> Server : retrieve invitation
|
Redis -> Server : retrieve invitation
|
||||||
Server -> Bastet : invitation message
|
Server -> Bastet : invitation message
|
||||||
Bastet -> NativeLib : please invitation message
|
Bastet -> NativeLib : decode invitation message
|
||||||
NativeLib -> Bastet : invitation message
|
NativeLib -> Bastet : invitation data
|
||||||
Bastet -> User : invitation data
|
Bastet -> User : invitation data
|
||||||
@enduml
|
@enduml
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/go-redis/redis"
|
"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)
|
id := r.createShortId(urlLen)
|
||||||
if timeout > serverTimeout {
|
if timeout > serverTimeout {
|
||||||
timeout = serverTimeout
|
timeout = serverTimeout
|
||||||
@ -38,7 +38,7 @@ func (r *RedisRouter) GetInvitation(id string, password string) ([]byte, error)
|
|||||||
return []byte(mwiv), nil
|
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 {
|
if timeout > serverTimeout {
|
||||||
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()
|
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()
|
mwan, err := r.Client.Get("mwiv:" + id).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -122,12 +122,14 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
switch msg.Invitation.Step {
|
switch msg.Invitation.Step {
|
||||||
case 1: // create invitation
|
// create invitation => provide shortcode and expiry
|
||||||
url, expiry := r.CreateInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
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 = &meowlib.Invitation{}
|
||||||
from_server.Invitation.Shortcode = url
|
from_server.Invitation.Shortcode = url
|
||||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
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{}
|
from_server.Invitation = &meowlib.Invitation{}
|
||||||
invitation, err := r.GetInvitation(msg.Invitation.Shortcode, msg.Invitation.Password)
|
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
|
from_server.Invitation.Payload = invitation // protobuf invitation
|
||||||
}
|
}
|
||||||
|
|
||||||
case 3: // answer invitation
|
// accept invitation => store accepted invitation for initiator
|
||||||
// just propagate the source publickey
|
case 3:
|
||||||
from_server.Invitation.From = msg.Invitation.From
|
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
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user