cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2020.11.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/errors.go

76lines · modecode

1package connection
2
3import (
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
10const (
11 DuplicateConnectionError = "EDUPCONN"
12)
13
14// RegisterTunnel error from client
15type clientRegisterTunnelError struct {
16 cause error
17}
18
19func newRPCError(cause error, counter *prometheus.CounterVec, name rpcName) clientRegisterTunnelError {
20 counter.WithLabelValues(cause.Error(), string(name)).Inc()
21 return clientRegisterTunnelError{cause: cause}
22}
23
24func (e clientRegisterTunnelError) Error() string {
25 return e.cause.Error()
26}
27
28type DupConnRegisterTunnelError struct{}
29
30var errDuplicationConnection = &DupConnRegisterTunnelError{}
31
32func (e DupConnRegisterTunnelError) Error() string {
33 return "already connected to this server, trying another address"
34}
35
36// RegisterTunnel error from server
37type serverRegisterTunnelError struct {
38 cause error
39 permanent bool
40}
41
42func (e serverRegisterTunnelError) Error() string {
43 return e.cause.Error()
44}
45
46func 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
59type muxerShutdownError struct{}
60
61func (e muxerShutdownError) Error() string {
62 return "muxer shutdown"
63}
64
65func 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