matriochka start send and route + doc upt

This commit is contained in:
ycc
2022-12-27 16:59:52 +01:00
parent 1912f89cc6
commit 52ae52ca9f
7 changed files with 434 additions and 132 deletions

View File

@ -11,17 +11,21 @@ import (
)
type Identity struct {
Nickname string `json:"nickname,omitempty"`
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
Status string `json:"status,omitempty"`
Peers PeerList `json:"peers,omitempty"`
KnownServers InternalServerList `json:"known_servers,omitempty"`
MessageServers InternalServerList `json:"message_servers,omitempty"`
ArchiveServers InternalServerList `json:"archive_servers,omitempty"`
OwnedServers InternalServerList `json:"owned_servers,omitempty"`
DefaultDbPassword string `json:"default_db_password,omitempty"`
DbPasswordStore bool `json:"db_password_store,omitempty"`
OwnedDevices PeerList `json:"owned_devices,omitempty"`
Nickname string `json:"nickname,omitempty"`
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
Status string `json:"status,omitempty"`
Peers PeerList `json:"peers,omitempty"`
HiddenPeers [][]byte `json:"hiddend_peers,omitempty"`
Device meowlib.KeyPair `json:"device,omitempty"`
KnownServers InternalServerList `json:"known_servers,omitempty"`
MessageServers InternalServerList `json:"message_servers,omitempty"`
ArchiveServers InternalServerList `json:"archive_servers,omitempty"`
OwnedServers InternalServerList `json:"owned_servers,omitempty"`
DefaultDbPassword string `json:"default_db_password,omitempty"`
DbPasswordStore bool `json:"db_password_store,omitempty"`
OwnedDevices PeerList `json:"owned_devices,omitempty"`
StaticMtkServerPaths []InternalServerList `json:"static_mtk_server_paths,omitempty"`
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
}
func CreateIdentity(nickname string) *Identity {

51
client/matriochka.go Normal file
View File

@ -0,0 +1,51 @@
package client
import (
"forge.redroom.link/yves/meowlib"
"github.com/google/uuid"
)
func ProcessForOutput(usermessage *meowlib.UserMessage, peer *Peer, servers *InternalServerList, trackingLookupKey string) ([]byte, error) {
lastIdx := len(servers.Servers) - 1
// LAST SERVER : Message delivery as usual
srv := &servers.Servers[lastIdx]
// Prepare cyphered + packed user message
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
if err != nil {
return nil, err
}
// Creating Server message for transporting the user message
toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg)
lastmsg, err := srv.ProcessOutboundMessage(toServerMessage)
if err != nil {
return nil, err
}
lastuuid := uuid.NewString()
// ALL PREVIOUS SERVERS
for i := lastIdx - 1; i >= 0; i-- {
srv = &servers.Servers[i]
var toServerMessage meowlib.ToServerMessage
toServerMessage.MatriochkaMessage.Data = lastmsg
toServerMessage.MatriochkaMessage.Next.Url = servers.Servers[i+1].ServerData.Url
toServerMessage.MatriochkaMessage.Next.PublicKey = servers.Servers[i+1].ServerData.PublicKey
toServerMessage.MatriochkaMessage.Next.Delay = int32(servers.Servers[i+1].AllowedDelay)
if trackingLookupKey != "" {
toServerMessage.MatriochkaMessage.Next.Uuid = lastuuid // change tracking uuid at each server
if i > 0 {
toServerMessage.MatriochkaMessage.Prev.Url = servers.Servers[i-1].ServerData.Url
toServerMessage.MatriochkaMessage.Prev.PublicKey = servers.Servers[i+1].ServerData.PublicKey
toServerMessage.MatriochkaMessage.Prev.Delay = int32(servers.Servers[i-1].AllowedDelay)
toServerMessage.MatriochkaMessage.Prev.Uuid = uuid.NewString()
lastuuid = toServerMessage.MatriochkaMessage.Prev.Uuid
} else { // for first message, no previous tracking but a lookupkey to stack the tracking messages
toServerMessage.MatriochkaMessage.LookupKey = trackingLookupKey
}
}
lastmsg, err = srv.ProcessOutboundMessage(&toServerMessage)
if err != nil {
return nil, err
}
}
return lastmsg, nil
}

View File

@ -10,13 +10,15 @@ import (
)
type InternalServer struct {
ServerData meowlib.Server `json:"server_data,omitempty"`
Presence bool `json:"presence,omitempty"`
LastCheck time.Time `json:"last_check,omitempty"`
Uptime time.Duration `json:"uptime,omitempty"`
Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"`
Me meowlib.KeyPair `json:"me,omitempty"`
ServerData meowlib.Server `json:"server_data,omitempty"`
Presence bool `json:"presence,omitempty"`
LastCheck time.Time `json:"last_check,omitempty"`
Uptime time.Duration `json:"uptime,omitempty"`
Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"`
Me meowlib.KeyPair `json:"me,omitempty"`
Country string `json:"country,omitempty"`
AllowedDelay int `json:"allowed_delay,omitempty"`
}
type InternalServerList struct {