cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
connection/errors.go
76lines · 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 | "github.com/prometheus/client_golang/prometheus" |
| 8 | ) |
| 9 | |
| 10 | const ( |
| 11 | DuplicateConnectionError = "EDUPCONN" |
| 12 | ) |
| 13 | |
| 14 | // RegisterTunnel error from client |
| 15 | type clientRegisterTunnelError struct { |
| 16 | cause error |
| 17 | } |
| 18 | |
| 19 | func newRPCError(cause error, counter *prometheus.CounterVec, name rpcName) clientRegisterTunnelError { |
| 20 | counter.WithLabelValues(cause.Error(), string(name)).Inc() |
| 21 | return clientRegisterTunnelError{cause: cause} |
| 22 | } |
| 23 | |
| 24 | func (e clientRegisterTunnelError) Error() string { |
| 25 | return e.cause.Error() |
| 26 | } |
| 27 | |
| 28 | type DupConnRegisterTunnelError struct{} |
| 29 | |
| 30 | var errDuplicationConnection = &DupConnRegisterTunnelError{} |
| 31 | |
| 32 | func (e DupConnRegisterTunnelError) Error() string { |
| 33 | return "already connected to this server, trying another address" |
| 34 | } |
| 35 | |
| 36 | // RegisterTunnel error from server |
| 37 | type serverRegisterTunnelError struct { |
| 38 | cause error |
| 39 | permanent bool |
| 40 | } |
| 41 | |
| 42 | func (e serverRegisterTunnelError) Error() string { |
| 43 | return e.cause.Error() |
| 44 | } |
| 45 | |
| 46 | func 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 | |
| 59 | type muxerShutdownError struct{} |
| 60 | |
| 61 | func (e muxerShutdownError) Error() string { |
| 62 | return "muxer shutdown" |
| 63 | } |
| 64 | |
| 65 | func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool { |
| 66 | switch err.(type) { |
| 67 | case edgediscovery.DialError: |
| 68 | observer.Errorf("Connection %d unable to dial edge: %s", connIndex, err) |
| 69 | case h2mux.MuxerHandshakeError: |
| 70 | observer.Errorf("Connection %d handshake with edge server failed: %s", connIndex, err) |
| 71 | default: |
| 72 | observer.Errorf("Connection %d failed: %s", connIndex, err) |
| 73 | return false |
| 74 | } |
| 75 | return true |
| 76 | } |
| 77 | |