2019-11-18 19:56:04 +00:00
|
|
|
package pogs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/tunnelrpc"
|
|
|
|
"zombiezen.com/go/capnproto2/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (i TunnelServer_PogsImpl) ReconnectTunnel(p tunnelrpc.TunnelServer_reconnectTunnel) error {
|
|
|
|
jwt, err := p.Params.Jwt()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-25 17:57:06 +00:00
|
|
|
eventDigest, err := p.Params.EventDigest()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-18 19:56:04 +00:00
|
|
|
hostname, err := p.Params.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
options, err := p.Params.Options()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pogsOptions, err := UnmarshalRegistrationOptions(options)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
server.Ack(p.Options)
|
2019-11-25 17:57:06 +00:00
|
|
|
registration, err := i.impl.ReconnectTunnel(p.Ctx, jwt, eventDigest, hostname, pogsOptions)
|
2019-11-18 19:56:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
result, err := p.Results.NewResult()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return MarshalTunnelRegistration(result, registration)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c TunnelServer_PogsClient) ReconnectTunnel(
|
|
|
|
ctx context.Context,
|
2019-11-25 17:57:06 +00:00
|
|
|
jwt,
|
|
|
|
eventDigest []byte,
|
2019-11-18 19:56:04 +00:00
|
|
|
hostname string,
|
|
|
|
options *RegistrationOptions,
|
2019-12-06 21:32:15 +00:00
|
|
|
) *TunnelRegistration {
|
2019-11-18 19:56:04 +00:00
|
|
|
client := tunnelrpc.TunnelServer{Client: c.Client}
|
|
|
|
promise := client.ReconnectTunnel(ctx, func(p tunnelrpc.TunnelServer_reconnectTunnel_Params) error {
|
|
|
|
err := p.SetJwt(jwt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-25 17:57:06 +00:00
|
|
|
err = p.SetEventDigest(eventDigest)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-18 19:56:04 +00:00
|
|
|
err = p.SetHostname(hostname)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
registrationOptions, err := p.NewOptions()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = MarshalRegistrationOptions(registrationOptions, options)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
retval, err := promise.Result().Struct()
|
|
|
|
if err != nil {
|
2019-12-06 21:32:15 +00:00
|
|
|
return NewRetryableRegistrationError(err, defaultRetryAfterSeconds).Serialize()
|
2019-11-18 19:56:04 +00:00
|
|
|
}
|
2019-12-06 21:32:15 +00:00
|
|
|
registration, err := UnmarshalTunnelRegistration(retval)
|
|
|
|
if err != nil {
|
|
|
|
return NewRetryableRegistrationError(err, defaultRetryAfterSeconds).Serialize()
|
|
|
|
}
|
|
|
|
return registration
|
2019-11-18 19:56:04 +00:00
|
|
|
}
|