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