cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
connection/errors.go
81lines · modecode
| 1 | package connection |
| 2 | |
| 3 | import ( |
| 4 | "github.com/cloudflare/cloudflared/edgediscovery" |
| 5 | "github.com/cloudflare/cloudflared/h2mux" |
| 6 | tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs" |
| 7 | ) |
| 8 | |
| 9 | const ( |
| 10 | DuplicateConnectionError = "EDUPCONN" |
| 11 | ) |
| 12 | |
| 13 | type DupConnRegisterTunnelError struct{} |
| 14 | |
| 15 | var errDuplicationConnection = DupConnRegisterTunnelError{} |
| 16 | |
| 17 | func (e DupConnRegisterTunnelError) Error() string { |
| 18 | return "already connected to this server, trying another address" |
| 19 | } |
| 20 | |
| 21 | // Dial to edge server with quic failed |
| 22 | type EdgeQuicDialError struct { |
| 23 | Cause error |
| 24 | } |
| 25 | |
| 26 | func (e *EdgeQuicDialError) Error() string { |
| 27 | return "failed to dial to edge with quic: " + e.Cause.Error() |
| 28 | } |
| 29 | |
| 30 | func (e *EdgeQuicDialError) Unwrap() error { |
| 31 | return e.Cause |
| 32 | } |
| 33 | |
| 34 | // RegisterTunnel error from server |
| 35 | type ServerRegisterTunnelError struct { |
| 36 | Cause error |
| 37 | Permanent bool |
| 38 | } |
| 39 | |
| 40 | func (e ServerRegisterTunnelError) Error() string { |
| 41 | return e.Cause.Error() |
| 42 | } |
| 43 | |
| 44 | func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError { |
| 45 | if retryable, ok := err.(*tunnelpogs.RetryableError); ok { |
| 46 | return ServerRegisterTunnelError{ |
| 47 | Cause: retryable.Unwrap(), |
| 48 | Permanent: false, |
| 49 | } |
| 50 | } |
| 51 | return ServerRegisterTunnelError{ |
| 52 | Cause: err, |
| 53 | Permanent: true, |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | type muxerShutdownError struct{} |
| 58 | |
| 59 | func (e muxerShutdownError) Error() string { |
| 60 | return "muxer shutdown" |
| 61 | } |
| 62 | |
| 63 | var errMuxerStopped = muxerShutdownError{} |
| 64 | |
| 65 | func 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 | |