Merge branch 'tuoyun' of github.com:OpenIMSDK/Open-IM-Server into tuoyun

This commit is contained in:
wangchuxiao
2022-03-17 16:31:55 +08:00
5 changed files with 34 additions and 5 deletions
+15
View File
@@ -202,6 +202,21 @@ func VerifyToken(token, uid string) (bool, error) {
if claims.UID != uid {
return false, &constant.ErrTokenUnknown
}
log.NewDebug("", claims.UID, claims.Platform)
return true, nil
}
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
claims, err := ParseToken(token)
if err != nil {
return false, err, "parse token err"
}
if claims.UID != uid {
return false, &constant.ErrTokenUnknown, "uid is not same to token uid"
}
if claims.Platform != constant.PlatformIDToName(utils.StringToInt32(platformID)) {
return false, &constant.ErrTokenUnknown, "platform is not same to token platform"
}
log.NewDebug("", claims.UID, claims.Platform)
return true, nil, ""
}
+12 -2
View File
@@ -78,15 +78,25 @@ func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName strin
log.Debug("", "KeepAlive kresp ok", pv)
} else {
log.Error("", "KeepAlive kresp failed", pv)
t := time.NewTicker(time.Duration(ttl) * time.Second)
t := time.NewTicker(time.Duration(ttl/2) * time.Second)
for {
select {
case <-t.C:
}
ctx, _ := context.WithCancel(context.Background())
resp, err := cli.Grant(ctx, int64(ttl))
if err != nil {
log.Error("", "Grant failed ", err.Error())
continue
}
if _, err := cli.Put(ctx, serviceKey, serviceValue, clientv3.WithLease(resp.ID)); err != nil {
log.Error("", "etcd Put failed ", err.Error(), serviceKey, serviceValue, resp.ID)
continue
} else {
log.Info("", "etcd Put ok", serviceKey, serviceValue, resp.ID)
}
log.Info("", "etcd Put ok", serviceKey, serviceValue, resp.ID)
}
}
}
+4
View File
@@ -25,6 +25,10 @@ func StringToInt64(i string) int64 {
j, _ := strconv.ParseInt(i, 10, 64)
return j
}
func StringToInt32(i string) int32 {
j, _ := strconv.ParseInt(i, 10, 64)
return int32(j)
}
func Int32ToString(i int32) string {
return strconv.FormatInt(int64(i), 10)
}