commit
1a14191d66
@ -1,15 +0,0 @@
|
||||
# Version logging for OpenIM
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_TOC -->
|
||||
|
||||
<!-- END MUNGE: GENERATED_TOC -->
|
||||
|
||||
<a name="unreleased"></a>
|
||||
## [Unreleased]
|
||||
|
||||
|
||||
<a name="v3.5.0+3.97baaac"></a>
|
||||
## [v3.5.0+3.97baaac] - 2024-01-12
|
||||
|
||||
[Unreleased]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+3.97baaac...HEAD
|
||||
[v3.5.0+3.97baaac]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+5.950e970...v3.5.0+3.97baaac
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@
|
||||
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() {
|
||||
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
package direct
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type ServiceAddresses map[string][]int
|
||||
|
||||
func getServiceAddresses() ServiceAddresses {
|
||||
return ServiceAddresses{
|
||||
config2.Config.RpcRegisterName.OpenImUserName: config2.Config.RpcPort.OpenImUserPort,
|
||||
config2.Config.RpcRegisterName.OpenImFriendName: config2.Config.RpcPort.OpenImFriendPort,
|
||||
config2.Config.RpcRegisterName.OpenImMsgName: config2.Config.RpcPort.OpenImMessagePort,
|
||||
config2.Config.RpcRegisterName.OpenImMessageGatewayName: config2.Config.LongConnSvr.OpenImMessageGatewayPort,
|
||||
config2.Config.RpcRegisterName.OpenImGroupName: config2.Config.RpcPort.OpenImGroupPort,
|
||||
config2.Config.RpcRegisterName.OpenImAuthName: config2.Config.RpcPort.OpenImAuthPort,
|
||||
config2.Config.RpcRegisterName.OpenImPushName: config2.Config.RpcPort.OpenImPushPort,
|
||||
config2.Config.RpcRegisterName.OpenImConversationName: config2.Config.RpcPort.OpenImConversationPort,
|
||||
config2.Config.RpcRegisterName.OpenImThirdName: config2.Config.RpcPort.OpenImThirdPort,
|
||||
}
|
||||
}
|
||||
|
||||
type ConnDirect struct {
|
||||
additionalOpts []grpc.DialOption
|
||||
currentServiceAddress string
|
||||
conns map[string][]*grpc.ClientConn
|
||||
resolverDirect *ResolverDirect
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetClientLocalConns() map[string][]*grpc.ClientConn {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) UnRegister() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) CreateRpcRootNodes(serviceNames []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) RegisterConf2Registry(key string, conf []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetConfFromRegistry(key string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) Close() {
|
||||
|
||||
}
|
||||
|
||||
func NewConnDirect() (*ConnDirect, error) {
|
||||
return &ConnDirect{
|
||||
conns: make(map[string][]*grpc.ClientConn),
|
||||
resolverDirect: NewResolverDirect(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetConns(ctx context.Context,
|
||||
serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
|
||||
|
||||
if conns, exists := cd.conns[serviceName]; exists {
|
||||
return conns, nil
|
||||
}
|
||||
ports := getServiceAddresses()[serviceName]
|
||||
var connections []*grpc.ClientConn
|
||||
for _, port := range ports {
|
||||
conn, err := cd.dialServiceWithoutResolver(ctx, fmt.Sprintf(config2.Config.Rpc.ListenIP+":%d", port), append(cd.additionalOpts, opts...)...)
|
||||
if err != nil {
|
||||
fmt.Printf("connect to port %d failed,serviceName %s, IP %s\n", port, serviceName, config2.Config.Rpc.ListenIP)
|
||||
}
|
||||
connections = append(connections, conn)
|
||||
}
|
||||
|
||||
if len(connections) == 0 {
|
||||
return nil, fmt.Errorf("no connections found for service: %s", serviceName)
|
||||
}
|
||||
return connections, nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
// Get service addresses
|
||||
addresses := getServiceAddresses()
|
||||
address, ok := addresses[serviceName]
|
||||
if !ok {
|
||||
return nil, errs.Wrap(errors.New("unknown service name"), "serviceName", serviceName)
|
||||
}
|
||||
var result string
|
||||
for _, addr := range address {
|
||||
if result != "" {
|
||||
result = result + "," + fmt.Sprintf(config2.Config.Rpc.ListenIP+":%d", addr)
|
||||
} else {
|
||||
result = fmt.Sprintf(config2.Config.Rpc.ListenIP+":%d", addr)
|
||||
}
|
||||
}
|
||||
// Try to dial a new connection
|
||||
conn, err := cd.dialService(ctx, result, append(cd.additionalOpts, opts...)...)
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, "address", result)
|
||||
}
|
||||
|
||||
// Store the new connection
|
||||
cd.conns[serviceName] = append(cd.conns[serviceName], conn)
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) GetSelfConnTarget() string {
|
||||
return cd.currentServiceAddress
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) AddOption(opts ...grpc.DialOption) {
|
||||
cd.additionalOpts = append(cd.additionalOpts, opts...)
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) CloseConn(conn *grpc.ClientConn) {
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (cd *ConnDirect) dialService(ctx context.Context, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
options := append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
conn, err := grpc.DialContext(ctx, cd.resolverDirect.Scheme()+":///"+address, options...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
func (cd *ConnDirect) dialServiceWithoutResolver(ctx context.Context, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
options := append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
conn, err := grpc.DialContext(ctx, address, options...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn, nil
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#**************************************************************************
|
||||
# Copyright (C) 2011, Paul Lutus *
|
||||
# *
|
||||
# This program is free software; you can redistribute it and/or modify *
|
||||
# it under the terms of the GNU General Public License as published by *
|
||||
# the Free Software Foundation; either version 2 of the License, or *
|
||||
# (at your option) any later version. *
|
||||
# *
|
||||
# This program is distributed in the hope that it will be useful, *
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# GNU General Public License for more details. *
|
||||
# *
|
||||
# You should have received a copy of the GNU General Public License *
|
||||
# along with this program; if not, write to the *
|
||||
# Free Software Foundation, Inc., *
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
#**************************************************************************
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
PVERSION = '1.0'
|
||||
|
||||
|
||||
class BeautifyBash:
|
||||
|
||||
def __init__(self):
|
||||
self.tab_str = ' '
|
||||
self.tab_size = 2
|
||||
|
||||
def read_file(self, fp):
|
||||
with open(fp) as f:
|
||||
return f.read()
|
||||
|
||||
def write_file(self, fp, data):
|
||||
with open(fp, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
def beautify_string(self, data, path=''):
|
||||
tab = 0
|
||||
case_stack = []
|
||||
in_here_doc = False
|
||||
defer_ext_quote = False
|
||||
in_ext_quote = False
|
||||
ext_quote_string = ''
|
||||
here_string = ''
|
||||
output = []
|
||||
line = 1
|
||||
for record in re.split('\n', data):
|
||||
record = record.rstrip()
|
||||
stripped_record = record.strip()
|
||||
|
||||
# collapse multiple quotes between ' ... '
|
||||
test_record = re.sub(r'\'.*?\'', '', stripped_record)
|
||||
# collapse multiple quotes between " ... "
|
||||
test_record = re.sub(r'".*?"', '', test_record)
|
||||
# collapse multiple quotes between ` ... `
|
||||
test_record = re.sub(r'`.*?`', '', test_record)
|
||||
# collapse multiple quotes between \` ... ' (weird case)
|
||||
test_record = re.sub(r'\\`.*?\'', '', test_record)
|
||||
# strip out any escaped single characters
|
||||
test_record = re.sub(r'\\.', '', test_record)
|
||||
# remove '#' comments
|
||||
test_record = re.sub(r'(\A|\s)(#.*)', '', test_record, 1)
|
||||
if(not in_here_doc):
|
||||
if(re.search('<<-?', test_record)):
|
||||
here_string = re.sub(
|
||||
'.*<<-?\s*[\'|"]?([_|\w]+)[\'|"]?.*', '\\1', stripped_record, 1)
|
||||
in_here_doc = (len(here_string) > 0)
|
||||
if(in_here_doc): # pass on with no changes
|
||||
output.append(record)
|
||||
# now test for here-doc termination string
|
||||
if(re.search(here_string, test_record) and not re.search('<<', test_record)):
|
||||
in_here_doc = False
|
||||
else: # not in here doc
|
||||
if(in_ext_quote):
|
||||
if(re.search(ext_quote_string, test_record)):
|
||||
# provide line after quotes
|
||||
test_record = re.sub(
|
||||
'.*%s(.*)' % ext_quote_string, '\\1', test_record, 1)
|
||||
in_ext_quote = False
|
||||
else: # not in ext quote
|
||||
if(re.search(r'(\A|\s)(\'|")', test_record)):
|
||||
# apply only after this line has been processed
|
||||
defer_ext_quote = True
|
||||
ext_quote_string = re.sub(
|
||||
'.*([\'"]).*', '\\1', test_record, 1)
|
||||
# provide line before quote
|
||||
test_record = re.sub(
|
||||
'(.*)%s.*' % ext_quote_string, '\\1', test_record, 1)
|
||||
if(in_ext_quote):
|
||||
# pass on unchanged
|
||||
output.append(record)
|
||||
else: # not in ext quote
|
||||
inc = len(re.findall(
|
||||
'(\s|\A|;)(case|then|do)(;|\Z|\s)', test_record))
|
||||
inc += len(re.findall('(\{|\(|\[)', test_record))
|
||||
outc = len(re.findall(
|
||||
'(\s|\A|;)(esac|fi|done|elif)(;|\)|\||\Z|\s)', test_record))
|
||||
outc += len(re.findall('(\}|\)|\])', test_record))
|
||||
if(re.search(r'\besac\b', test_record)):
|
||||
if(len(case_stack) == 0):
|
||||
sys.stderr.write(
|
||||
'File %s: error: "esac" before "case" in line %d.\n' % (
|
||||
path, line)
|
||||
)
|
||||
else:
|
||||
outc += case_stack.pop()
|
||||
# sepcial handling for bad syntax within case ... esac
|
||||
if(len(case_stack) > 0):
|
||||
if(re.search('\A[^(]*\)', test_record)):
|
||||
# avoid overcount
|
||||
outc -= 2
|
||||
case_stack[-1] += 1
|
||||
if(re.search(';;', test_record)):
|
||||
outc += 1
|
||||
case_stack[-1] -= 1
|
||||
# an ad-hoc solution for the "else" keyword
|
||||
else_case = (
|
||||
0, -1)[re.search('^(else)', test_record) != None]
|
||||
net = inc - outc
|
||||
tab += min(net, 0)
|
||||
extab = tab + else_case
|
||||
extab = max(0, extab)
|
||||
output.append(
|
||||
(self.tab_str * self.tab_size * extab) + stripped_record)
|
||||
tab += max(net, 0)
|
||||
if(defer_ext_quote):
|
||||
in_ext_quote = True
|
||||
defer_ext_quote = False
|
||||
if(re.search(r'\bcase\b', test_record)):
|
||||
case_stack.append(0)
|
||||
line += 1
|
||||
error = (tab != 0)
|
||||
if(error):
|
||||
sys.stderr.write(
|
||||
'File %s: error: indent/outdent mismatch: %d.\n' % (path, tab))
|
||||
return '\n'.join(output), error
|
||||
|
||||
def beautify_file(self, path):
|
||||
error = False
|
||||
if(path == '-'):
|
||||
data = sys.stdin.read()
|
||||
result, error = self.beautify_string(data, '(stdin)')
|
||||
sys.stdout.write(result)
|
||||
else: # named file
|
||||
data = self.read_file(path)
|
||||
result, error = self.beautify_string(data, path)
|
||||
if(data != result):
|
||||
# make a backup copy
|
||||
self.write_file(path + '~', data)
|
||||
self.write_file(path, result)
|
||||
return error
|
||||
|
||||
def main(self):
|
||||
error = False
|
||||
sys.argv.pop(0)
|
||||
if(len(sys.argv) < 1):
|
||||
sys.stderr.write(
|
||||
'usage: shell script filenames or \"-\" for stdin.\n')
|
||||
else:
|
||||
for path in sys.argv:
|
||||
error |= self.beautify_file(path)
|
||||
sys.exit((0, 1)[error])
|
||||
|
||||
# if not called as a module
|
||||
if(__name__ == '__main__'):
|
||||
BeautifyBash().main()
|
||||
|
Loading…
Reference in new issue