Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
121 lines (93 loc) · 3.26 KB
/
Copy patherrors.go
File metadata and controls
121 lines (93 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package dtls
import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
dtlserrors "github.com/pion/dtls/v4/internal/errors"
cryptosuite "github.com/pion/dtls/v4/pkg/crypto/ciphersuite"
"github.com/pion/dtls/v4/pkg/protocol/alert"
)
// ErrConnClosed indicates that the connection is closed.
var ErrConnClosed = dtlserrors.ErrConnClosed
// errPathMigrationUnavailable indicates that migration or probing requirements are not met.
var errPathMigrationUnavailable = errors.New("dtls: path migration or probing unavailable") //nolint:gochecknoglobals
// errPathNotValidated indicates that a path needs a successful Probe before Switch.
var errPathNotValidated = errors.New("dtls: path has not been validated") //nolint:gochecknoglobals
// errPathInUse indicates that a path is already being probed or is the active path.
var errPathInUse = errors.New("dtls: path is in use") //nolint:gochecknoglobals
// errNoConnectionID indicates that the peer supplied no unused nonempty CID for a new path.
var errNoConnectionID = errors.New("dtls: no unused peer connection ID") //nolint:gochecknoglobals
// ErrStateSerializationUnsupported indicates that the negotiated DTLS version
// cannot be represented by the public DTLS 1.2-shaped State snapshot.
var ErrStateSerializationUnsupported = errors.New("dtls: state serialization unsupported for this protocol version") //nolint:gochecknoglobals
// errInvalidCipherSuite indicates an attempt at using an unsupported cipher suite.
type invalidCipherSuiteError struct {
id cryptosuite.ID
}
func (e *invalidCipherSuiteError) Error() string {
return fmt.Sprintf("CipherSuite with id(%d) is not valid", e.id)
}
func (e *invalidCipherSuiteError) Is(err error) bool {
var other *invalidCipherSuiteError
if errors.As(err, &other) {
return e.id == other.id
}
return false
}
// errAlert wraps DTLS alert notification as an error.
type alertError struct {
*alert.Alert
}
func (e *alertError) Error() string {
return fmt.Sprintf("alert: %s", e.Alert.String())
}
func (e *alertError) IsFatalOrCloseNotify() bool {
return e.Level == alert.Fatal || e.Description == alert.CloseNotify
}
func (e *alertError) Is(err error) bool {
var other *alertError
if errors.As(err, &other) {
return e.Level == other.Level && e.Description == other.Description
}
return false
}
// netError translates an error from underlying Conn to corresponding net.Error.
func netError(err error) error {
switch {
case errors.Is(err, io.EOF), errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
// Return io.EOF and context errors as is.
return err
}
var (
opError *net.OpError
se *os.SyscallError
)
if errors.As(err, &opError) {
if errors.As(opError, &se) {
if isOpErrorTemporary(se) {
return temporaryNetworkError{err: err}
}
}
}
return err
}
type temporaryNetworkError struct {
err error
}
func (e temporaryNetworkError) Error() string { return e.err.Error() }
func (e temporaryNetworkError) Unwrap() error { return e.err }
func (e temporaryNetworkError) Timeout() bool {
var netErr net.Error
if errors.As(e.err, &netErr) {
return netErr.Timeout()
}
return false
}
func (temporaryNetworkError) Temporary() bool {
return true
}