mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 14:29:19 +08:00
05e66e9f8d
* fix: fix the bug
* fix: fix the imAdmin permission and searchNoficitaion resp
* 2023 Annual Summary Reflections and Aspirations
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
* fix: dissmissGroup and lack of keyword bug (#1678)
* Update docker-start-all.sh
* Update env-template.yaml
* Update docker-start-all.sh
* fix openim config mongo passwd env
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
* fix: fix some bug
* fix: group messages sync failed.
* fix: fix the valiable name
* fix: fix the getSortedConversation api
* fix: fix the mongo search error
* fix: GroupApplicationAcceptedNotification
(cherry picked from commit 4c3c4555a3)
* fix: GroupApplicationAcceptedNotification
* fix update friends
* fix pageFindUser
* Delete .devcontainer directory
* fix find user
* Your commit message here
* feat: direct conn
* fix: direct conn message gateway array exceed length
* fix: direct conn message gateway array exceed length
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: direct conn cannot find name
* fix: operation id invalid
* feat: multiple address
* feat: multiple address
* feat: multiple address
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: multiple addresses
* feat: direct conn with multiple ports
* Update user.go
* feat: direct conn with multiple ports
* feat: remove checkServiceHealth
* feat: update fmt error
* feat: update .devcontainer
* feat: update .devcontainer
* feat: update fmt.Errorf(
---------
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
Co-authored-by: luhaoling <2198702716@qq.com>
Co-authored-by: Xinwei Xiong <3293172751@qq.com>
Co-authored-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
Co-authored-by: Brabem <69128477+luhaoling@users.noreply.github.com>
Co-authored-by: OpenIM Bot <124379614+kubbot@users.noreply.github.com>
Co-authored-by: OpenIM Robot <139873238+openimbot@users.noreply.github.com>
Co-authored-by: Gordon <46924906+FGadvancer@users.noreply.github.com>
Co-authored-by: withchao <993506633@qq.com>
82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
package direct
|
|
|
|
import (
|
|
"context"
|
|
"github.com/OpenIMSDK/tools/log"
|
|
"google.golang.org/grpc/resolver"
|
|
"math/rand"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
slashSeparator = "/"
|
|
// EndpointSepChar is the separator char in endpoints.
|
|
EndpointSepChar = ','
|
|
|
|
subsetSize = 32
|
|
scheme = "direct"
|
|
)
|
|
|
|
type ResolverDirect struct {
|
|
}
|
|
|
|
func NewResolverDirect() *ResolverDirect {
|
|
return &ResolverDirect{}
|
|
}
|
|
|
|
func (rd *ResolverDirect) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (
|
|
resolver.Resolver, error) {
|
|
log.ZDebug(context.Background(), "Build", "target", target)
|
|
endpoints := strings.FieldsFunc(GetEndpoints(target), func(r rune) bool {
|
|
return r == EndpointSepChar
|
|
})
|
|
endpoints = subset(endpoints, subsetSize)
|
|
addrs := make([]resolver.Address, 0, len(endpoints))
|
|
|
|
for _, val := range endpoints {
|
|
addrs = append(addrs, resolver.Address{
|
|
Addr: val,
|
|
})
|
|
}
|
|
if err := cc.UpdateState(resolver.State{
|
|
Addresses: addrs,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &nopResolver{cc: cc}, nil
|
|
}
|
|
func init() {
|
|
resolver.Register(&ResolverDirect{})
|
|
}
|
|
func (rd *ResolverDirect) Scheme() string {
|
|
return scheme // return your custom scheme name
|
|
}
|
|
|
|
// GetEndpoints returns the endpoints from the given target.
|
|
func GetEndpoints(target resolver.Target) string {
|
|
return strings.Trim(target.URL.Path, slashSeparator)
|
|
}
|
|
func subset(set []string, sub int) []string {
|
|
rand.Shuffle(len(set), func(i, j int) {
|
|
set[i], set[j] = set[j], set[i]
|
|
})
|
|
if len(set) <= sub {
|
|
return set
|
|
}
|
|
|
|
return set[:sub]
|
|
}
|
|
|
|
type nopResolver struct {
|
|
cc resolver.ClientConn
|
|
}
|
|
|
|
func (n nopResolver) ResolveNow(options resolver.ResolveNowOptions) {
|
|
|
|
}
|
|
|
|
func (n nopResolver) Close() {
|
|
|
|
}
|