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