cloudflare/cloudflared

Public

mirrored fromhttps://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
794635fb54fd2c0c95295cbdaffa397ba2c3e8ff

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/errors.go

68lines · 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)
8
9const (
10 DuplicateConnectionError = "EDUPCONN"
11)
12
13type DupConnRegisterTunnelError struct{}
14
15var errDuplicationConnection = DupConnRegisterTunnelError{}
16
17func (e DupConnRegisterTunnelError) Error() string {
18 return "already connected to this server, trying another address"
19}
20
21// RegisterTunnel error from server
22type ServerRegisterTunnelError struct {
23 Cause error
24 Permanent bool
25}
26
27func (e ServerRegisterTunnelError) Error() string {
28 return e.Cause.Error()
29}
30
31func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
32 if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
33 return ServerRegisterTunnelError{
34 Cause: retryable.Unwrap(),
35 Permanent: false,
36 }
37 }
38 return ServerRegisterTunnelError{
39 Cause: err,
40 Permanent: true,
41 }
42}
43
44type muxerShutdownError struct{}
45
46func (e muxerShutdownError) Error() string {
47 return "muxer shutdown"
48}
49
50var errMuxerStopped = muxerShutdownError{}
51
52func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
53 log := observer.log.With().
54 Uint8(LogFieldConnIndex, connIndex).
55 Err(err).
56 Logger()
57
58 switch err.(type) {
59 case edgediscovery.DialError:
60 log.Error().Msg("Connection unable to dial edge")
61 case h2mux.MuxerHandshakeError:
62 log.Error().Msg("Connection handshake with edge server failed")
63 default:
64 log.Error().Msg("Connection failed")
65 return false
66 }
67 return true
68}
69