cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
94ca4f98dde5e66ecb475d7f305e8f4cdccbc05c

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

connection/errors.go

81lines · modecode

1package connection
2
3import (
4 "github.com/cloudflare/cloudflared/edgediscovery"
5 "github.com/cloudflare/cloudflared/h2mux"
6 tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
7 "github.com/prometheus/client_golang/prometheus"
8)
9
10const (
11 DuplicateConnectionError = "EDUPCONN"
12)
13
14// RegisterTunnel error from client
15type clientRegisterTunnelError struct {
16 cause error
17}
18
19func newRPCError(cause error, counter *prometheus.CounterVec, name rpcName) clientRegisterTunnelError {
20 counter.WithLabelValues(cause.Error(), string(name)).Inc()
21 return clientRegisterTunnelError{cause: cause}
22}
23
24func (e clientRegisterTunnelError) Error() string {
25 return e.cause.Error()
26}
27
28type DupConnRegisterTunnelError struct{}
29
30var errDuplicationConnection = &DupConnRegisterTunnelError{}
31
32func (e DupConnRegisterTunnelError) Error() string {
33 return "already connected to this server, trying another address"
34}
35
36// RegisterTunnel error from server
37type serverRegisterTunnelError struct {
38 cause error
39 permanent bool
40}
41
42func (e serverRegisterTunnelError) Error() string {
43 return e.cause.Error()
44}
45
46func serverRegistrationErrorFromRPC(err error) *serverRegisterTunnelError {
47 if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
48 return &serverRegisterTunnelError{
49 cause: retryable.Unwrap(),
50 permanent: false,
51 }
52 }
53 return &serverRegisterTunnelError{
54 cause: err,
55 permanent: true,
56 }
57}
58
59type muxerShutdownError struct{}
60
61func (e muxerShutdownError) Error() string {
62 return "muxer shutdown"
63}
64
65func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
66 log := observer.log.With().
67 Uint8(LogFieldConnIndex, connIndex).
68 Err(err).
69 Logger()
70
71 switch err.(type) {
72 case edgediscovery.DialError:
73 log.Error().Msg("Connection unable to dial edge")
74 case h2mux.MuxerHandshakeError:
75 log.Error().Msg("Connection handshake with edge server failed")
76 default:
77 log.Error().Msg("Connection failed")
78 return false
79 }
80 return true
81}
82