cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2024.7.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/errors.go

81lines · 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
c7a6304dDevin Carr4 years ago21// Dial to edge server with quic failed
22type EdgeQuicDialError struct {
23Cause error
24}
25
26func (e *EdgeQuicDialError) Error() string {
27return "failed to dial to edge with quic: " + e.Cause.Error()
28}
29
7a197986Nuno Diegues3 years ago30func (e *EdgeQuicDialError) Unwrap() error {
31return e.Cause
32}
33
9ac40dcfcthuang5 years ago34// RegisterTunnel error from server
db0562c7Igor Postelnik5 years ago35type ServerRegisterTunnelError struct {
36Cause error
37Permanent bool
9ac40dcfcthuang5 years ago38}
39
db0562c7Igor Postelnik5 years ago40func (e ServerRegisterTunnelError) Error() string {
41return e.Cause.Error()
9ac40dcfcthuang5 years ago42}
43
db0562c7Igor Postelnik5 years ago44func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
9ac40dcfcthuang5 years ago45if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
db0562c7Igor Postelnik5 years ago46return ServerRegisterTunnelError{
47Cause: retryable.Unwrap(),
48Permanent: false,
9ac40dcfcthuang5 years ago49}
50}
db0562c7Igor Postelnik5 years ago51return ServerRegisterTunnelError{
52Cause: err,
53Permanent: true,
9ac40dcfcthuang5 years ago54}
55}
56
a9455184Igor Postelnik5 years ago57type muxerShutdownError struct{}
9ac40dcfcthuang5 years ago58
a9455184Igor Postelnik5 years ago59func (e muxerShutdownError) Error() string {
9ac40dcfcthuang5 years ago60return "muxer shutdown"
61}
62
a9455184Igor Postelnik5 years ago63var errMuxerStopped = muxerShutdownError{}
db0562c7Igor Postelnik5 years ago64
9ac40dcfcthuang5 years ago65func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
55bf9046Areg Harutyunyan5 years ago66log := observer.log.With().
67Uint8(LogFieldConnIndex, connIndex).
68Err(err).
69Logger()
70
9ac40dcfcthuang5 years ago71switch err.(type) {
72case edgediscovery.DialError:
55bf9046Areg Harutyunyan5 years ago73log.Error().Msg("Connection unable to dial edge")
9ac40dcfcthuang5 years ago74case h2mux.MuxerHandshakeError:
55bf9046Areg Harutyunyan5 years ago75log.Error().Msg("Connection handshake with edge server failed")
9ac40dcfcthuang5 years ago76default:
55bf9046Areg Harutyunyan5 years ago77log.Error().Msg("Connection failed")
9ac40dcfcthuang5 years ago78return false
79}
80return true
81}