fix(relay): восстановление потоков при отказах turn и занятой квоте
This commit is contained in:
1 parent
e72157f4f7
commit
6570cd9dd7
12 files changed
+117
-12
No files matched your search
@@ -3,11 +3,13 @@ package turndial
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pion/stun/v3"
|
||||
"github.com/pion/turn/v5"
|
||||
"github.com/samosvalishe/free-turn-proxy/internal/logx"
|
||||
"github.com/samosvalishe/free-turn-proxy/internal/netconn"
|
||||
@@ -15,6 +17,10 @@ import (
|
||||
"github.com/samosvalishe/free-turn-proxy/internal/randx"
|
||||
)
|
||||
|
||||
// ErrAllocQuota - TURN-код 486: реквизиты валидны, но по ним уже висит предельное число
|
||||
// аллокаций. Лечится ожиданием, а не сменой реквизитов (см. IsAuthError в vkauth).
|
||||
var ErrAllocQuota = errors.New("turndial: allocation quota reached")
|
||||
|
||||
// Config задаёт параметры подключения к TURN-серверу.
|
||||
type Config struct {
|
||||
HostOverride string
|
||||
@@ -34,6 +40,11 @@ type Stream struct {
|
||||
close func() error
|
||||
}
|
||||
|
||||
func isQuotaError(err error) bool {
|
||||
turnErr, ok := errors.AsType[*stun.TurnError](err)
|
||||
return ok && turnErr.ErrorCodeAttr.Code == stun.CodeAllocQuotaReached
|
||||
}
|
||||
|
||||
// Close освобождает аллокацию, TURN-клиент и транспортное соединение.
|
||||
func (s *Stream) Close() error {
|
||||
if s == nil || s.close == nil {
|
||||
@@ -141,6 +152,9 @@ func Open(ctx context.Context, cfg Config, peer *net.UDPAddr, user, pass, rawAdd
|
||||
if cerr := closeConn(); cerr != nil {
|
||||
err = fmt.Errorf("%w (close: %v)", err, cerr)
|
||||
}
|
||||
if isQuotaError(err) {
|
||||
return nil, fmt.Errorf("%w: %w", ErrAllocQuota, err)
|
||||
}
|
||||
return nil, fmt.Errorf("TURN allocate: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user