修复一些边界问题
This commit is contained in:
@@ -24,7 +24,7 @@ var Channel = &channelServer{
|
||||
}
|
||||
|
||||
type ChannelServiceProvider interface {
|
||||
CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter ...EdgeFilter) ([]*m.Channel, error)
|
||||
CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error)
|
||||
RemoveChannels(batch string) error
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ type channelServer struct {
|
||||
provider ChannelServiceProvider
|
||||
}
|
||||
|
||||
func (s *channelServer) CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter ...EdgeFilter) ([]*m.Channel, error) {
|
||||
return s.provider.CreateChannels(source, resourceId, authWhitelist, authPassword, count, edgeFilter...)
|
||||
func (s *channelServer) CreateChannels(source netip.Addr, resourceId int32, authWhitelist bool, authPassword bool, count int, edgeFilter *EdgeFilter) ([]*m.Channel, error) {
|
||||
return s.provider.CreateChannels(source, resourceId, authWhitelist, authPassword, count, edgeFilter)
|
||||
}
|
||||
|
||||
func (s *channelServer) RemoveChannels(batch string) error {
|
||||
@@ -232,7 +232,7 @@ func regChans(proxy int32, chans []netip.AddrPort) error {
|
||||
// 缩容通道
|
||||
func remChans(proxy int32) error {
|
||||
key := freeChansKey + ":" + strconv.Itoa(int(proxy))
|
||||
err := g.Redis.SRem(context.Background(), key).Err()
|
||||
err := g.Redis.Del(context.Background(), key).Err()
|
||||
if err != nil {
|
||||
return fmt.Errorf("缩容通道失败: %w", err)
|
||||
}
|
||||
@@ -268,11 +268,12 @@ func lockChans(proxy int32, batch string, count int) ([]netip.AddrPort, error) {
|
||||
}
|
||||
|
||||
var RedisScriptLockChans = redis.NewScript(`
|
||||
local free_key = KEYS[1]
|
||||
local free_key = KEYS[1]
|
||||
local batch_key = KEYS[2]
|
||||
local count = tonumber(ARGV[1])
|
||||
|
||||
if redis.call("SCARD", free_key) < count then
|
||||
local free_count = redis.call("SCARD", free_key)
|
||||
if count <= 0 or free_count < count then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -301,16 +302,17 @@ func freeChans(proxy int32, batch string) error {
|
||||
}
|
||||
|
||||
var RedisScriptFreeChans = redis.NewScript(`
|
||||
local free_key = KEYS[1]
|
||||
local free_key = KEYS[1]
|
||||
local batch_key = KEYS[2]
|
||||
|
||||
local chans = redis.call("LRANGE", batch_key, 0, -1)
|
||||
redis.call("DEL", batch_key)
|
||||
|
||||
if redis.call("EXISTS", free_key) == 1 then
|
||||
redis.call("SADD", free_key, unpack(chans))
|
||||
if #chans == 0 then
|
||||
return 1
|
||||
end
|
||||
|
||||
redis.call("SADD", free_key, unpack(chans))
|
||||
redis.call("DEL", batch_key)
|
||||
|
||||
return 1
|
||||
`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user