Compare commits
No commits in common. "753cd30f38dbdbb69f9400ca6925d6b0154acf74" and "9d5ba42dfc72240aa6ff5a3d4488498b0a9e84d0" have entirely different histories.
753cd30f38
...
9d5ba42dfc
@ -31,7 +31,6 @@ type Identity struct {
|
||||
OwnedDevices PeerList `json:"owned_devices,omitempty"`
|
||||
StaticMtkServerPaths []InternalServerList `json:"static_mtk_server_paths,omitempty"`
|
||||
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
|
||||
InvitationTimeout int `json:"invitation_timeout,omitempty"`
|
||||
unlockedHiddenPeers PeerList
|
||||
}
|
||||
|
||||
|
@ -100,24 +100,6 @@ func (ints *InternalServer) BuildMessageRequestMessage(lookupKeys []string) ([]b
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||
func (ints *InternalServer) BuildToServerMessageInvitation(invitation *meowlib.ContactCard, password string, timeout int, urllen int) (*meowlib.ToServerMessage, error) {
|
||||
var msg meowlib.ToServerMessage
|
||||
var inv meowlib.Invitation
|
||||
payload, err := invitation.Compress()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msg.Type = "1"
|
||||
msg.From = ints.Me.Public
|
||||
inv.Password = password
|
||||
inv.Timeout = int32(timeout)
|
||||
inv.Urllen = int32(urllen)
|
||||
inv.Payload = payload
|
||||
msg.Invitation = &inv
|
||||
return &msg, nil
|
||||
}
|
||||
|
||||
func (ints *InternalServer) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
|
||||
var msg meowlib.PackedServerMessage
|
||||
msg.From = ints.Me.Public
|
||||
|
673
messages.pb.go
673
messages.pb.go
File diff suppressed because it is too large
Load Diff
@ -15,16 +15,6 @@ message PackedServerMessage {
|
||||
bytes signature = 3; // The message signature with the client public key |eo| the reference to teh symetrical key used
|
||||
}
|
||||
|
||||
// structure to hold an invitation through a server
|
||||
message Invitation {
|
||||
bytes payload = 1;
|
||||
int32 timeout = 2;
|
||||
int32 urllen = 3;
|
||||
string password = 4;
|
||||
string url = 5;
|
||||
int64 expiry = 6;
|
||||
}
|
||||
|
||||
// structure defining a message for a server, that will be encrypted, then sent in a "packedmessage" payload
|
||||
message ToServerMessage {
|
||||
string type = 1; // Type 1 : final destination / 2 : forward
|
||||
@ -49,8 +39,6 @@ message ToServerMessage {
|
||||
|
||||
string uuid = 8;
|
||||
|
||||
Invitation invitation = 9;
|
||||
|
||||
}
|
||||
|
||||
// structure defining a from server receiver message decrypted from a "packedmessage" payload
|
||||
@ -69,8 +57,6 @@ message FromServerMessage {
|
||||
|
||||
repeated Server knownServers = 7;
|
||||
|
||||
Invitation invitation = 8;
|
||||
|
||||
}
|
||||
|
||||
message MatriochkaServer {
|
||||
|
@ -1,70 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
func (r *RedisRouter) CreateInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
|
||||
id := r.createShortUrl(urlLen)
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
}
|
||||
r.Client.Set("mwiv:"+id, invitation, time.Duration(timeout*1000000))
|
||||
if len(password) > 0 {
|
||||
r.Client.Set("mwpw:"+id, password, time.Duration(timeout*1000000))
|
||||
}
|
||||
return id, time.Now().Add(time.Duration(timeout * 1000000)).UTC()
|
||||
}
|
||||
|
||||
func (r *RedisRouter) GetInvitation(id string, password string) ([]byte, error) {
|
||||
passRequired := false
|
||||
expectedpass, err := r.Client.Get("mwpw:" + id).Result()
|
||||
if err != nil {
|
||||
passRequired = false
|
||||
} else {
|
||||
passRequired = true
|
||||
}
|
||||
if passRequired && password != expectedpass {
|
||||
return nil, errors.New("invitation get : auth failed, wrong password")
|
||||
}
|
||||
mwiv, err := r.Client.Get("mwiv:" + id).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(mwiv), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) AnswerInvitation(id string, timeout int, invitation []byte, serverTimeout int) time.Time {
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
}
|
||||
r.Client.Set("mwan:"+id, invitation, time.Duration(timeout*1000000))
|
||||
return time.Now().Add(time.Duration(timeout * 1000000)).UTC()
|
||||
}
|
||||
|
||||
func (r *RedisRouter) GetAnswer(id string) ([]byte, error) {
|
||||
mwan, err := r.Client.Get("mwiv:" + id).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(mwan), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) createShortUrl(length int) string {
|
||||
url := ""
|
||||
alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
// for not in redis
|
||||
for {
|
||||
for i := 1; i <= length; i++ {
|
||||
url += string(alphabet[rand.Intn(61)])
|
||||
}
|
||||
if r.Client.Get("mwiv:"+url).Err() == redis.Nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return url
|
||||
}
|
Loading…
Reference in New Issue
Block a user