2020-10-08 10:12:26 +00:00
|
|
|
package connection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cloudflare/cloudflared/edgediscovery"
|
|
|
|
"github.com/cloudflare/cloudflared/h2mux"
|
|
|
|
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DuplicateConnectionError = "EDUPCONN"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DupConnRegisterTunnelError struct{}
|
|
|
|
|
2021-01-20 17:52:35 +00:00
|
|
|
var errDuplicationConnection = DupConnRegisterTunnelError{}
|
2020-10-08 10:12:26 +00:00
|
|
|
|
|
|
|
func (e DupConnRegisterTunnelError) Error() string {
|
|
|
|
return "already connected to this server, trying another address"
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterTunnel error from server
|
2021-01-20 17:52:35 +00:00
|
|
|
type ServerRegisterTunnelError struct {
|
|
|
|
Cause error
|
|
|
|
Permanent bool
|
2020-10-08 10:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 17:52:35 +00:00
|
|
|
func (e ServerRegisterTunnelError) Error() string {
|
|
|
|
return e.Cause.Error()
|
2020-10-08 10:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 17:52:35 +00:00
|
|
|
func serverRegistrationErrorFromRPC(err error) ServerRegisterTunnelError {
|
2020-10-08 10:12:26 +00:00
|
|
|
if retryable, ok := err.(*tunnelpogs.RetryableError); ok {
|
2021-01-20 17:52:35 +00:00
|
|
|
return ServerRegisterTunnelError{
|
|
|
|
Cause: retryable.Unwrap(),
|
|
|
|
Permanent: false,
|
2020-10-08 10:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-20 17:52:35 +00:00
|
|
|
return ServerRegisterTunnelError{
|
|
|
|
Cause: err,
|
|
|
|
Permanent: true,
|
2020-10-08 10:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 13:19:37 +00:00
|
|
|
type muxerShutdownError struct{}
|
2020-10-08 10:12:26 +00:00
|
|
|
|
2021-01-27 13:19:37 +00:00
|
|
|
func (e muxerShutdownError) Error() string {
|
2020-10-08 10:12:26 +00:00
|
|
|
return "muxer shutdown"
|
|
|
|
}
|
|
|
|
|
2021-01-27 13:19:37 +00:00
|
|
|
var errMuxerStopped = muxerShutdownError{}
|
2021-01-20 17:52:35 +00:00
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
func isHandshakeErrRecoverable(err error, connIndex uint8, observer *Observer) bool {
|
2020-12-28 18:10:01 +00:00
|
|
|
log := observer.log.With().
|
|
|
|
Uint8(LogFieldConnIndex, connIndex).
|
|
|
|
Err(err).
|
|
|
|
Logger()
|
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
switch err.(type) {
|
|
|
|
case edgediscovery.DialError:
|
2020-12-28 18:10:01 +00:00
|
|
|
log.Error().Msg("Connection unable to dial edge")
|
2020-10-08 10:12:26 +00:00
|
|
|
case h2mux.MuxerHandshakeError:
|
2020-12-28 18:10:01 +00:00
|
|
|
log.Error().Msg("Connection handshake with edge server failed")
|
2020-10-08 10:12:26 +00:00
|
|
|
default:
|
2020-12-28 18:10:01 +00:00
|
|
|
log.Error().Msg("Connection failed")
|
2020-10-08 10:12:26 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|