cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2021.12.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/errors.go

68lines · modeblame

9ac40dcfcthuang5 years ago1package connection
2
3import (
4"github.com/cloudflare/cloudflared/edgediscovery"
5"github.com/cloudflare/cloudflared/h2mux"
6tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
7)
8
9const (
10DuplicateConnectionError = "EDUPCONN"
11)
12
13type DupConnRegisterTunnelError struct{}
14
db0562c7Igor Postelnik5 years ago15var errDuplicationConnection = DupConnRegisterTunnelError{}
9ac40dcfcthuang5 years ago16
17func (e DupConnRegisterTunnelError) Error() string {
18return "already connected to this server, trying another address"
19}
20
21// RegisterTunnel error from server
db0562c7Igor Postelnik5 years ago22type ServerRegisterTunnelError struct {
23Cause error
24Permanent bool
9ac40dcfcthuang5 years ago25}
26
db0562c7Igor Postelnik5 years ago27func (e ServerRegisterTunnelError) Error() string {
28return e.Cause.Error()
9ac40dcfcthuang5 years ago29}
30
db0562c7Igor Postelnik5 years ago31func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
9ac40dcfcthuang5 years ago32if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
db0562c7Igor Postelnik5 years ago33return ServerRegisterTunnelError{
34Cause: retryable.Unwrap(),
35Permanent: false,
9ac40dcfcthuang5 years ago36}
37}
db0562c7Igor Postelnik5 years ago38return ServerRegisterTunnelError{
39Cause: err,
40Permanent: true,
9ac40dcfcthuang5 years ago41}
42}
43
a9455184Igor Postelnik5 years ago44type muxerShutdownError struct{}
9ac40dcfcthuang5 years ago45
a9455184Igor Postelnik5 years ago46func (e muxerShutdownError) Error() string {
9ac40dcfcthuang5 years ago47return "muxer shutdown"
48}
49
a9455184Igor Postelnik5 years ago50var errMuxerStopped = muxerShutdownError{}
db0562c7Igor Postelnik5 years ago51
9ac40dcfcthuang5 years ago52func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
55bf9046Areg Harutyunyan5 years ago53log := observer.log.With().
54Uint8(LogFieldConnIndex, connIndex).
55Err(err).
56Logger()
57
9ac40dcfcthuang5 years ago58switch err.(type) {
59case edgediscovery.DialError:
55bf9046Areg Harutyunyan5 years ago60log.Error().Msg("Connection unable to dial edge")
9ac40dcfcthuang5 years ago61case h2mux.MuxerHandshakeError:
55bf9046Areg Harutyunyan5 years ago62log.Error().Msg("Connection handshake with edge server failed")
9ac40dcfcthuang5 years ago63default:
55bf9046Areg Harutyunyan5 years ago64log.Error().Msg("Connection failed")
9ac40dcfcthuang5 years ago65return false
66}
67return true
68}